First time working with nextflow, nf-core, and rna...
# rnaseq
m
First time working with nextflow, nf-core, and rnaseq. I am learning UNIX and our institutional HPC (LSF) for this (so a bioinformatics newbie in a way). I was able to install nf-core, download the singularity containers, and the pipeline tested successfully using -profile test, singularity. nextflow v 25.10.0, nf-core 3.3.2, rnaseq 3.21.0. So I went for it. I have bacterial RNA in two treatments: The call:
Copy code
#!/bin/bash
#BSUB -J rnaseq
#BSUB -q standard
#BSUB -o /share/ajbvb/mgkaroun/rnaseq_run/nf-core-rnaseq_3.21.0/3_21_0/logs/%J.out
#BSUB -e /share/ajbvb/mgkaroun/rnaseq_run/nf-core-rnaseq_3.21.0/3_21_0/logs/%J.err
#BSUB -n 8
#BSUB -M 8000
#BSUB -W 12:00

module load apptainer
export NXF_EXECUTOR=lsf
export NXF_OFFLINE=true
export NXF_SINGULARITY_CACHEDIR="/share/ajbvb/mgkaroun/rnaseq_run/nf-core-rnaseq_3.21.0/singularity-images"
export PIPELINE_DIR="/share/ajbvb/mgkaroun/rnaseq_run/nf-core-rnaseq_3.21.0/3_21_0"
cd "$PIPELINE_DIR"
nextflow -log "logs/run.${LSB_JOBID:-$$}.log" run "$PIPELINE_DIR" \
  -profile singularity --input samplesheet.csv \
  --fasta /gpfs_common/share02/ajbvb/mgkaroun/scratch/refs/finny/CP170741.fasta \
  --gtf /gpfs_common/share02/ajbvb/mgkaroun/scratch/refs/finny/CP170741.gtf \
  --outdir results --skip_bbsplit true -resume
