comparison seq_shuffle_dinucleotide.py @ 2:e72172a0a429 default tip

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