Exemple #1
0
    def test_index(self):

        # Create the list of files
        files = ["trinity.gtf",
                 "trinity.gff3",
                 "trinity.cDNA_match.gff3",
                 "trinity.match_matchpart.gff3"]
        # files = [pkg_resources.resource_filename("Mikado.tests", filename) for filename in files]

        namespace = Namespace(default=False)
        namespace.distance = 2000
        namespace.index = True
        namespace.prediction = None
        namespace.log = os.path.join(tempfile.gettempdir(), "index.log")
        logger = create_null_logger("null")

        for ref in files:
            with self.subTest(ref=ref):
                temp_ref = os.path.join(tempfile.gettempdir(), ref)
                with pkg_resources.resource_stream("Mikado.tests", ref) as ref_handle,\
                        open(temp_ref, "wb") as out_handle:
                    out_handle.write(ref_handle.read())
                namespace.reference = to_gff(temp_ref)
                compare(namespace)

                self.assertTrue(os.path.exists(namespace.log))
                self.assertTrue(os.path.exists("{}.midx".format(namespace.reference.name)))
                self.assertGreater(os.stat("{}.midx".format(namespace.reference.name)).st_size, 0)
                genes, positions = load_index(namespace, logger)
                self.assertIsInstance(genes, dict)
                self.assertIsInstance(positions, dict)
                self.assertEqual(len(genes), 38)
                os.remove(namespace.reference.name)
                os.remove(namespace.log)
                os.remove("{}.midx".format(namespace.reference.name))
    def test_compare_trinity(self):

        # Create the list of files
        files = [
            "trinity.gtf", "trinity.gff3", "trinity.cDNA_match.gff3",
            "trinity.match_matchpart.gff3"
        ]
        files = [
            pkg_resources.resource_filename("Mikado.tests", filename)
            for filename in files
        ]

        namespace = Namespace(default=False)
        namespace.distance = 2000
        namespace.no_save_index = True

        for ref, pred in itertools.permutations(files, 2):

            with self.subTest(ref=ref, pred=pred):
                namespace.reference = to_gff(ref)
                namespace.prediction = to_gff(pred)
                namespace.log = os.path.join(
                    tempfile.gettempdir(),
                    "compare_{}_{}.log".format(files.index(ref),
                                               files.index(pred)))
                namespace.out = os.path.join(
                    tempfile.gettempdir(),
                    "compare_{}_{}".format(files.index(ref),
                                           files.index(pred)))
                compare(namespace)
                refmap = "{}.refmap".format(namespace.out)
                tmap = "{}.tmap".format(namespace.out)
                stats = "{}.stats".format(namespace.out)

                self.assertTrue(os.path.exists(namespace.log))
                # with open(log) as log_handle:
                #     log = [_.rstrip() for _ in log_handle]
                for fname in [refmap, stats, tmap]:
                    self.assertTrue(os.path.exists(fname))
                    self.assertGreater(os.stat(fname).st_size, 0)

                with open(refmap) as _:
                    reader = csv.DictReader(_, delimiter="\t")
                    counter = 0
                    for counter, line in enumerate(reader, start=1):
                        ccode = line["ccode"]
                        self.assertIn(ccode, ("_", "=", "f,_", "f,="),
                                      (ref, pred, line))

                    self.assertEqual(counter, 38)

        for suff in ["log", "refmap", "tmap", "stats"]:
            [
                os.remove(_) for _ in glob.glob(
                    os.path.join(tempfile.gettempdir(), "compare_*.{}".format(
                        suff)))
            ]
