Example #1
0
 def crossValidatePrimers( self, primers, excludeFile ):             
     
     excludeSequences = fastaparser.parseFastaFile( excludeFile )
     
     #write a primer search input file with using the primers argument
     primerInputFileName = utils.getTemporaryDirectory( ) + "/tmpinputprimers.ps"
     primerOutputFileName = utils.getTemporaryDirectory( ) + "/tmpoutputprimers.ps"
     primersearchutils.writePrimerSearchInputFile( primers, primerInputFileName )
     
     utils.logMessage( "PrimerManager::crossValidatePrimers", "finding primers that are not in the supplied exclude file" )
     #run primer search to identify the primers
     self.primersearch.execute( [ excludeFile, primerInputFileName, primerOutputFileName, "0" ] )
     
     #read the found primers from the file
     commonPrimers = primersearchutils.parsePrimerSearchFile( primerOutputFileName )
     
     #compose a list of primers that are not found in the exclude file...
     returnValue = [ ]
     
     for primer in primers:
         if primer.id not in commonPrimers:
             returnValue.append( primer )
     
     utils.logMessage( "PrimerManager::crossValidatePrimers", "{0} unique primers identified out of {1}".format( len( returnValue ), len( primers ) ) )
     
     if len( returnValue  ) == 0:
         raise utils.NoPrimersExistException( )
     
     return returnValue
 def processIncludeFile( self, includeFileName ):
     """
     A function that adds and processes and include file.
     An exclude file must be set for this function to be called.
     """
     
     utils.logMessage( "IncludeFileManager::processIncludeFile( )", "processing {0}".format( includeFileName ) )
     
     if self.isExcludeFileInitialized == False:
         utils.logMessage( "IncludeFileManager::processIncludeFile( )", "no exclude file set".format( includeFileName ) )
         raise utils.ModuleNotInitializedException( "includefilemanager", "no exclude file set" )
     
     if self.isReferenceFileInitialized == False:
         
         utils.logMessage( "IncludeFileManager::processIncludeFile( )", "running nucmer for reference file: {0}".format( includeFileName ) )
         self.uniqueSequences = self.findUniqueSequencesInFile( includeFileName, self.excludeFileName )
         
         self.referenceFile = includeFileName
         self.isReferenceFileInitialized = True
         
     else:
         #write the unique sequences to a temp file
         tempSequences = utils.getTemporaryDirectory( ) + "/tempSequences.fasta"
         fastaparser.writeFastaFile( self.uniqueSequences, tempSequences )
         self.findCommonSequencesInFile( includeFileName, tempSequences )
         self.includeFiles.append( includeFileName )
Example #3
0
    def findPrimers( self, sequences, outputFile, primerpairs = 20, returnPrimers = False ):
        '''
        A method to find a set of primers based on the given sequences
        '''
        
        utils.logMessage( "PrimerManager::findPrimer(s )", "writing sequences to a fasta file" )
        
        #eleminate all sequences that are lees than the desired amplification size...
       
        if len( sequences ) == 4 :
            print sequences
        sequences = filter( lambda x: len( x ) >= 200, sequences )
        
        primerFastaFile = utils.getTemporaryDirectory( ) + "/sequenceForEprimer.fasta"
        fastaparser.writeFastaFile( sequences, primerFastaFile )

        utils.logMessage( "PrimerManager::findPrimers( )", "executing eprimer3 program" )
        self.eprimer.execute( [ primerFastaFile, outputFile ] )
        utils.logMessage( "PrimerManager::findPrimer( )", "eprimer3 file {0} created. Parsing for primers.".format( outputFile ) )
        
        primers = eprimerparser.parsePrimerSequences( outputFile )
        
        utils.logMessage( "PrimerManager::findPrimers( )", "parsing for sequences complete" )
        
        if returnPrimers == True:
            return primers
Example #4
0
 def buildOutputFileName(self):
     """
     build a unique file name to store the combined output sequences to
     """
     self.outputFile = utils.getTemporaryDirectory(
     ) + "/combined_exlude.ffn"
     utils.logMessage("ExcludeFileManager::buildOutputFileName( )",
                      " exclude file: {0}".format(self.outputFile))
Example #5
0
 def getPrimers( self, sequences ):
     
     utils.logMessage( "PrimerManager::getCommonPrimers", "finding primers that are common to all include files" )
         
     if len( sequences ) == 0:
         raise utils.NoPrimersExistException( )
     
     referenceEPrimerFile = utils.getTemporaryDirectory( ) + "/referenceprimers.ep3"
     
     #run eprimer to find primers in the reference file
     primers = self.findPrimers( sequences, referenceEPrimerFile, 20, True )
     
     
     if len( primers ) == 0:
          raise utils.NoPrimersExistException( )
     
     return primers