Ejemplo n.º 1
0
    def __init__(self, resultFilenames, database, sortFilenames=True):
        if isinstance(resultFilenames, str):
            resultFilenames = [resultFilenames]
        if sortFilenames:
            self.resultFilenames = numericallySortFilenames(resultFilenames)
        else:
            self.resultFilenames = resultFilenames
        self._database = database

        # Add a dictionary that will allow us to look up database subjects
        # by title.
        self._subjects = dict((subject.read.id, subject.read.sequence)
                              for subject in database.getSubjects())

        # Prepare application parameters in order to initialize self.
        self._reader = self._getReader(self.resultFilenames[0])
        params = copy.deepcopy(self._reader.params)

        applicationParams = ReadsAlignmentsParams('light',
                                                  applicationParams=params,
                                                  subjectIsNucleotides=False)

        # We will add to self._reads as we go through the results (which
        # contain the read ids and sequences). Note that this means the
        # reads will not be available to the ReadsAlignments instance until
        # after all results have been read.
        self._reads = Reads()

        ReadsAlignments.__init__(self, self._reads, applicationParams)
Ejemplo n.º 2
0
    def __init__(self,
                 reads,
                 blastFilenames,
                 scoreClass=HigherIsBetterScore,
                 sortBlastFilenames=True,
                 randomizeZeroEValues=True):
        if type(blastFilenames) == str:
            blastFilenames = [blastFilenames]
        if sortBlastFilenames:
            self.blastFilenames = numericallySortFilenames(blastFilenames)
        else:
            self.blastFilenames = blastFilenames
        self.randomizeZeroEValues = randomizeZeroEValues

        # Prepare application parameters in order to initialize self.
        self._reader = self._getReader(self.blastFilenames[0], scoreClass)
        application = self._reader.application
        blastParams = copy.deepcopy(self._reader.params)
        subjectIsNucleotides = application != 'blastx'
        scoreTitle = ('Bit score' if scoreClass is HigherIsBetterScore else
                      '$- log_{10}(e)$')

        applicationParams = ReadsAlignmentsParams(
            application,
            blastParams,
            subjectIsNucleotides=subjectIsNucleotides,
            scoreTitle=scoreTitle)

        ReadsAlignments.__init__(self,
                                 reads,
                                 applicationParams,
                                 scoreClass=scoreClass)
Ejemplo n.º 3
0
    def __init__(self, reads, filenames, databaseFilename=None,
                 databaseDirectory=None, sqliteDatabaseFilename=None,
                 scoreClass=HigherIsBetterScore, sortFilenames=False,
                 randomizeZeroEValues=True):
        if type(filenames) == str:
            filenames = [filenames]
        if sortFilenames:
            self.filenames = numericallySortFilenames(filenames)
        else:
            self.filenames = filenames

        self._databaseFilename = databaseFilename
        self._sqliteDatabaseFilename = sqliteDatabaseFilename
        self._databaseDirectory = databaseDirectory
        self._subjectTitleToSubject = None
        self.randomizeZeroEValues = randomizeZeroEValues

        # Prepare diamondTask parameters in order to initialize self.
        self._reader = self._getReader(self.filenames[0], scoreClass)
        diamondTask = self._reader.diamondTask
        diamondParams = copy.deepcopy(self._reader.params)
        scoreTitle = ('Bit score' if scoreClass is HigherIsBetterScore
                      else '$- log_{10}(e)$')

        diamondTaskParams = ReadsAlignmentsParams(
            diamondTask, diamondParams,
            subjectIsNucleotides=False,  # DIAMOND dbs are always protein.
            scoreTitle=scoreTitle)

        ReadsAlignments.__init__(self, reads, diamondTaskParams,
                                 scoreClass=scoreClass)
Ejemplo n.º 4
0
 def testExpectedAttrs(self):
     """
     A ReadsAlignmentsParams instance must have the expected attributes.
     """
     applicationParams = {}
     params = ReadsAlignmentsParams('application name', applicationParams,
                                    False, 'Bit score')
     self.assertEqual('application name', params.application)
     self.assertIs(applicationParams, params.applicationParams)
     self.assertFalse(params.subjectIsNucleotides)
     self.assertEqual('Bit score', params.scoreTitle)