Exemple #1
0
    def printAnalysis(analysis, margin='', result=None):
        """
        Convert an analysis to a nicely formatted string.

        @param analysis: A C{dict} with information about the score and its
            calculation.
        @param margin: A C{str} that should be inserted at the start of each
            line of output.
        @param result: A C{MultilineString} instance, or C{None} if a new
            C{MultilineString} should be created.
        @return: If C{result} was C{None}, return a C{str} human-readable
            version of the last analysis, else C{None}.
        """
        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        result.extend([
            'Score method: %s' % analysis['scoreClass'].__name__,
            ('Matched offset range in query: %(minQueryOffset)d to '
             '%(maxQueryOffset)d' % analysis),
            ('Matched offset range in subject: %(minSubjectOffset)d to '
             '%(maxSubjectOffset)d' % analysis),
            ('Match score: %(matchScore).4f' % analysis),
            ('Mismatch score: %(mismatchScore).4f' % analysis),
            'Score: %(score).4f' % analysis,
        ])

        if not returnNone:
            return str(result)
Exemple #2
0
    def printAnalysis(analysis, margin='', result=None):
        """
        Convert an analysis to a nicely formatted string.

        @param analysis: A C{dict} with information about the score and its
            calculation.
        @param margin: A C{str} that should be inserted at the start of each
            line of output.
        @param result: A C{MultilineString} instance, or C{None} if a new
            C{MultilineString} should be created.
        @return: If C{result} was C{None}, return a C{str} human-readable
            version of the last analysis, else C{None}.
        """
        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        result.extend([
            'Score method: %s' % analysis['scoreClass'].__name__,
            'Minimum hash count: %(minHashCount)d' % analysis,
            'Bin count: %(binCount)d' % analysis,
            'Score: %(score).4f' % analysis,
        ])

        if not returnNone:
            return str(result)
Exemple #3
0
 def testExtendTwoLinesLineCount(self):
     """
     If a multiline string is extended by two strings, its line count
     must be 2.
     """
     s = MultilineString()
     s.extend(['test1', 'test2'])
     self.assertEqual(2, s.lineCount())
Exemple #4
0
 def testExtendTwoLines(self):
     """
     If a multiline string is extended by two strings, its str
     representation must have the two strings, separated by a newline.
     """
     s = MultilineString()
     s.extend(['test1', 'test2'])
     self.assertEqual('test1\ntest2', str(s))
Exemple #5
0
    def printAnalysis(analysis, margin='', result=None):
        """
        Convert an analysis to a nicely formatted string.

        @param analysis: A C{dict} with information about the score and its
            calculation.
        @param margin: A C{str} that should be inserted at the start of each
            line of output.
        @param result: A C{MultilineString} instance, or C{None} if a new
            C{MultilineString} should be created.
        @return: If C{result} was C{None}, return a C{str} human-readable
            version of the last analysis, else C{None}.
        """
        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        result.extend([
            'Score method: %s' % analysis['scoreClass'].__name__,
            ('Matched offset range in query: %(minQueryOffset)d to '
             '%(maxQueryOffset)d' % analysis),
            ('Matched offset range in subject: %(minSubjectOffset)d to '
             '%(maxSubjectOffset)d' % analysis),
            ('Total (query+subject) AA offsets in matched hashes: '
             '%(matchedOffsetCount)d' % analysis),
            ('Subject AA offsets in matched hashes: '
             '%(matchedSubjectOffsetCount)d' % analysis),
            ('Query AA offsets in matched hashes: '
             '%(matchedQueryOffsetCount)d' % analysis),
            ('Total (query+subject) AA offsets in hashes in matched region: '
             '%(totalOffsetCount)d' % analysis),
            ('Weighted Subject AA offsets in matched hashes: '
             '%(weightedMatchedSubjectOffsetCount)d' % analysis),
            ('Weighted Query AA offsets in matched hashes: '
             '%(weightedMatchedQueryOffsetCount)d' % analysis),
            ('Matched region score %(matchedRegionScore).4f '
             '(%(matchedOffsetCount)d / %(totalOffsetCount)d)' % analysis),
            ('Query normalizer: %(normaliserQuery).4f (%(numeratorQuery)d / '
             '%(denominatorQuery)d)' % analysis),
            ('Subject normalizer: %(normaliserSubject).4f '
             '(%(numeratorSubject)d / %(denominatorSubject)d)' % analysis),
            'Score: %(score).4f' % analysis,
        ])

        if not returnNone:
            return str(result)
Exemple #6
0
    def printAnalysis(analysis, margin='', result=None):
        """
        Convert an analysis to a nicely formatted string.

        @param analysis: A C{dict} with information about the score and its
            calculation.
        @param margin: A C{str} that should be inserted at the start of each
            line of output.
        @param result: A C{MultilineString} instance, or C{None} if a new
            C{MultilineString} should be created.
        @return: If C{result} was C{None}, return a C{str} human-readable
            version of the last analysis.
        """
        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        result.extend([
            'Overall score method: %s' % analysis['scoreClass'].__name__,
            'Overall score: %s' % analysis['score'],
            ('Total (query+subject) AA offsets in matched pairs in all bins: '
             '%(matchedOffsetCount)d' % analysis),
            ('Subject AA offsets in matched pairs in all bins: '
             '%(matchedSubjectOffsetCount)d' % analysis),
            ('Query AA offsets in matched pairs in all bins: '
             '%(matchedQueryOffsetCount)d' % analysis),
            ('Total (query+subject) AA offsets in hashes in matched region: '
             '%(totalOffsetCount)d' % analysis),
            ('Matched region score %(matchedRegionScore).4f '
             '(%(matchedOffsetCount)d / %(totalOffsetCount)d)' % analysis),
            ('Query normalizer: %(normalizerQuery).4f (%(numeratorQuery)d / '
             '%(denominatorQuery)d)' % analysis),
            ('Subject normalizer: %(normalizerSubject).4f '
             '(%(numeratorSubject)d / %(denominatorSubject)d)' % analysis),
            ('Total query offsets that are in a bin: '
             '%(queryOffsetsInBinsCount)d' % analysis),
            ('Total subject offsets that are in a bin: '
             '%(subjectOffsetsInBinsCount)d' % analysis),
            ('Number of bins included in the score calculation: '
             '%(numberOfBinsConsidered)d' % analysis),
        ])

        if not returnNone:
            return str(result)
