예제 #1
0
파일: colors.py 프로젝트: jb2263/qiime
def taxonomy_color_prefs_and_map_data_from_options(options):
    """Returns color prefs and counts data based on options.
       counts data is any file in a format that can be parsed by parse_otu_table  
    """
    data = {}
    data['counts'] = {}
    taxonomy_levels = []

    #need to set some other way from sample ids
    #Determine which mapping headers to color by, if none given, color by \
    #Sample ID's
    taxonomy_count_files = options.counts_fname
    for f in taxonomy_count_files:
        try:
            counts_f = open(f, 'U').readlines()
        except (TypeError, IOError):
            raise MissingFileError, 'Counts file required for this analysis'
        sample_ids, otu_ids, otu_table = \
                       parse_taxa_summary_table(counts_f)

        data['counts'][f] = (sample_ids, otu_ids, otu_table)
        level = max([len(t.split(';')) - 1 for t in otu_ids])

        taxonomy_levels.append(str(level))

    if options.prefs_path:
        prefs = eval(open(options.prefs_path, 'U').read())
        color_prefs=taxonomy_process_prefs(taxonomy_levels, \
                                                prefs['taxonomy_coloring'])

        if prefs.has_key('background_color'):
            background_color= prefs['background_color']
        else:
            background_color='black'
    else:
        background_color='black'
        color_prefs=taxonomy_process_prefs(taxonomy_levels, None)

    if options.prefs_path and options.background_color:
        background_color=options.background_color
    elif options.background_color:
        background_color=options.background_color

    if background_color=='black':
        label_color='white'
    else:
        label_color='black'
    return color_prefs,data,background_color,label_color
예제 #2
0
파일: colors.py 프로젝트: johnchase/qiime
def taxonomy_color_prefs_and_map_data_from_options(options):
    """Returns color prefs and counts data based on options.
       counts data is any file in a format that can be parsed by parse_otu_table
    """
    data = {}
    data["counts"] = {}
    taxonomy_levels = []

    # need to set some other way from sample ids
    # Determine which mapping headers to color by, if none given, color by \
    # Sample ID's
    taxonomy_count_files = options.counts_fname
    for f in taxonomy_count_files:
        try:
            counts_f = open(f, "U").readlines()
        except (TypeError, IOError):
            raise MissingFileError("Counts file required for this analysis")
        sample_ids, otu_ids, otu_table = parse_taxa_summary_table(counts_f)

        data["counts"][f] = (sample_ids, otu_ids, otu_table)
        level = max([len(t.split(";")) - 1 for t in otu_ids])

        taxonomy_levels.append(str(level))

    if options.prefs_path:
        prefs = eval(open(options.prefs_path, "U").read())
        color_prefs = taxonomy_process_prefs(taxonomy_levels, prefs["taxonomy_coloring"])

        if "background_color" in prefs:
            background_color = prefs["background_color"]
        else:
            background_color = "black"
    else:
        background_color = "black"
        color_prefs = taxonomy_process_prefs(taxonomy_levels, None)

    if options.prefs_path and options.background_color:
        background_color = options.background_color
    elif options.background_color:
        background_color = options.background_color

    if background_color == "black":
        label_color = "white"
    else:
        label_color = "black"
    return color_prefs, data, background_color, label_color