Exemple #1
0
    def testSymmetricFindScoresDifferingSubjectAndQuery(self):
        """
        The score of matching a sequence A against a sequence B must
        be the same as when matching B against A, including when the number
        of hashes in the two differs and the scores are not 1.0.
        """
        subject = AARead('subject', 'AFRRRFRRRFASAASAFRRRFRRRF')
        query = AARead('query', 'FRRRFRRRFASAVVVVVV')
        dbParams1 = DatabaseParameters(landmarks=[AlphaHelix, BetaStrand],
                                       trigPoints=[Peaks])
        db = Database(dbParams1)
        _, index, _ = db.addSubject(subject)
        hashCount1 = db.getSubjectByIndex(index).hashCount
        findParams = FindParameters(significanceFraction=0.0)
        result = db.find(query, findParams)
        score1 = result.analysis['0']['bestBinScore']

        dbParams2 = DatabaseParameters(landmarks=[AlphaHelix, BetaStrand],
                                       trigPoints=[Peaks])
        db = Database(dbParams2)
        _, index, _ = db.addSubject(query)
        hashCount2 = db.getSubjectByIndex(index).hashCount
        result = db.find(subject, findParams)
        score2 = result.analysis['0']['bestBinScore']

        self.assertNotEqual(hashCount1, hashCount2)
        self.assertEqual(score1, score2)
        self.assertNotEqual(1.0, score1)
Exemple #2
0
 def testGetSubjectHashCount(self):
     """
     If a subject is added, getSubjectByIndex must return a Subject
     instance that has the correct hash count.
     """
     dbParams = DatabaseParameters(landmarks=[AlphaHelix], trigPoints=[])
     db = Database(dbParams)
     subject = AARead('id', 'FRRRFRRRFAFRRRFRRRF')
     _, index, _ = db.addSubject(subject)
     self.assertEqual(1, db.getSubjectByIndex(index).hashCount)
Exemple #3
0
 def testGetSubjectByIndex(self):
     """
     If a subject is added, getSubjectByIndex must be able to return it
     given its string index.
     """
     dbParams = DatabaseParameters(landmarks=[AlphaHelix], trigPoints=[])
     db = Database(dbParams)
     subject = AARead('id', 'FRRRFRRRF')
     _, index, _ = db.addSubject(subject)
     self.assertEqual(Subject(AARead('id', 'FRRRFRRRF')),
                      db.getSubjectByIndex(index))
    def calculateScore(self, dbParams=None, findParams=None):
        """
        Using a given scoring method, calculate the score of the alignment
        between the query and subject in the template.

        @param findParams: An instance of C{light.parameters.FindParameters} or
            C{None} to use default find parameters.
        @raises ValueError: If C{dbParams} is passed and the landmarks and
            trig points it specifies do not include all the landmarks and trig
            points named in the template. Of if the C{binScoreMethod} in
            C{findParams} is unknown.
        @return: A 2-tuple, being the result of calling the C{calculateScore}
            method of the C{binScoreMethod} class. The tuple contains a
            C{float} score of the bin and a C{dict} with the analysis leading
            to the score (see light/bin_score.py).
        """
        findParams = findParams or FindParameters()
        if dbParams is None:
            dbParams = DatabaseParameters(landmarks=self.landmarks,
                                          trigPoints=self.trigPoints)
        else:
            missing = self.landmarks - set(dbParams.landmarkFinderNames())
            if missing:
                raise ValueError(
                    'The template mentions landmark finders (%s) that are '
                    'not present in the passed DatabaseParameters instance' %
                    ', '.join(sorted(missing)))

            missing = self.trigPoints - set(dbParams.trigPointFinderNames())
            if missing:
                raise ValueError(
                    'The template mentions trig point finders (%s) that are '
                    'not present in the passed DatabaseParameters instance' %
                    ', '.join(sorted(missing)))

        database = Database(dbParams=dbParams)
        _, subjectIndex, subjectHashCount = database.addSubject(
            self.subject.read)
        dbSubject = database.getSubjectByIndex(subjectIndex)

        binScoreMethod = findParams.binScoreMethod
        if binScoreMethod == 'NoneScore':
            scorer = NoneScore()
        elif binScoreMethod == 'MinHashesScore':
            be = database._connector._backend
            queryHashCount = 0
            scannedQuery = be.scan(self.query.read)
            for hashInfo in be.getHashes(scannedQuery).values():
                queryHashCount += len(hashInfo)
            scorer = MinHashesScore(self.histogram,
                                    min(queryHashCount, subjectHashCount))
        elif binScoreMethod == 'FeatureMatchingScore':
            scorer = FeatureMatchingScore(
                self.histogram, self.query.read, dbSubject, dbParams,
                findParams)
        elif binScoreMethod == 'FeatureAAScore':
            scorer = FeatureAAScore(
                self.histogram, self.query.read, dbSubject, dbParams)
        elif binScoreMethod == 'WeightedFeatureAAScore':
            scorer = WeightedFeatureAAScore(
                self.histogram, self.query.read, dbSubject, dbParams,
                findParams.weights)
        else:
            raise ValueError('Unknown bin score method %r' % binScoreMethod)

        return scorer.calculateScore(0)