Mercurial > repos > galaxyp > hirieftools
comparison pi_database_splitter.py @ 1:8a30d6e5b97d draft
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tools/pi_db_tools commit ddcc42d2a767f7c14eb710b8ac264745c25444d3
author | galaxyp |
---|---|
date | Mon, 24 Jul 2017 05:25:22 -0400 |
parents | 34c5c95740a1 |
children |
comparison
equal
deleted
inserted
replaced
0:34c5c95740a1 | 1:8a30d6e5b97d |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 import sys | 2 import sys |
3 import argparse | 3 import argparse |
4 from numpy import median | 4 from numpy import median |
5 from contextlib import ExitStack | 5 from contextlib import ExitStack |
6 | |
7 from peptide_pi_annotator import get_col_by_pattern | |
6 | 8 |
7 | 9 |
8 def main(): | 10 def main(): |
9 if sys.argv[1:] == []: | 11 if sys.argv[1:] == []: |
10 sys.argv.append('-h') | 12 sys.argv.append('-h') |
12 locfun = {False: locatefraction, | 14 locfun = {False: locatefraction, |
13 True: reverse_locatefraction}[args.reverse] | 15 True: reverse_locatefraction}[args.reverse] |
14 # Column nrs should start from 0 | 16 # Column nrs should start from 0 |
15 # If negative, -1 is last item in list, etc | 17 # If negative, -1 is last item in list, etc |
16 if args.fdrcol > 0: | 18 if args.fdrcol > 0: |
17 args.fdrcol -= 1 | 19 fdrcol = args.fdrcol - 1 |
20 elif args.fdrcol: | |
21 fdrcol = args.fdrcol | |
22 elif args.fdrcolpattern: | |
23 fdrcol = get_col_by_pattern(args.train_peptable, args.fdrcolpattern) | |
24 else: | |
25 fdrcol = False | |
18 if args.deltapicol > 0: | 26 if args.deltapicol > 0: |
19 args.deltapicol -= 1 | 27 deltapicol = args.deltapicol - 1 |
20 pishift = get_pishift(args.train_peptable, args.fdrcol, args.deltapicol, | 28 elif args.deltapicol: |
29 deltapicol = args.deltapicol | |
30 elif args.deltapicolpattern: | |
31 deltapicol = get_col_by_pattern(args.train_peptable, | |
32 args.deltapicolpattern) | |
33 else: | |
34 deltapicol = False | |
35 pishift = get_pishift(args.train_peptable, fdrcol, deltapicol, | |
21 args.fdrcutoff, args.picutoff) | 36 args.fdrcutoff, args.picutoff) |
22 binarray = get_bin_array(args.fr_amount, args.fr_width, args.intercept, | 37 binarray = get_bin_array(args.fr_amount, args.fr_width, args.intercept, |
23 args.tolerance, pishift) | 38 args.tolerance, pishift) |
24 write_fractions(args.pipeps, args.fr_amount, args.prefix, | 39 write_fractions(args.pipeps, args.fr_amount, args.prefix, |
25 binarray, locfun, args.minlen, args.maxlen) | 40 binarray, locfun, args.minlen, args.maxlen) |
58 'Tab separated file.') | 73 'Tab separated file.') |
59 parser.add_argument('--deltacol', dest='deltapicol', help='Delta pI column' | 74 parser.add_argument('--deltacol', dest='deltapicol', help='Delta pI column' |
60 ' number in peptide table. First column is nr. 1. ' | 75 ' number in peptide table. First column is nr. 1. ' |
61 'Negative number for counting from last col ' | 76 'Negative number for counting from last col ' |
62 '(-1 is last).', default=False, type=int) | 77 '(-1 is last).', default=False, type=int) |
78 parser.add_argument('--deltacolpattern', dest='deltapicolpattern', | |
79 help='Delta pI column header pattern in peptide ' | |
80 'table.', default=False, type=str) | |
63 parser.add_argument('--picutoff', dest='picutoff', | 81 parser.add_argument('--picutoff', dest='picutoff', |
64 help='delta pI value to filter experimental peptides' | 82 help='delta pI value to filter experimental peptides' |
65 ' when calculating pi shift.', default=0.2, type=float) | 83 ' when calculating pi shift.', default=0.2, type=float) |
84 parser.add_argument('--fdrcolpattern', dest='fdrcolpattern', | |
85 help='FDR column header pattern in peptide table.', | |
86 default=False, type=str) | |
66 parser.add_argument('--fdrcol', dest='fdrcol', help='FDR column number in ' | 87 parser.add_argument('--fdrcol', dest='fdrcol', help='FDR column number in ' |
67 'peptide table. First column is nr. 1. Empty includes ' | 88 'peptide table. First column is nr. 1. Empty includes ' |
68 'all peptides', default=False, type=int) | 89 'all peptides', default=False, type=int) |
69 parser.add_argument('--fdrcutoff', dest='fdrcutoff', | 90 parser.add_argument('--fdrcutoff', dest='fdrcutoff', |
70 help='FDR cutoff value to filter experimental peptides' | 91 help='FDR cutoff value to filter experimental peptides' |
82 action='store_const', const=True, default=False) | 103 action='store_const', const=True, default=False) |
83 parser.add_argument('--intercept', dest='intercept', | 104 parser.add_argument('--intercept', dest='intercept', |
84 help='pI Intercept of strip', type=float) | 105 help='pI Intercept of strip', type=float) |
85 parser.add_argument('--width', dest='fr_width', | 106 parser.add_argument('--width', dest='fr_width', |
86 help='Strip fraction width in pI', type=float) | 107 help='Strip fraction width in pI', type=float) |
87 parser.add_argument('--minlen', dest='minlen', help='Minimal peptide length', | 108 parser.add_argument('--minlen', dest='minlen', help='Minimal peptide length', |
88 type=int) | 109 type=int) |
89 parser.add_argument('--maxlen', dest='maxlen', help='Maximal peptide length', | 110 parser.add_argument('--maxlen', dest='maxlen', help='Maximal peptide length', |
90 type=int, default=False) | 111 type=int, default=False) |
91 return parser.parse_args(sys.argv[1:]) | 112 return parser.parse_args(sys.argv[1:]) |
92 | 113 |
144 pepcount = 0 | 165 pepcount = 0 |
145 for line in input_fp: | 166 for line in input_fp: |
146 accs, pep, pi = line.strip().split("\t") | 167 accs, pep, pi = line.strip().split("\t") |
147 pi = float(pi) | 168 pi = float(pi) |
148 if maxlen and len(pep) > maxlen: | 169 if maxlen and len(pep) > maxlen: |
149 continue | 170 continue |
150 elif len(pep) >= minlen: | 171 elif len(pep) >= minlen: |
151 pepcount += 1 | 172 pepcount += 1 |
152 if pep[-1] in {'K', 'R'}: | 173 if pep[-1] in {'K', 'R'}: |
153 rev_pep = pep[::-1][1:] + pep[-1] | 174 rev_pep = pep[::-1][1:] + pep[-1] |
154 else: | 175 else: |