Skip to content

Commit

Permalink
Merge pull request #229 from EBI-Metagenomics/feature/hybrid-and-long…
Browse files Browse the repository at this point in the history
…-read-assemblies

Hybrid and LR assemblies - experyment tpe
  • Loading branch information
mberacochea authored Sep 15, 2021
2 parents 8dc970f + d152477 commit 0cf61b6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
3 changes: 2 additions & 1 deletion emgapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ def get_queryset(self):

class ExperimentType(models.Model):
experiment_type_id = models.SmallIntegerField(
db_column='EXPERIMENT_TYPE_ID', primary_key=True, )
db_column='EXPERIMENT_TYPE_ID', primary_key=True)
experiment_type = models.CharField(
db_column='EXPERIMENT_TYPE', max_length=30,
help_text="Experiment type, e.g. metagenomic")
Expand Down Expand Up @@ -1165,6 +1165,7 @@ class Assembly(models.Model):
on_delete=models.SET_NULL, null=True, blank=True)

coverage = models.IntegerField(db_column="COVERAGE", null=True, blank=True)

min_gap_length = models.IntegerField(db_column="MIN_GAP_LENGTH", null=True, blank=True)

objects = AssemblyManager()
Expand Down
4 changes: 4 additions & 0 deletions emgapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ def get_experiment_type(self, obj):
read_only=True,
source='get_runs',
model=emg_models.Run,
related_link_view_name='emgapi_v1:assemblies-runs-list',
related_link_url_kwarg='accession',
related_link_lookup_field='accession',
related_link_self_view_name='emgapi_v1:runs-detail',
related_link_self_lookup_field='accession'
)
Expand Down Expand Up @@ -688,6 +691,7 @@ class BaseAnalysisSerializer(ExplicitFieldsModelSerializer,
'sample': 'emgapi.serializers.SampleSerializer',
'study': 'emgapi.serializers.StudySerializer',
'downloads': 'emgapi.serializers.AnalysisJobDownloadSerializer',
'assembly': 'emgapi.serializers.AssemblySerializer',
}

url = serializers.HyperlinkedIdentityField(
Expand Down
6 changes: 6 additions & 0 deletions emgapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
basename='assemblies-analyses'
)

router.register(
r'assemblies/(?P<accession>[^/]+)/runs',
views_relations.AssemblyRunsViewSet,
basename='assemblies-runs'
)

router.register(
r'studies/(?P<accession>[^/]+)'
r'/pipelines/(?P<release_version>[0-9\.]+)/file',
Expand Down
48 changes: 46 additions & 2 deletions emgapi/views_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ class RunAnalysisViewSet(emg_mixins.ListModelMixin,

ordering_fields = (
'pipeline',
# 'accession',
)

ordering = ('-pipeline',)
Expand Down Expand Up @@ -1004,7 +1003,6 @@ class AssemblyAnalysisViewSet(emg_mixins.ListModelMixin,

ordering_fields = (
'pipeline',
# 'accession',
)

ordering = ('-pipeline',)
Expand Down Expand Up @@ -1038,6 +1036,52 @@ def list(self, request, *args, **kwargs):
.list(request, *args, **kwargs)


class AssemblyRunsViewSet(emg_mixins.ListModelMixin,
viewsets.GenericViewSet):

serializer_class = emg_serializers.RunSerializer

filter_class = emg_filters.RunFilter

filter_backends = (
DjangoFilterBackend,
filters.OrderingFilter,
)

ordering_fields = (
'accession',
)

ordering = ('-accession',)

lookup_field = 'accession'
lookup_value_regex = '[^/]+'

def get_serializer_class(self):
return super(AssemblyRunsViewSet, self).get_serializer_class()

def get_queryset(self):
assembly = get_object_or_404(
emg_models.Assembly,
Q(accession=self.kwargs['accession']) |
Q(wgs_accession=self.kwargs['accession']) |
Q(legacy_accession=self.kwargs['accession'])
)
queryset = emg_models.Run.objects \
.available(self.request) \
.filter(assemblies__in=[assembly])
return queryset

def list(self, request, *args, **kwargs):
"""
Retrieves the runs for the given accession
Example:
---
`/assemblies/ERZ1385375/runs`
"""
return super(AssemblyRunsViewSet, self) \
.list(request, *args, **kwargs)

class GenomeCogsRelationshipsViewSet(emg_mixins.ListModelMixin,
viewsets.GenericViewSet):
serializer_class = emg_serializers.CogCountSerializer
Expand Down

0 comments on commit 0cf61b6

Please sign in to comment.