Esempio n. 1
0
 def testPropertyNameIsLowercased(self):
     """
     The property name must be lower-cased in the result.
     """
     read = AARead('id', '')
     self.assertTrue('hydropathy' in
                     propertiesForSequence(read, ['HYDROPATHY']))
Esempio n. 2
0
 def testPropertyNameIsLowercased(self):
     """
     The property name must be lower-cased in the result.
     """
     read = AARead('id', '')
     self.assertTrue(
         'hydropathy' in propertiesForSequence(read, ['HYDROPATHY']))
Esempio n. 3
0
 def testOneProperty(self):
     """
     If one property is wanted, a dict with the property must be returned,
     and have the expected property values.
     """
     read = AARead('id', 'AI')
     self.assertEqual({
         'hydropathy': [0.4, 1.0],
     }, propertiesForSequence(read, ['hydropathy']))
Esempio n. 4
0
 def testOnePropertyEmptySequence(self):
     """
     If one property is wanted but the sequence is empty, a dict with the
     property must be returned, and have an empty list value.
     """
     read = AARead('id', '')
     self.assertEqual({
         'hydropathy': [],
     }, propertiesForSequence(read, ['hydropathy']))
Esempio n. 5
0
 def testTwoProperties(self):
     """
     If two properties are wanted, a dict with the properties must be
     returned, and have the expected property values.
     """
     read = AARead('id', 'AI')
     self.assertEqual(
         {
             'composition': [-1.0, -1.0],
             'hydropathy': [0.4, 1.0],
         }, propertiesForSequence(read, ['composition', 'hydropathy']))
Esempio n. 6
0
 def testOneProperty(self):
     """
     If one property is wanted, a dict with the property must be returned,
     and have the expected property values.
     """
     read = AARead('id', 'AI')
     self.assertEqual(
         {
             'hydropathy': [0.4, 1.0],
         },
         propertiesForSequence(read, ['hydropathy']))
Esempio n. 7
0
 def testOnePropertyEmptySequence(self):
     """
     If one property is wanted but the sequence is empty, a dict with the
     property must be returned, and have an empty list value.
     """
     read = AARead('id', '')
     self.assertEqual(
         {
             'hydropathy': [],
         },
         propertiesForSequence(read, ['hydropathy']))
Esempio n. 8
0
 def testMissingAminoAcid(self):
     """
     If an unknown amino acid appears in the sequence, its property value
     must be the default (-1.1).
     """
     read = AARead('id', 'XX')
     self.assertEqual(
         {
             'composition': [-1.1, -1.1],
             'hydropathy': [-1.1, -1.1],
         }, propertiesForSequence(read, ['composition', 'hydropathy']))
Esempio n. 9
0
 def testMissingAminoAcid(self):
     """
     If an unknown amino acid appears in the sequence, its property value
     must be the default (-1.1).
     """
     read = AARead('id', 'XX')
     self.assertEqual(
         {
             'composition': [-1.1, -1.1],
             'hydropathy': [-1.1, -1.1],
         },
         propertiesForSequence(read, ['composition', 'hydropathy']))
Esempio n. 10
0
 def testTwoProperties(self):
     """
     If two properties are wanted, a dict with the properties must be
     returned, and have the expected property values.
     """
     read = AARead('id', 'AI')
     self.assertEqual(
         {
             'composition': [-1.0, -1.0],
             'hydropathy': [0.4, 1.0],
         },
         propertiesForSequence(read, ['composition', 'hydropathy']))
Esempio n. 11
0
 def testMissingAminoAcidWithNonDefaultMissingValue(self):
     """
     If an unknown amino acid appears in the sequence, its property value
     must be the missing AA value that was passed.
     """
     read = AARead('id', 'XX')
     self.assertEqual(
         {
             'composition': [-1.5, -1.5],
             'hydropathy': [-1.5, -1.5],
         },
         propertiesForSequence(read, ['composition', 'hydropathy'],
                               missingAAValue=-1.5))
Esempio n. 12
0
 def testMissingAminoAcidWithNonDefaultMissingValue(self):
     """
     If an unknown amino acid appears in the sequence, its property value
     must be the missing AA value that was passed.
     """
     read = AARead('id', 'XX')
     self.assertEqual(
         {
             'composition': [-1.5, -1.5],
             'hydropathy': [-1.5, -1.5],
         },
         propertiesForSequence(read, ['composition', 'hydropathy'],
                               missingAAValue=-1.5))
Esempio n. 13
0
 def testDuplicatedPropertyName(self):
     """
     If a property name is mentioned more than once, a dict with the
     wanted properties must be returned, and have the expected property
     values.
     """
     read = AARead('id', 'AI')
     self.assertEqual(
         {
             'composition': [-1.0, -1.0],
             'hydropathy': [0.4, 1.0],
         },
         propertiesForSequence(read,
                               ['composition', 'hydropathy', 'hydropathy']))
