Exemplo n.º 1
0
class TestBifrostEnterobase:
    component_name = "enterobase__v1_1_5__"
    current_dir = os.getcwd()
    test_dir = "/bifrost/test_data/output/test__enterobase/"
    json_entries = [{
        "_id": {
            "$oid": "000000000000000000000001"
        },
        "name": "SRR2094561",
        "components": [],
        "categories": {
            "paired_reads": {
                "summary": {
                    "data": [
                        "/bifrost/test_data/samples/SRR2094561_1.fastq.gz",
                        "/bifrost/test_data/samples/SRR2094561_2.fastq.gz"
                    ]
                }
            },
            "mlst": {
                "summary": {
                    "sequence_type": {
                        "senterica": "34"
                    }
                }
            },
            "species_detection": {
                "summary": {
                    "species": "Salmonella enterica"
                }
            }
        }
    }]
    bson_entries = [database_interface.json_to_bson(i) for i in json_entries]

    @classmethod
    def setup_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)
        col = db["samples"]
        col.insert_many(cls.bson_entries)
        launcher.initialize()
        os.chdir(cls.current_dir)

    @classmethod
    def teardown_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)

    @staticmethod
    def clear_all_collections(db):
        db.drop_collection("components")
        db.drop_collection("hosts")
        db.drop_collection("run_components")
        db.drop_collection("runs")
        db.drop_collection("sample_components")
        db.drop_collection("samples")

    def test_info(self):
        launcher.run_pipeline(["--info"])

    def test_help(self):
        launcher.run_pipeline(["--help"])

    def test_pipeline(self):
        if os.path.isdir(self.test_dir):
            shutil.rmtree(self.test_dir)

        os.mkdir(self.test_dir)
        test_args = ["--sample_name", "SRR2094561", "--outdir", self.test_dir]
        launcher.main(args=test_args)
        assert os.path.isfile(
            f"{self.test_dir}/{self.component_name}/datadump_complete")
        shutil.rmtree(self.test_dir)
        assert not os.path.isdir(f"{self.test_dir}/{self.component_name}")
Exemplo n.º 2
0
class TestRunComponents:
    json_entries_runs = [{
        "_id": {
            "$oid": "000000000000000000000001"
        },
        "name": "test_run1",
        "samples": [],
        "components": [],
        "hosts": []
    }]
    bson_entries_runs = [
        database_interface.json_to_bson(i) for i in json_entries_runs
    ]
    json_entries_components = [{
        "_id": {
            "$oid": "0000000000000000000000b1"
        },
        "name": "test_component1"
    }]
    bson_entries_components = [
        database_interface.json_to_bson(i) for i in json_entries_components
    ]
    json_entries = [{
        "_id": {
            "$oid": "000000000000000000000001"
        },
        "name": "test_sample_component1",
        "sample": {
            "_id": {
                "$oid": "0000000000000000000000a1"
            },
            "name": "test_sample1"
        },
        "component": {
            "_id": {
                "$oid": "0000000000000000000000b1"
            },
            "name": "test_component1"
        }
    }]
    bson_entries = [database_interface.json_to_bson(i) for i in json_entries]

    @classmethod
    def setup_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)
        col = db["runs"]
        col.insert_many(cls.bson_entries_runs)
        col = db["components"]
        col.insert_many(cls.bson_entries_components)
        col = db["run_components"]
        col.insert_many(cls.bson_entries)

    @classmethod
    def teardown_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)

    @staticmethod
    def clear_all_collections(db):
        db.drop_collection("components")
        db.drop_collection("hosts")
        db.drop_collection("run_components")
        db.drop_collection("runs")
        db.drop_collection("sample_components")
        db.drop_collection("samples")

    def test_run_component_create(self):
        run = Run(value=self.json_entries_runs[0])
        component = Component(value=self.json_entries_components[0])
        test_run_component = RunComponent(
            run_reference=run.to_reference(),
            component_reference=component.to_reference())
        test_run_component.save()
        assert "_id" in test_run_component.json

    def test_run_component_load(self):
        _id = "000000000000000000000001"
        name = "test_run_component1"
        # Test load on just _id
        reference = RunComponentReference(_id=_id)
        run_component = RunComponent.load(reference)
        json = run_component.json
        json.pop("version", None)
        json.pop("metadata", None)
        assert json == self.json_entries[0]
        del run_component
        # Test load on just name
        refrence = RunComponentReference(name=name)
        run_component = RunComponent.load(reference)
        json = run_component.json
        json.pop("version", None)
        json.pop("metadata", None)
        assert json == self.json_entries[0]
        del run_component
        # Test load on both _id and name
        reference = RunComponentReference(_id=_id, name=name)
        run_component = RunComponent.load(reference)
        json = run_component.json
        json.pop("version", None)
        json.pop("metadata", None)
        assert json == self.json_entries[0]
        del run_component
        # Test load on both _id and name
        reference = RunComponentReference(value=self.json_entries[0])
        run_component = RunComponent.load(reference)
        json = run_component.json
        json.pop("version", None)
        json.pop("metadata", None)
        assert json == self.json_entries[0]
        del run_component

    def test_run_component_delete(self):
        _id = "000000000000000000000001"
        name = "test_run_component"
        run_component = RunComponent.load(
            RunComponentReference(_id=_id, name=name))
        assert run_component.delete() == True
