annotate converter.py @ 0:37392af48c37 draft default tip

Uploaded
author izsam
date Thu, 19 Mar 2015 11:46:50 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
37392af48c37 Uploaded
izsam
parents:
diff changeset
1
37392af48c37 Uploaded
izsam
parents:
diff changeset
2 #!/usr/bin/env python
37392af48c37 Uploaded
izsam
parents:
diff changeset
3
37392af48c37 Uploaded
izsam
parents:
diff changeset
4 import sys
37392af48c37 Uploaded
izsam
parents:
diff changeset
5 import string
37392af48c37 Uploaded
izsam
parents:
diff changeset
6 import os
37392af48c37 Uploaded
izsam
parents:
diff changeset
7
37392af48c37 Uploaded
izsam
parents:
diff changeset
8 class convertitori:
37392af48c37 Uploaded
izsam
parents:
diff changeset
9 def __init__(self,input,inouttype,type,output):
37392af48c37 Uploaded
izsam
parents:
diff changeset
10 self.input = input
37392af48c37 Uploaded
izsam
parents:
diff changeset
11 self.inouttype = inouttype
37392af48c37 Uploaded
izsam
parents:
diff changeset
12 self.type = type
37392af48c37 Uploaded
izsam
parents:
diff changeset
13 self.output = output
37392af48c37 Uploaded
izsam
parents:
diff changeset
14
37392af48c37 Uploaded
izsam
parents:
diff changeset
15 def fp(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
16 count = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
17 cseq = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
18 fasta = []
37392af48c37 Uploaded
izsam
parents:
diff changeset
19 for riga in self.input:
37392af48c37 Uploaded
izsam
parents:
diff changeset
20 count += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
21 if ">" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
22 f = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
23 p = self.input.index(riga,count-1)
37392af48c37 Uploaded
izsam
parents:
diff changeset
24 c = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
25 y = riga[1:].replace(" ","_")
37392af48c37 Uploaded
izsam
parents:
diff changeset
26 if y >= 10:
37392af48c37 Uploaded
izsam
parents:
diff changeset
27 f = f + y[:10] + '\t'
37392af48c37 Uploaded
izsam
parents:
diff changeset
28 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
29 f = f + y + "_"*(10-len(y)) + '\t'
37392af48c37 Uploaded
izsam
parents:
diff changeset
30 try:
37392af48c37 Uploaded
izsam
parents:
diff changeset
31 while ">" not in self.input[p+c]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
32 f = f + (self.input[p+c].strip())
37392af48c37 Uploaded
izsam
parents:
diff changeset
33 c += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
34 except:
37392af48c37 Uploaded
izsam
parents:
diff changeset
35 pass
37392af48c37 Uploaded
izsam
parents:
diff changeset
36 fasta.append(f)
37392af48c37 Uploaded
izsam
parents:
diff changeset
37 num = str(len(fasta))
37392af48c37 Uploaded
izsam
parents:
diff changeset
38 lun = str(len(fasta[0].split("\t")[1]))
37392af48c37 Uploaded
izsam
parents:
diff changeset
39 for sequence in fasta:
37392af48c37 Uploaded
izsam
parents:
diff changeset
40 if str(len(sequence.split("\t")[1])) != lun:
37392af48c37 Uploaded
izsam
parents:
diff changeset
41 sys.exit("The input file does not contains a multiple alignment in fasta format. Please ensure that all the sequences have the same length")
37392af48c37 Uploaded
izsam
parents:
diff changeset
42 self.output.write(num + '\t' + lun + '\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
43 for seq in fasta:
37392af48c37 Uploaded
izsam
parents:
diff changeset
44 self.output.write(seq + '\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
45
37392af48c37 Uploaded
izsam
parents:
diff changeset
46 def fn(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
47 count = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
48 fasta = []
37392af48c37 Uploaded
izsam
parents:
diff changeset
49 for riga in self.input:
37392af48c37 Uploaded
izsam
parents:
diff changeset
50 count += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
51 if ">" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
52 f = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
53 p = self.input.index(riga,count-1)
37392af48c37 Uploaded
izsam
parents:
diff changeset
54 c = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
55 y = riga[1:].replace(" ","_")
37392af48c37 Uploaded
izsam
parents:
diff changeset
56 if y >= 10:
37392af48c37 Uploaded
izsam
parents:
diff changeset
57 f = f + y[:10] + '\t'
37392af48c37 Uploaded
izsam
parents:
diff changeset
58 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
59 f = f + y + "_"*(10-len(y)) + '\t'
37392af48c37 Uploaded
izsam
parents:
diff changeset
60 try:
37392af48c37 Uploaded
izsam
parents:
diff changeset
61 while ">" not in self.input[p+c]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
62 f = f + (self.input[p+c].strip())
37392af48c37 Uploaded
izsam
parents:
diff changeset
63 c += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
64 except:
37392af48c37 Uploaded
izsam
parents:
diff changeset
65 pass
37392af48c37 Uploaded
izsam
parents:
diff changeset
66 fasta.append(f)
37392af48c37 Uploaded
izsam
parents:
diff changeset
67 num = str(len(fasta))
37392af48c37 Uploaded
izsam
parents:
diff changeset
68 lun = str(len(fasta[0].split("\t")[1]))
37392af48c37 Uploaded
izsam
parents:
diff changeset
69 for sequence in fasta:
37392af48c37 Uploaded
izsam
parents:
diff changeset
70 if str(len(sequence.split("\t")[1])) != lun:
37392af48c37 Uploaded
izsam
parents:
diff changeset
71 sys.exit("The input file does not contains a multiple alignment in fasta format. Please ensure that all the sequences have the same length")
37392af48c37 Uploaded
izsam
parents:
diff changeset
72 self.output.write("#NEXUS\n\nBEGIN DATA;\nDIMENSIONS NTAX=%s NCHAR=%s;\nFORMAT DATATYPE=DNA INTERLEAVE MISSING=-;\n\nMATRIX\n"%(num,lun))
37392af48c37 Uploaded
izsam
parents:
diff changeset
73 porzioni = int(lun)/100
37392af48c37 Uploaded
izsam
parents:
diff changeset
74 for volte in range(porzioni):
37392af48c37 Uploaded
izsam
parents:
diff changeset
75 for seq in fasta:
37392af48c37 Uploaded
izsam
parents:
diff changeset
76 part = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
77 self.output.write(seq.split("\t")[0] + '\t')
37392af48c37 Uploaded
izsam
parents:
diff changeset
78 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
79 for chara in seq.split("\t")[1][volte*100:(volte+1)*100]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
80 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
81 part = part + chara
37392af48c37 Uploaded
izsam
parents:
diff changeset
82 if cont%20.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
83 part = part + " "
37392af48c37 Uploaded
izsam
parents:
diff changeset
84 part = part + "\n"
37392af48c37 Uploaded
izsam
parents:
diff changeset
85 self.output.write(part)
37392af48c37 Uploaded
izsam
parents:
diff changeset
86 self.output.write("\n\n\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
87 for seq in fasta:
37392af48c37 Uploaded
izsam
parents:
diff changeset
88 part = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
89 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
90 self.output.write(seq.split("\t")[0] + '\t')
37392af48c37 Uploaded
izsam
parents:
diff changeset
91 for chara in seq.split("\t")[1][(volte+1)*100:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
92 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
93 part = part + chara
37392af48c37 Uploaded
izsam
parents:
diff changeset
94 if cont%20.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
95 part = part + " "
37392af48c37 Uploaded
izsam
parents:
diff changeset
96 part = part + "\n"
37392af48c37 Uploaded
izsam
parents:
diff changeset
97 self.output.write(part)
37392af48c37 Uploaded
izsam
parents:
diff changeset
98
37392af48c37 Uploaded
izsam
parents:
diff changeset
99 def pn(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
100 num = int(self.input[0].split()[0])
37392af48c37 Uploaded
izsam
parents:
diff changeset
101 lun = float(self.input[0].split()[1])
37392af48c37 Uploaded
izsam
parents:
diff changeset
102 lunf = float(len(self.input))
37392af48c37 Uploaded
izsam
parents:
diff changeset
103 self.output.write("#NEXUS\n\nBEGIN DATA;\nDIMENSIONS NTAX=%s NCHAR=%s;\nFORMAT DATATYPE=DNA INTERLEAVE MISSING=-;\n\nMATRIX\n"%(int(num),lun))
37392af48c37 Uploaded
izsam
parents:
diff changeset
104 spia = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
105 porzioni = int(lun)/100
37392af48c37 Uploaded
izsam
parents:
diff changeset
106 if (lunf-1)/num == 1.0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
107 spia = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
108 if spia == 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
109 for volte in range(porzioni):
37392af48c37 Uploaded
izsam
parents:
diff changeset
110 for seq in self.input[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
111 part = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
112 self.output.write(seq.split("\t")[0] + '\t')
37392af48c37 Uploaded
izsam
parents:
diff changeset
113 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
114 for chara in seq.split("\t")[1][volte*100:(volte+1)*100]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
115 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
116 part = part + chara
37392af48c37 Uploaded
izsam
parents:
diff changeset
117 if cont%20.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
118 part = part + " "
37392af48c37 Uploaded
izsam
parents:
diff changeset
119 part = part + "\n"
37392af48c37 Uploaded
izsam
parents:
diff changeset
120 self.output.write(part)
37392af48c37 Uploaded
izsam
parents:
diff changeset
121 self.output.write("\n\n\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
122 for seq in self.input[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
123 part = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
124 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
125 self.output.write(seq.split("\t")[0] + '\t')
37392af48c37 Uploaded
izsam
parents:
diff changeset
126 for chara in seq.split("\t")[1][(volte+1)*100:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
127 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
128 part = part + chara
37392af48c37 Uploaded
izsam
parents:
diff changeset
129 if cont%20.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
130 part = part + " "
37392af48c37 Uploaded
izsam
parents:
diff changeset
131 part = part + "\n"
37392af48c37 Uploaded
izsam
parents:
diff changeset
132 self.output.write(part)
37392af48c37 Uploaded
izsam
parents:
diff changeset
133 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
134 if len(self.input[1])<=11:
37392af48c37 Uploaded
izsam
parents:
diff changeset
135 for volte in range(porzioni):
37392af48c37 Uploaded
izsam
parents:
diff changeset
136 interm = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
137 for seq in self.input[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
138 if seq == "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
139 interm += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
140 if (self.input.index(seq)+interm)%2 == 0 and seq != "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
141 part = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
142 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
143 for chara in seq[volte*100:(volte+1)*100]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
144 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
145 part = part + chara
37392af48c37 Uploaded
izsam
parents:
diff changeset
146 if cont%20.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
147 part = part + " "
37392af48c37 Uploaded
izsam
parents:
diff changeset
148 part = part + "\n"
37392af48c37 Uploaded
izsam
parents:
diff changeset
149 self.output.write(part)
37392af48c37 Uploaded
izsam
parents:
diff changeset
150 elif (self.input.index(seq)+interm)%2 != 0 and seq != "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
151 self.output.write(seq[:10] + "\t")
37392af48c37 Uploaded
izsam
parents:
diff changeset
152 self.output.write("\n\n\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
153 interm = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
154 for seq in self.input[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
155 if seq == "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
156 interm += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
157 if (self.input.index(seq)+interm)%2 == 0 and seq != "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
158 part = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
159 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
160 for chara in seq[(volte+1)*100:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
161 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
162 part = part + chara
37392af48c37 Uploaded
izsam
parents:
diff changeset
163 if cont%20.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
164 part = part + " "
37392af48c37 Uploaded
izsam
parents:
diff changeset
165 part = part + "\n"
37392af48c37 Uploaded
izsam
parents:
diff changeset
166 self.output.write(part)
37392af48c37 Uploaded
izsam
parents:
diff changeset
167 elif (self.input.index(seq)+interm)%2 != 0 and seq != "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
168 self.output.write(seq[:10] + "\t")
37392af48c37 Uploaded
izsam
parents:
diff changeset
169 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
170 try:
37392af48c37 Uploaded
izsam
parents:
diff changeset
171 diz = {}
37392af48c37 Uploaded
izsam
parents:
diff changeset
172 volta = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
173 for riga in self.input[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
174 if self.input.index(riga) in range(num+1):
37392af48c37 Uploaded
izsam
parents:
diff changeset
175 numriga = self.input.index(riga)
37392af48c37 Uploaded
izsam
parents:
diff changeset
176 diz[self.input.index(riga)] = [self.input[numriga][:10],self.input[numriga][10:].strip().replace(" ","")]
37392af48c37 Uploaded
izsam
parents:
diff changeset
177 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
178 if riga == "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
179 volta += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
180 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
181 numriga = self.input.index(riga)
37392af48c37 Uploaded
izsam
parents:
diff changeset
182 prima = diz[numriga - ((num+1)*volta)][1] + self.input[self.input.index(riga)].strip().replace(" ","")
37392af48c37 Uploaded
izsam
parents:
diff changeset
183 diz[numriga - ((num+1)*volta)] = [diz[numriga - ((num+1)*volta)][0],prima]
37392af48c37 Uploaded
izsam
parents:
diff changeset
184 for volte in range(porzioni):
37392af48c37 Uploaded
izsam
parents:
diff changeset
185 for seq in diz.keys():
37392af48c37 Uploaded
izsam
parents:
diff changeset
186 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
187 self.output.write(diz[seq][0] + "\t")
37392af48c37 Uploaded
izsam
parents:
diff changeset
188 for chara in diz[seq][1][volte*100:(volte+1)*100]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
189 self.output.write(chara)
37392af48c37 Uploaded
izsam
parents:
diff changeset
190 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
191 if cont%20.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
192 self.output.write(" ")
37392af48c37 Uploaded
izsam
parents:
diff changeset
193 self.output.write("\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
194 self.output.write("\n\n\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
195 for seq in diz.keys():
37392af48c37 Uploaded
izsam
parents:
diff changeset
196 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
197 self.output.write(diz[seq][0] + "\t")
37392af48c37 Uploaded
izsam
parents:
diff changeset
198 for chara in diz[seq][1][(volte+1)*100:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
199 self.output.write(chara)
37392af48c37 Uploaded
izsam
parents:
diff changeset
200 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
201 if cont%20.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
202 self.output.write(" ")
37392af48c37 Uploaded
izsam
parents:
diff changeset
203 self.output.write("\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
204 except:
37392af48c37 Uploaded
izsam
parents:
diff changeset
205 sys.exit("The input file is not in the proper format. Please check that your file is in Phylip standard interleaved (or sequential) format ")
37392af48c37 Uploaded
izsam
parents:
diff changeset
206
37392af48c37 Uploaded
izsam
parents:
diff changeset
207 def pf(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
208 num = int(self.input[0].split()[0])
37392af48c37 Uploaded
izsam
parents:
diff changeset
209 lun = float(len(self.input))
37392af48c37 Uploaded
izsam
parents:
diff changeset
210 spia = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
211 if (lun-1)/num == 1.0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
212 spia = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
213 if spia == 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
214 for riga in self.input[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
215 for ele in range(int(lun-1)):
37392af48c37 Uploaded
izsam
parents:
diff changeset
216 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
217 self.output.write(">" + self.input[ele+1][:10] + "\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
218 for char in self.input[ele+1][10:].strip().replace(" ",""):
37392af48c37 Uploaded
izsam
parents:
diff changeset
219 self.output.write(char)
37392af48c37 Uploaded
izsam
parents:
diff changeset
220 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
221 if cont%80.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
222 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
223 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
224 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
225 if len(self.input[1])<=11:
37392af48c37 Uploaded
izsam
parents:
diff changeset
226 interm = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
227 for riga in self.input[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
228 if riga == "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
229 interm += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
230 if (self.input.index(riga)+interm)%2 == 0 and riga != "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
231 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
232 for char in riga.strip().replace(" ",""):
37392af48c37 Uploaded
izsam
parents:
diff changeset
233 self.output.write(char)
37392af48c37 Uploaded
izsam
parents:
diff changeset
234 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
235 if cont%80.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
236 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
237 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
238 elif (self.input.index(riga)+interm)%2 != 0 and riga != "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
239 self.output.write(">" + riga[:10] + "\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
240 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
241 try:
37392af48c37 Uploaded
izsam
parents:
diff changeset
242 diz = {}
37392af48c37 Uploaded
izsam
parents:
diff changeset
243 volta = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
244 for riga in self.input[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
245 if self.input.index(riga) in range(num+1):
37392af48c37 Uploaded
izsam
parents:
diff changeset
246 numriga = self.input.index(riga)
37392af48c37 Uploaded
izsam
parents:
diff changeset
247 diz[self.input.index(riga)] = [self.input[numriga][:10],self.input[numriga][10:].strip().replace(" ","")]
37392af48c37 Uploaded
izsam
parents:
diff changeset
248 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
249 if riga == "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
250 volta += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
251 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
252 numriga = self.input.index(riga)
37392af48c37 Uploaded
izsam
parents:
diff changeset
253 prima = diz[numriga - ((num+1)*volta)][1] + self.input[self.input.index(riga)].strip().replace(" ","")
37392af48c37 Uploaded
izsam
parents:
diff changeset
254 diz[numriga - ((num+1)*volta)] = [diz[numriga - ((num+1)*volta)][0],prima]
37392af48c37 Uploaded
izsam
parents:
diff changeset
255 for elemento in diz.keys():
37392af48c37 Uploaded
izsam
parents:
diff changeset
256 self.output.write(">" + diz[elemento][0] + '\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
257 con = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
258 for char in diz[elemento][1]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
259 self.output.write(char)
37392af48c37 Uploaded
izsam
parents:
diff changeset
260 con += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
261 if con%80 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
262 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
263 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
264 except:
37392af48c37 Uploaded
izsam
parents:
diff changeset
265 sys.exit("The input file is not in the proper format. Please check that your file is in Phylip standard interleaved (or sequential) format ")
37392af48c37 Uploaded
izsam
parents:
diff changeset
266
37392af48c37 Uploaded
izsam
parents:
diff changeset
267 def nf(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
268 try:
37392af48c37 Uploaded
izsam
parents:
diff changeset
269 diz = {}
37392af48c37 Uploaded
izsam
parents:
diff changeset
270 spia = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
271 for riga in self.input:
37392af48c37 Uploaded
izsam
parents:
diff changeset
272 if "MATRIX" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
273 spia = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
274 if spia == 1 and "MATRIX" not in riga and riga != "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
275 if riga.split()[0] not in diz.keys():
37392af48c37 Uploaded
izsam
parents:
diff changeset
276 diz[riga.split()[0]] = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
277 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
278 for ele in riga.split()[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
279 diz[riga.split()[0]] = diz[riga.split()[0]] + ele.strip()
37392af48c37 Uploaded
izsam
parents:
diff changeset
280 for elemento in diz.keys():
37392af48c37 Uploaded
izsam
parents:
diff changeset
281 self.output.write(">" + elemento + '\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
282 con = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
283 for char in diz[elemento]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
284 self.output.write(char)
37392af48c37 Uploaded
izsam
parents:
diff changeset
285 con += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
286 if con%80 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
287 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
288 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
289 except:
37392af48c37 Uploaded
izsam
parents:
diff changeset
290 sys.exit("The input file is not in Nexus format. ")
37392af48c37 Uploaded
izsam
parents:
diff changeset
291
37392af48c37 Uploaded
izsam
parents:
diff changeset
292 def np(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
293 try:
37392af48c37 Uploaded
izsam
parents:
diff changeset
294 diz = {}
37392af48c37 Uploaded
izsam
parents:
diff changeset
295 spia = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
296 for riga in self.input:
37392af48c37 Uploaded
izsam
parents:
diff changeset
297 if "MATRIX" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
298 spia = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
299 if spia == 1 and "MATRIX" not in riga and riga != "\n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
300 if riga.split()[0] not in diz.keys():
37392af48c37 Uploaded
izsam
parents:
diff changeset
301 diz[riga.split()[0]] = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
302 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
303 for ele in riga.split()[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
304 diz[riga.split()[0]] = diz[riga.split()[0]] + ele.strip()
37392af48c37 Uploaded
izsam
parents:
diff changeset
305 num = str(len(diz.keys()))
37392af48c37 Uploaded
izsam
parents:
diff changeset
306 lun = str(len(diz.values()[0]))
37392af48c37 Uploaded
izsam
parents:
diff changeset
307 self.output.write(num + '\t' + lun + '\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
308 for elemento in diz.keys():
37392af48c37 Uploaded
izsam
parents:
diff changeset
309 if elemento >= 10:
37392af48c37 Uploaded
izsam
parents:
diff changeset
310 nome = elemento[:10] + '\t'
37392af48c37 Uploaded
izsam
parents:
diff changeset
311 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
312 nome = elemento + "_"*(10-len(elemento)) + '\t'
37392af48c37 Uploaded
izsam
parents:
diff changeset
313 self.output.write(nome + diz[elemento] + '\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
314 except:
37392af48c37 Uploaded
izsam
parents:
diff changeset
315 sys.exit("The input file is not in Nexus format. ")
37392af48c37 Uploaded
izsam
parents:
diff changeset
316
37392af48c37 Uploaded
izsam
parents:
diff changeset
317
37392af48c37 Uploaded
izsam
parents:
diff changeset
318 def fg(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
319 count = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
320 fasta = []
37392af48c37 Uploaded
izsam
parents:
diff changeset
321 for riga in self.input:
37392af48c37 Uploaded
izsam
parents:
diff changeset
322 count += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
323 if ">" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
324 f = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
325 p = self.input.index(riga,count-1)
37392af48c37 Uploaded
izsam
parents:
diff changeset
326 c = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
327 y = riga[1:-1].replace(" ","_")
37392af48c37 Uploaded
izsam
parents:
diff changeset
328 f = f + y + '\t'
37392af48c37 Uploaded
izsam
parents:
diff changeset
329 try:
37392af48c37 Uploaded
izsam
parents:
diff changeset
330 while ">" not in self.input[p+c]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
331 f = f + (self.input[p+c].strip())
37392af48c37 Uploaded
izsam
parents:
diff changeset
332 c += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
333 except:
37392af48c37 Uploaded
izsam
parents:
diff changeset
334 pass
37392af48c37 Uploaded
izsam
parents:
diff changeset
335 fasta.append(f)
37392af48c37 Uploaded
izsam
parents:
diff changeset
336 for seq in fasta:
37392af48c37 Uploaded
izsam
parents:
diff changeset
337 lun = str(len(seq.split("\t")[1]))
37392af48c37 Uploaded
izsam
parents:
diff changeset
338 self.output.write("LOCUS\t%s\t%s bp\nORIGIN\n"%(seq.split("\t")[0],lun))
37392af48c37 Uploaded
izsam
parents:
diff changeset
339 porzioni = int(lun)/60
37392af48c37 Uploaded
izsam
parents:
diff changeset
340 cont = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
341 for volte in range(porzioni):
37392af48c37 Uploaded
izsam
parents:
diff changeset
342 part = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
343 self.output.write(str(cont+1) + "\t")
37392af48c37 Uploaded
izsam
parents:
diff changeset
344 for chara in seq.split("\t")[1][volte*60:(volte+1)*60]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
345 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
346 part = part + chara
37392af48c37 Uploaded
izsam
parents:
diff changeset
347 if cont%10.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
348 part = part + " "
37392af48c37 Uploaded
izsam
parents:
diff changeset
349 self.output.write(part)
37392af48c37 Uploaded
izsam
parents:
diff changeset
350 self.output.write("\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
351 self.output.write(str(cont+1) + "\t")
37392af48c37 Uploaded
izsam
parents:
diff changeset
352 part = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
353 for chara in seq.split("\t")[1][(volte+1)*60:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
354 cont += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
355 part = part + chara
37392af48c37 Uploaded
izsam
parents:
diff changeset
356 if cont%10.0 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
357 part = part + " "
37392af48c37 Uploaded
izsam
parents:
diff changeset
358 self.output.write(part)
37392af48c37 Uploaded
izsam
parents:
diff changeset
359 self.output.write("\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
360 self.output.write("//\n\n")
37392af48c37 Uploaded
izsam
parents:
diff changeset
361
37392af48c37 Uploaded
izsam
parents:
diff changeset
362 def gf(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
363 for riga in self.input:
37392af48c37 Uploaded
izsam
parents:
diff changeset
364 if "LOCUS" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
365 nome = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
366 spia = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
367 len = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
368 seq = ""
37392af48c37 Uploaded
izsam
parents:
diff changeset
369 part = riga.split()
37392af48c37 Uploaded
izsam
parents:
diff changeset
370 for ele in part:
37392af48c37 Uploaded
izsam
parents:
diff changeset
371 if "bp" in ele:
37392af48c37 Uploaded
izsam
parents:
diff changeset
372 len = str(riga.index(ele)-1)
37392af48c37 Uploaded
izsam
parents:
diff changeset
373 nome = part[1] + '\t'
37392af48c37 Uploaded
izsam
parents:
diff changeset
374 if "DEFINITION" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
375 part = riga.split()
37392af48c37 Uploaded
izsam
parents:
diff changeset
376 for ele in part[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
377 nome = nome + ele + ' '
37392af48c37 Uploaded
izsam
parents:
diff changeset
378 if "ORIGIN" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
379 spia = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
380 if spia == 1 and "ORIGIN" not in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
381 part = riga.split()
37392af48c37 Uploaded
izsam
parents:
diff changeset
382 for ele in part[1:]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
383 seq = seq + ele.strip()
37392af48c37 Uploaded
izsam
parents:
diff changeset
384 if "//" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
385 self.output.write(">" + nome + '\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
386 con = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
387 for char in seq:
37392af48c37 Uploaded
izsam
parents:
diff changeset
388 self.output.write(char)
37392af48c37 Uploaded
izsam
parents:
diff changeset
389 con += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
390 if con%80 == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
391 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
392 self.output.write('\n')
37392af48c37 Uploaded
izsam
parents:
diff changeset
393 spia = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
394
37392af48c37 Uploaded
izsam
parents:
diff changeset
395 class check_fileformat:
37392af48c37 Uploaded
izsam
parents:
diff changeset
396 def __init__(self,inouttype,input):
37392af48c37 Uploaded
izsam
parents:
diff changeset
397 self.intype = inouttype[0]
37392af48c37 Uploaded
izsam
parents:
diff changeset
398 self.infile = input
37392af48c37 Uploaded
izsam
parents:
diff changeset
399 def single(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
400 if self.intype == "f":
37392af48c37 Uploaded
izsam
parents:
diff changeset
401 count = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
402 for riga in self.infile:
37392af48c37 Uploaded
izsam
parents:
diff changeset
403 if riga[0] == ">":
37392af48c37 Uploaded
izsam
parents:
diff changeset
404 count += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
405 if count == 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
406 if len(self.infile) < 2:
37392af48c37 Uploaded
izsam
parents:
diff changeset
407 sys.exit("The input file is not in fasta format. Please check that the first row starts with > and that the sequence starts from the second line")
37392af48c37 Uploaded
izsam
parents:
diff changeset
408 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
409 return "ok"
37392af48c37 Uploaded
izsam
parents:
diff changeset
410 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
411 if count >1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
412 sys.exit("The input file is a multi-fasta file. Please resubmit the job using the 'multi sequence' option")
37392af48c37 Uploaded
izsam
parents:
diff changeset
413 if count == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
414 sys.exit("The input file is not in fasta format. Please check that the first row starts with > and that the sequence starts from the second line")
37392af48c37 Uploaded
izsam
parents:
diff changeset
415 if self.intype == "g":
37392af48c37 Uploaded
izsam
parents:
diff changeset
416 locus = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
417 origin = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
418 end = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
419 lun = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
420 for riga in self.infile:
37392af48c37 Uploaded
izsam
parents:
diff changeset
421 if "LOCUS" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
422 locus = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
423 if "ORIGIN" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
424 origin = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
425 elif origin == 1 and len(riga.split()) >= 7:
37392af48c37 Uploaded
izsam
parents:
diff changeset
426 lun = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
427 if "//" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
428 end = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
429 if locus == 0 or origin == 0 or end == 0 or lun == 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
430 sys.exit("The input file is not in GenBank format. Please make sure that the file contains at least the LOCUS and ORIGIN fields. The file must also ends with //")
37392af48c37 Uploaded
izsam
parents:
diff changeset
431 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
432 return "ok"
37392af48c37 Uploaded
izsam
parents:
diff changeset
433 def multi(self):
37392af48c37 Uploaded
izsam
parents:
diff changeset
434 if self.intype == "p":
37392af48c37 Uploaded
izsam
parents:
diff changeset
435 if len(self.infile[0].split()) == 2 or len(self.infile[0].split()) == 3:
37392af48c37 Uploaded
izsam
parents:
diff changeset
436 if int(self.infile[0].split()[0]) > 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
437 return "ok"
37392af48c37 Uploaded
izsam
parents:
diff changeset
438 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
439 sys.exit("There is only one sequence in the file")
37392af48c37 Uploaded
izsam
parents:
diff changeset
440 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
441 sys.exit("the input file is not in phylip format.")
37392af48c37 Uploaded
izsam
parents:
diff changeset
442 if self.intype == "n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
443 begin = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
444 matrix = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
445 ntax = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
446 if "#NEXUS" in self.infile[0]:
37392af48c37 Uploaded
izsam
parents:
diff changeset
447 for riga in self.infile:
37392af48c37 Uploaded
izsam
parents:
diff changeset
448 if "begin data;" in riga.lower():
37392af48c37 Uploaded
izsam
parents:
diff changeset
449 begin = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
450 if "matrix" in riga.lower():
37392af48c37 Uploaded
izsam
parents:
diff changeset
451 matrix = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
452 if "ntax" in riga.lower():
37392af48c37 Uploaded
izsam
parents:
diff changeset
453 r = riga.split()
37392af48c37 Uploaded
izsam
parents:
diff changeset
454 ntax = int(r[1][5:])
37392af48c37 Uploaded
izsam
parents:
diff changeset
455 if begin==1 and matrix == 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
456 return "ok"
37392af48c37 Uploaded
izsam
parents:
diff changeset
457 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
458 sys.exit("the input file is not in nexus format.")
37392af48c37 Uploaded
izsam
parents:
diff changeset
459 if ntax <= 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
460 sys.exit("There is only one sequence in the file")
37392af48c37 Uploaded
izsam
parents:
diff changeset
461 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
462 sys.exit("the input file is not in nexus format.")
37392af48c37 Uploaded
izsam
parents:
diff changeset
463 if self.intype == "f":
37392af48c37 Uploaded
izsam
parents:
diff changeset
464 count = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
465 for riga in self.infile:
37392af48c37 Uploaded
izsam
parents:
diff changeset
466 if riga[0] == ">":
37392af48c37 Uploaded
izsam
parents:
diff changeset
467 count += 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
468 if count > 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
469 if len(self.infile) < 4:
37392af48c37 Uploaded
izsam
parents:
diff changeset
470 sys.exit("The input file is not in fasta format. Please check that the first row starts with > and that the sequence starts from the second line")
37392af48c37 Uploaded
izsam
parents:
diff changeset
471 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
472 return "ok"
37392af48c37 Uploaded
izsam
parents:
diff changeset
473 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
474 if count == 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
475 sys.exit("The input file is a single-fasta file. Please resubmit the job using the 'single sequence' option")
37392af48c37 Uploaded
izsam
parents:
diff changeset
476 if count == 0:
37392af48c37 Uploaded
izsam
parents:
diff changeset
477 sys.exit("The input file is not in fasta format. Please check that the first row starts with > and that the sequence starts from the second line")
37392af48c37 Uploaded
izsam
parents:
diff changeset
478 if self.intype == "g":
37392af48c37 Uploaded
izsam
parents:
diff changeset
479 locus = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
480 origin = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
481 end = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
482 lun = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
483 for riga in self.infile:
37392af48c37 Uploaded
izsam
parents:
diff changeset
484 if "LOCUS" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
485 locus = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
486 if "ORIGIN" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
487 origin = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
488 if origin == 1 and len(riga.split()) >= 7:
37392af48c37 Uploaded
izsam
parents:
diff changeset
489 lun = 0
37392af48c37 Uploaded
izsam
parents:
diff changeset
490 if "//" in riga:
37392af48c37 Uploaded
izsam
parents:
diff changeset
491 end = 1
37392af48c37 Uploaded
izsam
parents:
diff changeset
492 if locus == 0 or origin == 0 or end == 0 or lun == 1:
37392af48c37 Uploaded
izsam
parents:
diff changeset
493 sys.exit("The input file is not in GenBank format. Please make sure that the file contains at least the LOCUS and ORIGIN fields. The file must also ends with //")
37392af48c37 Uploaded
izsam
parents:
diff changeset
494 else:
37392af48c37 Uploaded
izsam
parents:
diff changeset
495 return "ok"
37392af48c37 Uploaded
izsam
parents:
diff changeset
496
37392af48c37 Uploaded
izsam
parents:
diff changeset
497
37392af48c37 Uploaded
izsam
parents:
diff changeset
498 def main(input,output,inouttype,type):
37392af48c37 Uploaded
izsam
parents:
diff changeset
499 check = check_fileformat(inouttype,input)
37392af48c37 Uploaded
izsam
parents:
diff changeset
500 if type == "single":
37392af48c37 Uploaded
izsam
parents:
diff changeset
501 c = check.single()
37392af48c37 Uploaded
izsam
parents:
diff changeset
502 if c == "ok":
37392af48c37 Uploaded
izsam
parents:
diff changeset
503 conv = convertitori(input,inouttype,type,output)
37392af48c37 Uploaded
izsam
parents:
diff changeset
504 if inouttype == "f-g":
37392af48c37 Uploaded
izsam
parents:
diff changeset
505 conv.fg()
37392af48c37 Uploaded
izsam
parents:
diff changeset
506 if inouttype == "g-f":
37392af48c37 Uploaded
izsam
parents:
diff changeset
507 conv.gf()
37392af48c37 Uploaded
izsam
parents:
diff changeset
508 if type == "multi":
37392af48c37 Uploaded
izsam
parents:
diff changeset
509 c = check.multi()
37392af48c37 Uploaded
izsam
parents:
diff changeset
510 if c == "ok":
37392af48c37 Uploaded
izsam
parents:
diff changeset
511 conv = convertitori(input,inouttype,type,output)
37392af48c37 Uploaded
izsam
parents:
diff changeset
512 if inouttype == "f-g":
37392af48c37 Uploaded
izsam
parents:
diff changeset
513 conv.fg()
37392af48c37 Uploaded
izsam
parents:
diff changeset
514 if inouttype == "g-f":
37392af48c37 Uploaded
izsam
parents:
diff changeset
515 conv.gf()
37392af48c37 Uploaded
izsam
parents:
diff changeset
516 if inouttype == "f-p":
37392af48c37 Uploaded
izsam
parents:
diff changeset
517 conv.fp()
37392af48c37 Uploaded
izsam
parents:
diff changeset
518 if inouttype == "f-n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
519 conv.fn()
37392af48c37 Uploaded
izsam
parents:
diff changeset
520 if inouttype == "p-f":
37392af48c37 Uploaded
izsam
parents:
diff changeset
521 conv.pf()
37392af48c37 Uploaded
izsam
parents:
diff changeset
522 if inouttype == "p-n":
37392af48c37 Uploaded
izsam
parents:
diff changeset
523 conv.pn()
37392af48c37 Uploaded
izsam
parents:
diff changeset
524 if inouttype == "n-p":
37392af48c37 Uploaded
izsam
parents:
diff changeset
525 conv.np()
37392af48c37 Uploaded
izsam
parents:
diff changeset
526 if inouttype == "n-f":
37392af48c37 Uploaded
izsam
parents:
diff changeset
527 conv.nf()
37392af48c37 Uploaded
izsam
parents:
diff changeset
528 output.close()
37392af48c37 Uploaded
izsam
parents:
diff changeset
529
37392af48c37 Uploaded
izsam
parents:
diff changeset
530 if __name__ == "__main__" :
37392af48c37 Uploaded
izsam
parents:
diff changeset
531 input = open(sys.argv[1],"r").readlines()
37392af48c37 Uploaded
izsam
parents:
diff changeset
532 output = open(sys.argv[2],"a")
37392af48c37 Uploaded
izsam
parents:
diff changeset
533 inouttype = sys.argv[3]
37392af48c37 Uploaded
izsam
parents:
diff changeset
534 type = sys.argv[4]
37392af48c37 Uploaded
izsam
parents:
diff changeset
535 main(input,output,inouttype,type)