Exemple #7
0
    def print_(self, printHashes=False, margin='', result=None):
        """
        Print information about the database.

        @param printHashes: If C{True}, print all hashes and associated
            subjects.
        @param margin: A C{str} that should be inserted at the start of each
            line of output.
        @param result: A C{MultilineString} instance, or C{None} if a new
            C{MultilineString} should be created.
        @return: If C{result} was C{None}, return a C{str} representation of
            the database, else C{None}.
        """
        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        self.dbParams.print_(margin=margin, result=result)

        totalResidues = self.totalResidues()
        result.extend([
            'Connector class: %s' % self._connector.__class__.__name__,
            'Subject count: %d' % self.subjectCount(),
            'Hash count: %d' % self.hashCount(),
            'Total residues: %d' % totalResidues,
        ])

        append = result.append

        if totalResidues:
            append('Coverage: %.2f%%' %
                   (100.0 * self.totalCoveredResidues() / totalResidues))
        else:
            append('Coverage: 0.00%')
        append('Checksum: %d' % self.checksum())

        append('Connector:')
        connector = self._connector.print_(printHashes=printHashes,
                                           margin=margin)
        if connector:
            append(connector, verbatim=True)

        if not returnNone:
            return str(result)
Exemple #8
0
    def __str__(self):
        """
        Summarize the variable's statistics.

        @return: A C{str} summary of the variable's statistics.
        """
        summary = self.summary()
        result = MultilineString()

        result.append('%s:' % self._description)
        result.indent()

        result.extend([
            'Count: %d' % summary['count'],
            'Max: %s' % summary['max'],
            'Mean: %.4f' % summary['mean'],
            'Median: %.4f' % summary['median'],
            'Min: %s' % summary['min'],
            'SD: %.4f' % summary['sd'],
            'Variance: %.4f' % summary['variance'],
        ])

        return str(result)
Exemple #9
0
    def print_(self, margin='', result=None):
        """
        Print find parameter values.

        @param margin: A C{str} that should be inserted at the start of each
            line of output.
        @param result: A C{MultilineString} instance, or C{None} if a new
            C{MultilineString} should be created.
        @return: If C{result} was C{None}, return a C{str} representation of
            the parameters, else C{None}.
        """
        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        result.append('Find parameters:')
        result.indent()
        result.extend([
            'Significance method: %s' % self.significanceMethod,
            'Significance fraction: %f' % self.significanceFraction,
            'Bin Score Method: %s' % self.binScoreMethod,
            'Feature match score: %f' % self.featureMatchScore,
            'Feature mismatch score: %f' % self.featureMismatchScore,
            'Overall Score Method: %s' % self.overallScoreMethod,
            'Delta scale: %f' % self.deltaScale, 'Weights: '
        ])
        result.indent()
        for key in sorted(self.weights):
            result.append('%s: %f' % (key, self.weights[key]))

        result.outdent()
        result.outdent()

        if not returnNone:
            return str(result)
Exemple #10
0
    def print_(self, margin='', result=None):
        """
        Print parameter values.

        @param margin: A C{str} that should be inserted at the start of each
            line of output.
        @param result: A C{MultilineString} instance, or C{None} if a new
            C{MultilineString} should be created.
        @return: If C{result} was C{None}, return a C{str} representation of
            the parameters, else C{None}.
        """
        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        append = result.append

        append('Parameters:')
        result.indent()

        if self.landmarkFinders:
            append('Landmark finders:')
            result.indent()
            for finder in self.landmarkFinders:
                append(finder.__class__.__name__)
            result.outdent()
        else:
            append('Landmark finders: none')

        if self.trigPointFinders:
            append('Trig point finders:')
            result.indent()
            for finder in self.trigPointFinders:
                append(finder.__class__.__name__)
            result.outdent()
        else:
            append('Trig point finders: none')

        result.extend([
            'Limit per landmark: %d' % self.limitPerLandmark,
            'Max distance: %d' % self.maxDistance,
            'Min distance: %d' % self.minDistance,
            'Distance base: %f' % self.distanceBase,
            'Feature length base: %f' % self.featureLengthBase,
            'Random landmark density: %f' % self.randomLandmarkDensity,
            'Random trig point density: %f' % self.randomTrigPointDensity,
            'AC AlphaHelix filename: %s' % basename(self.acAlphaHelixFilename),
            'AC AlphaHelix 3-10 filename: %s' %
            basename(self.acAlphaHelix310Filename),
            'AC AlphaHelix Combined filename: %s' %
            basename(self.acAlphaHelixCombinedFilename),
            'AC AlphaHelix pi filename: %s' %
            basename(self.acAlphaHelixPiFilename),
            'AC ExtendedStrand filename: %s' %
            basename(self.acExtendedStrandFilename),
        ])

        result.outdent()

        if not returnNone:
            return str(result)
Exemple #11
0
 def testExtendReturnsSelf(self):
     """
     The extend method must return the MultilineString instance.
     """
     s = MultilineString()
     self.assertIs(s, s.extend(['test']))