Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with open(fasta_path, 'w') as fasta_out:
fasta_out.write(">seq1\nCTCCGGGCCCAT\nAACACTTGGGGGTAGCTAAAGTGAA\nATAAAGCCTAAA\n")
builtins_open = builtins.open
opened_files=[]
def test_open(*args, **kwargs):
f = builtins_open(*args, **kwargs)
opened_files.append(f)
return f
with mock.patch('six.moves.builtins.open', side_effect=test_open):
try:
Faidx(fasta_path)
self.assertFail("Faidx construction should fail with 'FastaIndexingError'.")
except FastaIndexingError:
pass
self.assertTrue(all(f.closed for f in opened_files))
finally:
shutil.rmtree(tmp_dir)
new_home = "fragments/remove"
else:
self.json_conf["pick"]["clustering"][key] = self.json_conf["pick"]["run_options"].pop(key)
new_home = "clustering/{}".format(key)
warns = PendingDeprecationWarning(
"""The \"{}\" property has now been moved to pick/{}. \
Please update your configuration files in the future.""".format(
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 (pyfaidx.FastaIndexingError, FileNotFoundError, pyfaidx.FastaNotFoundError):
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:
self.regressor = pickle.load(forest)
if not isinstance(self.regressor["scoring"], (RandomForestRegressor, RandomForestClassifier)):
exc = TypeError("Invalid regressor provided, type: %s", type(self.regressor["scoring"]))
self.logger.critical(exc)
return
else:
def generate_exports():
"""Print export commands for setting environment variables."""
env = []
for name in list_installed_genomes():
try:
g = Genome(name)
env_name = re.sub(r"[^\w]+", "_", name).upper()
env.append(f"export {env_name}={g.filename}")
except FastaIndexingError:
pass
return env
if options.downsample <= 0:
message("Must set --downsample to be greater than 0", "error")
if options.downsample > 100:
message("Setting --downsample to >100 may result in poor performance", "warning")
OPEN_BROWSER = (not options.no_browser)
# Load reference
if ref_file is None:
config.REFFILE = "No reference loaded"
elif not os.path.exists(ref_file):
message("Could not find reference file %s" % ref_file, "warning")
config.REFFILE = "Could not find reference file %s" % ref_file
else:
try:
_ = pyfaidx.Fasta(ref_file) # Make sure we can open the fasta file
except pyfaidx.FastaIndexingError:
message("Invalid reference fasta file %s" % ref_file, "warning")
config.REFFILE = "Invalid fasta file %s" % ref_file
# Parse targets
target_file = options.targets
if target_file is not None:
if not os.path.exists(target_file):
message("Target file %s does not exist" % target_file, "warning")
else:
config.TARGET_LIST = ParseTargets(target_file)
# Start app
app = create_app(config_object=config)
success = False
for port in random_ports(default_port, app.config["PORT_RETRIES"] + 1):
try: