Skip to content

Commit

Permalink
Improved a bit calls, as per EI-CoreBioinformatics#142 and EI-CoreBio…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucventurini committed Jan 28, 2019
1 parent 05123f7 commit cbb419f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Mikado/configuration/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,6 @@ def to_json(string, simple=False, logger=None):
logger.exception(exc)
with open("ERROR.{}".format("json" if string.endswith("json") else "yaml"), "wt") as errored:
errored.write(open(string).read())
raise
raise OSError(exc)

return json_dict
37 changes: 37 additions & 0 deletions Mikado/tests/locus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ class LocusTester(unittest.TestCase):
logger = create_null_logger(inspect.getframeinfo(inspect.currentframe())[2])
logger_name = logger.name

@classmethod
def setUpClass(cls):
cls.__genomefile__ = None

cls.__genomefile__ = tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".fa", prefix="prepare")

with pkg_resources.resource_stream("Mikado.tests", "chr5.fas.gz") as _:
cls.__genomefile__.write(gzip.decompress(_.read()))
cls.__genomefile__.flush()
cls.fai = pyfaidx.Fasta(cls.__genomefile__.name)

@classmethod
def tearDownClass(cls):
os.remove(cls.__genomefile__.name)
os.remove(cls.fai.faidx.indexname)

def setUp(self):

