class Test_ForQuiverService(unittest.TestCase):
    """Test pbalign.forquiverservice.forquiver."""
    def setUp(self):
        self.rootDir = "/mnt/secondary-siv/" + \
                       "testdata/BlasrTestData/pbalign"
        self.inCmpFile = path.join(self.rootDir, "data/testforquiver.cmp.h5")
        #self.outCmpFile = path.join(self.rootDir, "out/testforquiver.cmp.h5")
        self.outCmpFile = mkstemp(suffix=".cmp.h5")[1]

        copyfile(self.inCmpFile, self.outCmpFile)
        self.basFile = path.join(self.rootDir, "data/lambda_bax.fofn")

        refpath = "/mnt/secondary/Smrtanalysis/opt/" + \
                  "smrtanalysis/common/references/lambda/"

        self.fileNames = PBAlignFiles()
        self.fileNames.SetInOutFiles(self.basFile, refpath,
                                     self.outCmpFile, None, None)
        self.options = Opt()
        self.obj = ForQuiverService(self.fileNames, self.options)

    def tearDown(self):
        remove(self.outCmpFile)

    def test_run(self):
        """Test ForQuiverService.__init__()."""
        self.obj.run()
Beispiel #2
0
    def setUp(self):
        self.inCmpFile = path.join(DATA_DIR, "testforquiver.cmp.h5")
        self.outCmpFile = mkstemp(suffix=".cmp.h5")[1]

        copyfile(self.inCmpFile, self.outCmpFile)
        self.basFile = path.join(DATA_DIR, "lambda_bax.fofn")

        refpath = "/pbi/dept/secondary/siv/references/lambda/"

        self.fileNames = PBAlignFiles()
        self.fileNames.SetInOutFiles(self.basFile, refpath, self.outCmpFile,
                                     None, None)
        self.options = Opt()
        self.obj = ForQuiverService(self.fileNames, self.options)
Beispiel #3
0
class Test_ForQuiverService(unittest.TestCase):
    """Test pbalign.forquiverservice.forquiver."""
    def setUp(self):
        self.inCmpFile = path.join(DATA_DIR, "testforquiver.cmp.h5")
        self.outCmpFile = mkstemp(suffix=".cmp.h5")[1]

        copyfile(self.inCmpFile, self.outCmpFile)
        self.basFile = path.join(DATA_DIR, "lambda_bax.fofn")

        refpath = "/pbi/dept/secondary/siv/references/lambda/"

        self.fileNames = PBAlignFiles()
        self.fileNames.SetInOutFiles(self.basFile, refpath, self.outCmpFile,
                                     None, None)
        self.options = Opt()
        self.obj = ForQuiverService(self.fileNames, self.options)

    def tearDown(self):
        remove(self.outCmpFile)

    def test_run(self):
        """Test ForQuiverService.__init__()."""
        self.obj.run()
    def setUp(self):
        self.inCmpFile = path.join(DATA_DIR, "testforquiver.cmp.h5")
        self.outCmpFile = mkstemp(suffix=".cmp.h5")[1]

        copyfile(self.inCmpFile, self.outCmpFile)
        self.basFile = path.join(DATA_DIR, "lambda_bax.fofn")

        refpath = "/pbi/dept/secondary/siv/references/lambda/"

        self.fileNames = PBAlignFiles()
        self.fileNames.SetInOutFiles(self.basFile, refpath,
                                     self.outCmpFile, None, None)
        self.options = Opt()
        self.obj = ForQuiverService(self.fileNames, self.options)
class Test_ForQuiverService(unittest.TestCase):
    """Test pbalign.forquiverservice.forquiver."""
    def setUp(self):
        self.inCmpFile = path.join(DATA_DIR, "testforquiver.cmp.h5")
        self.outCmpFile = mkstemp(suffix=".cmp.h5")[1]

        copyfile(self.inCmpFile, self.outCmpFile)
        self.basFile = path.join(DATA_DIR, "lambda_bax.fofn")

        refpath = "/pbi/dept/secondary/siv/references/lambda/"

        self.fileNames = PBAlignFiles()
        self.fileNames.SetInOutFiles(self.basFile, refpath,
                                     self.outCmpFile, None, None)
        self.options = Opt()
        self.obj = ForQuiverService(self.fileNames, self.options)

    def tearDown(self):
        remove(self.outCmpFile)

    def test_run(self):
        """Test ForQuiverService.__init__()."""
        self.obj.run()
    def setUp(self):
        self.rootDir = "/mnt/secondary-siv/" + \
                       "testdata/BlasrTestData/pbalign"
        self.inCmpFile = path.join(self.rootDir, "data/testforquiver.cmp.h5")
        #self.outCmpFile = path.join(self.rootDir, "out/testforquiver.cmp.h5")
        self.outCmpFile = mkstemp(suffix=".cmp.h5")[1]

        copyfile(self.inCmpFile, self.outCmpFile)
        self.basFile = path.join(self.rootDir, "data/lambda_bax.fofn")

        refpath = "/mnt/secondary/Smrtanalysis/opt/" + \
                  "smrtanalysis/common/references/lambda/"

        self.fileNames = PBAlignFiles()
        self.fileNames.SetInOutFiles(self.basFile, refpath,
                                     self.outCmpFile, None, None)
        self.options = Opt()
        self.obj = ForQuiverService(self.fileNames, self.options)
