def run(self):
        logger.info('CycleStep4 object running, %s' % self.thisDir)
        lsc.verifyDirExists(self.thisDir)
        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'cycle.step4.start.xml'))
        # lsc.subTypeTimestamp(self.thisDir, 'cycle', 'CycleStep4_start')

        outname = os.path.join(self.thisDir, 'logs', 'gene_deactivation.log')
        if not os.path.exists(outname):
            if not self.options.noGeneDeactivation:
                # by default gene deactivation is turned on.
                cmd = lsc.evolverGeneDeactivationStep(self.thisDir, self.thisParentDir)
                p = subprocess.Popen(cmd, cwd = self.getLocalTempDir(), 
                                     stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
                out = p.communicate()[0]
                f=open(outname + '.tmp', 'w')
                f.write(out)
                f.close()
                os.rename(outname + '.tmp', outname)
            else:
                # this could cause a proliferation of gene creation.
                cmd = [lsc.which('cp')]
                cmd.append(os.path.join(thisDir, 'intra', 'evannots.gff'))
                cmd.append(os.path.join(thisDir, 'annots.gff'))
                cmds = [cmd]
                cmds.append([lsc.which('touch'), outname])
                lsc.runCommands(cmds, self.getLocalTempDir())
        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'cycle.step4.end.xml'))
 def run(self):
     if self.thisParentDir is None:
         # happens when thisParentDir is the root
         return
     lsc.verifyDirExists(self.thisDir)
     self.addChildTarget(StatsStep1(self.thisDir, self.thisParentDir, self.options))
     self.setFollowOnTarget(Transalign(self.thisDir, self.thisParentDir, self.options))
    def run(self):
        chrNameDict, revChrNameDict = lsc.extractChrNamesDict(self.thisDir)
        logger.info('CycleStep2Chromosome object running, %s %s %s' 
                    % (self.thisDir, self.thisChr, chrNameDict[self.thisChr]))
        lsc.verifyDirExists(self.thisDir)
        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'cycle.step2.%s.start.xml' 
                                         % chrNameDict[self.thisChr]), 
                            extra = {'name': self.thisChr})

        # evolver intra on one chromosome
        cmds = lsc.evolverIntraStepCmd(self.thisDir, self.theChild, self.thisStepLength, 
                                       self.thisChr, self.options.seed, 
                                       self.options.paramsDir, self.getLocalTempDir(), self.options)
        lsc.runCommands(cmds, self.getLocalTempDir())

        # evolver conversion from .rev to fasta in localTempDir
        cmds = lsc.evolverIntraStepToFastaCmd(self.thisDir, self.thisStepLength, self.thisChr, 
                                              self.options.paramsDir, self.getLocalTempDir())
        lsc.runCommands(cmds, self.getLocalTempDir())
            
        # trf wrapper
        lsc.callEvolverIntraStepTRFCmd(self.thisDir, self.thisChr, self.getLocalTempDir())
        
        # move the resulting trf files out of localTempDir
        cmds = lsc.evolverIntraStepMoveTRFCmd(self.thisDir, self.thisChr, self.getLocalTempDir())
        lsc.runCommands(cmds, self.getLocalTempDir(), mode = 'p')
        
        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 
                                         'cycle.step2.%s.end.xml' % chrNameDict[self.thisChr]),
                            extra = {'name': self.thisChr})
    def run(self):
        logger.info('Transalign object running, thisDir: %s thisParentDir: %s' 
                    % (self.thisDir, self.thisParentDir))
        if self.thisParentDir is None:
            # happens when thisParentDir is the root
            return
        lsc.verifyDirExists(self.thisDir)

        self.addChildTarget(TransalignStep(self.thisDir, self.thisParentDir, self.options))
    def run(self):
        logger.info('StatsStep3 object running, %s' % self.thisDir)
        lsc.verifyDirExists(self.thisDir)
        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'stats.step3.start.xml'))

        cmds, pipes = lsc.statsStep3Cmds(self.thisDir, self.thisParentDir, self.options)
        lsc.runCommands(cmds, self.getLocalTempDir(), outPipes = pipes)

        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'stats.step3.end.xml'))
        self.setFollowOnTarget(StatsStep4(self.thisDir, self.thisParentDir, self.options))
    def run(self):
        logger.info('StatsStep4 object running, %s' % self.thisDir)
        lsc.verifyDirExists(self.thisDir)
        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'stats.step4.start.xml'))
        
        cmds, pipes = lsc.statsStep4Cmds(self.thisDir, self.thisParentDir, self.options)
        lsc.runCommands(cmds, self.getLocalTempDir(), outPipes = pipes)

        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'stats.step4.end.xml'))
        if lsc.isLeaf(self.thisDir):
            lsc.lastOneOutTurnOffTheLightsSimulation(self.options.simDir, self.options)
    def run(self):
        logger.info('CycleStep1 object running, %s' % self.thisDir)
        lsc.verifyDirExists(self.thisDir)
        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'cycle.step1.start.xml'))
        
        lsc.runEvolverInterCmds(self.thisDir, self.thisParentDir, self.theChild, self.theParent,
                                self.thisStepLength, self.options.seed, self.options.paramsDir,
                                self.getLocalTempDir(), self.options)

        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'cycle.step1.end.xml'))
        self.setFollowOnTarget(CycleStep2(self.thisNewickStr, self.thisParentDir, 
                                            self.thisStepLength, self.options))
 def run(self):
     logger.info('CycleStep2 object running, %s' % self.thisDir)
     lsc.verifyDirExists(self.thisDir)
     lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'cycle.step2.start.xml'))
     lsc.verifyDirExists(os.path.join(self.thisDir, 'inter'))
     lsc.verifyFileExists(os.path.join(self.thisDir, 'inter', 'inter.chrnames.txt'))
     f = open(os.path.join(self.thisDir, 'inter', 'inter.chrnames.txt'), 'r')
     for chrom in f:
         chrom = chrom.strip()
         self.addChildTarget(CycleStep2Chromosome(self.thisNewickStr, self.thisParentDir,
                                                    self.thisStepLength, chrom, self.options))
     f.close()
     self.setFollowOnTarget(CycleStep2FollowOn(self.thisNewickStr, self.thisParentDir, 
                                               self.thisStepLength, self.options))
 def run(self):
     logger.info('TransalignStep object running, thisDir: %s thisParentDir: %s' 
                 % (self.thisDir, self.thisParentDir))
     lsc.verifyDirExists(self.thisDir)
     lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'transalign.start.xml'))
     
     cmds, pipes = lsc.transalignStepCmds_1(self.thisDir, self.thisParentDir, self.options)
     lsc.runCommands(cmds, self.getLocalTempDir(), outPipes = pipes)
     
     lsc.runTransalignStepCmds_2(self.thisDir, self.thisParentDir, 
                                  self.getLocalTempDir(), self.options)
     
     lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'transalign.end.xml'))
     lsc.lastOneOutTurnOffTheLightsCycle(self.thisDir)
     if lsc.isLeaf(self.thisDir):
         lsc.lastOneOutTurnOffTheLightsSimulation(self.options.simDir, self.options)
    def run(self):
        logger.info('CycleStep3 object running, %s' % self.thisDir)
        lsc.verifyDirExists(self.thisDir)
        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'cycle.step3.start.xml'))

        # trf
        regex = r'^(chr\S+)\.outseq\.fa.*\.dat'
        pat = re.compile(regex)
        files = glob.glob(os.path.join(self.thisDir, 'intra', '*.dat'))
        cmds = []
        outPipes = []
        followCmds = []
        followPipes = []
        for f in files:
            # each file is the trf output for one chromosome
            m = re.match(regex, os.path.basename(f))
            if m is None:
                raise RuntimeError('Regex "%s" failed on filename %s' % (regex, os.path.basename(f)))
            outname = os.path.join(self.thisDir, 'intra', m.group(1) + '.trfannots.gff')
            if not os.path.exists(outname):
                # convert the .dat to .gff
                cmd = [lsc.which('evolver_trf2gff.py'), f]
                cmds.append(cmd)
                outPipes.append(outname + '.tmp')
                # atomic files
                followCmds.append([lsc.which('mv'), outname + '.tmp', outname])
                followPipes.append(None)
        lsc.runCommands(cmds, self.getLocalTempDir(), outPipes = outPipes, mode = 'p')
        lsc.runCommands(followCmds, self.getLocalTempDir(), outPipes = followPipes, mode = 'p')
        
        catCmd, evoCmd, cvtCmd, followCmds = lsc.evolverIntraMergeCmds(self.thisDir, self.theChild)
        
        lsc.runCommands([catCmd, evoCmd, cvtCmd], self.getLocalTempDir(),
                         outPipes = [os.path.join(self.thisDir, 'intra', 'evannots.gff.tmp'), None, None], 
                         mode = 'p')
        lsc.runCommands(followCmds, self.getLocalTempDir())
        
        lsc.createTimestamp(os.path.join(self.thisDir, 'xml', 'cycle.step3.end.xml'))
        self.setFollowOnTarget(CycleStep4(self.thisNewickStr, self.thisParentDir,
                                            self.thisStepLength, self.options))
