annotate seqshuffle.py @ 15:0e221dbd17b2 default tip

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