diff options
| -rwxr-xr-x | bin/pepseq | 99 | ||||
| -rw-r--r-- | pepseq/amino_acid.py | 63 | ||||
| -rw-r--r-- | sample-input | 20 |
3 files changed, 144 insertions, 38 deletions
@@ -17,6 +17,11 @@ if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'pepseq')) import logging import optparse import pepseq +import itertools + +import ConfigParser + +import pepseq.amino_acid import gettext from gettext import gettext as _ @@ -29,39 +34,105 @@ LEVELS = (logging.ERROR, def parse_args(): - usage = _("pepseq [options]") + usage = _("pepseq [options] <inputfile>") parser = optparse.OptionParser(version="pepseq %s" % pepseq.__version__, usage=usage) parser.add_option('-d', '--debug', dest='debug_mode', action='store_true', help=_('Print the maximum debugging info (implies -vv)')) parser.add_option('-v', '--verbose', dest='logging_level', action='count', help=_('set error_level output to warning, info, and then debug')) - parser.add_option("-f", "--foo", action="store", dest="foo", - help=_("foo should be assigned to bar")) - parser.set_defaults(logging_level=0, foo=None) - return parser.parse_args() + parser.set_defaults(logging_level=0) -def main(): - (options, args) = parse_args() + (options, args) = parser.parse_args() if options.debug_mode: loglevel = 3 else: try: loglevel = LEVELS[options.logging_level] - print 'loglevel: %d, options.logging_level: %d' % (loglevel, options.logging_level) except IndexError: loglevel = 3 - logging.basicConfig(level=loglevel, format='%(asctime)s %(levelname)s %(message)s') + logging.basicConfig(level=loglevel, + format='%(asctime)s %(levelname)s %(message)s') + + return parser.parse_args() + + +def main(): + (options, args) = parse_args() - if options.foo == 'bar': - logging.warning(_('easter egg found')) - print(_("Schweet")) + config = ConfigParser.ConfigParser() - print _("I'm launched and my args are: %s") % (" ".join(args)) - logging.debug(_('end of prog')) + try: + config.readfp(open(args[0])) + except IndexError: + try: + config.readfp(open("sample-input")) + except IOError: + config.readfp(open("../sample-input")) + + bucket1 = [] + for char in config.get('DEFAULT', 'bucket1').split(' '): + bucket1.append(pepseq.amino_acid.AminoAcid(char)) + + bucket2 = [] + for char in config.get('DEFAULT', 'bucket2').split(' '): + bucket2.append(pepseq.amino_acid.AminoAcid(char)) + + bucket3 = [] + for char in config.get('DEFAULT', 'bucket3').split(' '): + bucket3.append(pepseq.amino_acid.AminoAcid(char)) + + bucket4 = [] + for char in config.get('DEFAULT', 'bucket4').split(' '): + bucket4.append(pepseq.amino_acid.AminoAcid(char)) + + bucket5 = [] + for char in config.get('DEFAULT', 'bucket5').split(' '): + bucket5.append(pepseq.amino_acid.AminoAcid(char)) + bucket5.append(pepseq.amino_acid.AminoAcid('N')) + + bucket6 = [] + for char in config.get('DEFAULT', 'bucket6').split(' '): + bucket6.append(pepseq.amino_acid.AminoAcid(char)) + + bucket7 = [] + for char in config.get('DEFAULT', 'bucket7').split(' '): + bucket7.append(pepseq.amino_acid.AminoAcid(char)) + + bucket8 = [] + for char in config.get('DEFAULT', 'bucket8').split(' '): + bucket8.append(pepseq.amino_acid.AminoAcid(char)) + + bucket9 = [] + for char in config.get('DEFAULT', 'bucket9').split(' '): + bucket9.append(pepseq.amino_acid.AminoAcid(char)) + + possibilities = (bucket1, bucket2, bucket3, + bucket4, bucket5, bucket6, + bucket7, bucket8, bucket9) + + peptides = [] + sequences = tuple(itertools.product(*possibilities)) + for sequence in sequences: + if sequence[4].letter == 'K': + peptide = pepseq.amino_acid.Peptide(sequence) + peptide.branch_before(4) + peptides.append(peptide) + + peptides.sort() + + output = [] + for peptide in peptides: + if peptide.weight > float(config.get('DEFAULT', 'low')): + if peptide.weight < float(config.get('DEFAULT', 'high')): + output.append(peptide) + + print 'Number of matches: %d' % len(output) + for peptide in output: + print ("%.2f %s " % (peptide.weight, peptide) + ' '.join(peptide.subweights)) if __name__ == "__main__": main() diff --git a/pepseq/amino_acid.py b/pepseq/amino_acid.py index 05ecb07..ceced0e 100644 --- a/pepseq/amino_acid.py +++ b/pepseq/amino_acid.py @@ -6,27 +6,27 @@ class AminoAcid(object): """ Amino acids are molecules containing an amine group, a carboxylic acid group and a side chain that varies between different amino acids. """ - aminoAcids = {'G': ('Glycine', 'Gly', 57.05), - 'A': ('Alanine', 'Ala', 71.09), - 'S': ('Serine', 'Ser', 87.08), - 'T': ('Threonine', 'Thr', 101.11), - 'C': ('Cysteine', 'Cys', 103.15), - 'V': ('Valine', 'Val', 99.14), - 'L': ('Leucine', 'Leu', 113.16), - 'I': ('Isoleucine', 'Ile', 113.16), - 'M': ('Methionine', 'Met', 131.19), - 'P': ('Proline', 'Pro', 97.12), - 'F': ('Phenylalanine', 'Phe', 147.18), - 'Y': ('Tyrosine', 'Tyr', 163.18), - 'W': ('Tryptophan', 'Trp', 186.21), - 'D': ('Aspartic Acid', 'Asp', 115.09), - 'E': ('Glutamic Acid', 'Glu', 129.12), - 'N': ('Asparagine', 'Asn', 114.11), - 'Q': ('Glutamine', 'Gln', 128.14), - 'H': ('Histidine', 'His', 137.14), - 'K': ('Lysine', 'Lys', 128.17), - 'R': ('Arginine', 'Arg', 156.19), - 'B': ('Borono Phenylalanine', 'Bpa', 309.08), + aminoAcids = {'G': ('Glycine', 'Gly', 57.00), + 'A': ('Alanine', 'Ala', 71.00), + 'S': ('Serine', 'Ser', 87.00), + 'T': ('Threonine', 'Thr', 101.00), + 'C': ('Cysteine', 'Cys', 103.00), + 'V': ('Valine', 'Val', 99.10), + 'L': ('Leucine', 'Leu', 113.10), + 'I': ('Isoleucine', 'Ile', 113.10), + 'M': ('Methionine', 'Met', 131.00), + 'P': ('Proline', 'Pro', 97.10), + 'F': ('Phenylalanine', 'Phe', 147.10), + 'Y': ('Tyrosine', 'Tyr', 163.10), + 'W': ('Tryptophan', 'Trp', 186.10), + 'D': ('Aspartic Acid', 'Asp', 115.00), + 'E': ('Glutamic Acid', 'Glu', 129.00), + 'N': ('Asparagine', 'Asn', 114.00), + 'Q': ('Glutamine', 'Gln', 128.10), + 'H': ('Histidine', 'His', 137.10), + 'K': ('Lysine', 'Lys', 128.10), + 'R': ('Arginine', 'Arg', 156.10), + 'B': ('Borono Phenylalanine', 'Bpa', 394.10), } def __init__(self, letter): @@ -45,19 +45,34 @@ class Peptide(object): def __init__(self, amino_acids): self.amino_acids = amino_acids self.weight = 0 + self.subweights = [] self.string = "" for amino_acid in amino_acids: self.weight += amino_acid.weight self.string += ('%s' % (amino_acid.letter)) def branch_before(self, index): - self.weight = 0 + self.weight = 18.00 for (counter, amino_acid) in enumerate(self.amino_acids): if counter < index: self.weight += 2 * amino_acid.weight else: self.weight += amino_acid.weight - self.string = '(' + self.string[0:index] + ')2' + self.string[index:] + self.string = ('(' + self.string[0:index] + ')2 ' + + self.string[index + 1:]) + self._calculate_subweights() + + def _calculate_subweights(self): + + self.subweights.append(str(self.weight - self.amino_acids[0].weight)) + self.subweights.append(str(float(self.subweights[0]) - self.amino_acids[1].weight)) + self.subweights.append(str(float(self.subweights[1]) - self.amino_acids[2].weight)) + self.subweights.append(str(float(self.subweights[2]) - self.amino_acids[3].weight)) + + self.subweights.append(str(self.weight - 17.1 - self.amino_acids[-1].weight)) + self.subweights.append(str(float(self.subweights[-1]) - self.amino_acids[-2].weight)) + self.subweights.append(str(float(self.subweights[-1]) - self.amino_acids[-3].weight)) + self.subweights.append(str(float(self.subweights[-1]) - self.amino_acids[-4].weight)) def __cmp__(self, other): return cmp(self.weight, other.weight) @@ -70,7 +85,7 @@ if __name__ == '__main__': import itertools - LOW = 2636.0 + LOW = 2636.0 HIGH = 2637.0 possibilities = ( diff --git a/sample-input b/sample-input new file mode 100644 index 0000000..480624a --- /dev/null +++ b/sample-input @@ -0,0 +1,20 @@ +# This is a sample input file +# +# IMPORTANT: There MUST be 9 buckets and bucket 5 MUST be 'K'. There is nearly +# no input validation, so make sure you get this right. If the output looks +# wrong, start by verifying what you've recorded here. + +[DEFAULT] + +low = 1545.0 +high = 1546.0 + +bucket1 = B E T Y +bucket2 = B N A F +bucket3 = B D S H +bucket4 = B Q L W +bucket5 = K +bucket6 = B N I Y +bucket7 = B E V W +bucket8 = B Q P H +bucket9 = B E S F |