annotate seqshuffle.py @ 13:292186c14b08

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