Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 4 additions & 4 deletions django-data/image/uid/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'),
Expand Down Expand Up @@ -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')
Expand All @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions django-data/image/uid/fixtures/uid/animal.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions django-data/image/uid/migrations/0004_auto_20200131_1622.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
10 changes: 10 additions & 0 deletions django-data/image/uid/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 7 additions & 4 deletions django-data/image/uid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion django-data/image/uid/tests/biosample_animal.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,10 @@
}
]
},
"sampleRelationships": []
"sampleRelationships": [
{
"relationshipNature": "same as",
"accession": "SAMEA4450079"
}
]
}