Beispiel #1
0
 def testPropertyNameIsLowercased(self):
     """
     The property name must be lower-cased in the result.
     """
     read = AARead('id', '')
     self.assertTrue('hydropathy' in
                     clustersForSequence(read, ['HYDROPATHY']))
Beispiel #2
0
 def testPropertyNameIsLowercased(self):
     """
     The property name must be lower-cased in the result.
     """
     read = AARead('id', '')
     self.assertTrue(
         'hydropathy' in clustersForSequence(read, ['HYDROPATHY']))
Beispiel #3
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': [],
     }, clustersForSequence(read, ['hydropathy']))
Beispiel #4
0
 def testOneProperty(self):
     """
     If one property is wanted, a dict with the property must be returned,
     and have the expected property cluster number.
     """
     read = AARead('id', 'AI')
     self.assertEqual({
         'hydropathy': [3, 4],
     }, clustersForSequence(read, ['hydropathy']))
Beispiel #5
0
 def testTwoProperties(self):
     """
     If two properties are wanted, a dict with the properties must be
     returned, and have the expected property cluster numbers.
     """
     read = AARead('id', 'AI')
     self.assertEqual({
         'composition': [1, 1],
         'hydropathy': [3, 4],
     }, clustersForSequence(read, ['composition', 'hydropathy']))
Beispiel #6
0
 def testMissingAminoAcid(self):
     """
     If an unknown amino acid appears in the sequence, its property cluster
     must be the default (0).
     """
     read = AARead('id', 'XX')
     self.assertEqual({
         'composition': [0, 0],
         'hydropathy': [0, 0],
     }, clustersForSequence(read, ['composition', 'hydropathy']))
Beispiel #7
0
 def testOneProperty(self):
     """
     If one property is wanted, a dict with the property must be returned,
     and have the expected property cluster number.
     """
     read = AARead('id', 'AI')
     self.assertEqual(
         {
             'hydropathy': [3, 4],
         },
         clustersForSequence(read, ['hydropathy']))
Beispiel #8
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': [],
         },
         clustersForSequence(read, ['hydropathy']))
Beispiel #9
0
def plotAAClusters(sequence, propertyNames, showLines=True, showFigure=True):
    """
    Plot amino acid property cluster numbers 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_CLUSTERS} 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.clustersForSequence:
        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 = 0
    propertyClusters = clustersForSequence(sequence,
                                           propertyNames,
                                           missingAAValue=MISSING_AA_VALUE)
    if showFigure:
        minCluster = 1
        maxCluster = -1
        legend = []
        x = np.arange(0, len(sequence))
        plot = plt.plot if showLines else plt.scatter

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

            propertyMinCluster = min(clusterNumbers)
            if propertyMinCluster < minCluster:
                minCluster = propertyMinCluster

            propertyMaxCluster = max(clusterNumbers)
            if propertyMaxCluster > maxCluster:
                maxCluster = propertyMaxCluster

        plt.legend(handles=legend, loc=(0, 1.1))
        plt.xlim(-0.2, len(sequence) - 0.8)
        plt.ylim(minCluster - 0.5, maxCluster + 0.5)
        plt.yticks(range(maxCluster + 1))
        plt.xlabel('Sequence index')
        plt.ylabel('Property cluster number')
        plt.title(sequence.id)
        plt.show()

    return propertyClusters
Beispiel #10
0
def plotAAClusters(sequence, propertyNames, showLines=True, showFigure=True):
    """
    Plot amino acid property cluster numbers 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_CLUSTERS} 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.clustersForSequence:
        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 = 0
    propertyClusters = clustersForSequence(sequence, propertyNames,
                                           missingAAValue=MISSING_AA_VALUE)
    if showFigure:
        minCluster = 1
        maxCluster = -1
        legend = []
        x = np.arange(0, len(sequence))
        plot = plt.plot if showLines else plt.scatter

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

            propertyMinCluster = min(clusterNumbers)
            if propertyMinCluster < minCluster:
                minCluster = propertyMinCluster

            propertyMaxCluster = max(clusterNumbers)
            if propertyMaxCluster > maxCluster:
                maxCluster = propertyMaxCluster

        plt.legend(handles=legend, loc=(0, 1.1))
        plt.xlim(-0.2, len(sequence) - 0.8)
        plt.ylim(minCluster - 0.5, maxCluster + 0.5)
        plt.yticks(range(maxCluster + 1))
        plt.xlabel('Sequence index')
        plt.ylabel('Property cluster number')
        plt.title(sequence.id)
        plt.show()

    return propertyClusters
Beispiel #11
0
 def testMissingAminoAcid(self):
     """
     If an unknown amino acid appears in the sequence, its property cluster
     must be the default (0).
     """
     read = AARead('id', 'XX')
     self.assertEqual(
         {
             'composition': [0, 0],
             'hydropathy': [0, 0],
         },
         clustersForSequence(read, ['composition', 'hydropathy']))
Beispiel #12
0
 def testTwoProperties(self):
     """
     If two properties are wanted, a dict with the properties must be
     returned, and have the expected property cluster numbers.
     """
     read = AARead('id', 'AI')
     self.assertEqual(
         {
             'composition': [1, 1],
             'hydropathy': [3, 4],
         },
         clustersForSequence(read, ['composition', 'hydropathy']))
Beispiel #13
0
 def testMissingAminoAcidWithNonDefaultMissingValue(self):
     """
     If an unknown amino acid appears in the sequence, its property cluster
     must be the missing AA value that was passed.
     """
     read = AARead('id', 'XX')
     self.assertEqual({
         'composition': [10, 10],
         'hydropathy': [10, 10],
     },
                      clustersForSequence(read,
                                          ['composition', 'hydropathy'],
                                          missingAAValue=10))
Beispiel #14
0
 def testMissingAminoAcidWithNonDefaultMissingValue(self):
     """
     If an unknown amino acid appears in the sequence, its property cluster
     must be the missing AA value that was passed.
     """
     read = AARead('id', 'XX')
     self.assertEqual(
         {
             'composition': [10, 10],
             'hydropathy': [10, 10],
         },
         clustersForSequence(read, ['composition', 'hydropathy'],
                             missingAAValue=10))
Beispiel #15
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
     cluster numbers.
     """
     read = AARead('id', 'AI')
     self.assertEqual(
         {
             'composition': [1, 1],
             'hydropathy': [3, 4],
         },
         clustersForSequence(read, ['composition',
                                    'hydropathy', 'hydropathy']))
Beispiel #16
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
     cluster numbers.
     """
     read = AARead('id', 'AI')
     self.assertEqual(
         {
             'composition': [1, 1],
             'hydropathy': [3, 4],
         },
         clustersForSequence(read,
                             ['composition', 'hydropathy', 'hydropathy']))
Beispiel #17
0
 def testNoProperties(self):
     """
     If no properties are wanted, an empty dict must be returned.
     """
     read = AARead('id', 'RRR')
     self.assertEqual({}, clustersForSequence(read, []))
Beispiel #18
0
 def testNoProperties(self):
     """
     If no properties are wanted, an empty dict must be returned.
     """
     read = AARead('id', 'RRR')
     self.assertEqual({}, clustersForSequence(read, []))