Mercurial > repos > rnateam > splitfasta
annotate splitFasta.py @ 1:279e2625de3a draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit b1d68befbbaf3a74a67eef3e44dc035eb1a1e555
author | rnateam |
---|---|
date | Sun, 05 Jul 2015 08:48:09 -0400 |
parents | bc25ba9d9fcf |
children | ae4d5733272f |
rev | line source |
---|---|
0
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
1 import sys, os |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
2 if __name__ == "__main__": |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
3 #assuming perfect input, read every two lines |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
4 inpath = sys.argv[1] |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
5 file_contents = open(inpath, 'r').readlines() |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
6 os.makedirs('splits') |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
7 inname = os.path.basename(inpath) |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
8 for i in range(0, len(file_contents), 2): |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
9 headline = file_contents[i] |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
10 outname = headline[1:headline.index(' ')]+'.fa' |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
11 outfile = open(os.path.join('splits',outname), 'w') |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
12 outfile.write(file_contents[i]) |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
13 outfile.write(file_contents[i+1]) |
bc25ba9d9fcf
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit fcd6ef7e59971abd6b6a3a5401f92bcdef6ef76c
rnateam
parents:
diff
changeset
|
14 outfile.close() |