-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_gipz_counts.py
More file actions
27 lines (24 loc) · 1.17 KB
/
get_gipz_counts.py
File metadata and controls
27 lines (24 loc) · 1.17 KB
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
import argparse
import sys
from Bio import SeqIO
def do_count(passengers, alignments, countfile):
counts = initialize_counts(passengers)
for line in alignments:
tokens = line.rstrip().split('\t')
if tokens[2] != '*':
counts[tokens[2]] += 1
for key in counts.keys():
countfile.write(key+'\t'+str(counts[key])+'\n')
def initialize_counts(pool):
counts = {}
records = SeqIO.parse(pool, 'fasta')
for record in records:
counts[record.id] = 0
return counts
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Assign reads to GIPZ library constructs')
parser.add_argument('passengers', type=argparse.FileType('r'), help='FASTA sequence file of GIPZ Passengers (generated by get_gipz_passengers.py')
parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Optional input file of alignments (or read from STDIN)")
parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), default=sys.stdout, help="Optional output file of read counts (or write to STDOUT)")
args = parser.parse_args()
do_count(args.passengers, args.infile, args.outfile)