annotate summary_to_fasta.py @ 0:8a5a2abbb870 draft default tip

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