Skip to content

Commit

Permalink
add HD image info to visium pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
CuijieLu committed Jun 11, 2024
1 parent 6b08ed7 commit 05c46ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
37 changes: 21 additions & 16 deletions scripts/cellranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import subprocess
import os.path
import shutil
import scripts.get_sequencing_read_data
import scripts.cellranger_spatial
import scripts.cellranger_config as CONFIG
Expand Down Expand Up @@ -144,18 +145,11 @@ def lanuch_by_project(sequencer_and_run, project, sample_id_list, sample_genome_
sample_fastqfile_dict = find_fastq_file(sample_id_list)
send_json = {}
send_json["samples"] = []
# CREATE RUN FOLDER AND PROJECT FOLDER IF NOT ALREADY THERE
os.chdir(CONFIG.STATS_AREA)
runs = next(os.walk("."))[1]
if sequencer_and_run not in runs:
os.mkdir(sequencer_and_run, CONFIG.ACCESS)

stats_and_run = CONFIG.STATS_AREA + sequencer_and_run
os.chdir(stats_and_run)
projects = next(os.walk("."))[1]
if project not in projects:
os.mkdir(project, CONFIG.ACCESS)
work_area = stats_and_run + "/" + project + "/"
# CREATE RUN FOLDER AND PROJECT FOLDER IF NOT ALREADY THERE
work_area = CONFIG.STATS_AREA + sequencer_and_run + "/" + project + "/"
if not os.path.exists(work_area):
os.makedirs(work_area, CONFIG.ACCESS)

# GO TO project ID LOCATION to start cellranger command
os.chdir(work_area)

Expand Down Expand Up @@ -190,23 +184,34 @@ def lanuch_by_project(sequencer_and_run, project, sample_id_list, sample_genome_
cmd = "{}--id=Sample_{}{}".format(tool, sample, transcriptome) + "--fastqs=" + ",".join(sample_fastqfile_dict[sample]) + " --cytaimage={} --slide={} --area={}".format(sample_info.tiff_image, sample_info.chip_id, sample_info.chip_position)
if sample_genome_dict[sample] == "Human":
probe = CONFIG.config_dict[tag]["probe"]["Human_CytAssist"]
cmd = cmd + " --probe-set={}".format(probe)
elif sample_genome_dict[sample] == "Mouse":
probe = CONFIG.config_dict[tag]["probe"][sample_genome_dict[sample]]
cmd = cmd + " --probe-set={}".format(probe)
if sample_info.slide.startswith("H1"):
probe = CONFIG.config_dict[tag]["probe"]["Mouse_HD"]
else:
probe = CONFIG.config_dict[tag]["probe"]["Mouse"]
cmd = cmd + " --probe-set={}".format(probe)

elif sample_info.preservation == "FFPE":
probe = CONFIG.config_dict[tag]["probe"][sample_genome_dict[sample]]
cmd = cmd + " --probe-set={}".format(probe)

# Eventhough HE image is required internal, the pipeline doesn't need it. Add it if exists
if sample_info.HE_tiff_image != "EMPTY":
cmd = cmd + " --image={}".format(sample_info.HE_tiff_image)
# copy microsope image here in sub folder for delivery
HE_folder_loc = work_area + "Microscope/"
if not os.path.exists(HE_folder_loc):
os.makedirs(HE_folder_loc)
shutil.copy(sample_info.HE_tiff_image , HE_folder_loc)

# if there is manual alignment json file availabe, add that to the cmd
if sample_info.json != "EMPTY":
cmd = cmd + " --loupe-alignment={}".format(sample_info.json)

bsub_cmd = "bsub -J {}_{}_{}_SPATIAL -o {}_SPATIAL.out{}{}".format(sequencer_and_run, project, sample, sample, cmd, CONFIG.OPTIONS)
print(bsub_cmd)
subprocess.run(bsub_cmd, shell=True)

elif tag != "Skip":
cmd = generate_cellranger_cmd(sample, tag, sample_genome_dict[sample], sample_fastqfile_dict[sample], sequencer_and_run)
print(cmd)
Expand Down
18 changes: 16 additions & 2 deletions scripts/cellranger_spatial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pandas as pd
import os
import json
import os.path
Expand All @@ -16,6 +15,7 @@ def __init__(self, sample, project_id):
self.preservation = "EMPTY"
self.tiff_image = "EMPTY"
self.json = "EMPTY"
self.HE_tiff_image = "EMPTY"
self.get_info_from_LIMS()
self.copy_tiff(project_id)
self.copy_json(project_id)
Expand All @@ -33,9 +33,14 @@ def copy_tiff(self, project_id):
source_loc_dir = CONFIG.original_tiff_images_directory + project_id
destination_loc = CONFIG.tiff_images_directory + project_id
destination_file = destination_loc + "/" + self.sample_name + ".tif"
destination_HE_loc = destination_loc + "/Microscope"
destination_HE_file = destination_HE_loc + "/HE_" + self.sample_name + ".tif"
# create TIFF_images director if not exists
if not os.path.exists(destination_loc):
os.makedirs(destination_loc)
# create microscope image director if not exists
if not os.path.exists(destination_HE_loc):
os.makedirs(destination_HE_loc)

# copy image file per sample
original_tiff_image = source_loc_dir + "/" + self.sample_name + ".tif"
Expand All @@ -45,7 +50,16 @@ def copy_tiff(self, project_id):
print("copy {} to {}".format(original_tiff_image, destination_file))
else:
print("tif file is not in proper format for sample {}, please check".format(self.IGO_ID))


# copy HE file per sample if exists
original_HE_tiff_image = source_loc_dir + "/Microscope/HE_" + self.sample_name + ".tif"
if os.path.isfile(original_HE_tiff_image):
shutil.copy(original_HE_tiff_image, destination_HE_file)
self.HE_tiff_image = destination_HE_file
print("copy {} to {}".format(original_HE_tiff_image, destination_HE_file))
else:
print("HE tif file does not exist for sample {}, please check".format(self.IGO_ID))

# copy json file if exists
def copy_json(self, project_id):
# project_id format as Project_12345
Expand Down

0 comments on commit 05c46ae

Please sign in to comment.