Skip to content
Snippets Groups Projects
Commit 30ca8d1f authored by Ivan Vanát's avatar Ivan Vanát
Browse files

fixed permission check for non-existing output folder

parent 5a8784f3
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
import os
import sys
import click
import glob
......@@ -19,15 +20,16 @@ from nested.core.sequence_thread import SequenceThread
@click.option('--sketch', '-s', is_flag=True, default=False, help='Sketch output.')
@click.option('--format', '-f', default='genome_browser', help='Format for GFF.')
@click.option('--output_fasta_offset', '-o', default=0, help='Number of bases around the element included in output fasta files.')
@click.option('--output_folder', '-d', default="", type=click.Path(writable=True, resolve_path=True), help='Output data folder.')
@click.option('--output_folder', '-d', default="", type=click.Path(writable=True), help='Output data folder.')
@click.option('--initial_threshold', '-t', type=int, default=500, help='Initial threshold value.')
@click.option('--threshold_multiplier', '-m', type=float, default=1, help='Threshold multiplier.')
@click.option('--threads', '-n', type=int, default=1, help='Number of threads')
def main(input_fasta, sketch, format, output_fasta_offset, output_folder, initial_threshold, threshold_multiplier, threads):
check_permissions(output_folder, os.W_OK | os.X_OK)
number_of_errors = [0]
start_time = datetime.now()
sequences = list(SeqIO.parse(open(input_fasta), 'fasta'))
sketcher = Sketcher()
sketcher = Sketcher()
futuress = []
with futures.ThreadPoolExecutor(threads) as executor:
for sequence in sequences:
......@@ -64,6 +66,16 @@ def process_sequence(sequence, sketcher, sketch, format, output_fasta_offset, ou
errors[0] += 1
print('Processing {}: UNEXPECTED ERROR:'.format(sequence.id[:strlen]), sys.exc_info()[0])
def check_permissions(path, permissions):
path = os.getcwd() if len(path) == 0 else path
if not os.path.exists('{}/data'.format(path)):
try:
os.makedirs('{}/data'.format(path))
except PermissionError:
raise click.BadParameter("Path \"{}\" is not writable.".format(path), param=path, param_hint='\"--output_folder\" / \"-d\"')
except Exception:
return
def cleanup():
for file in glob.glob("*ltrs.fa"):
os.remove(file)
......
......@@ -16,7 +16,7 @@ class Sketcher(object):
self._gff_path = ''
def create_gff(self, nested_element, dirpath, output_fasta_offset=0, format='default'):
path = os.path.join(dirpath, DEFAULT_DIRPATH)
path = os.path.join(dirpath, DEFAULT_DIRPATH)
self._gff_maker.create_gff(nested_element, path, output_fasta_offset, format)
def create_solo_ltr_gff(self, solo_ltrs, dirpath):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment