Exemplo n.º 1
0
def main():
    option_parser, opts, args =\
        parse_command_line_parameters(**script_info)

    if isdir(opts.otu_table_fp):
        ret_code = create_dir(opts.output_fp, fail_on_exist=False)
        # run on each file in dir
        for fp in glob(opts.otu_table_fp + '/*biom'):
            parent_dir_name, file_name = split(fp)
            basename, extension = splitext(file_name)
            out_fp = opts.output_fp + "/" + basename + "_shared_OTUs.txt"

            with open(out_fp, 'w') as out_fh:
                out_fh.write(calc_shared_phylotypes(load_table(fp),
                                                    opts.reference_sample))
    else:
        # run in single file mode
        try:
            out_fh = open(opts.output_fp, "w")
        except IOError as message:
            exit(("Can't open output file %s for writing. Check the "
                  "permissions or existing directory with identical "
                  "name.\n%s") % (opts.output_fp, message))
        out_fh.write(calc_shared_phylotypes(load_table(opts.otu_table_fp),
                                            opts.reference_sample))
Exemplo n.º 2
0
def main():
    option_parser, opts, args =\
        parse_command_line_parameters(**script_info)

    if isdir(opts.otu_table_fp):
        ret_code = create_dir(opts.output_fp, fail_on_exist=False)
        # run on each file in dir
        for fp in glob(opts.otu_table_fp + '/*biom'):
            parent_dir_name, file_name = split(fp)
            basename, extension = splitext(file_name)
            out_fp = opts.output_fp + "/" + basename + "_shared_OTUs.txt"

            with open(out_fp, 'w') as out_fh:
                out_fh.write(
                    calc_shared_phylotypes(load_table(fp),
                                           opts.reference_sample))
    else:
        # run in single file mode
        try:
            out_fh = open(opts.output_fp, "w")
        except IOError as message:
            exit(("Can't open output file %s for writing. Check the "
                  "permissions or existing directory with identical "
                  "name.\n%s") % (opts.output_fp, message))
        out_fh.write(
            calc_shared_phylotypes(load_table(opts.otu_table_fp),
                                   opts.reference_sample))
Exemplo n.º 3
0
    def test_calc_shared_phylotypes(self):
        """calc_shared_phylotypes computes correct matrix"""
        
        observed = calc_shared_phylotypes(self.biom_as_string)
        expected = """\tS1\tS2\tS3
S1\t5\t2\t3
S2\t2\t2\t1
S3\t3\t1\t3\n"""
        self.assertEqual(observed, expected)
Exemplo n.º 4
0
    def test_calc_shared_phylotypes(self):
        """calc_shared_phylotypes computes correct matrix"""

        observed = calc_shared_phylotypes(self.biom_as_string)
        expected = """\tS1\tS2\tS3
S1\t5\t2\t3
S2\t2\t2\t1
S3\t3\t1\t3\n"""
        self.assertEqual(observed, expected)
Exemplo n.º 5
0
def main():
    option_parser, opts, args =\
       parse_command_line_parameters(**script_info)

    if exists(opts.output_fp) and not opts.force_overwrite:
        exit("Output file already exists. Choose another output "
             +"filename or use options --force_overwrite")
    
    if isdir(opts.otu_table_fp):
        ret_code = create_dir(opts.output_fp, fail_on_exist=False)
        if ret_code != 0:
            if ret_code==1 and opts.force_overwrite:
                #dir exists, ovewrite
                pass
            else:    
                exit("Failed to make output dir, Check permissions and "
                     +"check for file with identical name")
        #run on each file in dir
        for fp in glob(opts.otu_table_fp +'/*'):
            parent_dir_name, file_name = split(fp)
            basename, extension = splitext(file_name)
            out_fp = opts.output_fp +"/"+basename+"_shared_OTUs.txt"
            out_fh = open(out_fp, "w")
            
            out_fh.write(calc_shared_phylotypes(open(fp, "U"),
                                        opts.reference_sample))
            out_fh.close()
    else:
        #run in single file mode
        try:
            out_fh = open(opts.output_fp,"w")
        except IOError, message:
            exit(("Can't open output file %s for writing. Check the permissions "\
                     +"or existing directory with identical name.\n%s")
                 % (opts.output_fp,message))
        out_fh.write(calc_shared_phylotypes(open(opts.otu_table_fp, "U"),
                                            opts.reference_sample))