annotate seq_shuffle_dinucleotide.py @ 2:e72172a0a429 default tip

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