Example #1
0
    def print_(self,
               printSequence=False,
               printFeatures=False,
               description='Read',
               margin='',
               result=None):
        """
        Print the details of a scanned read.

        @param fp: A file pointer to print to.
        @param verbose: If C{True}, print details of landmark and trig
            point matches.
        @param printSequence: If C{True}, print the sequence.
        @param printFeatures: If C{True}, print details of landmark and trig
            point features.
        @param description: A C{str} description to print before the scanned
            read id. This allows us to be specific about what a read is, e.g.,
            a query or a subject.
        @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 scanned read, else C{None}.
        """
        read = self.read

        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        append = result.append
        coveredIndices = len(self.coveredIndices())

        append('%s: %s' % (description, read.id))
        result.indent()
        if printSequence:
            append('Sequence: %s' % read.sequence)
        append('Length: %d' % len(read.sequence))
        append('Covered indices: %d (%.2f%%)' %
               (coveredIndices,
                coveredIndices / float(len(read.sequence)) * 100.0))

        # Print read landmarks and trig points.
        append('Landmark count %d, trig point count %d' %
               (len(self.landmarks), len(self.trigPoints)))
        if printFeatures:
            result.indent()
            for landmark in self.landmarks:
                append(str(landmark))
            for trigPoint in self.trigPoints:
                append(str(trigPoint))
            result.outdent()

        result.outdent()

        if not returnNone:
            return str(result)
Example #2
0
    def print_(self, printHashes=False, margin='', result=None):
        """
        Print information about this connector.

        @param printHashes: If C{True}, print all hashes and associated
            subjects from the backend.
        @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 connector, else C{None}.
        """
        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        if printHashes:
            result.append('Backends:')
            result.indent()
            self._backend.print_(margin=margin, result=result)
            result.outdent()

        if not returnNone:
            return str(result)
Example #3
0
 def testAppendVerbatim(self):
     """
     If a multiline string is given a verbatim string to append, its
     representation must be as expected.
     """
     s = MultilineString()
     s.indent()
     s.append('test1')
     s.append('      test2\n      test3', verbatim=True)
     s.append('test4')
     self.assertEqual('  test1\n      test2\n      test3\n  test4', str(s))
Example #4
0
 def testAppendVerbatimLineCount(self):
     """
     If a multiline string is given a verbatim string to append, its
     line count must be correct.
     """
     s = MultilineString()
     s.indent()
     s.append('test1')
     s.append('      test2\n      test3', verbatim=True)
     s.append('test4')
     self.assertEqual(4, s.lineCount())
Example #5
0
 def testNonDefaultIndent(self):
     """
     If a multiline string has two things appended to it, and the second is
     indented, its str representation must have the two strings, separated
     by a newline, and the second string must be indented using the indent
     value passed to __init__.
     """
     s = MultilineString(indent='\t')
     s.append('test1')
     s.indent()
     s.append('test2')
     self.assertEqual('test1\n\ttest2', str(s))
Example #6
0
 def testDefaultIndent(self):
     """
     If a multiline string has two things appended to it, and the second is
     indented, its str representation must have the two strings, separated
     by a newline, and the second string must be indented by two spaces (the
     default).
     """
     s = MultilineString()
     s.append('test1')
     s.indent()
     s.append('test2')
     self.assertEqual('test1\n  test2', str(s))
Example #7
0
 def testIndentOutdent(self):
     """
     If a multiline string has three things appended to it, and only the
     second is indented, its str representation must have the three strings,
     separated by newlines, and the second string must be indented.
     """
     s = MultilineString()
     s.append('test1')
     s.indent()
     s.append('test2')
     s.outdent()
     s.append('test3')
     self.assertEqual('test1\n  test2\ntest3', str(s))
Example #8
0
 def testIndentOutdentWithMargin(self):
     """
     If a multiline string with a margin has three things appended to it,
     and only the second is indented, its str representation must have the
     three strings, separated by newlines, the second string must be
     indented, and each line must be preceeded by the margin.
     """
     s = MultilineString(indent='\t', margin='>>> ')
     s.append('test1')
     s.indent()
     s.append('test2')
     s.outdent()
     s.append('test3')
     self.assertEqual('>>> test1\n>>> \ttest2\n>>> test3', str(s))
Example #9
0
    def print_(self, printHashes=False, margin='', result=None):
        """
        Print information about this connector and its backends.

        @param printHashes: If C{True}, print all hashes and associated
            subjects from the backends.
        @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 connector, else C{None}.
        """
        if result is None:
            result = MultilineString(margin=margin)
            returnNone = False
        else:
            returnNone = True

        if printHashes:
            extend = result.extend
            append = result.append
            append('Backends:')

            sessionIds = [self._sessionIdToName.keys()]
            names = [
                self._sessionIdToName[sessionId] for sessionId in sessionIds
            ]
            calls = [
                self.call('print_-%d' % sessionId, margin=margin + '    ')
                for sessionId in sessionIds
            ]
            callResults = yield from asyncio.gather(*calls)

            for name, callResult in zip(names, callResults):
                result.indent()
                extend([
                    'Backend name: %s' % name,
                    'Backend details:',
                ])
                append(callResult, verbatim=True)
                result.outdent()

        if not returnNone:
            return str(result)
Example #10
0
    def compare(self, other):
        """
        Compare our parameters against another C{DatabaseParameters} instance.

        @param other: A C{DatabaseParameters} instance.
        @return: A C{str} summary of the parameter differences if any, else
            C{None}.
        """
        err = MultilineString()
        err.append('Summary of differences:')
        err.indent()

        ourLandmarks = self.landmarkFinderNames()
        otherLandmarks = other.landmarkFinderNames()
        if ourLandmarks != otherLandmarks:
            err.append("Param 'landmarks' values %r and %r differ." %
                       (ourLandmarks, otherLandmarks))

        ourTrigPoints = self.trigPointFinderNames()
        otherTrigPoints = other.trigPointFinderNames()
        if ourTrigPoints != otherTrigPoints:
            err.append("Param 'trigPoints' values %r and %r differ." %
                       (ourTrigPoints, otherTrigPoints))

        for param in ('limitPerLandmark', 'maxDistance', 'minDistance',
                      'distanceBase', 'featureLengthBase',
                      'randomLandmarkDensity', 'randomTrigPointDensity',
                      'acAlphaHelixFilename', 'acAlphaHelix310Filename',
                      'acAlphaHelixCombinedFilename', 'acAlphaHelixPiFilename',
                      'acExtendedStrandFilename'):
            ours = getattr(self, param)
            others = getattr(other, param)
            if ours != others:
                err.append('Param %r values %r and %r differ.' %
                           (param, ours, others))

        # We have an error if the multi-line string result has more than
        # the initial 'Summary of differences' heading line.
        return str(err) if err.lineCount() > 1 else None
Example #11
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)
Example #12
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)
Example #13
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)
Example #14
0
 def testIndentReturnsSelf(self):
     """
     The indent method must return the MultilineString instance.
     """
     s = MultilineString()
     self.assertIs(s, s.indent())