Exemplo n.º 3
0
class TestBifrostRunLauncher:
    component_name = "run_launcher__v2_2_7"
    test_dir = "/bifrost/test_data/output/test__run_launcher/"
    current_dir = os.getcwd()
    json_entries = [{
        "_id": {
            "$oid": "000000000000000000000001"
        },
        "name": "test_component1"
    }]

    bson_entries = [database_interface.json_to_bson(i) for i in json_entries]

    @classmethod
    def setup_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)
        launcher.initialize()

    @classmethod
    def teardown_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)

    @staticmethod
    def clear_all_collections(db):
        db.drop_collection("components")
        db.drop_collection("hosts")
        db.drop_collection("run_components")
        db.drop_collection("runs")
        db.drop_collection("sample_components")
        db.drop_collection("samples")

    def test_info(self):
        launcher.run_pipeline(["--info"])

    def test_help(self):
        launcher.run_pipeline(["--help"])

    def test_pipeline(self):

        bifrost_config_and_data_path = "/bifrost/test_data"

        if os.path.isdir(self.test_dir):
            shutil.rmtree(self.test_dir)

        os.mkdir(self.test_dir)
        test_args = [
            "--outdir", f"{self.test_dir}/{self.component_name}",
            "--pre_script", f"{bifrost_config_and_data_path}/pre.sh",
            "--per_sample_script",
            f"{bifrost_config_and_data_path}/per_sample.sh", "--post_script",
            f"{bifrost_config_and_data_path}/post.sh", "--run_metadata",
            f"{bifrost_config_and_data_path}/run_metadata.tsv",
            "--reads_folder", f"{bifrost_config_and_data_path}/samples",
            "--run_name", "bifrost_test", "--run_type", "test",
            "--component_subset",
            "bifrost_min_read_check_v2_2_8,bifrost_whats_my_species_v2_2_11__171019,bifrost_cge_mlst_v2_2_6__210314",
            "--sample_subset", "S1"
        ]
        launcher.main(args=test_args)
        #clear collection
        assert os.path.isfile(
            f"{self.test_dir}/{self.component_name}/run_script.sh")
        assert os.path.isfile(
            f"{self.test_dir}/{self.component_name}/run.yaml")
        assert os.path.isfile(
            f"{self.test_dir}/{self.component_name}/samples.yaml")
