-
Notifications
You must be signed in to change notification settings - Fork 0
/
rank_barcodes.py
executable file
·42 lines (28 loc) · 956 Bytes
/
rank_barcodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python
import sys
import gzip
from collections import defaultdict
import argparse
def count_barcodes(infile, barcodes):
inf = gzip.open(infile, 'r')
header = inf.readline()
while header:
seq = inf.readline()
comment = inf.readline()
quality = inf.readline()
barcode = header.rstrip().split(':')[-1]
barcodes[barcode] += 1
header = inf.readline()
inf.close()
return barcodes
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--infiles", nargs='+',
help="Undetermined fastq files")
parser.add_argument("-c", "--count", type=int, default=15)
opts = parser.parse_args()
barcodes = defaultdict(int)
for f in opts.infiles:
barcodes = count_barcodes(f, barcodes)
for k in sorted(barcodes.keys(), key=barcodes.get, reverse=True)[:opts.count]:
print k, barcodes[k]