annotate summary_to_fasta.py @ 85:a539d14d66b6 draft

"planemo upload commit 95767c430ea956636f95ec28bb749a84eabe0156"
author rhpvorderman
date Wed, 27 Oct 2021 09:41:34 +0000
parents 729738462297
children
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
83
729738462297 "planemo upload commit c0ffc68aec5836d5b20b543106493056a87edf57"
rhpvorderman
parents: 0
diff changeset
40 print("No results:", no_results)
729738462297 "planemo upload commit c0ffc68aec5836d5b20b543106493056a87edf57"
rhpvorderman
parents: 0
diff changeset
41 print("No sequences:", no_seqs)
729738462297 "planemo upload commit c0ffc68aec5836d5b20b543106493056a87edf57"
rhpvorderman
parents: 0
diff changeset
42 print("Written to fasta file:", passed)