Skip to content

Commit 17a0bf0

Browse files
authored
VEP: update logic for generating alt alleles in the vcf to json script (#36)
1 parent f4a939b commit 17a0bf0

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

app/vep/utils/vcf_results.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,20 @@ def _get_csq_value(
8181

8282

8383
def _get_alt_allele_details(
84-
alt: vcfpy.AltRecord, csqs: List[str], index_map: Dict
84+
alt: str, ref: str, csqs: List[str], index_map: Dict
8585
) -> model.AlternativeVariantAllele:
8686
"""Creates AlternativeVariantAllele based on
8787
target alt allele and CSQ entires"""
8888
frequency = None
8989
consequences = []
90+
allele_type = _set_allele_type(
91+
len(alt) < 2, len(ref) < 2, len(alt) == len(ref)
92+
)[0]
9093

9194
for str_csq in csqs:
9295
csq_values = str_csq.split("|")
9396

94-
if csq_values[index_map["Allele"]] != alt.value:
97+
if csq_values[index_map["Allele"]] != alt:
9598
continue
9699

97100
frequency = _get_csq_value(csq_values, "AF", frequency, index_map)
@@ -134,8 +137,8 @@ def _get_alt_allele_details(
134137
)
135138

136139
return model.AlternativeVariantAllele(
137-
allele_sequence=alt.value,
138-
allele_type=alt.type,
140+
allele_sequence=alt,
141+
allele_type=allele_type,
139142
representative_population_allele_frequency=frequency,
140143
predicted_molecular_consequences=consequences,
141144
)
@@ -152,7 +155,7 @@ def get_results_from_path(
152155

153156

154157
def get_results_from_stream(
155-
page_size: int, page: int, vcf_stream: IO
158+
page_size: int, page: int, vcf_stream: Any
156159
) -> model.VepResultsResponse:
157160
"""Generates a page of VCF data in the format described in
158161
APISpecification.yaml for a given VCF stream"""
@@ -215,14 +218,19 @@ def _get_results_from_vcfpy(
215218
# from competting vcf module
216219
location = model.Location(
217220
region_name=record.CHROM,
218-
start=record.begin,
219-
end=record.end if record.end else record.begin + ref_len,
221+
start=record.POS,
222+
end=record.POS + ref_len,
220223
)
221224
longest_alt = len(max((a.value for a in record.ALT), key=len))
222225

226+
alt_allele_strings = list(set([
227+
csq_string.split("|")[prediction_index_map["Allele"]]
228+
for csq_string in record.INFO["CSQ"]
229+
]))
230+
223231
alt_alleles = [
224-
_get_alt_allele_details(alt, record.INFO["CSQ"], prediction_index_map)
225-
for alt in record.ALT
232+
_get_alt_allele_details(alt, record.REF, record.INFO["CSQ"], prediction_index_map)
233+
for alt in alt_allele_strings
226234
]
227235

228236
variants.append(

0 commit comments

Comments
 (0)