Beispiel #7
0
    def run(self):
        """
        The main function, it is called by PBToolRunner.start().
        """
        startTime = time.time()
        logging.info("pbalign version: {version}".format(version=get_version()))
        logging.debug("Original arguments: " + str(self._argumentList))

        # Create an AlignService by algorithm name.
        self._alnService = self._createAlignService(self.args.algorithm,
                                                    self.args,
                                                    self.fileNames,
                                                    self._tempFileManager)

        # Make sane.
        self._makeSane(self.args, self.fileNames)

        # Run align service.
        try:
            self._alnService.run()
        except RuntimeError:
            return 1

        # Create a temporary filtered SAM file as output for FilterService.
        self.fileNames.filteredSam = self._tempFileManager.\
            RegisterNewTmpFile(suffix=".sam")

        # Call filter service.
        self._filterService = FilterService(self.fileNames.alignerSamOut,
                                            self.fileNames.targetFileName,
                                            self.fileNames.filteredSam,
                                            self._alnService.name,
                                            self._alnService.scoreSign,
                                            self.args,
                                            self.fileNames.adapterGffFileName)
        try:
            self._filterService.run()
        except RuntimeError:
            return 1

        # Output all hits either in SAM or CMP.H5.
        try:
            useSmrtTitle = False
            if (self.args.algorithm != "blasr" or
                self.fileNames.inputFileFormat == FILE_FORMATS.FASTA):
                useSmrtTitle = True

            self._output(
                self.fileNames.filteredSam,
                self.fileNames.targetFileName,
                self.fileNames.outputFileName,
                self.args.readType,
                useSmrtTitle)
        except RuntimeError:
            return 1

        # Call post service for quiver.
        if self.args.forQuiver or self.args.loadQVs:
            postService = ForQuiverService(self.fileNames,
                                           self.args)
            try:
                postService.run()
            except RuntimeError:
                return 1

        # Delete temporay files anyway to make
        self._cleanUp(False if (hasattr(self.args, "keepTmpFiles") and
                               self.args.keepTmpFiles is True) else True)

        endTime = time.time()
        logging.info("Total time: {:.2f} s.".format(float(endTime - startTime)))
        return 0
Beispiel #8
0
    def run(self):
        """
        The main function, it is called by PBToolRunner.start().
        """
        startTime = time.time()
        logging.info(
            "pbalign version: {version}".format(version=get_version()))
        # FIXME
        #logging.debug("Original arguments: " + str(self._argumentList))

        # Create an AlignService by algorithm name.
        self._alnService = self._createAlignService(self.args.algorithm,
                                                    self.args, self.fileNames,
                                                    self._tempFileManager)

        # Make sane.
        self._makeSane(self.args, self.fileNames)

        # Run align service.
        try:
            self._alnService.run()
        except RuntimeError:
            return 1

        # Create a temporary filtered SAM/BAM file as output for FilterService.
        outFormat = getFileFormat(self.fileNames.outputFileName)
        suffix = ".bam" if outFormat in \
                [FILE_FORMATS.BAM, FILE_FORMATS.XML] else ".sam"
        self.fileNames.filteredSam = self._tempFileManager.\
            RegisterNewTmpFile(suffix=suffix)

        # Call filter service on SAM or BAM file.
        self._filterService = FilterService(
            self.fileNames.alignerSamOut,
            self.fileNames.targetFileName,
            self.fileNames.filteredSam,
            self.args.algorithm,
            #self._alnService.name,
            self._alnService.scoreSign,
            self.args,
            self.fileNames.adapterGffFileName)
        try:
            self._filterService.run()
        except RuntimeError:
            return 1

        # Sort bam before output
        if outFormat in [FILE_FORMATS.BAM, FILE_FORMATS.XML]:
            # Sort/make index for BAM output.
            try:
                BamPostService(self.fileNames).run()
            except RuntimeError:
                return 1

        # Output all hits in SAM, BAM or CMP.H5.
        try:
            useSmrtTitle = False
            if (self.args.algorithm != "blasr"
                    or self.fileNames.inputFileFormat == FILE_FORMATS.FASTA):
                useSmrtTitle = True

            self._output(inSam=self.fileNames.filteredSam,
                         refFile=self.fileNames.targetFileName,
                         outFile=self.fileNames.outputFileName,
                         readType=self.args.readType,
                         smrtTitle=useSmrtTitle)
        except RuntimeError:
            return 1

        # Load QVs to cmp.h5 for Quiver
        if outFormat == FILE_FORMATS.CMP and \
            self.args.forQuiver or self.args.loadQVs:
            # Call post service for quiver.
            try:
                ForQuiverService(self.fileNames, self.args).run()
            except RuntimeError:
                return 1

        # Delete temporay files anyway to make
        self._cleanUp(False if (hasattr(self.args, "keepTmpFiles")
                                and self.args.keepTmpFiles is True) else True)

        endTime = time.time()
        logging.info("Total time: {:.2f} s.".format(float(endTime -
                                                          startTime)))
        return 0