annotate mytools/seqshuffle.py @ 7:f0dc65e7f6c0

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