Ejemplo n.º 1
0
 def testFindMultipleMatches(self):
     """
     It must be possible to find more than one matching amino acid.
     """
     aa1, aa2 = list(find('acid'))
     self.assertEqual('Aspartic acid', aa1.name)
     self.assertEqual('Glutamic acid', aa2.name)
Ejemplo n.º 2
0
def findOrDie(s):
    """
    Look up an amino acid.

    @param s: A C{str} amino acid specifier. This may be a full name,
        a 3-letter abbreviation or a 1-letter abbreviation. Case is ignored.
    @return: An C{AminoAcid} instance, if one can be found. Else exit.
    """
    aa = find(s)
    if aa:
        return aa
    else:
        print("Unknown amino acid or codon: %s" % s, file=sys.stderr)
        print("Valid arguments are: %s." % list(CODONS.keys()), file=sys.stderr)
        sys.exit(1)
Ejemplo n.º 3
0
def findOrDie(s):
    """
    Look up an amino acid.

    @param s: A C{str} amino acid specifier. This may be a full name,
        a 3-letter abbreviation or a 1-letter abbreviation. Case is ignored.
    @return: An C{AminoAcid} instance, if one can be found. Else exit.
    """
    aa = find(s)
    if aa:
        return aa
    else:
        print('Unknown amino acid or codon: %s' % s, file=sys.stderr)
        print('Valid arguments are: %s.' % list(CODONS.keys()),
              file=sys.stderr)
        sys.exit(1)
Ejemplo n.º 4
0
 def testFindByNameCaseIgnoredNameWithSpace(self):
     """
     It must be possible to find an amino acid by its name when the name is
     given in mixed case, including if the name has a space in it.
     """
     aa = find('asparTIC aCId')
     self.assertEqual('Aspartic acid', aa.name)
     self.assertEqual('Asp', aa.abbrev3)
     self.assertEqual('D', aa.abbrev1)
     self.assertEqual(('GAC', 'GAT'), aa.codons)
     self.assertEqual(HYDROPHILIC | SMALL | POLAR | NEGATIVE, aa.properties)
     self.assertEqual(
         {
             'aliphaticity': -0.818181818182,
             'aromaticity': -1.0,
             'composition': 0.00363636363636,
             'hydrogenation': -0.90243902439,
             'hydropathy': -0.777777777778,
             'hydroxythiolation': -0.348394768133,
             'iep': -1.0,
             'polar requirement': 1.0,
             'polarity': 1.0,
             'volume': -0.389221556886,
         },
         aa.propertyDetails)
     self.assertEqual(
         {
             'aliphaticity': 1,
             'aromaticity': 1,
             'composition': 2,
             'hydrogenation': 1,
             'hydropathy': 1,
             'hydroxythiolation': 2,
             'iep': 1,
             'polar requirement': 4,
             'polarity': 4,
             'volume': 3,
         },
         aa.propertyClusters)
Ejemplo n.º 5
0
 def testFindByNameCaseIgnored(self):
     """
     It must be possible to find an amino acid by its name when the name is
     given in mixed case.
     """
     aa = find('alaNIne')
     self.assertEqual('Alanine', aa.name)
     self.assertEqual('Ala', aa.abbrev3)
     self.assertEqual('A', aa.abbrev1)
     self.assertEqual(('GCA', 'GCC', 'GCG', 'GCT'), aa.codons)
     self.assertEqual(HYDROPHOBIC | SMALL | TINY, aa.properties)
     self.assertEqual(
         {
             'aliphaticity': 0.305785123967,
             'aromaticity': -0.550128534704,
             'composition': -1.0,
             'hydrogenation': 0.8973042362,
             'hydropathy': 0.4,
             'hydroxythiolation': -0.265160523187,
             'iep': -0.191489361702,
             'polar requirement': -0.463414634146,
             'polarity': -0.20987654321,
             'volume': -0.664670658683,
         },
         aa.propertyDetails)
     self.assertEqual(
         {
             'aliphaticity': 1,
             'aromaticity': 1,
             'composition': 1,
             'hydrogenation': 1,
             'hydropathy': 3,
             'hydroxythiolation': 2,
             'iep': 2,
             'polar requirement': 2,
             'polarity': 2,
             'volume': 2,
         },
         aa.propertyClusters)