Exemple #3
0
    def test_compare_trinity(self):

        # Create the list of files
        files = ["trinity.gtf",
                 "trinity.gff3",
                 "trinity.cDNA_match.gff3",
                 "trinity.match_matchpart.gff3"]
        files = [pkg_resources.resource_filename("Mikado.tests", filename) for filename in files]

        namespace = Namespace(default=False)
        namespace.distance = 2000
        namespace.no_save_index = True

        for ref, pred in itertools.permutations(files, 2):

            with self.subTest(ref=ref, pred=pred):
                namespace.reference = to_gff(ref)
                namespace.prediction = to_gff(pred)
                namespace.log = os.path.join(tempfile.gettempdir(), "compare_{}_{}.log".format(
                    files.index(ref), files.index(pred)))
                namespace.out = os.path.join(tempfile.gettempdir(), "compare_{}_{}".format(
                    files.index(ref), files.index(pred)))
                compare(namespace)
                refmap = "{}.refmap".format(namespace.out)
                tmap = "{}.tmap".format(namespace.out)
                stats = "{}.stats".format(namespace.out)

                self.assertTrue(os.path.exists(namespace.log))
                # with open(log) as log_handle:
                #     log = [_.rstrip() for _ in log_handle]
                for fname in [refmap, stats, tmap]:
                    self.assertTrue(os.path.exists(fname))
                    self.assertGreater(os.stat(fname).st_size, 0)

                with open(refmap) as _:
                    reader = csv.DictReader(_, delimiter="\t")
                    counter = 0
                    for counter, line in enumerate(reader, start=1):
                        ccode = line["ccode"]
                        self.assertIn(ccode,
                                      ("_", "=", "f,_", "f,="),
                                      (ref, pred, line))

                    self.assertEqual(counter, 38)

        for suff in ["log", "refmap", "tmap", "stats"]:
            [os.remove(_) for _ in glob.glob(os.path.join(tempfile.gettempdir(),
                                                          "compare_*.{}".format(suff)))]
Exemple #4
0
 def test_mikado_config(self):
     namespace = Namespace(default=False)
     namespace.scoring = None
     namespace.intron_range = None
     namespace.reference = ""
     namespace.external = None
     namespace.mode = ["permissive"]
     namespace.threads = 1
     namespace.blast_targets = []
     namespace.junctions = []
     out = os.path.join(tempfile.gettempdir(), "configuration.yaml")
     with open(out, "w") as out_handle:
         namespace.out = out_handle
         Mikado.subprograms.configure.create_config(namespace)
     self.assertGreater(os.stat(out).st_size, 0)
     conf = Mikado.configuration.configurator.to_json(out)
     conf = Mikado.configuration.configurator.check_json(conf)
     conf = Mikado.configuration.configurator.check_json(conf)
     os.remove(out)
 def test_mikado_config(self):
     namespace = Namespace(default=False)
     namespace.scoring = None
     namespace.intron_range = None
     namespace.reference = ""
     namespace.external = None
     namespace.mode = ["permissive"]
     namespace.threads = 1
     namespace.blast_targets = []
     namespace.junctions = []
     out = os.path.join(tempfile.gettempdir(), "configuration.yaml")
     with open(out, "w") as out_handle:
         namespace.out = out_handle
         Mikado.subprograms.configure.create_config(namespace)
     self.assertGreater(os.stat(out).st_size, 0)
     conf = Mikado.configuration.configurator.to_json(out)
     conf = Mikado.configuration.configurator.check_json(conf)
     conf = Mikado.configuration.configurator.check_json(conf)
     os.remove(out)
    def test_index(self):

        # Create the list of files
        files = [
            "trinity.gtf", "trinity.gff3", "trinity.cDNA_match.gff3",
            "trinity.match_matchpart.gff3"
        ]
        # files = [pkg_resources.resource_filename("Mikado.tests", filename) for filename in files]

        namespace = Namespace(default=False)
        namespace.distance = 2000
        namespace.index = True
        namespace.prediction = None
        namespace.log = os.path.join(tempfile.gettempdir(), "index.log")
        logger = create_null_logger("null")

        for ref in files:
            with self.subTest(ref=ref):
                temp_ref = os.path.join(tempfile.gettempdir(), ref)
                with pkg_resources.resource_stream("Mikado.tests", ref) as ref_handle,\
                        open(temp_ref, "wb") as out_handle:
                    out_handle.write(ref_handle.read())
                namespace.reference = to_gff(temp_ref)
                compare(namespace)

                self.assertTrue(os.path.exists(namespace.log))
                self.assertTrue(
                    os.path.exists("{}.midx".format(namespace.reference.name)))
                self.assertGreater(
                    os.stat("{}.midx".format(
                        namespace.reference.name)).st_size, 0)
                genes, positions = load_index(namespace, logger)
                self.assertIsInstance(genes, dict)
                self.assertIsInstance(positions, dict)
                self.assertEqual(len(genes), 38)
                os.remove(namespace.reference.name)
                os.remove(namespace.log)
                os.remove("{}.midx".format(namespace.reference.name))