Beispiel #1
0
    def test4_run_upload(self, upload_patch, verify_patch):
        sys.stderr = io.StringIO()
        sample = TenxSample(name='TEST_FAIL',
                            base_path=TenxApp.config['TENX_DATA_PATH'])
        aln = sample.alignment()
        rsample = TenxSample(name='TEST_FAIL',
                             base_path=TenxApp.config['TENX_REMOTE_URL'])
        raln = rsample.alignment()
        os.makedirs(os.path.join(aln.outs_path))
        with self.assertRaisesRegex(
                Exception, "Refusing to upload an unsuccessful alignment"):
            alignment.run_upload(aln, raln)

        upload_patch.return_value = "0"
        verify_patch.return_value = "1"

        sample = TenxSample(name='TEST_SUCCESS',
                            base_path=TenxApp.config['TENX_DATA_PATH'])
        aln = sample.alignment()
        os.makedirs(os.path.join(aln.path, "outs"))
        with open(os.path.join(aln.path, "outs", "summary.csv"), "w") as f:
            f.write("SUCCESS!")
        rsample = TenxSample(name='TEST_SUCCESS',
                             base_path=TenxApp.config['TENX_DATA_PATH'])
        raln = rsample.alignment()

        err = io.StringIO()
        sys.stderr = err

        alignment.run_upload(aln, raln)
        expected_err = f"Upload TEST_SUCCESS alignment...\nLocal path: {aln.path}\nEntering {aln.path} ...\nUploading to: {raln.path}\nVerify upload alignment...\nUpload alignment...OK\n".format(
            aln.path, raln.path)
        self.assertEqual(err.getvalue(), expected_err)
        sys.stderr = sys.__stderr__
Beispiel #2
0
def aln_upload_cmd(sample_name):
    """
    Upload an assembly from local disk to cloud storage.
    """
    assert bool(TenxApp.config) is True, "Must provide tenx yaml config file!"
    sample = TenxSample(name=sample_name, base_path=TenxApp.config["TENX_DATA_PATH"])
    aln = sample.alignment()
    rsample = TenxSample(name=sample_name, base_path=TenxApp.config["TENX_REMOTE_URL"])
    raln = rsample.alignment()
    alignment.run_upload(aln, raln)
Beispiel #3
0
    def test11_is_successful(self):
        sample = TenxSample(name="TEST_SUCCESS",
                            base_path=TenxApp.config['TENX_DATA_PATH'])
        aln = sample.alignment()
        os.makedirs(os.path.join(aln.outs_path))
        with open(os.path.join(aln.outs_path, "summary.csv"), "w") as f:
            f.write("SUCCESS!")
        self.assertTrue(aln.is_successful())

        sample = TenxSample(name="TEST_FAIL",
                            base_path=TenxApp.config['TENX_DATA_PATH'])
        aln = sample.alignment()
        os.makedirs(aln.path)
        self.assertFalse(aln.is_successful())
Beispiel #4
0
 def test10_alignment(self):
     sample = TenxSample(name="TESTER",
                         base_path=TenxApp.config['TENX_DATA_PATH'])
     aln = sample.alignment(self.ref)
     self.assertEqual(aln.ref, self.ref)
     self.assertEqual(os.path.join(sample.path, "alignment"), aln.path)
     self.assertEqual(os.path.join(aln.path, "outs"), aln.outs_path)
Beispiel #5
0
def aln_align_cmd(sample_name, ref_name):
    """
    Create alignments with longranger.
    """
    assert bool(TenxApp.config) is True, "Must provide tenx yaml config file!"
    sample = TenxSample(name=sample_name, base_path=TenxApp.config["TENX_DATA_PATH"])
    ref = TenxReference(name=ref_name)
    aln = sample.alignment(ref=ref)
    alignment.run_align(aln)
