Skip to content

Commit

Permalink
Temp, mock api
Browse files Browse the repository at this point in the history
  • Loading branch information
MGS-sails committed Oct 1, 2024
1 parent cc70aec commit 465b71b
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 51 deletions.
2 changes: 2 additions & 0 deletions emgapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

router = routers.DefaultRouter(trailing_slash=False)

router.register(r'mgs-data', views.DataViewSet, basename='mgsdata')

router.register(
r'biomes',
views.BiomeViewSet,
Expand Down
228 changes: 177 additions & 51 deletions emgapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,132 @@
logger = logging.getLogger(__name__)


class DataViewSet(viewsets.ViewSet):
def list(self, request):
data = {
"study_accession": "MGYS00006708",
"run_accession": "SRR12560534",
"sample_accession": "MGYS00006708",
"assembly_accession": None,
"accession": "MGYA00779423",
"experiment_type": "Amplicon",
"instrument_model": "Illumina MiSeq",
"instrument_platform": "Illumina",
"pipeline_version": "5",
"downloads": [
{
"alias": "SRR12560534_MERGED_FASTQ.fasta.gz",
"download_type": "Sequence data",
"file_type": "fasta",
"long_description": "Processed nucleotide reads",
"short_description": "Processed nucleotide reads",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ.fasta.gz",
"compression:": True
},
{
"alias": "SRR12560534_MERGED_FASTQ_SSU_MAPSeq.mseq.gz",
"download_type": "Taxonomic analysis",
"file_type": "tsv",
"long_description": "MAPSeq output file for SSU",
"short_description": "MAPseq SSU assignments",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_SSU_MAPSeq.mseq.gz",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_LSU_MAPSeq.mseq.gz",
"download_type": "Taxonomic analysis",
"file_type": "tsv",
"long_description": "MAPSeq output file for LSU",
"short_description": "MAPseq LSU assignments",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_LSU_MAPSeq.mseq.gz",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_SSU_OTU.tsv",
"download_type": "Taxonomic analysis",
"file_type": "tsv",
"long_description": "OTUs and taxonomic assignments for SSU rRNA",
"short_description": "OTUs, counts and taxonomic assignments for SSU rRNA",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_SSU_OTU.tsv",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_LSU_OTU.tsv",
"download_type": "Taxonomic analysis",
"file_type": "tsv",
"long_description": "OTUs and taxonomic assignments for LSU rRNA",
"short_description": "OTUs, counts and taxonomic assignments for LSU rRNA",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_LSU_OTU.tsv",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_SSU_OTU_TABLE_HDF5.biom",
"download_type": "Taxonomic analysis",
"file_type": "biom",
"long_description": "OTUs and taxonomic assignments for SSU rRNA",
"short_description": "OTUs, counts and taxonomic assignments for SSU rRNA",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_SSU_OTU_TABLE_HDF5.biom",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_LSU_OTU_TABLE_HDF5.biom",
"download_type": "Taxonomic analysis",
"file_type": "biom",
"long_description": "OTUs and taxonomic assignments for LSU rRNA",
"short_description": "OTUs, counts and taxonomic assignments for LSU rRNA",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_LSU_OTU_TABLE_HDF5.biom",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_SSU_OTU_TABLE_JSON.biom",
"download_type": "Taxonomic analysis",
"file_type": "biom",
"long_description": "OTUs and taxonomic assignments for SSU rRNA",
"short_description": "OTUs, counts and taxonomic assignments for SSU rRNA",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_SSU_OTU_TABLE_JSON.biom",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_LSU_OTU_TABLE_JSON.biom",
"download_type": "Taxonomic analysis",
"file_type": "biom",
"long_description": "OTUs and taxonomic assignments for LSU rRNA",
"short_description": "OTUs, counts and taxonomic assignments for LSU rRNA",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_LSU_OTU_TABLE_JSON.biom",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_SSU.fasta.gz",
"download_type": "Taxonomic analysis",
"file_type": "fasta",
"long_description": "All reads encoding SSU rRNA",
"short_description": "Reads encoding SSU rRNA",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_SSU.fasta.gz",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_LSU.fasta.gz",
"download_type": "Taxonomic analysis",
"file_type": "fasta",
"long_description": "All reads encoding LSU rRNA",
"short_description": "Reads encoding LSU rRNA",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_LSU.fasta.gz",
"compression:": False
},
{
"alias": "SRR12560534_MERGED_FASTQ_5.8S.fasta.gz",
"download_type": "non-coding RNAs",
"file_type": "fasta",
"long_description": "All reads encoding 5.8S",
"short_description": "Reads encoding 5.8S",
"url": "https://www.ebi.ac.uk/metagenomics/api/v1/analyses/MGYA00779423/file/SRR12560534_MERGED_FASTQ_5.8S.fasta.gz",
"compression:": False
}
]
}
return Response(data)


class UtilsViewSet(viewsets.GenericViewSet):
schema = None

Expand Down Expand Up @@ -119,7 +245,7 @@ def myaccounts(self, request, pk=None):
submitter = ena_models.Submitter.objects.using('era_pro') \
.filter(
submission_account__submission_account__iexact=self
.request.user.username
.request.user.username
) \
.select_related('submission_account')

Expand Down Expand Up @@ -723,8 +849,8 @@ def get_queryset(self):
return emg_models.Assembly.objects.available(self.request)

def get_object(self):
return get_object_or_404(
self.get_queryset(),
return get_object_or_404(
self.get_queryset(),
Q(accession=self.kwargs['accession']) |
Q(wgs_accession=self.kwargs['accession']) |
Q(legacy_accession=self.kwargs['accession'])
Expand Down Expand Up @@ -766,8 +892,8 @@ def retrieve(self, request, *args, **kwargs):
legacy_entry = emg_models.LegacyAssembly.objects. \
get(legacy_accession=self.kwargs['accession'])
return redirect("emgapi_v1:assemblies-detail",
accession=legacy_entry.new_accession,
permanent=True)
accession=legacy_entry.new_accession,
permanent=True)
except emg_models.LegacyAssembly.DoesNotExist:
raise Http404()
return super(AssemblyViewSet, self).retrieve(request, *args, **kwargs)
Expand Down Expand Up @@ -827,59 +953,60 @@ def retrieve(self, request, accession, alias,
file_path = obj.realname
return emg_utils.prepare_results_file_download_response(file_path, alias)


class RunExtraAnnotationViewSet(
emg_mixins.ListModelMixin,
viewsets.GenericViewSet
):
serializer_class = emg_serializers.RunExtraAnnotationSerializer
emg_mixins.ListModelMixin,
viewsets.GenericViewSet
):
serializer_class = emg_serializers.RunExtraAnnotationSerializer

filter_backends = (
filters.OrderingFilter,
)
filter_backends = (
filters.OrderingFilter,
)

ordering_fields = (
'alias',
)
ordering_fields = (
'alias',
)

ordering = ('alias',)
ordering = ('alias',)

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

def get_queryset(self):
try:
accession = self.kwargs['accession']
except ValueError:
raise Http404()
return emg_models.RunExtraAnnotation.objects.available(self.request) \
.filter(run__accession=accession)
def get_queryset(self):
try:
accession = self.kwargs['accession']
except ValueError:
raise Http404()
return emg_models.RunExtraAnnotation.objects.available(self.request) \
.filter(run__accession=accession)

def get_object(self):
return get_object_or_404(
self.get_queryset(), Q(alias=self.kwargs['alias'])
)
def get_object(self):
return get_object_or_404(
self.get_queryset(), Q(alias=self.kwargs['alias'])
)

def get_serializer_class(self):
return super(RunExtraAnnotationViewSet, self) \
.get_serializer_class()

def list(self, request, *args, **kwargs):
"""
Retrieves list of Run Extra Annotation downloads
Example:
---
`/run/<accession>/extra-annotations`
"""
return super(RunExtraAnnotationViewSet, self).list(request, *args, **kwargs)

def retrieve(self, request, accession, alias,
*args, **kwargs):
obj = self.get_object()
if obj.subdir is not None:
file_path = f'{obj.subdir}/{obj.realname}'
else:
file_path = obj.realname
return emg_utils.prepare_results_file_download_response(file_path, alias)
def get_serializer_class(self):
return super(RunExtraAnnotationViewSet, self) \
.get_serializer_class()

def list(self, request, *args, **kwargs):
"""
Retrieves list of Run Extra Annotation downloads
Example:
---
`/run/<accession>/extra-annotations`
"""
return super(RunExtraAnnotationViewSet, self).list(request, *args, **kwargs)

def retrieve(self, request, accession, alias,
*args, **kwargs):
obj = self.get_object()
if obj.subdir is not None:
file_path = f'{obj.subdir}/{obj.realname}'
else:
file_path = obj.realname
return emg_utils.prepare_results_file_download_response(file_path, alias)


class AnalysisJobViewSet(mixins.RetrieveModelMixin,
Expand Down Expand Up @@ -1354,7 +1481,6 @@ def europe_pmc_annotations(self, request, pubmed_id=None):
class GenomeCatalogueViewSet(mixins.RetrieveModelMixin,
emg_mixins.ListModelMixin,
emg_viewsets.BaseGenomeCatalogueGenericViewSet):

filterset_class = emg_filters.GenomeCatalogueFilter

lookup_field = 'catalogue_id'
Expand Down

0 comments on commit 465b71b

Please sign in to comment.