Skip to content

Commit

Permalink
Finally fixed #137!
Browse files Browse the repository at this point in the history
  • Loading branch information
lucventurini committed Jan 31, 2019
1 parent c1b7efe commit d54008f
Show file tree
Hide file tree
Showing 9 changed files with 3,146 additions and 26 deletions.
5 changes: 1 addition & 4 deletions Mikado/configuration/configuration_blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,7 @@
"type": "string",
"default": ""
},
"log": {
"type": "string",
"default": "mikado_pick.log"
}
"log": {"oneOf": [null, {"type": "string", "default": null}]}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Mikado/configuration/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ def to_json(string, simple=False, logger=None):
json_dict = check_json(json_dict, simple=simple, logger=logger)
except Exception as exc:
logger.exception(exc)
with open("ERROR.{}".format("json" if string.endswith("json") else "yaml"), "wt") as errored:
errored.write(open(string).read())
# with open("ERROR.{}".format("json" if string.endswith("json") else "yaml"), "wt") as errored:
# errored.write(open(string).read())
raise OSError(exc)

return json_dict
27 changes: 25 additions & 2 deletions Mikado/picking/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
import pickle
import warnings
# from math import floor
import pyfaidx
logging.captureWarnings(True)
warnings.simplefilter("always")
import sqlite3
Expand All @@ -47,6 +47,7 @@
except ImportError:
import json


# pylint: disable=too-many-instance-attributes
class Picker:

Expand Down Expand Up @@ -170,7 +171,14 @@ def __load_configuration(self):
multiprocessing.set_start_method(self.json_conf["multiprocessing_method"],
force=True)
self.setup_logger()
self.json_conf = check_json(self.json_conf, logger=self.logger)
self.logger.debug("Checking the configuration dictionary")
try:
self.json_conf = check_json(self.json_conf, logger=self.logger)
self.logger.debug("Configuration dictionary passes checks")
except Exception as exc:
self.logger.critical("Something went wrong with the configuration, critical error, aborting.")
self.logger.critical(exc)
sys.exit(1)
else:
raise TypeError(type(self.json_conf))
assert isinstance(self.json_conf, dict)
Expand All @@ -190,6 +198,19 @@ def __load_configuration(self):
key, new_home))
self.logger.warning(warns)

if self.json_conf.get("pick", {}).get("alternative_splicing", {}).get("pad", False) is True:
# Check that, when asks for padding, the reference genome is present
self.logger.debug("Checking for the presence of the reference genome")
try:
_ = pyfaidx.Fasta(self.json_conf["reference"]["genome"])
except:
self.logger.error("Transcript padding cannot be executed without a valid genome file.\
Please, either disable the padding or provide a valid genome sequence.")
sys.exit(1)
self.logger.debug("Valid reference genome found")
else:
pass

self.context = multiprocessing.get_context()
if self.json_conf["pick"]["scoring_file"].endswith((".pickle", ".model")):
with open(self.json_conf["pick"]["scoring_file"], "rb") as forest:
Expand All @@ -201,6 +222,8 @@ def __load_configuration(self):
else:
self.regressor = None

self.logger.debug("Configuration loaded successfully")

def __create_output_handles(self):

"""Create all the output-related variables."""
Expand Down
13 changes: 13 additions & 0 deletions Mikado/subprograms/pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,21 @@ def check_run_options(args, logger=None):

args.json_conf["pick"]["files"][key] = val

if getattr(args, "fasta"):
args.fasta.close()
args.json_conf["reference"]["genome"] = args.fasta.name

if args.scoring_file is not None:
if not os.path.exists(args.scoring_file) and os.path.isfile(args.scoring_file):
raise ValueError("Invalid/inexistent scoring file: {}".format(args.scoring_file))
args.json_conf["pick"]["scoring_file"] = args.scoring_file

if (args.json_conf["pick"]["alternative_splicing"]["pad"] and
not os.path.exists(args.json_conf["reference"]["genome"])):
logger.critical("Transcript padding cannot function unless the genome file is specified. \
Please either provide a valid genome file or disable the padding.")
sys.exit(1)

args.json_conf = check_json(args.json_conf, logger=logger)

return args
Expand Down Expand Up @@ -189,6 +199,9 @@ def pick_parser():
help="""Range into which intron lengths should fall, as a couple of integers.
Transcripts with intron lengths outside of this range will be penalised.
Default: (60, 900)""")
parser.add_argument("--fasta", type=argparse.FileType(),
help="Genome FASTA file. Required if pad is enabled (default).")
parser.add_argument("--no-pad", dest="pad", action="store_false", help="Disable transcript padding.")
parser.add_argument("--pad", default=False,
action="store_true",
help="Whether to pad transcripts in loci.")
Expand Down
Binary file added Mikado/tests/chunk-001-proteins.xml.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion Mikado/tests/locus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_invalid_sublocus(self):
self.transcript1.json_conf = None
_ = Sublocus(self.transcript1, json_conf=None)

with self.assertRaises(FileNotFoundError):
with self.assertRaises((OSError, FileNotFoundError)):
_ = Sublocus(self.transcript1, json_conf="test")

def test_sublocus_from_sublocus(self):
Expand Down
Loading

0 comments on commit d54008f

Please sign in to comment.