Beispiel #6
0
    def setUp(self):
        self.temp_d = tempfile.TemporaryDirectory()
        if TenxApp.config is None: TenxApp()
        TenxApp.config = {
                "TENX_DATA_PATH": self.temp_d.name,
                "TENX_REMOTE_URL": "gs://data",
                "TENX_REMOTE_REFS_URL": "gs://data/refs",
                "TENX_ALN_VCMODE": "freebayes",
                "TENX_ALN_MODE": "wgs",
                "TENX_ALN_MEM": "1",
                "TENX_ALN_CORES": "1",
                }

        sample = TenxSample(name="__SAMPLE__", base_path=TenxApp.config["TENX_DATA_PATH"])
        ref = TenxReference(name="__REF__")
        self.aln= sample.alignment(ref)
        rsample = TenxSample(name="__SAMPLE__", base_path=TenxApp.config["TENX_REMOTE_URL"])
        self.raln = rsample.alignment(ref)

        os.chdir(self.temp_d.name)
        os.makedirs(self.aln.outs_path)
        os.makedirs(os.path.join(TenxApp.config["TENX_DATA_PATH"], "references"))
Beispiel #7
0
 def setUp(self):
     self.temp_d = tempfile.TemporaryDirectory()
     sample = TenxSample(name="__SAMPLE__", base_path=self.temp_d.name)
     ref = TenxReference(name="__REF__")
     self.aln = sample.alignment(ref=ref)
     os.makedirs(os.path.join(self.aln.path))
     tenx.app.TenxApp.config = {
         "TENX_DATA_PATH":
         os.path.join(self.temp_d.name),
         "TENX_REMOTE_URL":
         "gs://data",
         "TENX_REMOTE_REFSU_URL":
         "gs://resources/refs",
         "TENX_CROMWELL_PATH":
         os.path.join(os.path.dirname(__file__), "data", "app"),
     }
Beispiel #8
0
    def test1_aln_asm(self):
        base_path = TenxApp.config.get("TENX_DATA_PATH")
        sample = TenxSample(base_path=base_path, name="TEST-001")
        ref = TenxReference(name='refdata-GRCh38-2.1.0')

        aln = sample.alignment(ref=ref)
        self.assertTrue(bool(aln))
        self.assertEqual(aln.__class__.__name__, "TenxAlignment")
        self.assertEqual(os.path.join(sample.path, "alignment"), aln.path)
        self.assertEqual(sample, aln.sample)
        self.assertEqual(ref, aln.ref)

        asm = sample.assembly()
        self.assertTrue(bool(asm))
        self.assertEqual(asm.__class__.__name__, "TenxAssembly")
        self.assertEqual(os.path.join(sample.path, "assembly"), asm.path)
        self.assertEqual(sample, asm.sample)
Beispiel #9
0
    def test2_run_align(self, test_patch):
        test_patch.return_value = '0'
        err = io.StringIO()
        sys.stderr = err

        sample = TenxSample(name="TEST_SUCCESS",
                            base_path=TenxApp.config['TENX_DATA_PATH'])
        aln = sample.alignment(self.ref)
        os.makedirs(os.path.join(aln.path, "outs"))
        with open(os.path.join(aln.path, "outs", "summary.csv"), "w") as f:
            f.write("SUCCESS!")
        alignment.run_align(aln)

        expected_err = "Creating alignments for TEST_SUCCESS\nEntering {}\nRunning longranger wgs --id=alignment --sample=TEST_SUCCESS --reference={} --fastqs={} --vcmode=freebayes --disable-ui --jobmode=local --localmem=6 --localcores=1 ...\n".format(
            aln.sample.path, self.ref.directory(), aln.sample.reads_path)
        self.assertEqual(err.getvalue(), expected_err)
        sys.stderr = sys.__stderr__
