humann/quantify/modules.py
def gap_fill(key_reactions, reaction_scores):
    """
    If all but one of the key reactions have abundance scores, then fill gap
    Boost the lowest abundance score
    """
    
    reaction_scores_gap_filled=reaction_scores.copy()
    
    # do not apply gap fill, if set to off
    if config.gap_fill_toggle == "off":
        return reaction_scores_gap_filled
    
    # get the scores for all of the key reactions
    key_reactions_nonzero_scores=[]
    for reaction in key_reactions:
        score=reaction_scores.get(reaction,0)
        if score > 0:
            key_reactions_nonzero_scores.append(score)

    if len(key_reactions)-len(key_reactions_nonzero_scores) == 1:
        # fill single zero gap with lowest key reaction score
        min_score=min(key_reactions_nonzero_scores)
        for reaction in key_reactions:
            score=reaction_scores.get(reaction,0)
            if score == 0:
                reaction_scores_gap_filled[reaction]=min_score
    elif len(key_reactions)-len(key_reactions_nonzero_scores) == 0:
        # boost lowest abundance score
        sorted_key_reactions_nonzero_scores=sorted(key_reactions_nonzero_scores)
        for reaction in key_reactions:
            score=reaction_scores.get(reaction,0)
            if score == sorted_key_reactions_nonzero_scores[0]:
                try:
                    reaction_scores_gap_filled[reaction]=sorted_key_reactions_nonzero_scores[1]
                except IndexError:
                    pass

    return reaction_scores_gap_filled

    If all but one of the key reactions have abundance scores, then fill gap
    Boost the lowest abundance score
    
If all but one of the key reactions have abundance scores, then fill gap
Boost the lowest abundance score
If all but one of the key reactions have abundance scores then fill gap Boost the lowest abundance score
def gap_fill(key_reactions, reaction_scores):
    reaction_scores_gap_filled=reaction_scores.copy()
    if config.gap_fill_toggle == "off":
        return reaction_scores_gap_filled
    key_reactions_nonzero_scores=[]
    for reaction in key_reactions:
        score=reaction_scores.get(reaction,0)
        if score > 0:
            key_reactions_nonzero_scores.append(score)
    if len(key_reactions)-len(key_reactions_nonzero_scores) == 1:
        min_score=min(key_reactions_nonzero_scores)
        for reaction in key_reactions:
            score=reaction_scores.get(reaction,0)
            if score == 0:
                reaction_scores_gap_filled[reaction]=min_score
    elif len(key_reactions)-len(key_reactions_nonzero_scores) == 0:
        sorted_key_reactions_nonzero_scores=sorted(key_reactions_nonzero_scores)
        for reaction in key_reactions:
            score=reaction_scores.get(reaction,0)
            if score == sorted_key_reactions_nonzero_scores[0]:
                try:
                    reaction_scores_gap_filled[reaction]=sorted_key_reactions_nonzero_scores[1]
                except IndexError:
                    pass
    return reaction_scores_gap_filled
def gap_fill ( key_reactions , reaction_scores ) : reaction_scores_gap_filled = reaction_scores . copy ( ) if config . gap_fill_toggle == "off" : return reaction_scores_gap_filled key_reactions_nonzero_scores = [ ] for reaction in key_reactions : score = reaction_scores . get ( reaction , 0 ) if score > 0 : key_reactions_nonzero_scores . append ( score ) if len ( key_reactions ) - len ( key_reactions_nonzero_scores ) == 1 : min_score = min ( key_reactions_nonzero_scores ) for reaction in key_reactions : score = reaction_scores . get ( reaction , 0 ) if score == 0 : reaction_scores_gap_filled [ reaction ] = min_score elif len ( key_reactions ) - len ( key_reactions_nonzero_scores ) == 0 : sorted_key_reactions_nonzero_scores = sorted ( key_reactions_nonzero_scores ) for reaction in key_reactions : score = reaction_scores . get ( reaction , 0 ) if score == sorted_key_reactions_nonzero_scores [ 0 ] : try : reaction_scores_gap_filled [ reaction ] = sorted_key_reactions_nonzero_scores [ 1 ] except IndexError : pass return reaction_scores_gap_filled
If all but one of the key reactions have abundance scores, then fill gap
Boost the lowest abundance score
If all but one of the key reactions have abundance scores then fill gap Boost the lowest abundance score
"""
    If all but one of the key reactions have abundance scores, then fill gap
    Boost the lowest abundance score
    """ # do not apply gap fill, if set to off # get the scores for all of the key reactions # fill single zero gap with lowest key reaction score # boost lowest abundance score
key_reactions
reaction_scores