gff_transcript1 = """Chr1\tfoo\ttranscript\t101\t400\t.\t+\t.\tID=t0
Expand Down Expand Up @@ -230,7 +246,9 @@ def setUp(self):
# with self.assertRaises(exceptions.NoJsonConfigError):
# _ = Superlocus(self.transcript1)
self.my_json = os.path.join(os.path.dirname(__file__), "configuration.yaml")

self.my_json = configurator.to_json(self.my_json)
self.my_json["reference"]["genome"] = self.fai.filename
self.assertIn("scoring", self.my_json, self.my_json.keys())

def test_locus(self):
Expand Down Expand Up @@ -1102,6 +1120,22 @@ class TestLocus(unittest.TestCase):

logger = Mikado.utilities.log_utils.create_default_logger("tester")

@classmethod
def setUpClass(cls):
cls.__genomefile__ = None

cls.__genomefile__ = tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".fa", prefix="prepare")

with pkg_resources.resource_stream("Mikado.tests", "chr5.fas.gz") as _:
cls.__genomefile__.write(gzip.decompress(_.read()))
cls.__genomefile__.flush()
cls.fai = pyfaidx.Fasta(cls.__genomefile__.name)

@classmethod
def tearDownClass(cls):
os.remove(cls.__genomefile__.name)
os.remove(cls.fai.faidx.indexname)

def setUp(self):

"""Set up for the unit test."""
Expand Down Expand Up @@ -1205,6 +1239,7 @@ def setUp(self):
# self.logger = logging.getLogger("tester")
# self.handler = logging.StreamHandler()
self.logger.setLevel(logging.WARNING)
self.json_conf["reference"]["genome"] = self.fai.filename
# self.logger.addHandler(self.handler)

def test_validity(self):
Expand Down Expand Up @@ -1396,10 +1431,12 @@ def test_remove_AS_overlapping(self):
"parameters": {
"cdna_length": {"operator": "gt", "value": 0, "name": "cdna_length"}
}}
conf["pick"]["alternative_splicing"]["pad"] = False

with self.subTest():
superlocus_one = Superlocus(t1, json_conf=conf)
superlocus_one.add_transcript_to_locus(t1_1)

locus_one = Locus(t1, json_conf=conf)
locus_one.logger = logger
superlocus_one.loci[locus_one.id] = locus_one
Expand Down
51 changes: 47 additions & 4 deletions Mikado/tests/test_system_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def test_reference_selection(self):
self.conf["prepare"]["files"]["labels"] = ["T1", "T2"]

for round in rounds:
for iteration in range(4): # Repeat each test 4 times
for iteration in range(2): # Repeat each test 2 times, not more for time length reasons
with self.subTest(round=round, format=format, iteration=iteration,
msg="Starting round {} ({})".format(round, rounds[round])):
t1_score, t2_score, is_ref, res, corr_strand = rounds[round]
Expand Down Expand Up @@ -703,7 +703,7 @@ def test_reference_cds_kept(self):
self.conf["prepare"]["files"]["labels"] = ["T1", "T2"]

for round in rounds:
for iteration in range(4): # Repeat each test 4 times
for iteration in range(2): # Repeat each test 2 times for time length reasons
with self.subTest(round=round, format=format, iteration=iteration,
msg="Starting round {} ({})".format(round, rounds[round])):
t1_score, t2_score, is_ref, res, coding = rounds[round]
Expand Down Expand Up @@ -873,6 +873,7 @@ def test_stat(self):
namespace.gff.close()
dir.cleanup()


class ConfigureCheck(unittest.TestCase):

"""Test for creating configuration files"""
Expand Down Expand Up @@ -1044,14 +1045,31 @@ class PickTest(unittest.TestCase):
def setUp(self):

self.json_conf = configurator.to_json(None)
self.json_conf["reference"]["genome"] = self.fai.filename

@classmethod
def setUpClass(cls):
cls.__genomefile__ = None

cls.__genomefile__ = tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".fa", prefix="prepare")

with pkg_resources.resource_stream("Mikado.tests", "chr5.fas.gz") as _:
cls.__genomefile__.write(gzip.decompress(_.read()))
cls.__genomefile__.flush()
cls.fai = pyfaidx.Fasta(cls.__genomefile__.name)

@classmethod
def tearDownClass(cls):
os.remove(cls.__genomefile__.name)
os.remove(cls.fai.faidx.indexname)

def test_single_proc(self):

self.json_conf["pick"]["run_options"]["procs"] = 1
self.json_conf["db_settings"]["db"] = pkg_resources.resource_filename("Mikado.tests", "mikado.db")

self.json_conf["pick"]["files"]["input"] = pkg_resources.resource_filename("Mikado.tests",
"mikado_prepared.gtf")
"mikado_prepared.gtf")
dir = tempfile.TemporaryDirectory()
self.json_conf["pick"]["files"]["output_dir"] = dir.name
self.json_conf["pick"]["files"]["loci_out"] = "mikado.monoproc.loci.gff3"
Expand Down Expand Up @@ -1103,7 +1121,7 @@ def test_multi_proc(self):
def test_subprocess(self):

self.json_conf["pick"]["files"]["input"] = pkg_resources.resource_filename("Mikado.tests",
"mikado_prepared.gtf")
"mikado_prepared.gtf")
dir = tempfile.TemporaryDirectory()
self.json_conf["pick"]["files"]["output_dir"] = dir.name
self.json_conf["pick"]["files"]["loci_out"] = "mikado.subproc.loci.gff3"
Expand Down Expand Up @@ -1361,5 +1379,30 @@ def test_purging(self):
dir.cleanup()


class SerialiseChecker(unittest.TestCase):

def setUp(self):
self.json_conf = configurator.to_json(None)
self.json_conf["reference"]["genome"] = self.fai.filename

@classmethod
def setUpClass(cls):
cls.__genomefile__ = None

cls.__genomefile__ = tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".fa", prefix="serialise")

with pkg_resources.resource_stream("Mikado.tests", "chr5.fas.gz") as _:
cls.__genomefile__.write(gzip.decompress(_.read()))
cls.__genomefile__.flush()
cls.fai = pyfaidx.Fasta(cls.__genomefile__.name)

@classmethod
def tearDownClass(cls):
os.remove(cls.__genomefile__.name)
os.remove(cls.fai.faidx.indexname)




if __name__ == "__main__":
unittest.main()
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ wheel>=0.28.0
pyyaml
jsonschema
cython>=0.25
numpy>=1.15.0
numpy>=1.16.0
networkx>=2
sqlalchemy>=1
sqlalchemy_utils
biopython>=1.70
intervaltree
nose # for numpy tester
pytest
pyfaidx
scikit-learn>=0.17.0
scipy>=0.15.0
scipy>=1.0.0
frozendict
python-magic
drmaa
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
test=pytest

[tool:pytest]
addopts = --cov Mikado
# addopts = --cov Mikado
norecursedirs = datrie*

0 comments on commit cbb419f

Please sign in to comment.