Skip to content

Commit

Permalink
Merge pull request #606 from NBISweden/cleanup/unnecessary-comprehension
Browse files Browse the repository at this point in the history
Remove unnecessary comprehension
  • Loading branch information
MalinAhlberg authored Oct 8, 2019
2 parents bd48154 + a2506c0 commit f2ff62b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
46 changes: 23 additions & 23 deletions backend/modules/browser/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ def get_coverage_for_bases(dataset: str, chrom: str, start_pos: int,

if end_pos is None:
end_pos = start_pos
coverage = [row for row in (db.Coverage.select()
.where((db.Coverage.pos >= start_pos) &
(db.Coverage.pos <= end_pos) &
(db.Coverage.chrom == chrom) &
(db.Coverage.dataset_version == dataset_version.id))
.dicts())]
coverage = list(db.Coverage.select()
.where((db.Coverage.pos >= start_pos) &
(db.Coverage.pos <= end_pos) &
(db.Coverage.chrom == chrom) &
(db.Coverage.dataset_version == dataset_version.id))
.dicts())
if not coverage:
raise error.NotFoundError('No coverage found for the region')
return coverage
Expand Down Expand Up @@ -457,9 +457,9 @@ def get_transcripts_in_gene(dataset: str, gene_id: str, ds_version: str = None)
logging.info('get_transcripts_in_gene({dataset}, {gene_id}): unable to retrieve gene')
raise error.NotFoundError(f'Gene {gene_id} not found in reference data') from err

return [transcript for transcript in (db.Transcript.select()
.where(db.Transcript.gene == gene['id'])
.dicts())]
return list(db.Transcript.select()
.where(db.Transcript.gene == gene['id'])
.dicts())


def get_transcripts_in_gene_by_dbid(gene_dbid: int) -> list:
Expand All @@ -473,9 +473,9 @@ def get_transcripts_in_gene_by_dbid(gene_dbid: int) -> list:
list: transcripts (dict) associated with the gene; empty if no hits
"""
return [transcript for transcript in (db.Transcript.select()
.where(db.Transcript.gene == gene_dbid)
.dicts())]
return list(db.Transcript.select()
.where(db.Transcript.gene == gene_dbid)
.dicts())


def get_variant(dataset: str, pos: int, chrom: str, ref: str, # pylint: disable=too-many-arguments
Expand Down Expand Up @@ -560,11 +560,11 @@ def get_variants_in_gene(dataset: str, gene_id: str, ds_version: str = None) ->
if not gene:
raise error.NotFoundError(f'Gene {gene_id} not found in reference data')

variants = [variant for variant in (db.Variant.select()
.join(db.VariantGenes)
.where((db.VariantGenes.gene == gene['id']) &
(db.Variant.dataset_version == dataset_version))
.dicts())]
variants = list(db.Variant.select()
.join(db.VariantGenes)
.where((db.VariantGenes.gene == gene['id']) &
(db.Variant.dataset_version == dataset_version))
.dicts())
for variant in variants:
if not variant['hom_count']:
variant['hom_count'] = 0
Expand Down Expand Up @@ -603,7 +603,7 @@ def get_variants_in_region(dataset: str, chrom: str, start_pos: int,
(db.Variant.dataset_version == dataset_version))
.dicts())

variants = [variant for variant in query]
variants = list(query)

for variant in variants:
if not variant['hom_count']:
Expand Down Expand Up @@ -637,11 +637,11 @@ def get_variants_in_transcript(dataset: str, transcript_id: str, ds_version: str
if not transcript:
raise error.NotFoundError(f'Transcript {transcript_id} not found in reference data')

variants = [variant for variant in db.Variant.select()
.join(db.VariantTranscripts)
.where((db.VariantTranscripts.transcript == transcript['id']) &
(db.Variant.dataset_version == dataset_version))
.dicts()]
variants = list(db.Variant.select()
.join(db.VariantTranscripts)
.where((db.VariantTranscripts.transcript == transcript['id']) &
(db.Variant.dataset_version == dataset_version))
.dicts())

for variant in variants:
if not variant['hom_count']:
Expand Down
4 changes: 2 additions & 2 deletions scripts/importer/data_importer/raw_data_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def _select_dataset_version(self):
logging.info(f"Using dataset {chosen_ds.short_name}")
self.dataset = chosen_ds

versions = [v for v in (db.DatasetVersion.select().
where(db.DatasetVersion.dataset == chosen_ds))]
versions = list(db.DatasetVersion.select().
where(db.DatasetVersion.dataset == chosen_ds))

# Make sure that the dataset version exists
if not versions:
Expand Down

0 comments on commit f2ff62b

Please sign in to comment.