예제 #1
0
 def setUp(self):
     self.temp_d = tempfile.TemporaryDirectory()
     self.ref = TenxReference(name='refdata-GRCh38-2.1.0')
     if TenxApp.config is None: TenxApp()
     TenxApp.config['TENX_DATA_PATH'] = self.temp_d.name
     TenxApp.config['TENX_REMOTE_URL'] = 'gs://data'
     TenxApp.config['TENX_REMOTE_REFS_URL'] = 'gs://data/references'
     TenxApp.config['TENX_ALN_MODE'] = 'local'
     TenxApp.config['TENX_ALN_CORES'] = '1'
     TenxApp.config['TENX_ALN_MEM'] = '6'
     TenxApp.config['TENX_ALN_VCMODE'] = 'freebayes'
예제 #2
0
 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
예제 #3
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)
예제 #4
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"),
     }
예제 #5
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)
예제 #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"))
예제 #7
0
def ref_download(ref_name):
    """
    Download reference sequences from cloud storage to local disk.
    """
    assert bool(TenxApp.config) is True, "Must provide tenx yaml config file!"
    download(TenxReference(name=ref_name))
예제 #8
0
    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))
예제 #9
0
class TenxAlignmentTest(unittest.TestCase):
    def setUp(self):
        self.temp_d = tempfile.TemporaryDirectory()
        self.ref = TenxReference(name='refdata-GRCh38-2.1.0')
        if TenxApp.config is None: TenxApp()
        TenxApp.config['TENX_DATA_PATH'] = self.temp_d.name
        TenxApp.config['TENX_REMOTE_URL'] = 'gs://data'
        TenxApp.config['TENX_REMOTE_REFS_URL'] = 'gs://data/references'
        TenxApp.config['TENX_ALN_MODE'] = 'local'
        TenxApp.config['TENX_ALN_CORES'] = '1'
        TenxApp.config['TENX_ALN_MEM'] = '6'
        TenxApp.config['TENX_ALN_VCMODE'] = 'freebayes'

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

    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)

    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())

    @patch('subprocess.check_call')
    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__

    @patch('subprocess.check_call')
    @patch('tenx.util.verify_upload')
    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__