Ejemplo n.º 1
0
def background(list_of_replicates, input_fragment_value,
               unlabeled_fragment_value, isotope_dict):
    parent_frag, daughter_frag = input_fragment_value.frag
    iso_elem = helpers.get_isotope_element(parent_frag.isotracer)
    parent_label = parent_frag.get_num_labeled_atoms_isotope(
        parent_frag.isotracer)
    parent_atoms = parent_frag.number_of_atoms(iso_elem)
    na = helpers.get_isotope_na(parent_frag.isotracer, isotope_dict)
    daughter_atoms = daughter_frag.number_of_atoms(iso_elem)
    daughter_label = daughter_frag.get_num_labeled_atoms_isotope(
        parent_frag.isotracer)
    replicate_value = {}
    for replicate_group in list_of_replicates:

        background_list = []
        for each_replicate in replicate_group:
            noise = background_noise(
                unlabeled_fragment_value.data[each_replicate], na,
                parent_atoms, parent_label, daughter_atoms, daughter_label)
            background = background_subtraction(
                input_fragment_value.data[each_replicate], noise)
            background_list.append(background)
        background_value = max(background_list)
        for each_replicate in replicate_group:
            replicate_value[each_replicate] = background_value
    return replicate_value
Ejemplo n.º 2
0
def make_all_corr_matrices(isotracers, formula_dict, na_dict, autodetect,
                           corr_limit):
    """
    This function forms correction matrix M, such that Mx=y where y is the 
    observed isotopic distribution and x is the expected distribution of input
    labels, for each indistinguishable element for a particular isotracer one by one. 
    Args:
    isotracers - list of isotracers presnt in the formula.
    formula_dict - dict of form- element:number of atoms in molecule (e.g. {'C':2,'O':1,'H':6})
    na_dict - dict of form- element:expected isotopic distribution
    eleme_corr - dict of form- isotracer_element:indistinguishable elements list(elements with identical mass shift)
                 Eg- { 'C13': ['H', 'O17'], 'N15': ['H']}

    Returns:
    corr_mats - dict of form- isotracer_element: correction matrix
    """
    corr_mats = {}
    for isotracer in isotracers:
        trac_atom = get_isotope_element(isotracer)
        try:
            indist_list = corr_limit[str(trac_atom)].keys()
        except KeyError:
            indist_list = []
        corr_mats[isotracer] = make_correction_matrix(isotracer, formula_dict,
                                                      na_dict, indist_list,
                                                      autodetect,
                                                      corr_limit[trac_atom])
    return corr_mats
Ejemplo n.º 3
0
def make_all_corr_matrices(isotracers, formula_dict, na_dict, eleme_corr):
    corr_mats = {}
    for isotracer in isotracers:
        trac_atom = get_isotope_element(isotracer)
        try:
            indist_list = eleme_corr[trac_atom]
        except KeyError:
            indist_list = []
        corr_mats[isotracer] = make_correction_matrix(trac_atom, formula_dict,
                                                      na_dict, indist_list)
    return corr_mats
Ejemplo n.º 4
0
def na_correct_mimosa_algo_array(parent_frag_m, daughter_frag_n, intensity_m_n, intensity_m_1_n, intensity_m_1_n_1,
                                 isotope, na, decimals):
    iso_elem = helpers.get_isotope_element(isotope)
    p = parent_frag_m.number_of_atoms(iso_elem)
    d = daughter_frag_n.number_of_atoms(iso_elem)
    m = parent_frag_m.get_num_labeled_atoms_isotope(isotope)
    n = daughter_frag_n.get_num_labeled_atoms_isotope(isotope)
    corrected_intensity = intensity_m_n * (1 + na * (p - m)) - intensity_m_1_n * na * ((p - d) - (m - n - 1)) -\
        intensity_m_1_n_1 * na * (d - (n - 1))

    return np.around(corrected_intensity, decimals)
Ejemplo n.º 5
0
def eleme_corr_invalid_entry(iso_tracers, eleme_corr):
    """
    This function raises an error if the user inputs incorrect values in  eleme_corr dictionary.
    The indistinguishable element specified in the eleme_corr dictionary cannot be an isotracer
    element. This is logically incorrect input, hence raises an error.
    """
    for key, value in eleme_corr.iteritems():
        for isotracer in iso_tracers:
            el = get_isotope_element(isotracer)
            if el in value:
                raise KeyError('An iso tracer cannot'
                               ' be an Indistinguishable element (' + el +
                               ') , invalid input in eleme_corr dictionary')
