Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add STRdust #60

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions stranger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,17 @@ def get_repeat_info(variant_info, repeat_info):

repeat_id = variant_info['info_dict'].get('REPID')
if not repeat_id:
repeat_id = variant_info['info_dict'].get('TRID').split('_')[1]

for key in ['TRID', 'ID']:
value = variant_info['info_dict'].get(key)
if value is not None:
# Some IDs may have _, some may not
if '_' in value:
repeat_id = value.split('_')[1]
else:
repeat_id = value
break

if not repeat_id in repeat_info:
LOG.warning("No info for repeat id %s", repeat_id)
return None
Expand Down Expand Up @@ -223,7 +233,17 @@ def get_trgt_repeat_res(variant_info, repeat_info):

repeat_id = variant_info['info_dict'].get('REPID')
if not repeat_id:
repeat_id = variant_info['info_dict'].get('TRID').split('_')[1]

for key in ['TRID', 'ID']:
value = variant_info['info_dict'].get(key)
if value is not None:
# Some IDs may have _, some may not
if '_' in value:
repeat_id = value.split('_')[1]
else:
repeat_id = value
break

if not repeat_id in repeat_info:
LOG.warning("No info for repeat id %s", repeat_id)
return None
Expand All @@ -236,6 +256,10 @@ def get_trgt_repeat_res(variant_info, repeat_info):
for allele in mc.split(","):
mcs = allele.split('_')
# GT would have the index of the MC in the ALT field list if we wanted to be specific...

# What should we do if MC is . ?
if allele == ".":
continue

if len(mcs) > 1:
pathologic_mcs = repeat_info[repeat_id].get('pathologic_struc', range(len(mcs)))
Expand Down Expand Up @@ -365,8 +389,8 @@ def decompose_var(variant_info):

for index, alt in enumerate(variant_info['alts']):
for individual_index, format_dict in enumerate(variant_info['format_dicts']):
gts = format_dict["GT"].split("/")

gts = re.split(r'[\/|]', format_dict["GT"])
delimiter = "/" if "/" in format_dict["GT"] else "|"
updated_fields = []
for gt_component, decomposed_field in enumerate(gts):
if decomposed_field == "0":
Expand All @@ -386,7 +410,7 @@ def decompose_var(variant_info):
# unclear component
updated_fields.append(".")

result_variants[index]['format_dicts'][individual_index]['GT'] = "/".join(updated_fields)
result_variants[index]['format_dicts'][individual_index]['GT'] = delimiter.join(updated_fields)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


for field, individual_value in format_dict.items():
if field in ["GT"]:
Expand Down