forked from brianpenghe/fasta-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shufflefasta.py
44 lines (35 loc) · 952 Bytes
/
shufflefasta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
##################################
# #
# Last modified 05/23/2011 #
# #
# Georgi Marinov #
# #
##################################
import sys
import string
import random
try:
import psyco
psyco.full()
except:
pass
def main(argv):
if len(argv) < 2:
print 'usage: python %s inputfilename outfilename' % argv[0]
sys.exit(1)
inputfilename = argv[1]
outputfilename = argv[2]
outfile = open(outputfilename, 'w')
listoflines = open(inputfilename)
for line in listoflines:
if line.startswith('>'):
outfile.write(line)
else:
sequence=line.strip()
s=list(sequence)
random.shuffle(s)
shuffled=''.join(s)
outfile.write(shuffled.upper()+'\n')
outfile.close()
if __name__ == '__main__':
main(sys.argv)