예제 #1
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)
예제 #2
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)
예제 #3
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))
예제 #4
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))
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
0
 def testOutdentReturnsSelf(self):
     """
     The outdent method must return the MultilineString instance.
     """
     s = MultilineString()
     self.assertIs(s, s.outdent())