Skip to content

Commit

Permalink
New genome fields and _metadata_yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
neoformit committed Dec 7, 2023
1 parent acc3ecd commit 6c17bb5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 4.2 on 2023-12-07 19:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tracks', '0009_genome_group'),
]

operations = [
migrations.RemoveField(
model_name='genome',
name='_metadata',
),
migrations.RemoveField(
model_name='track',
name='_metadata',
),
migrations.AddField(
model_name='genome',
name='_metadata_yaml',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='genome',
name='description',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='genome',
name='doi',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='genome',
name='ncbi_bioproject',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='genome',
name='reference',
field=models.TextField(blank=True, null=True),
),
]
29 changes: 11 additions & 18 deletions apollo_portal/tracks/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Models for managing Apollo instances and their genome tracks."""

import json
import yaml
from django.db import models
from django.conf import settings
from django.contrib.auth.models import Group
Expand Down Expand Up @@ -76,7 +76,11 @@ class Genome(models.Model):
condition = models.CharField(max_length=255, null=True, blank=True)
thumbnail = models.ImageField(null=True, blank=True, upload_to="genomes")
apollo_url = models.URLField(null=True, blank=True)
_metadata = models.TextField(default="{}")
description = models.TextField(null=True, blank=True)
reference = models.TextField(null=True, blank=True)
ncbi_bioproject = models.TextField(null=True, blank=True)
doi = models.CharField(max_length=255, null=True, blank=True)
_metadata_yaml = models.TextField(null=True, blank=True)

def __str__(self):
"""Return string representation."""
Expand All @@ -85,14 +89,16 @@ def __str__(self):
@property
def metadata(self):
"""Return metadata as a dictionary."""
return json.loads(self._metadata)
if not self._metadata_yaml:
return {}
return yaml.safe_load(self._metadata_yaml)

@property
def set_metadata(self, k, v):
"""Set metadata key to given value."""
data = json.loads(self._metadata)
data = self.metadata
data[k] = v
self._metadata = json.dumps(data)
self._metadata_yaml = yaml.safe_dump(data)

def as_json(self):
"""Serialize model for JSON encoding."""
Expand Down Expand Up @@ -137,20 +143,7 @@ class Track(models.Model):
name = models.CharField(max_length=255)
accession_id = models.CharField(max_length=255, null=True, blank=True)
track_type = models.CharField(max_length=255)
_metadata = models.TextField(null=True, blank=True)

def __str__(self):
"""Return string representation."""
return f"{self.genome.lab.name}: {self.genome.name}: {self.name}"

@property
def metadata(self):
"""Return metadata as a dictionary."""
return json.loads(self._metadata)

@property
def set_metadata(self, k, v):
"""Set metadata key to given value."""
data = json.loads(self._metadata)
data[k] = v
self._metadata = json.dumps(data)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Pillow==10.0
factory_boy==3.3
requests
psycopg2-binary
pyyaml

0 comments on commit 6c17bb5

Please sign in to comment.