humann/quantify/modules.py
def compute_pathways_abundance(pathways_and_reactions_store, pathways_database):
    """
    Compute the abundance of pathways for each bug
    Also find the set of the reactions with abundance in all pathways present
    """
    
    # Store the reactions which have abundance in the pathways with abundance
    reactions_in_pathways_present={}
    
    # Process through each pathway for each bug to compute abundance
    pathways_abundance_store=store.Pathways()
    for bug in pathways_and_reactions_store.bug_list():
        
        logger.debug("Compute pathway abundance for bug: " + bug)
        
        reactions_in_pathways_present[bug]=set()
        for pathway in pathways_and_reactions_store.pathway_list(bug):
            
            reaction_scores=pathways_and_reactions_store.reaction_scores(bug,pathway)
            
            # Check if the pathways database is structured
            if pathways_database.is_structured():
                structure=pathways_database.get_structure_for_pathway(pathway)
                key_reactions=pathways_database.get_key_reactions_for_pathway(pathway)
                # Apply gap fill
                reaction_scores_gap_filled=gap_fill(key_reactions, reaction_scores)
                # Compute the structured pathway abundance
                abundance=compute_structured_pathway_abundance_or_coverage(structure,
                    key_reactions,reaction_scores_gap_filled,False,0)
            
            else:
                # Initialize any reactions in the pathway not found to 0
                for reaction in pathways_database.find_reactions(pathway):
                    reaction_scores.setdefault(reaction, 0)
                    
                # Sort the scores for all of the reactions in the pathway from low to high
                sorted_reaction_scores=sorted(reaction_scores.values())
                    
                # Select the second half of the list of reaction scores
                abundance_set=sorted_reaction_scores[int(len(sorted_reaction_scores)/ 2):]
                
                # Compute abundance
                abundance=sum(abundance_set)/len(abundance_set)
                
            # If this pathway is present, store those reactions with abundance
            if abundance > 0:
                for reaction,score in reaction_scores.items():
                    if score > 0:
                        reactions_in_pathways_present[bug].add(reaction)
            
            # Store the abundance
            pathways_abundance_store.add(bug, pathway, abundance)
    
    return pathways_abundance_store, reactions_in_pathways_present

    Compute the abundance of pathways for each bug
    Also find the set of the reactions with abundance in all pathways present
    
Compute the abundance of pathways for each bug
Also find the set of the reactions with abundance in all pathways present
Compute the abundance of pathways for each bug Also find the set of the reactions with abundance in all pathways present
def compute_pathways_abundance(pathways_and_reactions_store, pathways_database):
    reactions_in_pathways_present={}
    pathways_abundance_store=store.Pathways()
    for bug in pathways_and_reactions_store.bug_list():
        logger.debug("Compute pathway abundance for bug: " + bug)
        reactions_in_pathways_present[bug]=set()
        for pathway in pathways_and_reactions_store.pathway_list(bug):
            reaction_scores=pathways_and_reactions_store.reaction_scores(bug,pathway)
            if pathways_database.is_structured():
                structure=pathways_database.get_structure_for_pathway(pathway)
                key_reactions=pathways_database.get_key_reactions_for_pathway(pathway)
                reaction_scores_gap_filled=gap_fill(key_reactions, reaction_scores)
                abundance=compute_structured_pathway_abundance_or_coverage(structure,
                    key_reactions,reaction_scores_gap_filled,False,0)
            else:
                for reaction in pathways_database.find_reactions(pathway):
                    reaction_scores.setdefault(reaction, 0)
                sorted_reaction_scores=sorted(reaction_scores.values())
                abundance_set=sorted_reaction_scores[int(len(sorted_reaction_scores)/ 2):]
                abundance=sum(abundance_set)/len(abundance_set)
            if abundance > 0:
                for reaction,score in reaction_scores.items():
                    if score > 0:
                        reactions_in_pathways_present[bug].add(reaction)
            pathways_abundance_store.add(bug, pathway, abundance)
    return pathways_abundance_store, reactions_in_pathways_present
def compute_pathways_abundance ( pathways_and_reactions_store , pathways_database ) : reactions_in_pathways_present = { } pathways_abundance_store = store . Pathways ( ) for bug in pathways_and_reactions_store . bug_list ( ) : logger . debug ( "Compute pathway abundance for bug: " + bug ) reactions_in_pathways_present [ bug ] = set ( ) for pathway in pathways_and_reactions_store . pathway_list ( bug ) : reaction_scores = pathways_and_reactions_store . reaction_scores ( bug , pathway ) if pathways_database . is_structured ( ) : structure = pathways_database . get_structure_for_pathway ( pathway ) key_reactions = pathways_database . get_key_reactions_for_pathway ( pathway ) reaction_scores_gap_filled = gap_fill ( key_reactions , reaction_scores ) abundance = compute_structured_pathway_abundance_or_coverage ( structure , key_reactions , reaction_scores_gap_filled , False , 0 ) else : for reaction in pathways_database . find_reactions ( pathway ) : reaction_scores . setdefault ( reaction , 0 ) sorted_reaction_scores = sorted ( reaction_scores . values ( ) ) abundance_set = sorted_reaction_scores [ int ( len ( sorted_reaction_scores ) / 2 ) : ] abundance = sum ( abundance_set ) / len ( abundance_set ) if abundance > 0 : for reaction , score in reaction_scores . items ( ) : if score > 0 : reactions_in_pathways_present [ bug ] . add ( reaction ) pathways_abundance_store . add ( bug , pathway , abundance ) return pathways_abundance_store , reactions_in_pathways_present
Compute the abundance of pathways for each bug
Also find the set of the reactions with abundance in all pathways present
Compute the abundance of pathways for each bug Also find the set of the reactions with abundance in all pathways present
"""
    Compute the abundance of pathways for each bug
    Also find the set of the reactions with abundance in all pathways present
    """ # Store the reactions which have abundance in the pathways with abundance # Process through each pathway for each bug to compute abundance # Check if the pathways database is structured # Apply gap fill # Compute the structured pathway abundance # Initialize any reactions in the pathway not found to 0 # Sort the scores for all of the reactions in the pathway from low to high # Select the second half of the list of reaction scores # Compute abundance # If this pathway is present, store those reactions with abundance # Store the abundance
pathways_and_reactions_store
pathways_database