Skip to content

Commit 97f4740

Browse files
committed
add func to prepare observed var section
1 parent 4859c20 commit 97f4740

3 files changed

Lines changed: 31 additions & 28 deletions

File tree

pori_python/ipr/inputs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
'comments',
6060
'library',
6161
'germline',
62-
'flags'
62+
'flags',
6363
]
6464

6565
SMALL_MUT_REQ = ['gene', 'proteinChange']
@@ -98,7 +98,7 @@
9898
'tumourRefCount',
9999
'tumourRefCopies',
100100
'zygosity',
101-
'flags'
101+
'flags',
102102
]
103103

104104
EXP_REQ = ['gene', 'kbCategory']
@@ -131,7 +131,7 @@
131131
'rnaReads',
132132
'rpkm',
133133
'tpm',
134-
'flags'
134+
'flags',
135135
]
136136

137137
SV_REQ = [
@@ -164,7 +164,7 @@
164164
'tumourDepth',
165165
'germline',
166166
'mavis_product_id',
167-
'flags'
167+
'flags',
168168
]
169169

170170
SIGV_REQ = ['signatureName', 'variantTypeName']
@@ -335,6 +335,7 @@ def preprocess_expression_variants(rows: Iterable[Dict]) -> List[IprExprVariant]
335335
Validate the input rows contain the minimum required fields and
336336
generate any default values where possible
337337
"""
338+
338339
def row_key(row: Dict) -> Tuple[str, ...]:
339340
return tuple(['expression'] + [row[key] for key in EXP_KEY])
340341

@@ -375,7 +376,6 @@ def row_key(row: Dict) -> Tuple[str, ...]:
375376

376377
if errors:
377378
raise ValueError(f'{len(errors)} Invalid expression variants in file')
378-
379379
return result
380380

381381

pori_python/ipr/ipr.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ def get_kb_disease_matches(
668668
verbose: bool = True,
669669
useSubgraphsRoute: bool = True,
670670
) -> list[Dict]:
671-
672671
disease_matches = []
673672

674673
if not kb_disease_match:
@@ -736,9 +735,9 @@ def ensure_str_list(val):
736735
return [val]
737736
if isinstance(val, list):
738737
if not all(isinstance(item, str) for item in val):
739-
raise TypeError("All items in flags must be strings")
738+
raise TypeError('All items in flags must be strings')
740739
return val
741-
raise TypeError(f"Unexpected type in flags field: {type(val).__name__}")
740+
raise TypeError(f'Unexpected type in flags field: {type(val).__name__}')
742741

743742
flags = []
744743

@@ -748,19 +747,19 @@ def ensure_str_list(val):
748747
if not raw_flags: # skips None and ''
749748
continue
750749

751-
flags.append({
752-
'variant': item['key'],
753-
'variantType': item['variantType'],
754-
'flags': [f for f in ensure_str_list(raw_flags) if f]
755-
})
750+
flags.append(
751+
{
752+
'variant': item['key'],
753+
'variantType': item['variantType'],
754+
'flags': [f for f in ensure_str_list(raw_flags) if f],
755+
}
756+
)
756757
item.pop('flags', None) # remove after extraction
757758

758759
return flags
759760

760761
observed_vars_section = [
761-
flag
762-
for variants in variant_sources
763-
for flag in extract_flags(variants)
762+
flag for variants in variant_sources for flag in extract_flags(variants)
764763
]
765764

766765
return observed_vars_section

pori_python/ipr/main.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
get_kb_disease_matches,
4747
get_kb_matches_sections,
4848
select_expression_plots,
49-
get_variant_flags
49+
get_variant_flags,
5050
)
5151
from .summary import auto_analyst_comments, get_ipr_analyst_comments
5252
from .therapeutic_options import create_therapeutic_options
@@ -528,7 +528,7 @@ def ipr_report(
528528
gkb_matches, all_variants, kb_matched_sections['kbMatches']
529529
)
530530

531-
if True:
531+
if False:
532532

533533
def extract_flags(variant_list):
534534
# convert item to list of str, if it's just a str
@@ -541,12 +541,14 @@ def ensure_list(val):
541541

542542
# extract only the relevant fields for creating an observed variant annotation record
543543
flags = [
544-
{'variant': item['key'],
545-
'variantType': item['variantType'],
546-
'flags': ensure_list(item['flags'])
544+
{
545+
'variant': item['key'],
546+
'variantType': item['variantType'],
547+
'flags': ensure_list(item['flags']),
547548
}
548-
for item in variant_list if item['flags'] is not None and item['flags'] != ''
549-
]
549+
for item in variant_list
550+
if item['flags'] is not None and item['flags'] != ''
551+
]
550552
_ = [item.pop('flags', '') for item in variant_list]
551553

552554
return flags
@@ -556,11 +558,13 @@ def ensure_list(val):
556558
flags = extract_flags([item for item in varlist if item['gene'] in genes_with_variants])
557559
observed_vars_section.extend(flags)
558560
observed_vars_section.extend(extract_flags(signature_variants))
559-
observed_vars_section.extend(extract_flags(filter_structural_variants(
560-
structural_variants, gkb_matches, gene_information
561-
)))
561+
observed_vars_section.extend(
562+
extract_flags(
563+
filter_structural_variants(structural_variants, gkb_matches, gene_information)
564+
)
565+
)
562566

563-
if False:
567+
if True:
564568
variant_sources = [
565569
v
566570
for source in [
@@ -606,7 +610,7 @@ def ensure_list(val):
606610
'variantCounts': variant_counts,
607611
'analystComments': comments,
608612
'therapeuticTarget': targets,
609-
'observedVariantAnnotations': observed_vars_section
613+
'observedVariantAnnotations': observed_vars_section,
610614
}
611615
)
612616

0 commit comments

Comments
 (0)