def testPropertyNameIsLowercased(self): """ The property name must be lower-cased in the result. """ read = AARead('id', '') self.assertTrue('hydropathy' in clustersForSequence(read, ['HYDROPATHY']))
def testPropertyNameIsLowercased(self): """ The property name must be lower-cased in the result. """ read = AARead('id', '') self.assertTrue( 'hydropathy' in clustersForSequence(read, ['HYDROPATHY']))
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']))
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']))
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']))
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']))
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']))
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']))
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
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']))
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']))
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))
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))
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']))
def testNoProperties(self): """ If no properties are wanted, an empty dict must be returned. """ read = AARead('id', 'RRR') self.assertEqual({}, clustersForSequence(read, []))