def __perform_normalization(self, normalization_type, musicc_intra='use_generic'):
     """ Normalizes the data in the metagenomic profile of this test block.
     """
     mgprofile = self.block.metagenomic_profile
     if normalization_type == "relative":
         normalization.relative_normalization(mgprofile, self.new_dir)
     elif normalization_type == "musicc":
         normalization.musicc_normalization(mgprofile, self.block.gen_params['abundance_data'], 
                                            self.new_dir, musicc_intra=musicc_intra)
示例#2
0
 def __perform_normalization(self,
                             normalization_type,
                             musicc_intra='use_generic'):
     """ Normalizes the data in the metagenomic profile of this test block.
     """
     mgprofile = self.block.metagenomic_profile
     if normalization_type == "relative":
         normalization.relative_normalization(mgprofile, self.new_dir)
     elif normalization_type == "musicc":
         normalization.musicc_normalization(
             mgprofile,
             self.block.gen_params['abundance_data'],
             self.new_dir,
             musicc_intra=musicc_intra)
示例#3
0
def main():
    """ Main script for running comparative analysis from the command line.
    """    
    
    tests, genparams = parse(filename)      
    
    # dictionary to hold tests and test results
    test_results = dict() 
    
    abundance_sep = genparams['abundance_sep']
    metadata_sep = genparams['metadata_sep']
    abundance_data_path = genparams["abundance_data"]
    metadata_path = genparams["sample_metadata"]
    metadata_hdr = genparams["metadata_header"]
    output_dir = genparams["output_directory"]
    lbl = genparams["class_label"]
    class_names = genparams["class_names"]
    
    # give each test block a copy of the profile
    
    run_order = list()
    
    master_mp = mgp.metagenomic_profile(abundance_data_path, metadata_path, a_sep=abundance_sep, 
                                     m_sep=metadata_sep, metadata_header=metadata_hdr, metadata_label=lbl,
                                     class_names=class_names)
                                     
    if genparams["normalization"] == "relative":
        normalization.relative_normalization(master_mp, output_dir)
    elif genparams["normalization"] == "musicc":
        normalization.musicc_normalization(master_mp, abundance_data_path, output_dir)        
    
    for tb in tests:
         
        tb_class_names = tb.params["class_names"] if "class_names" in list(tb.params.keys()) else genparams["class_names"] 
        if "class_label" in tb.params:
            lbl = tb.params["class_label"]
        
        rules = tb.params["filter_rules"] if "filter_rules" in tb.params else None
        labels = tb.params["filter_labels"] if "filter_labels" in tb.params else None
        mp = mgp.metagenomic_profile(abundance_data_path, metadata_path, a_sep=abundance_sep, 
                                     m_sep=metadata_sep, metadata_header=metadata_hdr, metadata_label=lbl,
                                     class_names=tb_class_names, filter_rules=rules, filter_labels=labels)
                                     
        if "feature_metadata" in list(genparams.keys()):
            mp.add_feature_metadata(genparams["feature_metadata"])
        tb.set_metagenomic_profile(mp)
        
        # work around for plug-in issues
        if "area_plot" in tb.params:
            run_order.insert(0, tb)
        else:
            run_order.append(tb)
    
    # Copy parameters file to new directory.
    shutil.copyfile(filename, output_dir + "/" + filename)    
    
    os.chdir(output_dir)
    
    # Call run on each test.
    for tb in run_order:
        result = tb.run()
        test_results[tb] = result
    try:
        if genparams["to_html"][0] == "t":    
            results_web_page = generate_html.create_page(test_results, output_dir, filename, order=tests)
            try:            
                if genparams["open_page"][0] == "t":
                    webbrowser.open(results_web_page)
            except IndexError:
                print("Warning: HTML page could not be opened. Value for 'open_page' missing in parameters file.")
    except IndexError:
        print("Warning: HTML page could not be created. Value for 'to_html' missing in parameters file.")
        
    # Done
    print("Tests complete.")
    print(("Output saved at " + genparams["output_directory"]))