Ejemplo n.º 6
0
 def testFindByNameCaseIgnoredNameWithSpace(self):
     """
     It must be possible to find an amino acid by its name when the name is
     given in mixed case, including if the name has a space in it.
     """
     aa = find('asparTIC aCId')
     self.assertEqual('Aspartic acid', aa.name)
     self.assertEqual('Asp', aa.abbrev3)
     self.assertEqual('D', aa.abbrev1)
     self.assertEqual(('GAC', 'GAT'), aa.codons)
     self.assertEqual(HYDROPHILIC | SMALL | POLAR | NEGATIVE, aa.properties)
     self.assertEqual(
         {
             'aliphaticity': -0.818181818182,
             'aromaticity': -1.0,
             'composition': 0.00363636363636,
             'hydrogenation': -0.90243902439,
             'hydropathy': -0.777777777778,
             'hydroxythiolation': -0.348394768133,
             'iep': -1.0,
             'polar requirement': 1.0,
             'polarity': 1.0,
             'volume': -0.389221556886,
         },
         aa.propertyDetails)
     self.assertEqual(
         {
             'aliphaticity': 1,
             'aromaticity': 1,
             'composition': 2,
             'hydrogenation': 1,
             'hydropathy': 1,
             'hydroxythiolation': 2,
             'iep': 1,
             'polar requirement': 4,
             'polarity': 4,
             'volume': 3,
         },
         aa.propertyClusters)
Ejemplo n.º 7
0
 def testFindByNameCaseIgnored(self):
     """
     It must be possible to find an amino acid by its name when the name is
     given in mixed case.
     """
     aa = find('alaNIne')
     self.assertEqual('Alanine', aa.name)
     self.assertEqual('Ala', aa.abbrev3)
     self.assertEqual('A', aa.abbrev1)
     self.assertEqual(('GCA', 'GCC', 'GCG', 'GCT'), aa.codons)
     self.assertEqual(HYDROPHOBIC | SMALL | TINY, aa.properties)
     self.assertEqual(
         {
             'aliphaticity': 0.305785123967,
             'aromaticity': -0.550128534704,
             'composition': -1.0,
             'hydrogenation': 0.8973042362,
             'hydropathy': 0.4,
             'hydroxythiolation': -0.265160523187,
             'iep': -0.191489361702,
             'polar requirement': -0.463414634146,
             'polarity': -0.20987654321,
             'volume': -0.664670658683,
         },
         aa.propertyDetails)
     self.assertEqual(
         {
             'aliphaticity': 1,
             'aromaticity': 1,
             'composition': 1,
             'hydrogenation': 1,
             'hydropathy': 3,
             'hydroxythiolation': 2,
             'iep': 2,
             'polar requirement': 2,
             'polarity': 2,
             'volume': 2,
         },
         aa.propertyClusters)
Ejemplo n.º 8
0
 def testFindUnknown(self):
     """
     find must return C{None} when called with an unrecognized value.
     """
     self.assertEqual(None, find('silly'))
Ejemplo n.º 9
0
 def testFindUnknown(self):
     """
     find must return C{None} when called with an unrecognized value.
     """
     self.assertEqual(None, find('silly'))
Ejemplo n.º 10
0
#!/usr/bin/env python

from __future__ import print_function

import sys

from dark.aa import find
from dark.aa import CODONS

from dark.aa import AA_LETTERS, ALL_PROPERTIES, PROPERTY_NAMES

args = AA_LETTERS if len(sys.argv) == 1 else sys.argv[1:]
error = False

for arg in args:
    aas = list(find(arg))
    if aas:
        for aa in aas:
            print(aa.name)
            print('  3-letter abbreviation: %s' % aa.abbrev3)
            print('  1-letter abbreviation: %s' % aa.abbrev1)
            print('  Codons: %s' % ', '.join(sorted(aa.codons)))

            properties = []
            print('  Properties:', end=' ')
            for prop in ALL_PROPERTIES:
                if aa.properties & prop:
                    properties.append(PROPERTY_NAMES[prop])
            print(', '.join(properties))

            print('  Property details:')
Ejemplo n.º 11
0
 def testFindByPartialNameMixedCase(self):
     """
     It must be possible to find an amino acid by a mixed-case partial name.
     """
     aa = list(find('NiNe'))[0]
     self.assertEqual('Alanine', aa.name)
Ejemplo n.º 12
0
 def testFindUnknown(self):
     """
     find must return an empty generator when called with an unrecognized
     value.
     """
     self.assertEqual([], list(find('silly')))