thank you for your help
Good morning everybody, I need you expertise : In fact I'm trying to write a script using python object oriented programming to perform STARsolo to generate count matrix of differentially expressed genes (exons only that's why I used --quantMode GeneCounts ) but I have an erro that I can not solve ( the bash command line works )
this is the bash command line:
/opt/conda/envs/scRNA_seq_env/bin/STAR --outSAMattributes All \
--outSAMtype BAM Unsorted \
--quantMode GeneCounts \
--readFilesCommand gunzip -c \
--runThreadN 7 \
--outReadsUnmapped Fastx \
--outMultimapperOrder Random \
--genomeDir /home/output/genome_index \
--readFilesIn home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L001_R2_001.fastq.gz,/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L002_R2_001.fastq.gz /home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L001_R1_001.fastq.gz,/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L002_R1_001.fastq.gz \
--outFileNamePrefix home/output/testou_testou_sh \
--soloType CB_UMI_Simple \
--soloCBwhitelist home/cellranger-7.1.0/lib/python/cellranger/barcodes/3M-february-2018.txt \
--soloUMIlen 12 \
--soloCBlen 16 \
--soloUMIstart 17 \
--soloCBstart 1 \
--soloBarcodeReadLength 28 \
--soloUMIfiltering MultiGeneUMI_CR \
--soloUMIdedup 1MM_CR \
--clipAdapterType CellRanger4 \
--outFilterScoreMin 30 \
--soloCBmatchWLtype 1MM_multi_Nbase_pseudocounts \
--soloCellFilter EmptyDrops_CR
OOP version where I get the error:
import subprocess
class StarCommand:
def __init__(self, genome_dir, output_prefix, read_files, threads=7):
self.genome_dir = genome_dir
self.output_prefix = output_prefix
self.read_files = read_files
self.threads = threads
self.command = ["/opt/conda/envs/scRNA_seq_env/bin/STAR",
"--outSAMattributes", "All",
"--outSAMtype", "BAM", "Unsorted",
"--quantMode", "GeneCounts",
"--readFilesCommand", "gunzip -c",
"--runThreadN", str(self.threads),
"--outReadsUnmapped", "Fastx",
"--outMultimapperOrder", "Random",
"--genomeDir", self.genome_dir,
"--readFilesIn", self.read_files,
"--outFileNamePrefix", self.output_prefix,
"--soloType", "CB_UMI_Simple",
"--soloCBwhitelist", "home/cellranger-7.1.0/lib/python/cellranger/barcodes/3M-february-2018.txt",
"--soloUMIlen", "12",
"--soloCBlen", "16",
"--soloUMIstart", "17",
"--soloCBstart", "1",
"--soloBarcodeReadLength", "28",
"--soloUMIfiltering", "MultiGeneUMI_CR",
"--soloUMIdedup", "1MM_CR",
"--clipAdapterType", "CellRanger4",
"--outFilterScoreMin", "30",
"--soloCBmatchWLtype", "1MM_multi_Nbase_pseudocounts",
"--soloCellFilter", "EmptyDrops_CR"]
def run_command(self):
try:
subprocess.run(self.command, check=True)
print("STAR command finished successfully!")
except subprocess.CalledProcessError as e:
print(f"STAR command failed with exit code {e.returncode}:")
print(e.output)
genome_dir = "/home/output/genome_index"
output_prefix = "/home/output/testou_testou_sh"
read_files = "/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L001_R2_001.fastq.gz,/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L002_R2_001.fastq.gz /home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L001_R1_001.fastq.gz,/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L002_R1_001.fastq.gz"
star_command = StarCommand(genome_dir, output_prefix, read_files)
star_command.run_command()
the error:
EXITING: because of fatal INPUT file error: could not open read file: /home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L002_R2_001.fastq.gz /home/pbmc_1k_v3_S1_L001_R1_001.fastq.gz
SOLUTION: check that this file exists and has read permision.
Mar 16 09:22:35 ...... FATAL ERROR, exiting
STAR command failed with exit code 102:
None
thank you in advance
2 answers
Can you try putting quotes around it?
read_files = "\"/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L001_R2_001.fastq.gz,/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L002_R2_001.fastq.gz /home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L001_R1_001.fastq.gz,/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L002_R1_001.fastq.gz\""
If that doesn't work, can you try shell=True in your subprocess.run()?
Does this mean the problem was solved? If so I will move this comment to an answer so you can accept it.
what I did is that I created two lists one for R1 reads seperated by (,) and another for R2 seperated by (,) "--readFilesIn", ",".join(self.r2_files), ",".join(self.r1_files),
yes sure:
import re
import subprocess
class STAR:
def __init__(self, r1_files, r2_files, output_prefix , genome_index , whitelist ):
self.r1_files = self._filter_files(r1_files, r"_S\d+_L\d+_R1_\d+.fastq.gz")
self.r2_files = self._filter_files(r2_files, r"_S\d+_L\d+_R2_\d+.fastq.gz")
self.output_prefix = output_prefix
self.genome_index = genome_index
self.whitelist = whitelist
def _filter_files(self, file_list, pattern):
filtered_files = []
for file in file_list:
if re.search(pattern, file):
filtered_files.append(file)
else:
raise ValueError(f"Invalid filename format ")
return filtered_files
def run(self):
command = [
"/opt/conda/envs/scRNA_seq_env/bin/STAR",
"--outSAMattributes", "All",
"--outSAMtype", "BAM", "Unsorted",
"--quantMode", "GeneCounts",
"--readFilesCommand", "gunzip -c",
"--runThreadN", "8",
"--outReadsUnmapped", "Fastx",
"--outMultimapperOrder", "Random",
"--genomeDir", self.genome_index,
"--readFilesIn", ",".join(self.r2_files), ",".join(self.r1_files),
"--outFileNamePrefix", self.output_prefix,
"--soloType", "CB_UMI_Simple",
"--soloCBwhitelist", self.whitelist,
"--soloUMIlen", "12",
"--soloCBlen", "16",
"--soloUMIstart", "17",
"--soloCBstart", "1",
"--soloBarcodeReadLength", "28",
"--soloUMIfiltering", "MultiGeneUMI_CR",
"--soloUMIdedup", "1MM_CR",
"--clipAdapterType", "CellRanger4",
"--outFilterScoreMin", "30",
"--soloCBmatchWLtype", "1MM_multi_Nbase_pseudocounts",
"--soloCellFilter", "EmptyDrops_CR"
]
subprocess.run(command)
r1_files = [
"/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L001_R1_001.fastq.gz",
"/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L002_R1_001.fastq.gz"
]
r2_files = [
"/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L001_R2_001.fastq.gz",
"/home/pbmc_1k_v3_fastqs/pbmc_1k_v3_S1_L002_R2_001.fastq.gz"
]
output_prefix = "/home/output/STARsolo/"
genome_index = "/home/output/genome_index"
whitelist ="/home/cellranger-7.1.0/lib/python/cellranger/barcodes/3M-february-2018.txt"
star = STAR(r1_files, r2_files, output_prefix , genome_index,whitelist)
star.run()
Log in to answer this question.
my files are readable because the bash command line works perfectly :/
Are those files in two separate directories? That is what is in the error message. On command line version they are in the same directory or so it looks.
In command line version you seem to be missing a leading
/beforehomebut that may be a copy paste error since you say that line works.and
no they are in the same directory I just missed copying the script here but I do it right in my terminal and keep having the same error :/
This exatly how my codes looks like and the error generated : (bash script works )
this is the bash command line:
OOP version where I get the error:
the error:
thank you in advance