Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vBassewitz committed Aug 23, 2024
1 parent 192ea20 commit 04bd587
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
11 changes: 6 additions & 5 deletions workflow/rules/preprocessing.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"../scripts/barcode_rename.py"
21 changes: 12 additions & 9 deletions workflow/scripts/barcode_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
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)

if os.path.exists(source_path):
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):
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 04bd587

Please sign in to comment.