Exemplo n.º 4
0
class TestHosts:
    json_entries = [{
        "_id": {
            "$oid": "000000000000000000000001"
        },
        "name": "test_host1",
        "samples": []
    }]
    bson_entries = [database_interface.json_to_bson(i) for i in json_entries]

    @classmethod
    def setup_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)
        col = db["hosts"]
        col.insert_many(cls.bson_entries)

    @classmethod
    def teardown_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)

    @staticmethod
    def clear_all_collections(db):
        db.drop_collection("components")
        db.drop_collection("hosts")
        db.drop_collection("run_components")
        db.drop_collection("runs")
        db.drop_collection("sample_components")
        db.drop_collection("samples")

    def test_host_create(self):
        test_host = Host(name="test_host")
        test_host.save()
        assert "_id" in test_host.json

    def test_host_create_from_ref(self):
        _id = "000000000000000000000001"
        name = "test_host"
        host = Host.load(HostReference(_id=_id, name=name))
        assert host.delete() == True
        test_host = Host(value=self.json_entries[0])
        test_host.save()
        json = host.json
        json.pop("version", None)
        json.pop("metadata", None)
        assert json == self.json_entries[0]

    def test_host_load(self):
        _id = "000000000000000000000001"
        name = "test_host1"
        # Test load on just _id
        reference = HostReference(_id=_id)
        host = Host.load(reference)
        json = host.json
        json.pop("version", None)
        json.pop("metadata", None)
        assert json == self.json_entries[0]
        del host
        # Test load on just name
        refrence = HostReference(name=name)
        host = Host.load(reference)
        json = host.json
        json.pop("version", None)
        json.pop("metadata", None)
        assert json == self.json_entries[0]
        del host
        # Test load on both _id and name
        reference = HostReference(_id=_id, name=name)
        host = Host.load(reference)
        json = host.json
        json.pop("version", None)
        json.pop("metadata", None)
        assert json == self.json_entries[0]
        del host
        # Test load on both _id and name
        reference = HostReference(value=self.json_entries[0])
        host = Host.load(reference)
        json = host.json
        json.pop("version", None)
        json.pop("metadata", None)
        assert json == self.json_entries[0]
        del host

    def test_host_delete(self):
        _id = "000000000000000000000001"
        name = "test_host"
        host = Host.load(HostReference(_id=_id, name=name))
        assert host.delete() == True
class TestCGEVirulencefinder:
    component_name = "cge_virulencefinder__v2_0_1"
    component_name = component_name + "__0479a98"
    current_dir = os.getcwd()
    test_dir = "/bifrost/test_data/output/test__cge_virulencefinder/"
    json_entries = [
        {
            "_id": {"$oid": "000000000000000000000001"},
            "name": "S1",
            "components": [],
            "categories": {
                "paired_reads": {
                    "summary": {
                        "data": ["/bifrost/test_data/samples/S1_R1.fastq.gz",
                                 "/bifrost/test_data/samples/S1_R2.fastq.gz"]
                    }
                },
                "species_detection": {
                    "summary": {
                        "species": "Staphylococcus aureus"
                    }
                }
            }
        }
    ]
    bson_entries = [database_interface.json_to_bson(i) for i in json_entries]

    @classmethod
    def setup_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)
        col = db["samples"]
        col.insert_many(cls.bson_entries)
        launcher.initialize()
        os.chdir(cls.current_dir)

    @classmethod
    def teardown_class(cls):
        client = pymongo.MongoClient(os.environ['BIFROST_DB_KEY'])
        db = client.get_database()
        cls.clear_all_collections(db)

    @staticmethod
    def clear_all_collections(db):
        db.drop_collection("components")
        db.drop_collection("hosts")
        db.drop_collection("run_components")
        db.drop_collection("runs")
        db.drop_collection("sample_components")
        db.drop_collection("samples")

    def test_info(self):
        launcher.run_pipeline(["--info"])

    def test_help(self):
        launcher.run_pipeline(["--help"])

    def test_pipeline(self):
        if os.path.isdir(self.test_dir):
            shutil.rmtree(self.test_dir)

        os.mkdir(self.test_dir)
        test_args = [
            "--sample_name", "S1",
            "--outdir", self.test_dir
        ]
        launcher.main(args=test_args)
        assert os.path.isfile(f"{self.test_dir}/{self.component_name}/datadump_complete")
        shutil.rmtree(self.test_dir)
        assert not os.path.isdir(f"{self.test_dir}/{self.component_name}")