Mercurial > repos > galaxyp > hirieftools
diff peptide_pi_annotator.py @ 3:78afc81ab244 draft default tip
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/pi_db_tools commit decb06dc90d7069d317968b979f649a04720b264
author | galaxyp |
---|---|
date | Thu, 14 Sep 2017 11:55:02 -0400 |
parents | 8a30d6e5b97d |
children |
line wrap: on
line diff
--- a/peptide_pi_annotator.py Fri Sep 01 03:14:54 2017 -0400 +++ b/peptide_pi_annotator.py Thu Sep 14 11:55:02 2017 -0400 @@ -43,10 +43,10 @@ fp.write('\n') -def get_first_matching_pattern(patterns, string): - for pattern in patterns: +def get_strip(strips, string): + for pattern in strips.keys(): if re.search(pattern, string): - return pattern + return strips[pattern] return False @@ -71,11 +71,6 @@ yield header + ['Experimental pI', 'Predicted pI', 'Delta pI'] for line in fp: line = line.strip('\n').split('\t') - strip = strips[get_first_matching_pattern(strips.keys(), - line[stripcol])] - exp_pi = (strip['fr_width'] * int(line[frac_col]) + - strip['intercept']) - sequence = line[seqcol] for weight in ignoremods: if weight == '*': @@ -90,12 +85,26 @@ not_predicted_count += 1 pred_pi, delta_pi = 'NA', 'NA' else: - delta_pi = exp_pi - pred_pi predicted_count += 1 + strip = get_strip(strips, line[stripcol]) + if not strip: + exp_pi, delta_pi = 'NA', 'NA' + else: + try: + exp_pi = (strip['fr_width'] * int(line[frac_col]) + + strip['intercept']) + except ValueError: + print('Cannot detect fraction for PSM {}'.format(sequence)) + exp_pi, delta_pi = 'NA', 'NA' + else: + if pred_pi != 'NA': + delta_pi = exp_pi - pred_pi + else: + delta_pi = 'NA' yield line + [exp_pi, pred_pi, delta_pi] print('Number of peptides without pI prediction: {}\n' - 'Number of peptides with predicion: {}\n'.format(not_predicted_count, - predicted_count)) + 'Number of peptides predicted: {}\n'.format(not_predicted_count, + predicted_count)) def parse_commandline():