From 04bd587ba94299d18c685b2e83cce25dbc83ea62 Mon Sep 17 00:00:00 2001 From: vBassewitz Date: Fri, 23 Aug 2024 08:49:42 +0000 Subject: [PATCH] Formatting --- workflow/rules/preprocessing.smk | 11 ++++++----- workflow/scripts/barcode_rename.py | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/workflow/rules/preprocessing.smk b/workflow/rules/preprocessing.smk index f02849cd..62cf3404 100644 --- a/workflow/rules/preprocessing.smk +++ b/workflow/rules/preprocessing.smk @@ -14,15 +14,16 @@ rule update_sample: script: "../scripts/update-sample-sheet.py" + rule barcode_rename: input: - barcodes = "barcode-rename.csv", - source_dir = config["source_dir"], - output: - out_dir = directory(config["output_dir"]) + barcodes="barcode-rename.csv", + source_dir=config["source_dir"], + output: + out_dir=directory(config["output_dir"]), log: "logs/barcode_rename.txt", conda: "../envs/python.yaml" script: - "../scripts/barcode_rename.py" \ No newline at end of file + "../scripts/barcode_rename.py" diff --git a/workflow/scripts/barcode_rename.py b/workflow/scripts/barcode_rename.py index 5b36731a..99136bb7 100644 --- a/workflow/scripts/barcode_rename.py +++ b/workflow/scripts/barcode_rename.py @@ -6,11 +6,11 @@ import os -def get_barcode_dirs(source_directory, barcode_numbers): +def get_barcode_dirs(source_directory, barcode_numbers): try: barcode_dirs = [] for barcode_number in barcode_numbers: - #Construct the source file path + # Construct the source file path source_file = f"barcode{barcode_number}" source_path = os.path.join(source_directory, source_file) @@ -18,20 +18,20 @@ def get_barcode_dirs(source_directory, barcode_numbers): barcode_dirs.append(source_path) else: print(f"Directory '{source_path}' does not exist.") - + return barcode_dirs - + except Exception as e: print(f"An error occurred: {str(e)}") return [] def concatenate_fastq(bc_directory, outfile): - input_files = os.path.join(bc_directory, '*.fastq.gz') + input_files = os.path.join(bc_directory, "*.fastq.gz") print(input_files) out_file = f"{os.path.join(outfile, os.path.split(bc_directory)[1])}_all.fastq" print(out_file) - subprocess.Popen(f'zcat {input_files} > {out_file}', shell=True).wait() + subprocess.Popen(f"zcat {input_files} > {out_file}", shell=True).wait() def run_sample_prep(source_directory, barcode_numbers, outfile): @@ -42,7 +42,7 @@ def run_sample_prep(source_directory, barcode_numbers, outfile): def rename_files(final_dir): - # rename files + # rename files renames = pd.read_csv(barcode_csv) renames.reset_index(drop=True, inplace=True) @@ -54,10 +54,13 @@ def rename_files(final_dir): for file in files: num = file.split("_")[0][-2:] print(num) - print(final_dir + file + " " + final_dir + str(rename_dict[int(num)]) + ".fastq") + print( + final_dir + file + " " + final_dir + str(rename_dict[int(num)]) + ".fastq" + ) os.rename(final_dir + file, final_dir + str(rename_dict[int(num)]) + ".fastq") print(files) + config = snakemake.config barcode_csv = str(snakemake.input.barcodes) @@ -72,7 +75,7 @@ def rename_files(final_dir): os.makedirs(out_dir) # getting barcode numbers -barcode_csv_ = pd.read_csv(barcode_csv, dtype={'barcode': str}) +barcode_csv_ = pd.read_csv(barcode_csv, dtype={"barcode": str}) used_barcodes = barcode_csv_["barcode"] run_sample_prep(source_path, used_barcodes, out_dir)