I have 62 cached tasks and 1 failed, a STAR_ALIGN. The weird thing is it isn't really failing, it's just exiting out of the pipeline early (waits ~7 mins) while the STAR_ALIGN is still pending. Then the task finishes after the pipeline exits. Each time I resume the pipeline it attempts to rerun this task anew, with a new hash work directory despite the previous tmp directory already having the completed output, including .exitcode = 0. I have this STAR_ALIGN complete in two directories: rnaseq_run/nf-core-rnaseq_3.21.0/3_21_0/work/f2/d4973e6ba53602411642f983ca2ac8 and rnaseq_run/nf-core-rnaseq_3.21.0/3_21_0/work/37/b3930888693a3a8649a1cd844bfb2b Is there a simple way to point the pipeline to this? or any help is appreciated - i may be approaching this completely wrong way... I think I may need to alter the config more, i.e. executer = lsf, etc which I've been avoiding.
j
It's hard to know what's going on here from the outside I'm afraid. But you really should get to use proper configuration, it will make your life better. What you seem to be doing is running the entire workflow within one LSF job, while you should be able to make every task run on a separate machine, vastly speeding up the workflows (by using that
executor
). The way you do that will depend on cluster configuration, if your nodes are submission hosts, you can do as you're doing, supplying custom config to the nexflow command (e.g. via
-c
) to set up the executor, and your Nextflow job will send the child jobs out to other nodes. Some clusters don't allow nodes to submit jobs, in which case you'd have to run the nextflow 'head job' from a login node (rather than as a job itself). One note of caution: a number of folks have had difficulties running bacterial data due to formats of annotation files etc, and nobody has fixed that up yet.
✅ 1
m
thanks for the reply. I figured i was treading a difficult path. Unfortunately our HPC cluster is offline and works with this LSF. Yes the tasks have been running on NCSU's HPC offline compute nodes separately using the LSF as the executor and then multiple nodes for computing tasks as you say (from the exports in the submission script). To the best of my ability, all the configuration in my provided script should work with NCSU's specifications ( i dont expect anyone to verify that for me but it's doc'd here: https://hpc.ncsu.edu/Documents/LSF.php). Everything seems to work well except this strange situation with this task pending until the lsf terminates for "unknown reason" -> usually memory issues from what i understand, and then bizarrely the task continues on after the executor closes the pipeline and completes in the hash work folder. The errors for terminating and more info are found in the log files I provided
I am trying to modify the config from Sanger, since they also use an LSF
t
I would try to talk your sysadmins, maybe they know what is going on and might even be able to fix it. If it is a memory issue, I can allocate more to any process via a config file.
m
OK thanks, I haven't reached out to them before so this is a good idea. FYI, I have moved past that particular task but am still getting similar exits downstream with that sample (it's probably a large one):
Copy code
Process NFCORE_RNASEQ:RNASEQ:QUANTIFY_STAR_SALMON:SALMON_QUANT (R_FNY_030D-R2) terminated for an unknown reason -- Likely it has been terminated by the external system
🤞 1
👍 1
t
If you look in the work dir of a failed job, the
.command.log
should have the output of the LSF scheduler (together with the program output), and for LSF that shows (if I remember correctly) the resources requested and used. Maybe that helps in figuring out what is going on ...
m
I'm not sure. I did a few different tweaks to the config and added retries, but especially just continued resuming the pipeline (probably 6 separate bsub ... -resume) until it successfully completed, so to speak. I think, judging from this multiqc report, and the message:
-[nf-core/rnaseq] Pipeline completed successfully with skipped sampl(es)-
-[nf-core/rnaseq] Please check MultiQC report: 6/6 samples skipped since they failed STAR 5% mapped threshold.-
that my problem is in host contamination, so I shouldn't --skip_bbsplit I'm stoked that it's not completely jammed though!
t
If you have >95% host (or other) contamination (have a look at the Kraken2 results, if you ran that, otherwise grab a few of the unmapped reads and BLAST them), I'm not sure the sample is usable (not much left ...), there is nothing the pipeline can do. I don't think BBSplit would make a difference, it would just introduce a different mapping step to remove the contamination, but wouldn't give you more usable reads in the end (it would by-pass the 5% threshold, but if the sample is unusable, that doesn't matter for practical purposes).
👀 1
m
To be clear, I'm looking at prokaryotic samples (1.3mbp genome) in mammalian cell culture. Looks like we have between 4m and 8m reads for them across 6 samples. I'm not surprised by this since the seq. core warned us we wouldn't have enough from the first sequencing. I am running now with the merged fastqs of both replicates, but BBsplit is gorging the resources and may not finish. Should I prefilter with something else? Turn off min_mapped? I saw here and elsehwere you regard the low % stuff as garbage and unusable. Would this maybe, hopefully not be true for this scenario? or will the seq /pcr errors overwhelm even the pro/eukaryotic divide?
t
Do you care about both the host cell culture and the bacteria? (BTW, I dislike the term "prokaryotic". There are tree large domains in the tree of life -- archaea, bacteria, and eukaryotes. The first two are very different from each other, so lumping them together does not make any sense. In effect, the term "prokaryote" just is a way to say "non-eukaryote".) If so (and probably even if not), I personally would forget about BBSplit and just map against a combined genome, i.e. you concatenate both the FASTAs (of mammal and bacterium) and the GTFs (note that you need exons annotated and probably assigned to transcripts and genes in the GTF, which is not a given for bacteria, since there the whole concept of "transcript" is very different there); the contig/chromosome names are likely different, so you probably don't have to disambiguate them. When you get the results, you can split the table to separate mammalian from bacterial genes, and the nice thing is that you can analyze both. (If you are 1000% certain that the mammal is of no interest, not even for quantifying reads, you can leave its GTF out when you merge genomes.) It is also the most accurate way to separate two organisms, because the mapper can see both genomes at the same time and decide the best fit. (There is little homology between bacteria and mammals, so in your case that should not make a difference, but if you had mouse/human, it would.) Lastly, I am not convinced that using BBSplit saves any time, let alone resources, compared to just using STAR. If you follow that combined approach, your unmapped reads should be <5% (unless there are quality issues). When I said "unusable", I meant that if you just have a few thousand reads of the organism you care about, then that is most likely not enough to draw conclusions about it transcription, let alone about differences between samples. To measure gene expression, the gene should have dozens if not hundreds of reads assigned to it. If that is the case for the (expressed) genes in your bacterium, you should be fine, but because of the huge genome size difference, the host RNA is often so predominant that you are getting very few bacterial reads unless you do some kind of enrichment (prior to sequencing), hence my fear about unusable samples.
m
Thank you for the response Thomas! i won't say 1000%, but we mostly care about the Rickettsia. I think differences of how it affects the mammalian cell lines might be interesting but we don't have appropriate treatment / neg control. So i'll skip bbsplit and concatenate the host genomes to move ahead. If i understand correctly, I'm going to convert my bacterial CDS (genes) to 'exons' in my concatenated GTF so we get results for my genes of interest
👍 1
t
Yes, the `CDS`s would correspond to `exon`s. Make sure they also have a
gene_id
and
transcript_id
. If you are in luck, you may be able to find a GTF in Ensembl for your strain, which should have the correct format.
✅ 1
m
I have gotten much farther using the concatenations. I'm currently running into some weird redundancy issues. I.e. It's spawning directories and not reusing the previous NXF_CHDIR on retry or resume. I.e.: Failed twice then aborted QUALIMAP_RNASEQ_(R_FNY_030D_R2) //sample ID == R_FNY_030D_R2 Attempt using 36 GB allocated (by the LSF) has workdir: "PIPELINE_DIR/work/5c/c3e9d15c17605fb01409a857f834f2", du = 207G. Retry with 72 GB allocated given a distinct workdir, "PIPELINE_DIR/work/9b/bacb291ee7b3dd6e59cabee2270f3e" containing another 212 GB. Weirder still, in a previous submission last week, the pipeline had fully successfully completed this same task. It has appropriately marked the other replicates (R1 and R3) as cached, but it's redoing R2 and struggling (above). It still exists completed in its working dir (yet another different one from above). Is there some way to prevent this or point the pipeline to this completed task? Secondly, and maybe a more minor issue is DUPRADAR is failing. I presume skipping this is OK.
t
For DupRadar you have basically three options: • Make it work by adding more resources (via config file). • Skip it altogether via the
--skip_dupradar
parameter. • Allow it to fail without taking down the pipeline, i.e. you get the results for the samples where it works, but not where it fails. You do that like this:
Copy code
process {
    withName: "DUPRADAR" {
        errorStrategy = 'ignore'
    }
}
(Hope I didn't mistype anything.) The reason this works is that nothing depends on DupRadar, so the pipeline can continue after an error. I think DupRadar results are instructive, but you may not want to wait for days for it to complete. In that case something like this would be my recommendation. I don't think you can point the pipeline to a complete process and make it use it as cache (unfortunately). You might be able to build on the results manually, but not with the pipeline.
NXF_CHDIR
is not a valid Nextflow environment variable, AFAIK, is this a typo? Why is this process crashing? Do the
.nextflow.{err,out,log}
files show any informative messages? What's the exit code? My guess is that it might have something to do with resources. I'm not sure how well LSF enforces constraints, so it could be that the process was able to use more (e.g. memory) in the past run, but not since then. If you set the resource allocation to what it needs, it should work (if that's the issue).
m
yes it's either 140 or 130. SIGINT, etc exiting. Not a typo, taken from .command.log the LSF generated for the job:
Copy code
Sender: LSF System lsfadmin@c016n02
Subject: Job 590126: nf-NFCORE_RNASEQ_RNASEQ_QUALIMAP_RNASEQ_(R_FNY_030D_R2) in cluster Hazel Exited

Job nf-NFCORE_RNASEQ_RNASEQ_QUALIMAP_RNASEQ_(R_FNY_030D_R2) was submitted from host c015n04 by user mgkaroun in cluster Hazel at Tue Dec  2 15:45:47 2025
Job was executed on host(s) 6*c016n02, in queue single_chassis, as user mgkaroun in cluster Hazel at Tue Dec  2 15:45:48 2025
/home/mgkaroun was used as the home directory.
/gpfs_common/share02/ajbvb/mgkaroun/rnaseq_run/nf-core-rnaseq_3.21.0/3_21_0/work/5c/c3e9d15c17605fb01409a857f834f2 was used as the working directory.
Started at Tue Dec  2 15:45:48 2025
Terminated at Tue Dec  2 23:46:05 2025
Results reported at Tue Dec  2 23:46:05 2025

Your job looked like:

------------------------------------------------------------
# LSBATCH: User input
#!/bin/bash
#BSUB -o /gpfs_common/share02/ajbvb/mgkaroun/rnaseq_run/nf-core-rnaseq_3.21.0/3_21_0/work/5c/c3e9d15c17605fb01409a857f834f2/.comm>
#BSUB -n 6
#BSUB -R "span[hosts=1]"
#BSUB -W 08:00
#BSUB -M 6
#BSUB -R "select[mem>=36] rusage[mem=36]"
#BSUB -J nf-NFCORE_RNASEQ_RNASEQ_QUALIMAP_RNASEQ_(R_FNY_030D_R2)
NXF_CHDIR=/gpfs_common/share02/ajbvb/mgkaroun/rnaseq_run/nf-core-rnaseq_3.21.0/3_21_0/work/5c/c3e9d15c17605fb01409a857f834f2
### ---
### name: 'NFCORE_RNASEQ:RNASEQ:QUALIMAP_RNASEQ (R_FNY_030D_R2)'
### container: '/share/ajbvb/mgkaroun/rnaseq_run/nf-core-rnaseq_3.21.0/singularity-images/depot.galaxyproject.org-singularity-qua>
### outputs:
### - 'R_FNY_030D_R2'
### - 'versions.yml'
### ...
set -e
set -u
NXF_DEBUG=${NXF_DEBUG:=0}; [[ $NXF_DEBUG > 1 ]] && set -x
NXF_ENTRY=${1:-nxf_main}

nxf_tree() {
    local pid=$1
I see the LSF is calling it with #BSUB -n 6 #BSUB -R "span[hosts=1]" #BSUB -W 08:00 #BSUB -M 6 Probably not enough resources/time?
t
OK, that
NXF_CHDIR
is just an internal variable of that script, not something you can set (unlike e.g.
NXF_WORK
). Yes, exit code
140
is (typically) "wall time exceeded", not sure about
130
(
SIGINT
-- you didn't kill something manually by accident, did you?). The only other resource leading to a kill if lacking would be memory (RAM), which typically is
137
. So I would focus on fixing the time problem. Does your config allow retries? If so, that exit code should trigger that and multiply time, memory, and CPUs each time. (There is no guarantee that would be enough, though, and it depends on the number of retries.) Either way, you can make a config for the specific process (use
withName
, like above) with
time = 24.h
(or whatever you can/want to give it).