diff --git a/TODO.md b/TODO.md index 351636af..893ad818 100644 --- a/TODO.md +++ b/TODO.md @@ -10,15 +10,6 @@ InjectTool TODO - if needed, should be implemented using [django-rest-framework](https://www.django-rest-framework.org/) * Regarding data submissions - - implement the sameAs key for already submitted biosamples: - ``` - "sampleRelationships": [ - { - "relationshipNature": "same as", - "alias": "502-W-133-4FE274B" - } - ] - ``` - Supposing a submission has issues in USI validation. Shuold I track it in validation tables? should I have tables for USI errors, since if the data is validated using `image_validation` is not a user error? diff --git a/django-data/image/uid/admin.py b/django-data/image/uid/admin.py index 5441ba09..bdcd5f4c 100644 --- a/django-data/image/uid/admin.py +++ b/django-data/image/uid/admin.py @@ -98,7 +98,7 @@ class SampleAdmin(admin.ModelAdmin): 'animal_age_at_collection', 'animal_age_at_collection_units', 'availability', 'storage', 'storage_processing', 'preparation_interval', 'preparation_interval_units', - 'description', 'publication', 'owner' + 'description', 'publication', 'owner', "same_as", ) # To tell Django we want to perform a join instead of fetching the names of @@ -112,7 +112,7 @@ class SampleAdmin(admin.ModelAdmin): list_filter = ('owner', 'status') fields = ( - ('name', 'alternative_id', 'biosample_id'), + ('name', 'alternative_id', 'biosample_id', "same_as"), ('submission', 'owner', 'status'), ('description', 'publication'), ('animal', 'protocol', 'organism_part'), @@ -140,7 +140,7 @@ class AnimalAdmin(admin.ModelAdmin): 'last_submitted', 'alternative_id', 'breed', 'sex', 'father', 'mother', 'birth_date', 'birth_location', 'birth_location_latitude', 'birth_location_longitude', 'birth_location_accuracy', 'description', - 'publication', 'owner' + 'publication', 'owner', "same_as", ) list_filter = ('owner', 'status') @@ -149,7 +149,7 @@ class AnimalAdmin(admin.ModelAdmin): readonly_fields = ("owner",) fields = ( - ('name', 'alternative_id', 'biosample_id'), + ('name', 'alternative_id', 'biosample_id', "same_as"), ('submission', 'owner', 'status'), ('description', 'publication'), ('breed', 'sex'), diff --git a/django-data/image/uid/fixtures/uid/animal.json b/django-data/image/uid/fixtures/uid/animal.json index 41a08df7..db27f400 100644 --- a/django-data/image/uid/fixtures/uid/animal.json +++ b/django-data/image/uid/fixtures/uid/animal.json @@ -7,6 +7,7 @@ "submission": 1, "biosample_id": null, "publication": 1, + "same_as": "SAMEA4450079", "alternative_id": "11", "description": "a 4-year old pig organic fed", "material": "Organism", diff --git a/django-data/image/uid/migrations/0004_auto_20200131_1622.py b/django-data/image/uid/migrations/0004_auto_20200131_1622.py new file mode 100644 index 00000000..f9b45a1f --- /dev/null +++ b/django-data/image/uid/migrations/0004_auto_20200131_1622.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.9 on 2020-01-31 15:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('uid', '0003_auto_20200129_1630'), + ] + + operations = [ + migrations.AddField( + model_name='animal', + name='same_as', + field=models.CharField(blank=True, max_length=255, null=True), + ), + migrations.AddField( + model_name='sample', + name='same_as', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/django-data/image/uid/mixins.py b/django-data/image/uid/mixins.py index 3f6bf242..9ae7b093 100644 --- a/django-data/image/uid/mixins.py +++ b/django-data/image/uid/mixins.py @@ -234,6 +234,16 @@ def to_biosample(self, release_date=None): # define attributes that will be customized in Animal and sample result['attributes'] = self.get_attributes() + # define an empty relationship array + result['sampleRelationships'] = [] + + # test for same as relationship + if self.same_as and self.same_as != '': + result['sampleRelationships'].append({ + "relationshipNature": "same as", + "accession": self.same_as + }) + return result def __status_not_in(self, statuses): diff --git a/django-data/image/uid/models.py b/django-data/image/uid/models.py index 2c8608b6..92592a0c 100644 --- a/django-data/image/uid/models.py +++ b/django-data/image/uid/models.py @@ -140,6 +140,12 @@ class Name(BaseMixin, models.Model): null=True, unique=True) + # model a same as relationship + same_as = models.CharField( + max_length=255, + blank=True, + null=True) + # '+' instructs Django that we don’t need this reverse relationship owner = models.ForeignKey( User, @@ -669,9 +675,6 @@ def to_biosample(self, release_date=None): # with USI mandatory keys and attributes result = super().to_biosample(release_date) - # define relationship with mother and father (if possible) - result['sampleRelationships'] = [] - father_relationship = self.get_father_relationship() if father_relationship is not None: @@ -869,7 +872,7 @@ def to_biosample(self, release_date=None): result = super().to_biosample(release_date) # define relationship to the animal where this sample come from - result['sampleRelationships'] = [self.animal.get_relationship()] + result['sampleRelationships'].append(self.animal.get_relationship()) return result diff --git a/django-data/image/uid/tests/biosample_animal.json b/django-data/image/uid/tests/biosample_animal.json index 5f770967..197a05b6 100644 --- a/django-data/image/uid/tests/biosample_animal.json +++ b/django-data/image/uid/tests/biosample_animal.json @@ -192,5 +192,10 @@ } ] }, - "sampleRelationships": [] + "sampleRelationships": [ + { + "relationshipNature": "same as", + "accession": "SAMEA4450079" + } + ] }