Mercurial > repos > galaxyp > hirieftools
comparison peptide_pi_annotator.py @ 3:a6341e757422 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:54:46 -0400 |
| parents | 70757404c4f6 |
| children |
comparison
equal
deleted
inserted
replaced
| 2:c093af6f2a6c | 3:a6341e757422 |
|---|---|
| 41 args.ignoremods): | 41 args.ignoremods): |
| 42 fp.write('\t'.join([str(x) for x in outline])) | 42 fp.write('\t'.join([str(x) for x in outline])) |
| 43 fp.write('\n') | 43 fp.write('\n') |
| 44 | 44 |
| 45 | 45 |
| 46 def get_first_matching_pattern(patterns, string): | 46 def get_strip(strips, string): |
| 47 for pattern in patterns: | 47 for pattern in strips.keys(): |
| 48 if re.search(pattern, string): | 48 if re.search(pattern, string): |
| 49 return pattern | 49 return strips[pattern] |
| 50 return False | 50 return False |
| 51 | 51 |
| 52 | 52 |
| 53 def get_col_by_pattern(peptable, colpattern): | 53 def get_col_by_pattern(peptable, colpattern): |
| 54 with open(peptable) as fp: | 54 with open(peptable) as fp: |
| 69 with open(peptable) as fp: | 69 with open(peptable) as fp: |
| 70 header = next(fp).strip('\n').split('\t') | 70 header = next(fp).strip('\n').split('\t') |
| 71 yield header + ['Experimental pI', 'Predicted pI', 'Delta pI'] | 71 yield header + ['Experimental pI', 'Predicted pI', 'Delta pI'] |
| 72 for line in fp: | 72 for line in fp: |
| 73 line = line.strip('\n').split('\t') | 73 line = line.strip('\n').split('\t') |
| 74 strip = strips[get_first_matching_pattern(strips.keys(), | |
| 75 line[stripcol])] | |
| 76 exp_pi = (strip['fr_width'] * int(line[frac_col]) + | |
| 77 strip['intercept']) | |
| 78 | |
| 79 sequence = line[seqcol] | 74 sequence = line[seqcol] |
| 80 for weight in ignoremods: | 75 for weight in ignoremods: |
| 81 if weight == '*': | 76 if weight == '*': |
| 82 regex = '[+-]\d*\.\d*' | 77 regex = '[+-]\d*\.\d*' |
| 83 else: | 78 else: |
| 88 except KeyError: | 83 except KeyError: |
| 89 print('CANNOT PREDICT', sequence) | 84 print('CANNOT PREDICT', sequence) |
| 90 not_predicted_count += 1 | 85 not_predicted_count += 1 |
| 91 pred_pi, delta_pi = 'NA', 'NA' | 86 pred_pi, delta_pi = 'NA', 'NA' |
| 92 else: | 87 else: |
| 93 delta_pi = exp_pi - pred_pi | |
| 94 predicted_count += 1 | 88 predicted_count += 1 |
| 89 strip = get_strip(strips, line[stripcol]) | |
| 90 if not strip: | |
| 91 exp_pi, delta_pi = 'NA', 'NA' | |
| 92 else: | |
| 93 try: | |
| 94 exp_pi = (strip['fr_width'] * int(line[frac_col]) + | |
| 95 strip['intercept']) | |
| 96 except ValueError: | |
| 97 print('Cannot detect fraction for PSM {}'.format(sequence)) | |
| 98 exp_pi, delta_pi = 'NA', 'NA' | |
| 99 else: | |
| 100 if pred_pi != 'NA': | |
| 101 delta_pi = exp_pi - pred_pi | |
| 102 else: | |
| 103 delta_pi = 'NA' | |
| 95 yield line + [exp_pi, pred_pi, delta_pi] | 104 yield line + [exp_pi, pred_pi, delta_pi] |
| 96 print('Number of peptides without pI prediction: {}\n' | 105 print('Number of peptides without pI prediction: {}\n' |
| 97 'Number of peptides with predicion: {}\n'.format(not_predicted_count, | 106 'Number of peptides predicted: {}\n'.format(not_predicted_count, |
| 98 predicted_count)) | 107 predicted_count)) |
| 99 | 108 |
| 100 | 109 |
| 101 def parse_commandline(): | 110 def parse_commandline(): |
| 102 parser = argparse.ArgumentParser( | 111 parser = argparse.ArgumentParser( |
| 103 formatter_class=argparse.RawTextHelpFormatter) | 112 formatter_class=argparse.RawTextHelpFormatter) |
