nmt/utils/peaks_utils.py
def compute_evidence_correlation(source_file_name, result_file_name):
  '''Compute correlation between amino acid eviden and correctness of prediction
  Args:
    source_file_name: data file
    result_file_name: result file, same number of line as data file.
      each line consisting of 1 or 0 indicating the correctness of the predictions
  '''
  with open(source_file_name, 'r') as source_file, open(result_file_name, 'r') as result_file:
    count = 0
    amino_acid_count, amino_acid_with_evidence_count = 0., 0.
    has_evidence_correct_count, has_evidence_incorrect_count = 0., 0.
    no_evidence_correct_count, no_evidence_incorrect_count = 0., 0.
    for row in source_file:
      result = result_file.readline().strip()
      result = result.split(',')

      (seq, charge, mass_p_charge, peptide_mass, positions, values) = parse_row(row)
      # print(seq, charge, mass_p_charge, peptide_mass, positions, values)
      assert len(seq) == len(result)

      relevant_peak_dict = get_relevant_peak_mass_dict(seq, peptide_mass, charge)
      # considered_ion = ['b_ion','y_ion']
      considered_ion = ['b_ion','y_ion','b_plus2_charge1','y_plus2_charge1']
      # considered_ion = ['b_ion','y_ion','b_H2O','y_H2O','b_NH3','y_NH3','b_plus2_charge1','y_plus2_charge1']
      
      # positions must be sorted
      positions = np.array([float(posi) for posi in positions])
      amino_acid_count += len(seq)
      has_evidence_in_previous_step = True
      for pos in range(len(seq)):
        has_evidence = False
        for ion_type in considered_ion:
          has_evidence |= has_peak_within_threshold(positions, relevant_peak_dict[ion_type][pos])
        evidence_for_next_step = has_evidence
        has_evidence = has_evidence_in_previous_step and has_evidence
        
        if result[pos] == '1' and has_evidence:
          has_evidence_correct_count += 1
        elif result[pos] == '1' and not has_evidence:
          no_evidence_correct_count += 1
        elif result[pos] == '0' and has_evidence:
          has_evidence_incorrect_count += 1
        elif result[pos] == '0' and not has_evidence:
          no_evidence_incorrect_count += 1
        else:
          print("Something is worng here")

        if has_evidence:
          amino_acid_with_evidence_count += 1
        has_evidence_in_previous_step = evidence_for_next_step
      count += 1
      if count % 5000 == 0: print(count) # break

  print("Amino acid with evidence: %.2f %%" % (100 * amino_acid_with_evidence_count/amino_acid_count))
  print("Amino acid with evidence: %.0f, Total amino acid: %0.f" % (amino_acid_with_evidence_count,amino_acid_count))
  print("Has evidence and correct: %.0f (%.2f %%), Has evidence but incorrect: %.0f (%.2f %%)" % 
        (has_evidence_correct_count, 100 * has_evidence_correct_count/amino_acid_count,
         has_evidence_incorrect_count, 100 * has_evidence_incorrect_count/amino_acid_count))
  print("No evidence but correct: %.0f (%.2f %%), No evidence and incorrect: %.0f (%.2f %%)" % 
        (no_evidence_correct_count, 100 * no_evidence_correct_count/amino_acid_count,
         no_evidence_incorrect_count, 100 * no_evidence_incorrect_count/amino_acid_count))
  print("Of all incorrect amino acids, %.2f %% has no evidence" % 
        (100 * no_evidence_incorrect_count / (no_evidence_incorrect_count + has_evidence_incorrect_count)))
  return
Compute correlation between amino acid eviden and correctness of prediction
  Args:
    source_file_name: data file
    result_file_name: result file, same number of line as data file.
      each line consisting of 1 or 0 indicating the correctness of the predictions
  
Compute correlation between amino acid eviden and correctness of prediction
Compute correlation between amino acid eviden and correctness of prediction
def compute_evidence_correlation(source_file_name, result_file_name):
  with open(source_file_name, 'r') as source_file, open(result_file_name, 'r') as result_file:
    count = 0
    amino_acid_count, amino_acid_with_evidence_count = 0., 0.
    has_evidence_correct_count, has_evidence_incorrect_count = 0., 0.
    no_evidence_correct_count, no_evidence_incorrect_count = 0., 0.
    for row in source_file:
      result = result_file.readline().strip()
      result = result.split(',')
      (seq, charge, mass_p_charge, peptide_mass, positions, values) = parse_row(row)
      assert len(seq) == len(result)
      relevant_peak_dict = get_relevant_peak_mass_dict(seq, peptide_mass, charge)
      considered_ion = ['b_ion','y_ion','b_plus2_charge1','y_plus2_charge1']
      positions = np.array([float(posi) for posi in positions])
      amino_acid_count += len(seq)
      has_evidence_in_previous_step = True
      for pos in range(len(seq)):
        has_evidence = False
        for ion_type in considered_ion:
          has_evidence |= has_peak_within_threshold(positions, relevant_peak_dict[ion_type][pos])
        evidence_for_next_step = has_evidence
        has_evidence = has_evidence_in_previous_step and has_evidence
        if result[pos] == '1' and has_evidence:
          has_evidence_correct_count += 1
        elif result[pos] == '1' and not has_evidence:
          no_evidence_correct_count += 1
        elif result[pos] == '0' and has_evidence:
          has_evidence_incorrect_count += 1
        elif result[pos] == '0' and not has_evidence:
          no_evidence_incorrect_count += 1
        else:
          print("Something is worng here")
        if has_evidence:
          amino_acid_with_evidence_count += 1
        has_evidence_in_previous_step = evidence_for_next_step
      count += 1
      if count % 5000 == 0: print(count) 
  print("Amino acid with evidence: %.2f %%" % (100 * amino_acid_with_evidence_count/amino_acid_count))
  print("Amino acid with evidence: %.0f, Total amino acid: %0.f" % (amino_acid_with_evidence_count,amino_acid_count))
  print("Has evidence and correct: %.0f (%.2f %%), Has evidence but incorrect: %.0f (%.2f %%)" % 
        (has_evidence_correct_count, 100 * has_evidence_correct_count/amino_acid_count,
         has_evidence_incorrect_count, 100 * has_evidence_incorrect_count/amino_acid_count))
  print("No evidence but correct: %.0f (%.2f %%), No evidence and incorrect: %.0f (%.2f %%)" % 
        (no_evidence_correct_count, 100 * no_evidence_correct_count/amino_acid_count,
         no_evidence_incorrect_count, 100 * no_evidence_incorrect_count/amino_acid_count))
  print("Of all incorrect amino acids, %.2f %% has no evidence" % 
        (100 * no_evidence_incorrect_count / (no_evidence_incorrect_count + has_evidence_incorrect_count)))
  return