Esempio n. 14
0
 def testDuplicatedPropertyName(self):
     """
     If a property name is mentioned more than once, a dict with the
     wanted properties must be returned, and have the expected property
     values.
     """
     read = AARead('id', 'AI')
     self.assertEqual(
         {
             'composition': [-1.0, -1.0],
             'hydropathy': [0.4, 1.0],
         },
         propertiesForSequence(read, ['composition',
                                      'hydropathy', 'hydropathy']))
Esempio n. 15
0
def plotAAProperties(sequence, propertyNames, showLines=True, showFigure=True):
    """
    Plot amino acid property values for a sequence.

    @param sequence: An C{AARead} (or a subclass) instance.
    @param propertyNames: An iterable of C{str} property names (each of which
        must be a key of a key in the C{dark.aa.PROPERTY_DETAILS} C{dict}).
    @param showLines: If C{True}, lines will be drawn between successive AA
        property values. If not, just the values will be plotted as a scatter
        plot (this greatly reduces visual clutter if the sequence is long and
        AA property values are variable).
    @param showFigure: If C{True}, display the plot. Passing C{False} is useful
        in testing.
    @raise ValueError: If an unknown property is given in C{propertyNames}.
    @return: The return value from calling dark.aa.propertiesForSequence:
        a C{dict} keyed by (lowercase) property name, with values that are
        C{list}s of the corresponding property value according to sequence
        position.
    """
    MISSING_AA_VALUE = -1.1
    propertyValues = propertiesForSequence(sequence,
                                           propertyNames,
                                           missingAAValue=MISSING_AA_VALUE)
    if showFigure:
        legend = []
        x = np.arange(0, len(sequence))
        plot = plt.plot if showLines else plt.scatter

        for index, propertyName in enumerate(propertyValues):
            color = TABLEAU20[index]
            plot(x, propertyValues[propertyName], color=color)
            legend.append(patches.Patch(color=color, label=propertyName))

        plt.legend(handles=legend, loc=(0, 1.1))
        plt.xlim(-0.2, len(sequence) - 0.8)
        plt.ylim(min(MISSING_AA_VALUE, -1.1), 1.1)
        plt.xlabel('Sequence index')
        plt.ylabel('Property value')
        plt.title(sequence.id)
        plt.show()

    return propertyValues
Esempio n. 16
0
def plotAAProperties(sequence, propertyNames, showLines=True, showFigure=True):
    """
    Plot amino acid property values for a sequence.

    @param sequence: An C{AARead} (or a subclass) instance.
    @param propertyNames: An iterable of C{str} property names (each of which
        must be a key of a key in the C{dark.aa.PROPERTY_DETAILS} C{dict}).
    @param showLines: If C{True}, lines will be drawn between successive AA
        property values. If not, just the values will be plotted as a scatter
        plot (this greatly reduces visual clutter if the sequence is long and
        AA property values are variable).
    @param showFigure: If C{True}, display the plot. Passing C{False} is useful
        in testing.
    @raise ValueError: If an unknown property is given in C{propertyNames}.
    @return: The return value from calling dark.aa.propertiesForSequence:
        a C{dict} keyed by (lowercase) property name, with values that are
        C{list}s of the corresponding property value according to sequence
        position.
    """
    MISSING_AA_VALUE = -1.1
    propertyValues = propertiesForSequence(sequence, propertyNames,
                                           missingAAValue=MISSING_AA_VALUE)
    if showFigure:
        legend = []
        x = np.arange(0, len(sequence))
        plot = plt.plot if showLines else plt.scatter

        for index, propertyName in enumerate(propertyValues):
            color = TABLEAU20[index]
            plot(x, propertyValues[propertyName], color=color)
            legend.append(patches.Patch(color=color, label=propertyName))

        plt.legend(handles=legend, loc=(0, 1.1))
        plt.xlim(-0.2, len(sequence) - 0.8)
        plt.ylim(min(MISSING_AA_VALUE, -1.1), 1.1)
        plt.xlabel('Sequence index')
        plt.ylabel('Property value')
        plt.title(sequence.id)
        plt.show()

    return propertyValues
Esempio n. 17
0
 def testNoProperties(self):
     """
     If no properties are wanted, an empty dict must be returned.
     """
     read = AARead('id', 'RRR')
     self.assertEqual({}, propertiesForSequence(read, []))
Esempio n. 18
0
 def testNoProperties(self):
     """
     If no properties are wanted, an empty dict must be returned.
     """
     read = AARead('id', 'RRR')
     self.assertEqual({}, propertiesForSequence(read, []))