annotate summary_to_fasta.py @ 20:ba2511ebd36a draft

Uploaded
author davidvanzessen
date Mon, 28 Nov 2016 07:23:50 -0500
parents c33d93683a09
children 729738462297
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
1 import argparse
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
2
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
3 parser = argparse.ArgumentParser()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
4 parser.add_argument("--input", help="The 1_Summary file of an IMGT zip file")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
5 parser.add_argument("--fasta", help="The output fasta file")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
6
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
7 args = parser.parse_args()
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
8
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
9 infile = args.input
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
10 fasta = args.fasta
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
11
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
12 with open(infile, 'r') as i, open(fasta, 'w') as o:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
13 first = True
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
14 id_col = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
15 seq_col = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
16 no_results = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
17 no_seqs = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
18 passed = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
19 for line in i:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
20 splt = line.split("\t")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
21 if first:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
22 id_col = splt.index("Sequence ID")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
23 seq_col = splt.index("Sequence")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
24 first = False
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
25 continue
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
26 if len(splt) < 5:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
27 no_results += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
28 continue
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
29
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
30 ID = splt[id_col]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
31 seq = splt[seq_col]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
32
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
33 if not len(seq) > 0:
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
34 no_seqs += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
35 continue
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
36
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
37 o.write(">" + ID + "\n" + seq + "\n")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
38 passed += 1
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
39
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
40 print "No results:", no_results
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
41 print "No sequences:", no_seqs
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
42 print "Written to fasta file:", passed