humann/quantify/modules.py
def compute_structured_pathway_abundance_or_coverage(structure, key_reactions, reaction_scores, 
    coverage_computation, median_value):
    """
    Compute the abundance or coverage for a structured pathway
    """
    
    # Process through the structure to compute the abundance
    required_reaction_abundances=[]
    optional_reaction_abundances=[]
    # Select the join instead of removing from the list to not alter the list for
    # the calling function
    join=structure[0]
    for item in structure[1:]:
        if isinstance(item, list):
            required_reaction_abundances.append(compute_structured_pathway_abundance_or_coverage(item, 
                key_reactions, reaction_scores, coverage_computation, median_value))
        else:
            score=reaction_scores.get(item,0)
                
            # Update the score for the reaction if this is a coverage computation
            if coverage_computation:
                score=chi2cdf.chi2cdf(score,median_value)

            # Check if this is an optional reaction
            if item in key_reactions:
                required_reaction_abundances.append(score)
            else:
                optional_reaction_abundances.append(score)
    
    # If this is an OR join then use the max of all of the reaction abundances
    if join == config.pathway_OR:
        all_reaction_abundances=required_reaction_abundances + optional_reaction_abundances
        abundance=0
        if all_reaction_abundances:
            abundance = max(all_reaction_abundances)
    else:
        # If this is not an OR, then take the harmonic mean of the reactions
        abundance=harmonic_mean(required_reaction_abundances)
        # Add the optional reactions if they are present
        if optional_reaction_abundances:
            # Filter the optional abundances to only include those that are greater than the abundance
            # from the required reactions
            optional_reaction_abundances_filtered=[value for value in optional_reaction_abundances if value > abundance]
            abundance=harmonic_mean(required_reaction_abundances + optional_reaction_abundances_filtered)
        
    return abundance

    Compute the abundance or coverage for a structured pathway
    
Compute the abundance or coverage for a structured pathway
Compute the abundance or coverage for a structured pathway
def compute_structured_pathway_abundance_or_coverage(structure, key_reactions, reaction_scores, 
    coverage_computation, median_value):
    required_reaction_abundances=[]
    optional_reaction_abundances=[]
    join=structure[0]
    for item in structure[1:]:
        if isinstance(item, list):
            required_reaction_abundances.append(compute_structured_pathway_abundance_or_coverage(item, 
                key_reactions, reaction_scores, coverage_computation, median_value))
        else:
            score=reaction_scores.get(item,0)
            if coverage_computation:
                score=chi2cdf.chi2cdf(score,median_value)
            if item in key_reactions:
                required_reaction_abundances.append(score)
            else:
                optional_reaction_abundances.append(score)
    if join == config.pathway_OR:
        all_reaction_abundances=required_reaction_abundances + optional_reaction_abundances
        abundance=0
        if all_reaction_abundances:
            abundance = max(all_reaction_abundances)
    else:
        abundance=harmonic_mean(required_reaction_abundances)
        if optional_reaction_abundances:
            optional_reaction_abundances_filtered=[value for value in optional_reaction_abundances if value > abundance]
            abundance=harmonic_mean(required_reaction_abundances + optional_reaction_abundances_filtered)
    return abundance
def compute_structured_pathway_abundance_or_coverage ( structure , key_reactions , reaction_scores , coverage_computation , median_value ) : required_reaction_abundances = [ ] optional_reaction_abundances = [ ] join = structure [ 0 ] for item in structure [ 1 : ] : if isinstance ( item , list ) : required_reaction_abundances . append ( compute_structured_pathway_abundance_or_coverage ( item , key_reactions , reaction_scores , coverage_computation , median_value ) ) else : score = reaction_scores . get ( item , 0 ) if coverage_computation : score = chi2cdf . chi2cdf ( score , median_value ) if item in key_reactions : required_reaction_abundances . append ( score ) else : optional_reaction_abundances . append ( score ) if join == config . pathway_OR : all_reaction_abundances = required_reaction_abundances + optional_reaction_abundances abundance = 0 if all_reaction_abundances : abundance = max ( all_reaction_abundances ) else : abundance = harmonic_mean ( required_reaction_abundances ) if optional_reaction_abundances : optional_reaction_abundances_filtered = [ value for value in optional_reaction_abundances if value > abundance ] abundance = harmonic_mean ( required_reaction_abundances + optional_reaction_abundances_filtered ) return abundance
Compute the abundance or coverage for a structured pathway
Compute the abundance or coverage for a structured pathway
"""
    Compute the abundance or coverage for a structured pathway
    """ # Process through the structure to compute the abundance # Select the join instead of removing from the list to not alter the list for # the calling function # Update the score for the reaction if this is a coverage computation # Check if this is an optional reaction # If this is an OR join then use the max of all of the reaction abundances # If this is not an OR, then take the harmonic mean of the reactions # Add the optional reactions if they are present # Filter the optional abundances to only include those that are greater than the abundance # from the required reactions
structure
key_reactions
reaction_scores
coverage_computation
median_value