annotate PDAUG_TSVtoFASTA/PDAUG_TSVtoFASTA.py @ 2:c9078a576efe draft

"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 8b18552f6d2b2261efebe1075ff4c18a295b94dd"
author jay
date Tue, 29 Dec 2020 18:26:34 +0000
parents f85327600c11
children 6e18702da4f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
1 import os
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
2 import argparse
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
3
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
4
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
5 def TSVtoFASTA(InFile, Method, Positive, Negative, OutFile):
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
6
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
7 if Method == 'WithClassLabel':
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
8
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
9 f = open(InFile)
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
10 lines = f.readlines()
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
11
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
12 of1 = open(Positive,'w')
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
13 of2 = open(Negative,'w')
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
14
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
15 n = 0
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
16 m = 0
1
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
17
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
18 l = []
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
19
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
20 for line in lines[1:]:
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
21 l.append(line.split('\t')[1].strip('\n').strip('\r'))
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
22 l = list(set(l))
0
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
23
2
c9078a576efe "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 8b18552f6d2b2261efebe1075ff4c18a295b94dd"
jay
parents: 1
diff changeset
24 print(l)
c9078a576efe "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 8b18552f6d2b2261efebe1075ff4c18a295b94dd"
jay
parents: 1
diff changeset
25
0
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
26 for line in lines:
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
27
2
c9078a576efe "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 8b18552f6d2b2261efebe1075ff4c18a295b94dd"
jay
parents: 1
diff changeset
28 if l[1] in line.split('\t')[1].strip('\n').strip('\r'):
0
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
29 n= n+1
1
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
30 of1.write('>peptide_'+str(n)+'_'+str(l[0])+'\n')
0
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
31 of1.write(line.split('\t')[0]+'\n')
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
32
2
c9078a576efe "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 8b18552f6d2b2261efebe1075ff4c18a295b94dd"
jay
parents: 1
diff changeset
33 if l[0] in line.split('\t')[1].strip('\n').strip('\r'):
0
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
34 m= m+1
1
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
35 of2.write('>peptide_'+str(m)+'_'+str(l[1])+'\n')
0
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
36 of2.write(line.split('\t')[0]+'\n')
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
37
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
38 elif Method == 'NoClassLabel':
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
39
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
40 f = open(InFile)
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
41 lines = f.readlines()
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
42 of1 = open(OutFile,'w')
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
43
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
44 for i, line in enumerate(lines[1:]):
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
45 of1.write('>peptide_'+str(i)+'\n')
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
46 of1.write(line.split('\t')[0]+'\n')
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
47
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
48 else:
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
49 pass
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
50
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
51 if __name__=="__main__":
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
52
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
53 import argparse
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
54
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
55 parser = argparse.ArgumentParser()
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
56
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
57 parser.add_argument("-I", "--InFile", required=True, default=None, help=".fasta or .tsv")
1
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
58 parser.add_argument("-P", "--Postvs", required=False, default='FirstDataFile.fasta', help="Path to target tsv file")
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
59 parser.add_argument("-N", "--Negtvs", required=False, default='SecondDataFile.fasta', help="Path to target tsv file")
0
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
60 parser.add_argument("-O", "--OutFile", required=False, default='OutFile.fasta', help="Path to target tsv file")
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
61 parser.add_argument("-M", "--Method", required=True, default=None, help="Path to target tsv file")
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
62 args = parser.parse_args()
6c12ca9f5d88 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
jay
parents:
diff changeset
63
1
f85327600c11 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 3c91f421d26c8f42cf2671e47db735d2cf69dde8"
jay
parents: 0
diff changeset
64 TSVtoFASTA(args.InFile, args.Method, args.Postvs, args.Negtvs, args.OutFile)