annotate splitFasta.py @ 3:7439ffbd8943 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/hacked/splitFasta commit 9ffd40a178fb3aa8fff618f95d8b3fd7bf58240d
author rnateam
date Wed, 08 Jul 2015 06:23:46 -0400
parents bc25ba9d9fcf
children ae4d5733272f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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()