annotate tools/mytools/seqshuffle.py @ 2:c2a356708570

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:42 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 import sys
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 from altschulEriksonDinuclShuffle import *
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 def readFastaFile(infile,outfile):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 fin = open(infile)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 out = open(outfile,'w')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 currSeq=''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 currSeqname=None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 for line in fin:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 if '>' in line:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 if currSeqname !=None:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 out.write(currSeqname+dinuclShuffle(currSeq)+'\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 currSeqname=None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 currSeq=''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 currSeqname=line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 currSeq=currSeq+line.strip().upper()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 if currSeqname!=None:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 out.write(currSeqname+dinuclShuffle(currSeq)+'\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 fin.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 out.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 def readrawseq(infile,outfile):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 '''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 each line is a sequence
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 '''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 fin = open(infile)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 out = open(outfile,'w')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 for line in fin:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 out.write(dinuclShuffle(line.strip().upper())+'\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 fin.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 out.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 def main():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 seqfile = sys.argv[1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 outfile = sys.argv[2]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 fasta = sys.argv[3]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 if fasta == 'fasta':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 readFastaFile(seqfile,outfile)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 readrawseq(seqfile,outfile)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 main()