Exemplo n.º 1
0
 def testTwoValuesString(self):
     """
     If two values have been added to a Stats instance, its __str__
     method must return the expected result.
     """
     s = Stats()
     s.append(3)
     s.append(4)
     self.assertEqual(('Summary:\n'
                       '  Count: 2\n'
                       '  Max: 4\n'
                       '  Mean: 3.5000\n'
                       '  Median: 3.5000\n'
                       '  Min: 3\n'
                       '  SD: 0.5000\n'
                       '  Variance: 0.2500'), str(s))
Exemplo n.º 2
0
 def testNoValuesString(self):
     """
     If no values have been added to a Stats instance, its __str__
     method must raise ValueError.
     """
     s = Stats()
     error = '^No values have been added to Stats instance\.$'
     six.assertRaisesRegex(self, ValueError, error, str, s)
Exemplo n.º 3
0
 def testNoValuesSummary(self):
     """
     If no values have been added to a Stats instance, its summary
     method must raise ValueError.
     """
     s = Stats()
     error = '^No values have been added to Stats instance\.$'
     six.assertRaisesRegex(self, ValueError, error, s.summary)
Exemplo n.º 4
0
 def testUnequal(self):
     """
     Stats instances that have had the same values added to them, but in
     a different order must be considered unequal.
     """
     s1 = Stats()
     s1.extend([3, 4, 8])
     s2 = Stats()
     s2.extend([3, 8, 4])
     self.assertNotEqual(s1, s2)
Exemplo n.º 5
0
 def testEqual(self):
     """
     Stats instances that have had the same values added to them in
     the same order must be considered equal.
     """
     s1 = Stats()
     s1.extend([3, 4, 8])
     s2 = Stats()
     s2.extend([3, 4, 8])
     self.assertEqual(s1, s2)
Exemplo n.º 6
0
    def testThreeValues(self):
        """
        If three values have been added to a Stats instance, its summary
        method must return the expected result.
        """
        s = Stats()
        s.append(3)
        s.append(4)
        s.append(8)
        result = s.summary()

        self.assertAlmostEqual(2.16024689, result['sd'])
        self.assertAlmostEqual(4.66666666, result['variance'])
        del result['sd']
        del result['variance']

        self.assertEqual(
            {
                'count': 3,
                'max': 8,
                'mean': 5.0,
                'median': 4.0,
                'min': 3,
                'sum': 15,
            }, result)
Exemplo n.º 7
0
 def testOneValue(self):
     """
     If one value has been added to a Stats instance, its summary
     method must return the expected result.
     """
     s = Stats()
     s.append(3)
     self.assertEqual(
         {
             'count': 1,
             'max': 3,
             'mean': 3.0,
             'median': 3.0,
             'min': 3,
             'sd': 0.0,
             'sum': 3,
             'variance': 0.0,
         }, s.summary())
Exemplo n.º 8
0
 def testTwoValues(self):
     """
     If two values have been added to a Stats instance, its summary
     method must return the expected result.
     """
     s = Stats()
     s.append(3)
     s.append(4)
     self.assertEqual(
         {
             'count': 2,
             'max': 4,
             'mean': 3.5,
             'median': 3.5,
             'min': 3,
             'sd': 0.5,
             'sum': 7,
             'variance': 0.25,
         }, s.summary())
Exemplo n.º 9
0
 def testDescription(self):
     """
     If a description string is given to Stats.__init__, it must appear
     in the __str__ result.
     """
     s = Stats('Arm length')
     s.append(3)
     s.append(4)
     s.append(8)
     self.assertEqual(('Arm length:\n'
                       '  Count: 3\n'
                       '  Max: 8\n'
                       '  Mean: 5.0000\n'
                       '  Median: 4.0000\n'
                       '  Min: 3\n'
                       '  SD: 2.1602\n'
                       '  Variance: 4.6667'), str(s))
Exemplo n.º 10
0
 def testThreeValuesString(self):
     """
     If three values have been added to a Stats instance, its __str__
     method must return the expected result.
     """
     s = Stats()
     s.append(3)
     s.append(4)
     s.append(8)
     self.assertEqual(('Summary:\n'
                       '  Count: 3\n'
                       '  Max: 8\n'
                       '  Mean: 5.0000\n'
                       '  Median: 4.0000\n'
                       '  Min: 3\n'
                       '  SD: 2.1602\n'
                       '  Variance: 4.6667'), str(s))
Exemplo n.º 11
0
def analyzeAlphaHelices(reads):
    """
    Analyze a set of reads that contain alpha helices using
    C{analyzeAlphaHelix} and return their overall statistics.

    @return: A C{dict} with the following keys, each of which has a C{Stats}
        instance as its value:

            'length': The alpha helix lengths.
            'initial': The C{int} number of amino acids at the start of
                alpha helices that occurred before the first-found extremum.
            'final': The C{int} number of amino acids at the end of
                alpha helices that occurred after the last-found extremum.
            'extremaCount': The number of extrema found in each alpha helix.
            'consecutivePeaks': A C{list} of C{int} counts of the number of
                consecutive peak AAs found for each time the hydropathy graph
                of an alpha helix goes through an overall peak. See the
                docstring for C{analyzeAlphaHelix} above.
            'consecutiveTroughs': A C{list} of C{int} counts of the number of
                consecutive trough AAs found for each time the hydropathy graph
                of an alpha helix goes through an overall trough. See the
                docstring for C{analyzeAlphaHelix} above.
            'noExtremaLength': The lengths of the alpha helies that do not
                contain any extrema.
    """
    length = Stats('Alpha helix length')
    initial = Stats('Initial non-peak non-trough AAs')
    final = Stats('Final non-peak non-trough AAs')
    extremaCount = Stats('Number of extrema')
    consecutivePeaks = Stats('Consecutive peaks')
    consecutiveTroughs = Stats('Consecutive troughs')
    noExtremaLength = Stats('Length of helices with no extrema')

    for read in reads:
        readLen = len(read)
        length.append(readLen)
        analysis = analyzeAlphaHelix(read)

        if analysis['initial'] is None:
            # No extrema were found in the read.
            noExtremaLength.append(readLen)
            extremaCount.append(0)
        else:
            initial.append(analysis['initial'])
            final.append(analysis['final'])
            extremaCount.append(analysis['extremaCount'])
            consecutivePeaks.extend(analysis['consecutivePeaks'])
            consecutiveTroughs.extend(analysis['consecutiveTroughs'])

    return {
        'length': length,
        'initial': initial,
        'final': final,
        'extremaCount': extremaCount,
        'consecutivePeaks': consecutivePeaks,
        'consecutiveTroughs': consecutiveTroughs,
        'noExtremaLength': noExtremaLength,
    }