humann/tools/build_custom_database.py
def process_taxonomic_profile(taxonomic_profile, abundance_threshold):
    """ Store those genus which pass the threshold """
    
    # The taxonomic profile will be formatted like the metaphlan2 output file
    
    try:
        file_handle=open(taxonomic_profile, "rt")
    except EnvironmentError:
        sys.exit("ERROR: Unable to read taxonomic profile: " + taxonomic_profile)
        
    print("Reading taxonomic profile")
    genus_found=set()
    for line in file_handle:

        # search for the lines that have the genus-level information
        if re.search(GENUS_IDENTIFIER, line):
            # check threshold
            data=line.rstrip().split("\t")
            try:
                read_percent=float(data[1])
            except (IndexError, ValueError):
                read_percent=0
                
            if read_percent >= abundance_threshold:
                genus=list(filter(lambda x: GENUS_IDENTIFIER in x, data[0].split(TAXONOMY_DELIMITER)))[0].replace(GENUS_IDENTIFIER,"").lower()
                if not genus in genus_found:
                    print("Adding genus: " + genus)
                genus_found.add(genus)
        
    file_handle.close()
    
    return genus_found
 Store those genus which pass the threshold 
Store those genus which pass the threshold
Store those genus which pass the threshold
def process_taxonomic_profile(taxonomic_profile, abundance_threshold):
    try:
        file_handle=open(taxonomic_profile, "rt")
    except EnvironmentError:
        sys.exit("ERROR: Unable to read taxonomic profile: " + taxonomic_profile)
    print("Reading taxonomic profile")
    genus_found=set()
    for line in file_handle:
        if re.search(GENUS_IDENTIFIER, line):
            data=line.rstrip().split("\t")
            try:
                read_percent=float(data[1])
            except (IndexError, ValueError):
                read_percent=0
            if read_percent >= abundance_threshold:
                genus=list(filter(lambda x: GENUS_IDENTIFIER in x, data[0].split(TAXONOMY_DELIMITER)))[0].replace(GENUS_IDENTIFIER,"").lower()
                if not genus in genus_found:
                    print("Adding genus: " + genus)
                genus_found.add(genus)
    file_handle.close()
    return genus_found
def process_taxonomic_profile ( taxonomic_profile , abundance_threshold ) : try : file_handle = open ( taxonomic_profile , "rt" ) except EnvironmentError : sys . exit ( "ERROR: Unable to read taxonomic profile: " + taxonomic_profile ) print ( "Reading taxonomic profile" ) genus_found = set ( ) for line in file_handle : if re . search ( GENUS_IDENTIFIER , line ) : data = line . rstrip ( ) . split ( "\t" ) try : read_percent = float ( data [ 1 ] ) except ( IndexError , ValueError ) : read_percent = 0 if read_percent >= abundance_threshold : genus = list ( filter ( lambda x : GENUS_IDENTIFIER in x , data [ 0 ] . split ( TAXONOMY_DELIMITER ) ) ) [ 0 ] . replace ( GENUS_IDENTIFIER , "" ) . lower ( ) if not genus in genus_found : print ( "Adding genus: " + genus ) genus_found . add ( genus ) file_handle . close ( ) return genus_found
Store those genus which pass the threshold
Store those genus which pass the threshold
""" Store those genus which pass the threshold """ # The taxonomic profile will be formatted like the metaphlan2 output file # search for the lines that have the genus-level information # check threshold
taxonomic_profile
abundance_threshold