Beispiel #10
0
class TenxAppTest1(unittest.TestCase):
    def setUp(self):
        self.data_dn = os.path.join(os.path.dirname(__file__), "data", "app")
        self.temp_d = tempfile.TemporaryDirectory()
        self.sample = TenxSample(name="__TEST__", base_path=self.temp_d.name)
        self.asm = self.sample.assembly()
        self.ref = TenxReference(name="__REF__")
        self.aln = self.sample.alignment(ref=self.ref)
        TenxApp.config = None

    def tearDown(self):
        TenxApp.config = None
        self.temp_d.cleanup()

    def test_init_fails(self):
        if TenxApp.config is None: TenxApp()
        TenxApp.config = None
        with self.assertRaisesRegex(IOError, "No such file or directory"):
            TenxApp("/tenx.yaml")

    def test_init(self):
        # init w/o config
        tenxapp = TenxApp()
        self.assertIsNotNone(TenxApp.config)

        # re-init w/ config
        TenxApp.config = None
        self.assertIsNone(TenxApp.config)

        conf_f = tempfile.NamedTemporaryFile()
        config = {
            "environment": "test",
            "TENX_SCRIPTS_PATH": "tests/test_app",
            "TENX_NOTIFICATIONS_SLACK": "https://slack.com",
        }
        conf_f.write(yaml.dump(config).encode())
        conf_f.flush()

        tenxapp = TenxApp(conf_f.name)
        self.assertIsNotNone(tenxapp)
        self.assertDictEqual(tenxapp.config, config)

    def test_cromwell_fails(self):
        with self.assertRaisesRegex(Exception,
                                    "Tenx config has not been initialized!"):
            cromwell = TenxCromwell(entity=self.asm)

        TenxApp.config = {
            "TENX_CROMWELL_PATH": "/",
        }
        with self.assertRaisesRegex(
                Exception, "Cromwell jar not found at /cromwell.jar!"):
            cromwell = TenxCromwell(entity=self.asm)

        with self.assertRaisesRegex(Exception, "Unknown entity:"):
            cromwell = TenxCromwell(entity=self.sample)

    def test_cromwell(self):
        TenxApp.config = {
            "TENX_CROMWELL_PATH": self.data_dn,
        }

        ref = TenxReference(name="__REF__")
        test_params = [
            {
                "pipeline": "supernova",
                "entity": self.asm,
                "inputs": {
                    "SAMPLE_NAME": self.asm.sample.name
                },
            },
            {
                "pipeline": "longranger",
                "entity": self.aln,
                "inputs": {
                    "SAMPLE_NAME": self.aln.sample.name,
                    "REF_NAME": self.aln.ref.name
                },
            },
        ]
        for p in test_params:
            pipeline_name = p["pipeline"]
            entity = p["entity"]
            cromwell = TenxCromwell(entity=entity)
            self.assertTrue(cromwell)
            self.assertEqual(cromwell.entity, entity)
            self.assertEqual(cromwell.pipeline_name, pipeline_name)

            templates_dn = cromwell.templates_dn
            self.assertTrue(templates_dn)

            cromwell_dn = cromwell.cromwell_dn
            self.assertEqual(cromwell_dn,
                             TenxApp.config.get("TENX_CROMWELL_PATH"))
            self.assertEqual(cromwell.cromwell_jar,
                             os.path.join(cromwell_dn, "cromwell.jar"))

            inputs_bn = ".".join([pipeline_name, "inputs", "json"])
            self.assertEqual(cromwell.inputs_bn, inputs_bn)
            wdl_bn = ".".join([pipeline_name, "gcloud", "wdl"])
            self.assertEqual(cromwell.wdl_bn, wdl_bn)
            conf_bn = ".".join([pipeline_name, "conf"])
            self.assertEqual(cromwell.conf_bn, conf_bn)

            self.assertDictEqual(cromwell.inputs_for_entity(), p["inputs"])

            conf_fn = os.path.join(cromwell.pipeline_dn, conf_bn)
            inputs_fn = os.path.join(cromwell.pipeline_dn, inputs_bn)
            wdl_fn = os.path.join(cromwell.pipeline_dn, wdl_bn)

            cmd = cromwell.command()
            expected_cmd = [
                "java", "-Dconfig={}".format(conf_fn), "-jar",
                cromwell.cromwell_jar, wdl_fn, "-i", inputs_fn
            ]

            self.assertTrue(os.path.exists(conf_fn))
            self.assertTrue(os.path.exists(inputs_fn))
            self.assertTrue(os.path.exists(wdl_fn))