annotate sam2counts_galaxy_edger.py @ 0:ce3a667012c2 draft

Uploaded
author nikhil-joshi
date Thu, 22 Jan 2015 03:54:22 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
1 #!/usr/bin/python
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
2
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
3 """
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
4 sam2count_galaxy_edger.py -- Take SAM files and output a table of counts with column
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
5 names that are the filenames, and rowname that are the reference
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
6 names.
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
7 """
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
8
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
9 VERSION = 0.90
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
10
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
11 import sys
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
12 import csv
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
13 from os import path
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
14 try:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
15 import pysam
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
16 except ImportError:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
17 sys.exit("pysam not installed; please install it\n")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
18
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
19 import argparse
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
20
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
21 def SAM_file_to_counts(filename, sname, ftype="sam", extra=False, use_all_references=True):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
22 """
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
23 Take SAM filename, and create a hash of mapped and unmapped reads;
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
24 keys are reference sequences, values are the counts of occurences.
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
25
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
26 Also, a hash of qualities (either 0 or >0) of mapped reads
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
27 is output, which is handy for diagnostics.
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
28 """
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
29 counts = dict()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
30 unique = dict()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
31 nonunique = dict()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
32 mode = 'r'
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
33 if ftype == "bam":
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
34 mode = 'rb'
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
35 sf = pysam.Samfile(filename, mode)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
36
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
37 if use_all_references:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
38 # Make dictionary of all entries in header
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
39 try:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
40 for sn in sf.header['SQ']:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
41 if extra:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
42 unique[sn['SN']] = 0
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
43 nonunique[sn['SN']] = 0
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
44 counts[sn['SN']] = 0
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
45 except KeyError:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
46 print "Sample file of sample " + sname + " does not have header."
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
47
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
48 for read in sf:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
49 if not read.is_unmapped:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
50 id_name = sf.getrname(read.rname) if read.rname != -1 else 0
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
51
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
52 if not use_all_references and not counts.get(id_name, False):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
53 ## Only make keys based on aligning reads, make empty hash
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
54 if extra:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
55 unique[id_name] = 0
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
56 nonunique[id_name] = 0
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
57 ## initiate entry; even if not mapped, record 0 count
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
58 counts[id_name] = counts.get(id_name, 0)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
59
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
60
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
61 counts[id_name] = counts.get(id_name, 0) + 1
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
62
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
63 if extra:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
64 if read.mapq == 0:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
65 nonunique[id_name] = nonunique[id_name] + 1
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
66 else:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
67 unique[id_name] = unique[id_name] + 1
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
68
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
69 if extra:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
70 return {'counts':counts, 'unique':unique, 'nonunique':nonunique}
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
71
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
72 return {'counts':counts}
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
73
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
74 def collapsed_nested_count_dict(counts_dict, all_ids, order=None):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
75 """
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
76 Takes a nested dictionary `counts_dict` and `all_ids`, which is
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
77 built with the `table_dict`. All files (first keys) in
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
78 `counts_dict` are made into columns with order specified by
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
79 `order`.
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
80
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
81 Output is a dictionary with keys that are the id's (genes or
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
82 transcripts), with values that are ordered counts. A header will
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
83 be created on the first row from the ordered columns (extracted
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
84 from filenames).
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
85 """
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
86 if order is None:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
87 col_order = counts_dict.keys()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
88 else:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
89 col_order = order
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
90
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
91 collapsed_dict = dict()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
92 for i, filename in enumerate(col_order):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
93 for id_name in all_ids:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
94 if not collapsed_dict.get(id_name, False):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
95 collapsed_dict[id_name] = list()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
96
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
97 # get counts and append
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
98 c = counts_dict[filename].get(id_name, 0)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
99 collapsed_dict[id_name].append(c)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
100 return {'table':collapsed_dict, 'header':col_order}
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
101
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
102
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
103 def counts_to_file(table_dict, outfilename, delimiter=','):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
104 """
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
105 A function for its side-effect of writing `table_dict` (which
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
106 contains a table and header), to `outfilename` with the specified
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
107 `delimiter`.
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
108 """
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
109 writer = csv.writer(open(outfilename, 'a'), delimiter=delimiter, lineterminator='\n')
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
110 table = table_dict['table']
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
111 header = table_dict['header']
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
112
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
113 #header_row = True
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
114 for id_name, fields in table.items():
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
115 #if header_row:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
116 #row = ['id'] + header
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
117 #writer.writerow(row)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
118 #header_row = False
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
119
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
120 if id_name == 0:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
121 continue
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
122 row = [id_name]
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
123 row.extend(fields)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
124 writer.writerow(row)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
125
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
126 if __name__ == '__main__':
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
127 parser = argparse.ArgumentParser(description='parser for sam2counts')
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
128 parser.add_argument("-d", "--delimiter", help="the delimiter (default: tab)", default='\t')
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
129 parser.add_argument("-o", "--out-file", help="output filename (default: counts.txt)", default='counts.txt')
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
130 parser.add_argument("-u", "--extra-output", help="output extra information on non-unique and unique mappers (default: False)")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
131 parser.add_argument("-r", "--use-all-references", dest="use_all_references",
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
132 help="Use all the references from the SAM header (default: True)",
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
133 default=True, action="store_false")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
134 parser.add_argument("-f", "--extra-out-files", dest="extra_out_files",
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
135 help="comma-delimited filenames of unique and non-unique output "
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
136 "(default: unique.txt,nonunique.txt)",
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
137 default='unique.txt,nonunique.txt')
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
138 parser.add_argument("-v", "--verbose", dest="verbose",
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
139 help="enable verbose output")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
140 parser.add_argument("--bam-file", help="bam file", nargs="+", action="append", required=True)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
141 parser.add_argument("--group", help="group", nargs="+", action="append", required=True)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
142 parser.add_argument("--treatment", help="treatment", nargs="+", action="append", required=True)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
143 parser.add_argument("--sample-name", help="sample name", nargs="+", action="append", required=True)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
144 parser.add_argument("--file-type", help="file type", nargs="+", action="append", required=True, choices=['sam','bam'])
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
145 args = parser.parse_args()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
146
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
147 args.bam_file = [item for sublist in args.bam_file for item in sublist]
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
148 args.group = [item for sublist in args.group for item in sublist]
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
149 args.treatment = [item for sublist in args.treatment for item in sublist]
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
150 args.sample_name = [item for sublist in args.sample_name for item in sublist]
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
151 args.file_type = [item for sublist in args.file_type for item in sublist]
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
152 #print(args.sample_name)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
153
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
154 if (len(args.sample_name) != len(set(args.sample_name))):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
155 parser.error("Sample names must be unique.")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
156
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
157 if not(len(args.bam_file) == len(args.group) and len(args.group) == len(args.treatment) and len(args.treatment) == len(args.sample_name) and len(args.sample_name) == len(args.file_type)):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
158 parser.error("Number of total BAM files, groups, treatments, sample names, and types must be the same.")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
159
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
160 file_counts = dict()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
161 file_unique_counts = dict()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
162 file_nonunique_counts = dict()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
163 all_ids = list()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
164
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
165 ## do a pre-run check that all files exist
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
166 for full_filename in args.bam_file:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
167 if not path.exists(full_filename):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
168 parser.error("file '%s' does not exist" % full_filename)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
169
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
170 outf = open(args.out_file, "w")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
171 outf.write("#")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
172 for (g,t) in zip(args.group,args.treatment):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
173 outf.write("\t" + g + ":" + t)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
174 outf.write("\n#Feature")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
175 for s in args.sample_name:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
176 outf.write("\t" + s)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
177 outf.write("\n")
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
178 outf.close()
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
179
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
180 for (full_filename, sn, ft) in zip(args.bam_file, args.sample_name, args.file_type):
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
181 ## read in SAM file, extract counts, and unpack counts
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
182 tmp = SAM_file_to_counts(full_filename, sn, ftype=ft, extra=args.extra_output,
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
183 use_all_references=args.use_all_references)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
184
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
185 if args.extra_output:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
186 counts, unique, nonunique = tmp['counts'], tmp['unique'], tmp['nonunique']
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
187 else:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
188 counts = tmp['counts']
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
189
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
190 ## save counts, and unique/non-unique counts
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
191 file_counts[sn] = counts
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
192
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
193 if args.extra_output:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
194 file_unique_counts[sn] = unique
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
195 file_nonunique_counts[sn] = nonunique
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
196
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
197 ## add all ids encountered in this in this file
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
198 all_ids.extend(file_counts[sn].keys())
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
199
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
200 ## Uniquify all_ids, and then take the nested file_counts
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
201 ## dictionary, collapse, and write to file.
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
202 all_ids = set(all_ids)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
203 table_dict = collapsed_nested_count_dict(file_counts, all_ids, order=args.sample_name)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
204 counts_to_file(table_dict, args.out_file, delimiter=args.delimiter)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
205
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
206 if args.extra_output:
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
207 unique_fn, nonunique_fn = args.extra_out_files.split(',')
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
208 unique_table_dict = collapsed_nested_count_dict(file_unique_counts, all_ids, order=files)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
209 nonunique_table_dict = collapsed_nested_count_dict(file_nonunique_counts, all_ids, order=files)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
210
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
211 counts_to_file(unique_table_dict, unique_fn, delimiter=args.delimiter)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
212 counts_to_file(nonunique_table_dict, nonunique_fn, delimiter=args.delimiter)
ce3a667012c2 Uploaded
nikhil-joshi
parents:
diff changeset
213