Skip to content

Commit

Permalink
accept wildcard <group> as parameter to improve usability
Browse files Browse the repository at this point in the history
  • Loading branch information
riasc committed Feb 27, 2024
1 parent 6e5e861 commit e44668b
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions workflow/scripts/add_infos_to_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
This script combines multiple vcfs into one vcf. It adds a new INFO field for the group name
Usage:
python combine_vcf.py '<input_vcfs>' <method> <output_vcf>
python combine_vcf.py '<input_vcfs>' <method> <group> <output_vcf>
'''

def main():
vcf = sys.argv[1]
# extract the replicate (e.g., {rep1}_*.vcf)
if '_call.indel.vcf' in str(Path(vcf).name):
rpl = Path(vcf).name.split('_call.indel.vcf')[0]
elif '_somatic.short.indels.vcf' in str(Path(vcf).name):
rpl = Path(vcf).name.split('_somatic.short.indels.vcf')[0]
elif '_somatic.snvs.vcf' in str(Path(vcf).name):
rpl = Path(vcf).name.split('_somatic.snvs.vcf')[0]
elif '_fusions.vcf' in str(Path(vcf).name):
rpl = Path(vcf).name.split('_fusions.vcf')[0]
elif '_exitrons.vcf' in str(Path(vcf).name):
rpl = Path(vcf).name.split('_exitrons.vcf')[0]

# if '_call.indel.vcf' in str(Path(vcf).name):
# rpl = Path(vcf).name.split('_call.indel.vcf')[0]
# elif '_somatic.short.indels.vcf' in str(Path(vcf).name):
# rpl = Path(vcf).name.split('_somatic.short.indels.vcf')[0]
# elif '_somatic.snvs.vcf' in str(Path(vcf).name):
# rpl = Path(vcf).name.split('_somatic.snvs.vcf')[0]
# elif '_fusions.vcf' in str(Path(vcf).name):
# rpl = Path(vcf).name.split('_fusions.vcf')[0]
# elif '_exitrons.vcf' in str(Path(vcf).name):
# rpl = Path(vcf).name.split('_exitrons.vcf')[0]

reader = vcfpy.Reader.from_path(vcf)
reader.header.add_info_line(
Expand All @@ -37,12 +38,12 @@ def main():
('Type', 'String'),
('Description', 'Source of the variant')]))

writer = vcfpy.Writer.from_path(sys.argv[3], reader.header)
writer = vcfpy.Writer.from_path(sys.argv[4], reader.header)

# iterate through all records
for record in reader:
record.INFO['GRP'] = rpl
record.INFO['SRC'] = sys.argv[2]
record.INFO['GRP'] = sys.argv[3]
writer.write_record(record)

main()

0 comments on commit e44668b

Please sign in to comment.