Mercurial > repos > xuebing > seq_shuffle_dinucleotide
diff seq_shuffle_dinucleotide.py @ 2:e72172a0a429 default tip
Uploaded
author | xuebing |
---|---|
date | Sat, 31 Mar 2012 21:49:00 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/seq_shuffle_dinucleotide.py Sat Mar 31 21:49:00 2012 -0400 @@ -0,0 +1,49 @@ +import sys + +from altschulEriksonDinuclShuffle import * + +def readFastaFile(infile,outfile): + + fin = open(infile) + out = open(outfile,'w') + + currSeq='' + currSeqname=None + for line in fin: + if '>' in line: + if currSeqname !=None: + out.write(currSeqname+dinuclShuffle(currSeq)+'\n') + currSeqname=None + currSeq='' + currSeqname=line + else: + currSeq=currSeq+line.strip().upper() + + if currSeqname!=None: + out.write(currSeqname+dinuclShuffle(currSeq)+'\n') + + fin.close() + out.close() + +def readrawseq(infile,outfile): + ''' + each line is a sequence + ''' + fin = open(infile) + out = open(outfile,'w') + for line in fin: + out.write(dinuclShuffle(line.strip().upper())+'\n') + fin.close() + out.close() + +def main(): + seqfile = sys.argv[1] + outfile = sys.argv[2] + fasta = sys.argv[3] + + if fasta == 'fasta': + readFastaFile(seqfile,outfile) + else: + readrawseq(seqfile,outfile) + +main()