def compute_evidence_correlation ( source_file_name , result_file_name ) : with open ( source_file_name , 'r' ) as source_file , open ( result_file_name , 'r' ) as result_file : count = 0 amino_acid_count , amino_acid_with_evidence_count = 0. , 0. has_evidence_correct_count , has_evidence_incorrect_count = 0. , 0. no_evidence_correct_count , no_evidence_incorrect_count = 0. , 0. for row in source_file : result = result_file . readline ( ) . strip ( ) result = result . split ( ',' ) ( seq , charge , mass_p_charge , peptide_mass , positions , values ) = parse_row ( row ) assert len ( seq ) == len ( result ) relevant_peak_dict = get_relevant_peak_mass_dict ( seq , peptide_mass , charge ) considered_ion = [ 'b_ion' , 'y_ion' , 'b_plus2_charge1' , 'y_plus2_charge1' ] positions = np . array ( [ float ( posi ) for posi in positions ] ) amino_acid_count += len ( seq ) has_evidence_in_previous_step = True for pos in range ( len ( seq ) ) : has_evidence = False for ion_type in considered_ion : has_evidence |= has_peak_within_threshold ( positions , relevant_peak_dict [ ion_type ] [ pos ] ) evidence_for_next_step = has_evidence has_evidence = has_evidence_in_previous_step and has_evidence if result [ pos ] == '1' and has_evidence : has_evidence_correct_count += 1 elif result [ pos ] == '1' and not has_evidence : no_evidence_correct_count += 1 elif result [ pos ] == '0' and has_evidence : has_evidence_incorrect_count += 1 elif result [ pos ] == '0' and not has_evidence : no_evidence_incorrect_count += 1 else : print ( "Something is worng here" ) if has_evidence : amino_acid_with_evidence_count += 1 has_evidence_in_previous_step = evidence_for_next_step count += 1 if count % 5000 == 0 : print ( count ) print ( "Amino acid with evidence: %.2f %%" % ( 100 * amino_acid_with_evidence_count / amino_acid_count ) ) print ( "Amino acid with evidence: %.0f, Total amino acid: %0.f" % ( amino_acid_with_evidence_count , amino_acid_count ) ) print ( "Has evidence and correct: %.0f (%.2f %%), Has evidence but incorrect: %.0f (%.2f %%)" % ( has_evidence_correct_count , 100 * has_evidence_correct_count / amino_acid_count , has_evidence_incorrect_count , 100 * has_evidence_incorrect_count / amino_acid_count ) ) print ( "No evidence but correct: %.0f (%.2f %%), No evidence and incorrect: %.0f (%.2f %%)" % ( no_evidence_correct_count , 100 * no_evidence_correct_count / amino_acid_count , no_evidence_incorrect_count , 100 * no_evidence_incorrect_count / amino_acid_count ) ) print ( "Of all incorrect amino acids, %.2f %% has no evidence" % ( 100 * no_evidence_incorrect_count / ( no_evidence_incorrect_count + has_evidence_incorrect_count ) ) ) return
Compute correlation between amino acid eviden and correctness of prediction
Compute correlation between amino acid eviden and correctness of prediction
'''Compute correlation between amino acid eviden and correctness of prediction
  Args:
    source_file_name: data file
    result_file_name: result file, same number of line as data file.
      each line consisting of 1 or 0 indicating the correctness of the predictions
  ''' # print(seq, charge, mass_p_charge, peptide_mass, positions, values) # considered_ion = ['b_ion','y_ion'] # considered_ion = ['b_ion','y_ion','b_H2O','y_H2O','b_NH3','y_NH3','b_plus2_charge1','y_plus2_charge1'] # positions must be sorted # break
source_file_name
None
result_file_name
result file, same number of line as data file.
each line consisting of 1 or 0 indicating the correctness of the predictions
result file same number of line as data file . each line consisting of 1 or 0 indicating the correctness of the predictions