annotate mytools/seqshuffle.py @ 9:8cec2078632a

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