From 4a2d984b1e10b9524b115fd5a86f12d8a5b7b8ab Mon Sep 17 00:00:00 2001 From: davidstew Date: Tue, 5 Jun 2018 16:16:52 -0700 Subject: [PATCH] sort output vcf positions numerically (resolves #290) resolves #290 outputted vcfs after merging are sorted chromosomes 1..22,X,Y,M and positions within are sorted numerically. --- src/protect/mutation_calling/common.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/protect/mutation_calling/common.py b/src/protect/mutation_calling/common.py index 947426d2..cb07b3c1 100644 --- a/src/protect/mutation_calling/common.py +++ b/src/protect/mutation_calling/common.py @@ -134,10 +134,9 @@ def merge_perchrom_mutations(job, chrom, mutations, univ_options): file=outfile) print('#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO', file=outfile) for chrom in chrom_sorted(accepted_hits.keys()): - for position in sorted(accepted_hits[chrom]): - print(chrom, position, '.', accepted_hits[chrom][position][0], - accepted_hits[chrom][position][1], '.', 'PASS', - 'callers=' + accepted_hits[chrom][position][2], sep='\t', file=outfile) + for position in sorted(accepted_hits[chrom], key=lambda x: int(x)): + print(chrom, position, '.', accepted_hits[chrom][position][0], accepted_hits[chrom][position][1], '.', + 'PASS', 'callers=' + accepted_hits[chrom][position][2], sep='\t', file=outfile) fsid = job.fileStore.writeGlobalFile(outfile.name) export_results(job, fsid, outfile.name, univ_options, subfolder='mutations/merged') return fsid