Created
July 20, 2012 02:14
-
-
Save gregcaporaso/3148235 to your computer and use it in GitHub Desktop.
Quick-and-dirty script to take combined bl6 file and split it into per-metagenome bl6 files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# File created on 19 Jul 2012 | |
from __future__ import division | |
__author__ = "Greg Caporaso" | |
__copyright__ = "Copyright 2011, The QIIME project" | |
__credits__ = ["Greg Caporaso"] | |
__license__ = "GPL" | |
__version__ = "1.5.0-dev" | |
__maintainer__ = "Greg Caporaso" | |
__email__ = "[email protected]" | |
__status__ = "Development" | |
from os.path import join | |
from cogent.util.misc import create_dir | |
from qiime.util import parse_command_line_parameters, make_option, gzip_open | |
script_info = {} | |
script_info['brief_description'] = "Quick-and-dirty script to take combined bl6 file and split it into per-metagenome bl6 files." | |
script_info['script_description'] = "" | |
script_info['script_usage'] = [("","","")] | |
script_info['output_description']= "" | |
script_info['required_options'] = [ | |
make_option('-i','--input_fp',type="existing_filepath",help='the input filepath'),\ | |
make_option('-o','--output_dir',type="new_dirpath",help='the output directory'),\ | |
] | |
script_info['optional_options'] = [] | |
script_info['version'] = __version__ | |
def qiime_to_humann(bl6_lines,output_dir): | |
output_fs = {} | |
for line in bl6_lines: | |
id_ = line.split('_')[0] | |
try: | |
f = output_fs[id_] | |
except KeyError: | |
output_fs[id_] = open(join(output_dir,'%s.bl6' % id_),'w') | |
f = output_fs[id_] | |
f.write(line) | |
for e in output_fs.values(): | |
e.close() | |
def main(): | |
option_parser, opts, args =\ | |
parse_command_line_parameters(**script_info) | |
print "WARNING: This script is untested! Use at your own risk!" | |
create_dir(opts.output_dir) | |
if opts.input_fp.endswith('.gz'): | |
qiime_to_humann(gzip_open(opts.input_fp),opts.output_dir) | |
else: | |
qiime_to_humann(open(opts.input_fp,'U'),opts.output_dir) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment