Skip to content

Commit

Permalink
Process each sample in its own subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Minot committed Feb 6, 2018
1 parent 450593d commit 9e0a162
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/fastq_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from lib.exec_helpers import run_cmds


def get_reads_from_url(input_str, temp_folder, random_string=uuid.uuid4()):
def get_reads_from_url(
input_str,
temp_folder,
random_string=str(uuid.uuid4())[:8]
):
"""Get a set of reads from a URL -- return the downloaded filepath."""
logging.info("Getting reads from {}".format(input_str))

Expand Down
26 changes: 20 additions & 6 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
args = parser.parse_args()

# Make a temporary folder for all files to be placed in
temp_folder = os.path.join(args.temp_folder, str(uuid.uuid4()))
temp_folder = os.path.join(args.temp_folder, str(uuid.uuid4())[:8])
assert os.path.exists(temp_folder) is False
os.mkdir(temp_folder)

Expand Down Expand Up @@ -82,12 +82,20 @@
# Keep track of the time elapsed to process each sample
start_time = time.time()

# Make a new temporary folder for this sample
sample_temp_folder = os.path.join(temp_folder, str(uuid.uuid4())[:8])
assert os.path.exists(sample_temp_folder) is False
logging.info(
"Making temp folder for this sample: {}".format(sample_temp_folder)
)
os.mkdir(sample_temp_folder)

logging.info("Processing input argument: " + input_str)

# Capture each command in a try statement
# Get the input reads
try:
read_fp = get_reads_from_url(input_str, temp_folder)
read_fp = get_reads_from_url(input_str, sample_temp_folder)
except:
exit_and_clean_up(temp_folder)

Expand All @@ -96,7 +104,7 @@
output_folder = run_midas(
read_fp, # FASTQ file path
db_fp, # Local path to DB
temp_folder, # Folder for results
sample_temp_folder, # Folder for results
threads=args.threads,
)
except:
Expand Down Expand Up @@ -137,11 +145,17 @@
"total_reads": n_reads,
"time_elapsed": time.time() - start_time
}
return_results(output, output_prefix, args.output_folder, temp_folder)
return_results(
output, output_prefix, args.output_folder, sample_temp_folder
)

# Delete any files that were created for this sample
logging.info("Removing temporary folder: " + temp_folder)
shutil.rmtree(temp_folder)
logging.info("Removing temporary folder: " + sample_temp_folder)
shutil.rmtree(sample_temp_folder)

# Delete all files created for this analysis
logging.info("Removing temporary folder: " + temp_folder)
shutil.rmtree(sample_temp_folder)

# Stop logging
logging.info("Done")
Expand Down
Binary file not shown.

0 comments on commit 9e0a162

Please sign in to comment.