Skip to content
Snippets Groups Projects
Commit 74ff090f authored by Megens, Hendrik-Jan's avatar Megens, Hendrik-Jan
Browse files

helper scripts

parent e5576dc2
Branches
No related tags found
No related merge requests found
......@@ -11,8 +11,21 @@ parser.add_argument("-m", "--method", help="annotation method", type=str, choice
def vcfelements(line): # parse the main, tab-delimited elements of the VCF line
vcf_elements=line.split('\t')
vcf_elements[7]=tagelements(vcf_elements[7])
if len(vcf_elements)>9: # check if genotype fields present; this requires at least 2 additional columns
vcf_elements=list_genotypes(vcf_elements)
else :
vcf_elements.append([]) # make sure that the data structure is allways of lenth 9
return vcf_elements # return list
def list_genotypes(vcflist): # reshape the genotypes to a single list
genotypes=vcflist[9:]
gt_field=list()
gt_field.append(vcflist[8])
gt_field.append(genotypes)
vcflist=vcflist[0:8]
vcflist.append(gt_field)
return vcflist
def tagelements(tag): # parse the fields/tags in the 8th column - ';' delimited
tags=tag.split(';')
tagdict={tag.split('=')[0]:tag.split('=')[1] for tag in tags}
......@@ -73,6 +86,7 @@ if __name__=="__main__":
myline=myline[:-1]
if not myline.startswith('#'): # avoid VCF comment lines
vcf_line=vcfelements(myline)
print(vcf_line)
print_by_method(vcf_line,method)
except (BrokenPipeError,IOError): # exception handling for BrokenPipeError; works in P3.3, not P3.4! Need this workaround
sys.stdout.write = _void_f
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment