Skip to content

Commit

Permalink
Add basic snakemake script (test)
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Dec 3, 2024
1 parent f7eb891 commit dd44529
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ venv/

# custom scripts
examples/*.sh

# snakemake
.snakemake/*
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include LICENSE
include README.md
include Snakefile
exclude .pre-commit-config.yaml

recursive-include calcium_imaging_automation *.py
Expand Down
6 changes: 6 additions & 0 deletions Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rule setup:
input:
datasets_path="/nfs/winstor/margrie/SimonWeiler/RawData/Invivo_imaging/3photon_rotation/shared/",
writing_path="/ceph/margrie/laura/cimaut/",
output: "setup_output.txt"
shell: "python calcium_imaging_automation/core/rules/setup.py {input.datasets_path} {input.writing_path} --folder_read_pattern '2*' --file_read_pattern 'rotation_00001.tif' --file_read_pattern '*.bin' > {output}"
70 changes: 70 additions & 0 deletions calcium_imaging_automation/core/rules/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import argparse
import shutil
from pathlib import Path

from calcium_imaging_automation.core.reader import ReadAquiredData
from calcium_imaging_automation.core.writer import DatashuttleWrapper


def setup(raw_data_path, folder_read_pattern, file_read_pattern, output_path):
try:
shutil.rmtree("/ceph/margrie/laura/cimaut/derivatives/")
shutil.rmtree("/ceph/margrie/laura/cimaut/submitit/")
except FileNotFoundError:
print("No derivatives folder found")

print(f"Reading data from {raw_data_path}")
reader = ReadAquiredData(
raw_data_path,
folder_read_pattern,
file_read_pattern,
)
print(f"Found {len(reader.datasets_paths)} datasets.")

number_of_tiffs = reader.max_session_number(filetype="tif")
print(f"Max of tiffs found: {number_of_tiffs}")

writer = DatashuttleWrapper(output_path)
print(f"Dataset names: {reader.dataset_names}")
writer.create_folders(reader.dataset_names, session_number=number_of_tiffs)
print("Folders created")


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Example usage of the pipeline manager."
)

parser.add_argument(
"raw_data_path", type=Path, help="Path to the raw data."
)
parser.add_argument(
"output_path", type=Path, help="Path to the output data."
)
parser.add_argument(
"--folder_read_pattern",
type=str,
help="Glob pattern for reading folder.",
default="*",
)
parser.add_argument(
"--file_read_pattern",
type=str,
help="List of glob patterns for reading files.",
action="append",
)

args = parser.parse_args()

try:
setup(
args.raw_data_path,
args.folder_read_pattern,
args.file_read_pattern,
args.output_path,
)

print("Success")
except Exception as e:
print(f"Error: {e.args}")
print(e.with_traceback(e.__traceback__))

0 comments on commit dd44529

Please sign in to comment.