comparison tools/mytools/shuffleSequenceUsingAltschulErikson.txt @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9071e359b9a3
1 #! /usr/bin/env python
2
3 #shuffleSequenceUsingAltschulErikson.py
4 #P. Clote, Oct 2003
5
6 #------------------------------------------------------------------
7 #Input RNAs in FASTA file, and compute NUM many shufflings of RNA sequence
8 #using Altman-Erikson randomly shuffled dinucleotide method.
9 #------------------------------------------------------------------
10
11 PRINT = 0
12 LINELEN = 70
13
14 import sys,os,stats,string
15 from altschulEriksonDinuclShuffle import dinuclShuffle
16 import computeRNAfoldEnergyForRNAsInFile
17
18
19
20
21 def file2string(fileName):
22 file = open(fileName,"r")
23 L = []
24 line = file.readline()
25 while line:
26 while line[0]==">": # treat lines beginning with '>' as comment and skip
27 line = file.readline()
28 continue
29 else:
30 line = line[:-1]
31 L.append(line)
32 line = file.readline()
33 text = string.join(L,"")
34 return text
35
36
37 def main(fileName,NUM):
38 seq = file2string(fileName)
39 for i in range(NUM):
40 shuffledSeq = dinuclShuffle(seq)
41 sys.stdout.write(">%d\n" % (i+1))
42 sys.stdout.write("%s\n" % shuffledSeq)
43
44
45
46
47 if __name__ == '__main__':
48 if len(sys.argv) < 3 :
49 print "Usage: %s RNAs.faa NUM" % sys.argv[0]
50 text = """
51 1) RNA.faa is FASTA file of ONE RNA sequence
52 2) NUM is number of random sequences to generate by
53 shuffling the dinucleotides of RNAs input
54 Script to compute Altman-Erikson randomly shuffled dinucleotides.
55 """
56 print text
57 sys.exit(1)
58 fileName = sys.argv[1]
59 NUM = int(sys.argv[2])
60 main(fileName,NUM)
61