Ejemplo n.º 6
0
def add_mass_and_no_of_atoms_info_frm_label(df):
    """
    This function adds column of parent isotopic mass, daughter isotopic mass, parent molecular mass,
    daughter molecular mass, no of labeled atoms parent and daughter,
    total no of atoms parent and daughter and isotracer column to the dataframe.
    """
    msms_df = get_parent_daughter_iso_mass_col_and_isotracer_from_label(df)
    isotracer = msms_df[multiquant.ISOTRACER].unique()
    iso_elem = hlp.get_isotope_element(isotracer[0])
    input_df = pd.DataFrame()
    final_df = pd.DataFrame()

    input_df = get_mol_mass_and_number_of_atoms(msms_df,
                                                multiquant.PARENT_FORM,
                                                'PARENT', isotracer[0],
                                                iso_elem, input_df)
    final_df = get_mol_mass_and_number_of_atoms(input_df, multiquant.FORMULA,
                                                'DAUGHTER', isotracer[0],
                                                iso_elem, final_df)

    return final_df, isotracer
Ejemplo n.º 7
0
def test_get_isotope_details():
    assert help.get_isotope_element('C13') == 'C'
Ejemplo n.º 8
0
def make_correction_matrix(isotracer, formuladict, na_dict, indist_elems,
                           autodetect, corr_limit):
    """create matrix M such that Mx=y where y is the observed isotopic distribution
    and x is the expected distribution of input labels

    formuladict: dict of element:number of atoms in molecule (e.g. {'C':2,'O':1,'H':6})
    trac_atom: element with input labeling
    indist_elems: elements with identical mass shift
    na_dict: dict of - element:expected isotopic distribution
    :TODO This function relates to issue NCT-247. Need to change the function
    in more appropriate way.
    """
    lookup_dict = {
        'O': ['O16', 'O17', 'O18'],
        'S': ['S32', 'S33', 'S34'],
        'Si': ['Si28', 'Si29', 'Si30']
    }
    trac_atom = get_isotope_element(isotracer)
    if (isotracer == 'O18' or isotracer == 'S34' or isotracer == 'Si30'):
        M = make_expected_na_matrix_heavy(formuladict.get(trac_atom, 0),
                                          na_dict[trac_atom])
    else:
        M = make_expected_na_matrix(formuladict.get(trac_atom, 0),
                                    na_dict[trac_atom])
    M_indist = []

    indist_elems_copy = copy(indist_elems)
    na_dict_copy = copy(na_dict)
    for e in indist_elems:
        if e in indist_elems_copy:
            e2 = get_isotope_element(e)
            if e2 in formuladict:
                try:
                    if (lookup_dict[e2][1]
                            in indist_elems_copy) and (lookup_dict[e2][2]
                                                       in indist_elems_copy):
                        corr_limit_1 = int(corr_limit[lookup_dict[e2][1]])
                        corr_limit_2 = int(corr_limit[lookup_dict[e2][2]])
                        M_indist.append(
                            add_indistinguishable_element_for_autodetect_heavy(
                                M, formuladict[e2], na_dict_copy[e2],
                                corr_limit_1, corr_limit_2))
                        indist_elems_copy.remove(lookup_dict[e2][1])
                        indist_elems_copy.remove(lookup_dict[e2][2])

                    elif ((lookup_dict[e2][1] in indist_elems_copy) and (lookup_dict[e2][2] not in indist_elems_copy)) or \
                                ((lookup_dict[e2][1] not in indist_elems_copy) and (lookup_dict[e2][2] in indist_elems_copy)):
                        pos = lookup_dict[e2].index(str(e))
                        list_values = [0] * 3
                        list_values[0] = na_dict_copy[e2][0]
                        list_values[pos] = na_dict_copy[e2][pos]
                        na_dict_copy[str(e)] = list_values
                        corr_limit_1 = int(corr_limit[e])
                        M_indist.append(
                            add_indistinguishable_element_for_autodetect(
                                M, formuladict[e2], na_dict_copy[e],
                                corr_limit_1))

                    else:
                        corr_limit_1 = int(corr_limit[e])
                        M_indist.append(
                            add_indistinguishable_element_for_autodetect(
                                M, formuladict[e2], na_dict_copy[e],
                                corr_limit_1))

                except Exception, exception_str:
                    corr_limit_1 = int(corr_limit[e])
                    M_indist.append(
                        add_indistinguishable_element_for_autodetect(
                            M, formuladict[e2], na_dict_copy[e], corr_limit_1))