<commit_before>import sys
from statistics import median, StatisticsError

from app.readers import tsv as reader


def calc_psm_ratios(psm, channels, denom_channels, min_intensity):
    # set values below min_intensity to NA
    psm_intensity = {ch: float(psm[ch])
                     if psm[ch] != 'NA' and float(psm[ch]) > min_intensity
                     else 'NA' for ch in channels}
    denom = sum([psm_intensity[ch] for ch in denom_channels
                 if psm_intensity[ch] != 'NA']) / len(denom_channels)
    if denom == 0:
        return ['NA'] * len(channels)
    return [psm_intensity[ch] / denom
            if psm_intensity[ch] != 'NA' else 'NA' for ch in channels]


def calc_normalized(psm, channel, medians):
    return psm[channel] / medians[channel]


def get_normalized_ratios(psmfn, header, channels, denom_channels,
                          min_intensity, second_psmfn, secondheader):<commit_msg>Fix bug where if one of denominator channel values has NA then the denominator becomes too small because divide by a fixed amount of channels<commit_after>import sys
from statistics import median, StatisticsError

from app.readers import tsv as reader


def calc_psm_ratios(psm, channels, denom_channels, min_intensity):
    # set values below min_intensity to NA
    psm_intensity = {ch: float(psm[ch])
                     if psm[ch] != 'NA' and float(psm[ch]) > min_intensity
                     else 'NA' for ch in channels}
    denomvalues = [psm_intensity[ch] for ch in denom_channels
                   if psm_intensity[ch] != 'NA']
    denom = sum(denomvalues) / len(denomvalues)
    if denom == 0:
        return ['NA'] * len(channels)
    return [psm_intensity[ch] / denom
            if psm_intensity[ch] != 'NA' else 'NA' for ch in channels]


def calc_normalized(psm, channel, medians):
    return psm[channel] / medians[channel]


def get_normalized_ratios(psmfn, header, channels, denom_channels,
                          min_intensity, second_psmfn, secondheader):
{'fraction_non_alphanumeric': 0.09118086696562033, 'fraction_numerical': 0.000996512207274539, 'mean_word_length': 3.016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1872187', 'n_tokens_mistral': 629, 'n_tokens_neox': 608, 'n_words': 189}