annotate mut2sscs.py @ 2:3f1dbd2c59bf draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
author iuc
date Tue, 10 Nov 2020 12:55:29 +0000
parents 3556001ff2db
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
1 #!/usr/bin/env python
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
2
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
3 """mut2sscs.py
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
4
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
5 Author -- Gundula Povysil
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
6 Contact -- povysil@bioinf.jku.at
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
7
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
8 Takes a tabular file with mutations from DCS and a BAM file of SSCS as input
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
9 and extracts all tags of reads that carry the mutation.
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
10 Calculates statistics about number of ab/ba/duplex per mutation.
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
11
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
12 ======= ========== ================= ================================
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
13 Version Date Author Description
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
14 2.0.0 2020-10-30 Gundula Povysil -
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
15 ======= ========== ================= ================================
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
16
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
17 USAGE: python mut2sscs.py DCS_Mutations.tabular SSCS.bam SSCS_counts.json
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
18
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
19 """
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
20
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
21 from __future__ import division
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
22
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
23 import argparse
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
24 import json
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
25 import os
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
26 import sys
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
27
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
28 import pysam
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
29 from cyvcf2 import VCF
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
30
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
31
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
32 def make_argparser():
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
33 parser = argparse.ArgumentParser(description='Takes a vcf file with mutations and a BAM file as input and prints all tags of reads that carry the mutation to a user specified output file.')
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
34 parser.add_argument('--mutFile',
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
35 help='VCR file with DCS mutations.')
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
36 parser.add_argument('--bamFile',
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
37 help='BAM file with aligned SSCS reads.')
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
38 parser.add_argument('--outputJson',
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
39 help='Output JSON file to store SSCS counts.')
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
40 return parser
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
41
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
42
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
43 def mut2sscs(argv):
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
44 parser = make_argparser()
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
45 args = parser.parse_args(argv[1:])
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
46
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
47 file1 = args.mutFile
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
48 file2 = args.bamFile
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
49 sscs_counts_json = args.outputJson
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
50
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
51 if os.path.isfile(file1) is False:
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
52 sys.exit("Error: Could not find '{}'".format(file1))
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
53
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
54 if os.path.isfile(file2) is False:
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
55 sys.exit("Error: Could not find '{}'".format(file2))
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
56
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
57 # read SSCS bam file
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
58 bam = pysam.AlignmentFile(file2, "rb")
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
59
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
60 # get tags
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
61 mut_pos_dict = {}
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
62 ref_pos_dict = {}
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
63
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
64 for variant in VCF(file1):
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
65 chrom = variant.CHROM
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
66 stop_pos = variant.start
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
67 chrom_stop_pos = str(chrom) + "#" + str(stop_pos)
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
68 ref = variant.REF
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
69 alt = variant.ALT[0]
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
70
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
71 if len(ref) == len(alt):
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
72 for pileupcolumn in bam.pileup(chrom, stop_pos - 1, stop_pos + 1, max_depth=1000000000):
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
73 if pileupcolumn.reference_pos == stop_pos:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
74 count_alt = 0
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
75 count_ref = 0
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
76 count_indel = 0
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
77 print("unfiltered reads=", pileupcolumn.n, "filtered reads=", len(pileupcolumn.pileups),
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
78 "difference= ", len(pileupcolumn.pileups) - pileupcolumn.n)
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
79 for pileupread in pileupcolumn.pileups:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
80 if not pileupread.is_del and not pileupread.is_refskip:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
81 tag = pileupread.alignment.query_name
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
82 abba = tag[-2:]
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
83 # query position is None if is_del or is_refskip is set.
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
84 if pileupread.alignment.query_sequence[pileupread.query_position] == alt:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
85 count_alt += 1
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
86 if chrom_stop_pos in mut_pos_dict:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
87 if abba in mut_pos_dict[chrom_stop_pos]:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
88 mut_pos_dict[chrom_stop_pos][abba] += 1
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
89 else:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
90 mut_pos_dict[chrom_stop_pos][abba] = 1
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
91 else:
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
92 mut_pos_dict[chrom_stop_pos] = {}
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
93 mut_pos_dict[chrom_stop_pos][abba] = 1
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
94 if chrom_stop_pos not in ref_pos_dict:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
95 ref_pos_dict[chrom_stop_pos] = {}
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
96 ref_pos_dict[chrom_stop_pos][abba] = 0
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
97
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
98 elif pileupread.alignment.query_sequence[pileupread.query_position] == ref:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
99 count_ref += 1
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
100 if chrom_stop_pos in ref_pos_dict:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
101 if abba in ref_pos_dict[chrom_stop_pos]:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
102 ref_pos_dict[chrom_stop_pos][abba] += 1
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
103 else:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
104 ref_pos_dict[chrom_stop_pos][abba] = 1
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
105 else:
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
106 ref_pos_dict[chrom_stop_pos] = {}
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
107 ref_pos_dict[chrom_stop_pos][abba] = 1
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
108 else:
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
109 count_indel += 1
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
110
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
111 print("coverage at pos %s = %s, ref = %s, alt = %s, indel = %s,\n" %
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
112 (pileupcolumn.pos, count_ref + count_alt, count_ref, count_alt, count_indel))
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
113
2
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
114 # if mutation is in DCS file but not in SSCS, then set counts to NA
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
115 if chrom_stop_pos not in mut_pos_dict.keys():
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
116 mut_pos_dict[chrom_stop_pos] = {}
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
117 mut_pos_dict[chrom_stop_pos]["ab"] = 0
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
118 mut_pos_dict[chrom_stop_pos]["ba"] = 0
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
119 ref_pos_dict[chrom_stop_pos] = {}
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
120 ref_pos_dict[chrom_stop_pos]["ab"] = 0
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
121 ref_pos_dict[chrom_stop_pos]["ba"] = 0
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
122 else:
3f1dbd2c59bf "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit f492e9717cb946f0eb5689cd7b6eb8067abf6468"
iuc
parents: 1
diff changeset
123 print("indels are currently not evaluated")
0
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
124 bam.close()
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
125
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
126 # save counts
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
127 with open(sscs_counts_json, "w") as f:
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
128 json.dump((mut_pos_dict, ref_pos_dict), f)
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
129
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
130
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
131 if __name__ == '__main__':
8d29173d49a9 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/variant_analyzer commit 5a438f76d0ecb6478f82dae6b9596bc7f5a4f4e8"
iuc
parents:
diff changeset
132 sys.exit(mut2sscs(sys.argv))