Example #11
0
def checkForFiles(options):
    """ If files are missing, complains and dies.
    """
    lsc.verifyDirExists(os.path.join(options.rootInputDir, 'stats'))
    for f in [os.path.join(options.rootInputDir, 'seq.rev'), 
              os.path.join(options.rootInputDir, 'annots.gff'), 
              os.path.join(options.paramsDir, 'model.txt'),
              os.path.join(options.rootInputDir, 'stats', 'merged_root.stats.txt'),
              os.path.join(options.rootInputDir, 'stats', 'cds_annots.gff'),
              os.path.join(options.rootInputDir, 'stats', 'exons.gff'),
              os.path.join(options.rootInputDir, 'stats', 'introns.gff'),
              os.path.join(options.rootInputDir, 'stats', 'expanded_annots.gff'),
              os.path.join(options.rootInputDir, 'stats', 'annotstats.txt')]:
        lsc.verifyFileExists(f)
    if not options.noMEs:
        lsc.verifyDirExists(os.path.join(options.rootInputDir, 'mobiles'))
        for f in [os.path.join(options.paramsDir, 'model.mes.txt'), 
                  os.path.join(options.paramsDir, 'mes.cfg'),
                  os.path.join(options.rootInputDir, 'mobiles', 'LTR.fa'),
                  os.path.join(options.rootInputDir, 'mobiles', 'ME.fa'),
                  os.path.join(options.rootInputDir, 'mobiles', 'ME.gff')]:
            lsc.verifyFileExists(f)