Visitar URL original
STAR .sam files chunks clog the work area · Issue #281 · ncbi/egapx · GitHub
Skip to content

STAR .sam files chunks clog the work area #281

Open

Description

@NickPanyushev

Hi,

I's using egapx, but after short-read STAR alignment and sorting it leaves a lot of temporary files. This is due to the default behaviour - STAR produces SAM files.

The solution seems to be quite feasible - to change the default parameter --outSAMtype from "SAM" to "BAM Unsorted". Because samtools can work equally well with the SAM and BAM files, but it will save computational time on compression and IO disk operations

I'm currently testing this solution, but repeatedly running into the issues with argument parsing. I've tries single-quoting, double-quoting of the --outSAMtype value, but this is not working.

Maybe there is an obvious workaround I can't see?
Maybe you can also suggest the strategy for quick testing - currently I'm relaunching the full pipeline from the beginning - this takes a lot of time :(

I'm using these parameters from yaml, and the release 1.0.1

genome: /full/path/to/genome/EG_chr1.fa 
taxid: 51953

trnascan:
  enabled: false

cmsearch:
  enabled: false

max_intron: 250000

tasks:
  star_wnode:
    star-params: >-
      --alignSJoverhangMin 8
      --outFilterMultimapNmax 200
      --outFilterMismatchNmax 50
      --genomeLoad NoSharedMemory
      --outSAMtype BAM\ Unsorted
      --outSAMprimaryFlag AllBestScore
      --outFilterMultimapScoreRange 50
      --seedSearchStartLmax 15
      --limitOutSAMoneReadBytes 1000000
      --outSJtype None
      --runRNGseed 777
      --outMultimapperOrder Old_2.4
    star_wnode: -preserve-star-logs

short_reads:
 - - DRR016807
   - - /scratch/users/paniushevn/EG11_annotation_data/DRR016807_1.fastq.gz
     - /scratch/users/paniushevn/EG11_annotation_data/DRR016807_2.fastq.gz

Activity

  1. NickPanyushev commented on Oct 23, 2026

    @NickPanyushev
    Author

    Here is the full error message from the .out

    ERROR ~ Error executing process > 'egapx:rnaseq_short_plane:rnaseq_short_plane:star:run_star (2)'
    
    Caused by:
      Process `egapx:rnaseq_short_plane:rnaseq_short_plane:star:run_star (2)` terminated with an error exit st
    atus (3)
    
    
    Command executed:
    
      echo "Assembly: EG_chr1 sampleID: AL3943-RI-2 Query: AL3943-RI-2_R1.fastq.gz,AL3943-RI-2_R2.fastq.gz"
          echo "list.seqids" > seqid_list.mft
          lds2_indexer -source genome
          mkdir -p out
          mkdir -p wrkarea
          mkdir -p STAR_C_logs
          if [[ -n ${TMPDIR-} ]]; then
              mkdir -p ${TMPDIR} || true
          fi
          if [[ -n ${TEMP-} ]]; then
              mkdir -p ${TEMP} || true
          fi
          echo "<job query =\"lcl|AL3943-RI-2_R1.fastq.gz,AL3943-RI-2_R2.fastq.gz\" subject=\"EG_chr1.index\">
    </job>" > jobfile
          star=$(which star-with-filter)
          samtools=$(which samtools)
          fastq=$(which fasterq-dump)
          seqkit=$(which seqkit)
          echo AL3943-RI-2_R1.fastq.gz; zstdcat AL3943-RI-2_R1.fastq.gz | seqkit stats
      echo AL3943-RI-2_R2.fastq.gz; zstdcat AL3943-RI-2_R2.fastq.gz | seqkit stats
      
          star_wnode -cpus-per-worker 16 -csi-threshold 0 -max-intron 250000 -preserve-star-logs -star-params 
    "--readFilesCommand zstdcat --alignSJoverhangMin 8 --outFilterMultimapNmax 200 --outFilterMismatchNmax 50 
    --runThreadN 16 --genomeLoad NoSharedMemory --outSAMtype BAM Unsorted --outSAMattributes NH HI AS nM NM MD
     jM jI XS MC --outSAMprimaryFlag AllBestScore --outFilterMultimapScoreRange 50 --seedSearchStartLmax 15 --
    limitOutSAMoneReadBytes 1000000 --outSJtype None --runRNGseed 777 --outMultimapperOrder Old_2.4 --outSAMor
    der PairedKeepInputOrder" -input-jobs jobfile -genome-sequences-manifest seqid_list.mft -seqkit-executable
     $seqkit -fastq-executable $fastq  -samtools-executable $samtools -star-executable $star -output-dir . -wo
    rk-area wrkarea -O out -lds2 genome/lds2.db
      
          # re-header BAM, dropping @PG and @CO lines containing non-deterministic elements.
          for bam in *.bam; do
              hdr="$bam".hdr
              samtools view -H "$bam" | grep -vE '^@PG|^@CO' > "$hdr"
              samtools reheader --no-PG "$hdr" "$bam" > "$bam".new  # NB: couldn't get --in-place to work
              rm -f "$hdr"
              mv "$bam".new "$bam"
      
              # recreate index
              [[ -f "${bam}.bai" ]] && samtools index -@ 4 -b "$bam"
              [[ -f "${bam}.csi" ]] && samtools index -@ 4 -c "$bam"
      
              normalized_bam="EG_chr1_genomic-AL3943_RI_2-Aligned.out.Sorted.bam"
              if [[ "$bam" != "$normalized_bam" ]]; then
                  if [[ -e "$normalized_bam" ]]; then
                      echo "Refusing to overwrite duplicate normalized BAM name: $normalized_bam" >&2
                      exit 1
                  fi
                  mv "$bam" "$normalized_bam"
                  [[ ! -f "${bam}.bai" ]] || mv "${bam}.bai" "${normalized_bam}.bai"
                  [[ ! -f "${bam}.csi" ]] || mv "${bam}.csi" "${normalized_bam}.csi"
              fi
          done
          cat STAR_logs/*-Log.out > STAR_C_logs/EG_chr1-AL3943-RI-2.2-Log.out
          cat STAR_logs/*-Log.progress.out > STAR_C_logs/EG_chr1-AL3943-RI-2.2-Log.progress.out
          cat STAR_logs/*-Log.final.out > STAR_C_logs/EG_chr1-AL3943-RI-2.2-Log.final.out
    
    Command output:
      Assembly: EG_chr1 sampleID: AL3943-RI-2 Query: AL3943-RI-2_R1.fastq.gz,AL3943-RI-2_R2.fastq.gz
      AL3943-RI-2_R1.fastq.gz
      file  format  type    num_seqs        sum_len  min_len  avg_len  max_len
      -     FASTQ   DNA   12,941,625  1,741,231,971       35    134.5      150
      AL3943-RI-2_R2.fastq.gz
      file  format  type    num_seqs        sum_len  min_len  avg_len  max_len
      -     FASTQ   DNA   12,941,625  1,735,116,857       35    134.1      150
    
    Command error:
      +++ for i in "${!row[@]}"
      +++ '[' 2 '!=' 0 ']'
      +++ sum[i]=940600
      +++ for i in "${!row[@]}"
      +++ '[' 3 '!=' 0 ']'
      +++ sum[i]=168052
      +++ for i in "${!row[@]}"
      +++ '[' 4 '!=' 0 ']'
      +++ sum[i]=940600
      +++ for i in "${!row[@]}"
      +++ '[' 5 '!=' 0 ']'
      +++ sum[i]=204920
      +++ for i in "${!row[@]}"
      +++ '[' 6 '!=' 0 ']'
      +++ sum[i]=2449
      +++ for i in "${!row[@]}"
      +++ '[' 7 '!=' 0 ']'
      +++ sum[i]=6
      +++ '[' 0 = 1 ']'
      +++ for i in {1..7}
      +++ '[' 0 -lt 0 ']'
      +++ cpu_peak[i]=0
      +++ for i in {1..7}
      +++ '[' 940600 -lt 887868 ']'
      +++ cpu_peak[i]=940600
      +++ for i in {1..7}
      +++ '[' 168052 -lt 33740 ']'
      +++ cpu_peak[i]=168052
      +++ for i in {1..7}
      +++ '[' 940600 -lt 953404 ']'
      +++ sum[i]=953404
      +++ for i in {1..7}
      +++ '[' 204920 -lt 33740 ']'
      +++ cpu_peak[i]=204920
      +++ for i in {1..7}
      +++ '[' 2449 -lt 320 ']'
      +++ cpu_peak[i]=2449
      +++ for i in {1..7}
      +++ '[' 6 -lt 38 ']'
      +++ sum[i]=38
      +++ '[' 0 = 1 ']'
      +++ nxf_stat_ret=(${sum[*]})
      +++ '[' 12 -lt 10 ']'
      +++ '[' 12 -lt 120 ']'
      +++ timeout=5
      +++ read -t 5 -r DONE
      00962/000/0000/P  11B403C2ADB3CE81 0032/0013 2026-10-23T10:54:36.528792 io-cpu-14.io.internal UNK_CLIENT      UNK_SESSION              star_wnode Error: LIB(CException::eUnknown) "wn_app_core.cpp", line 256: ncbi::CGPX_WorkerAppCore::Run() --- 1 jobs failed
      00962/000/0000/P  11B403C2ADB3CE81 0033/0014 2026-10-23T10:54:36.528819 io-cpu-14.io.internal UNK_CLIENT      UNK_SESSION              star_wnode Error: CORELIB(106.16) "ncbiapp.cpp", line 726: ncbi::CNcbiApplicationAPI::x_TryMain() --- Application's execution failed (CException::eUnknown) 1 jobs failed
      00962/000/0000/PE 11B403C2ADB3CE81 0034/0015 2026-10-23T10:54:36.550858 io-cpu-14.io.internal UNK_CLIENT      UNK_SESSION              star_wnode stop          3 3.688549995
      ++ kill 38
    
  2. murphyte commented on Oct 23, 2026

    @murphyte

    The solution seems to be quite feasible - to change the default parameter --outSAMtype from "SAM" to "BAM Unsorted"

    This won't work. star_wnode pipes the SAM output to a custom program compact_sam which applies some cleanup to the output to reduce artifact alignments spanning neighboring paralogs. compact_sam then applies its own selection for top hits (after removing the artifacts), and the SAM output is then converted to BAM. Changing --outSAMtype will cause a failure at compact_sam.

    Are you having files persist in wrkarea?

  3. NickPanyushev commented on Oct 23, 2026

    @NickPanyushev
    Author

    Yes, i've just relaunched the pipeline with small files and got this

    Image

    Last time the total volume of egapx_work grew up to !48 Tb! with small RNA-seq runs and blocked completely the disk. And sam chunks occupied quite a lot of space.
    Currently I'm seeing in realtime how the occupied space is growing during the cmsearch. - it's already occupied 654Gb!!

    This is the latest status of running egapx

    executor >  slurm (182)
    [16/916420] ega…tup_genome:get_genome_info | 1 of 1 ✔
    [52/d6a571] ega…sk_stats:run_winmask_stats | 1 of 1 ✔
    [a0/e1fd10] ega…:winmask_wnode:gpx_qsubmit | 1 of 1 ✔
    [95/dbc187] ega…node:run_winmask_wnode (4) | 16 of 16 ✔
    [2b/9769ce] ega…ask_wnode:gpx_make_outputs | 1 of 1 ✔
    [59/5f611a] ega…ask_wnode:combine_blast_db | 1 of 1 ✔
    [36/021b94] ega…pare_masks:gp_annot_format | 1 of 1 ✔
    [ce/28cfb4] ega…re_masks:convert_rfam_mask | 1 of 1 ✔
    [4e/324dfb] ega…:combine_blast_db_softmask | 1 of 1 ✔
    [84/595fc1] ega…bine_blast_db_alt_softmask | 1 of 1 ✔
    [3b/9f65f1] ega…are_masks:convert_softmask | 1 of 1 ✔
    [f2/b68e74] ega…blastdb:run_gc_makeblastdb | 1 of 1 ✔
    [8e/2e50ef] ega…_stats:run_mask_assm_stats | 1 of 1 ✔
    [38/413ecb] ega…_proteins:convert_proteins | 1 of 1 ✔
    [7f/7b6220] ega…ne:miniprot:split_proteins | 1 of 1 ✔
    [eb/42da04] ega…:miniprot:run_miniprot (8) | 15 of 15 ✔
    [12/a7225e] ega…e:paf2asn:run_paf2asn (14) | 15 of 15 ✔
    [71/eb10ac] ega…prot:run_best_aligned_prot | 1 of 1 ✔
    [b6/a28d79] ega…only:run_align_filter_only | 1 of 1 ✔
    [8a/0ca7bb] ega…t_filter_sa:run_align_sort | 1 of 1 ✔
    [38/135bae] ega…sa:run_align_as_tabular_sa | 1 of 1 ✔
    [5f/c0dd79] ega…axid:run_proteins_by_taxid | 1 of 1 ✔
    [99/8cc20f] ega…lity:run_align_filter_only | 1 of 1 ✔
    [1e/50842c] ega…st:run_align_as_tabular_sa | 1 of 1 ✔
    [25/538f8e] ega…ed:run_align_as_tabular_sa | 1 of 1 ✔
    [dc/088ff5] ega…stats:run_prot_align_stats | 1 of 1 ✔
    [61/212573] ega…ane:star_index:build_index | 1 of 1 ✔
    [a8/97f693] ega…rt_plane:star:run_star (3) | 0 of 3
    [f7/5e8670] ega…2_index:run_minimap2_index | 1 of 1 ✔
    [01/59030d] ega…plane:rename_fasta_ids (1) | 3 of 3 ✔
    [a9/af4e85] ega…asta:split_fasta_files (1) | 3 of 3 ✔
    [98/408443] ega…:minimap2_wnode_fasta (46) | 48 of 48 ✔
    [fa/905f8d] ega…e:minimap2_fasta:gpx_qdump | 1 of 1 ✔
    [1f/bfd3d8] ega…p2_fasta:gp_register_stats | 1 of 1 ✔
    [7e/d680f8] ega…ane:merge_sra_metadata (1) | 1 of 1 ✔
    [27/4f14fc] ega…ter_est_align:align_filter | 1 of 1 ✔
    [12/4201b8] ega…ilter_est_align:align_sort | 1 of 1 ✔
    [31/fbbbfb] ega…st_align:gp_register_stats | 1 of 1 ✔
    [de/0437c7] ega…long_read_align_report (1) | 1 of 1 ✔
    [83/c47b5f] ega…plane:fetch_swiss_prot_asn | 1 of 1 ✔
    [13/a6fc5b] ega…n_plane:get_swiss_prot_ids | 1 of 1 ✔
    [19/86a861] ega…cmsearch_plane:prime_cache | 1 of 1 ✔
    [e4/8043d1] ega…h_plane:cmsearch_wnode (5) | 6 of 16
    [8f/1af788] ega…trnascan_plane:prime_cache | 1 of 1 ✔
    [30/da41fd] ega…n_plane:trnascan_wnode (6) | 16 of 16 ✔
    [d7/d4f521] ega…nascan_plane:trnascan_dump | 1 of 1 ✔
    [f4/f83b67] ega…_plane:print_fake_lxr_data | 1 of 1 ✔
    [21/e5c61c] ega…:fetch_ortholog_references | 1 of 1 ✔
    [aa/c71c25] ega…ext_genome:get_genome_info | 1 of 1 ✔
    [c7/36b643] ega…_proteins:convert_proteins | 1 of 1 ✔
    [45/f67c48] ega…ogy_plane:get_prot_ref_ids | 1 of 1 ✔
    [89/7f798d] ega…at_multiqc_mask_assm_stats | 1 of 1 ✔
    [da/762068] ega…aseq_long_align_report (1) | 1 of 1 ✔
    [87/950a4c] ega…t_multiqc_prot_align_stats | 1 of 1 ✔
    [0a/02695f] ega…:multiqc:get_tool_versions | 1 of 1 ✔
    [56/55b4a6] ega…ld_software_versions_table | 1 of 1 ✔
    Plus 50 more processes waiting for tasks…
    
    

    So, the problem is not solely in sam chunks, I guess. But last time they occupied a significant fraction of the space

  4. murphyte commented on Oct 23, 2026

    @murphyte

    Are you running on a full cluster? How many nodes are you allowing in your config? How many RNA-seq runs are you aligning.
    That'll relate to how many STAR runs can run in parallel, which will affect temp space usage.

  5. NickPanyushev commented on Oct 26, 2026

    @NickPanyushev
    Author

    Yes, I'm running on the full SLURM cluster.

    This is the process_resources.config used for the run

    // Part of nextflow config describing resource requirements for EGAPx processes
    // We rely on labels to define 3 tiers of processes - default, big, and huge.
    // Make sure that executor you use supports job memory and CPU requirements
    //To be set based on the environment where Nextflow is run
    params.threads = 16
    params.nodes = 16
    params.num_cpus_per_node = 96
    
    process {
     
    }
    process {
        memory = 60.GB
        cpus = 7
        ext.align_mem = '13'
        time = 6.h
        errorStrategy = 'retry'
        maxRetries = 3
    
        withLabel: 'long_job' {
            time = 36.h
        }
        withLabel: 'small_mem' { 
            memory = 8.GB
        }
        withLabel: 'med_mem' {
            memory = 64.GB
        }
        withLabel: 'large_mem' { 
            memory = 128.GB
        }
        withLabel: 'single_cpu' {
            ext {
                split_jobs = 1
                threads = 1
            }
            cpus = 1 
        }
        withLabel: 'multi_cpu' {
            ext {
                split_jobs = 1
                threads = params.threads
            }
            cpus = params.threads
        }
        withLabel: 'multi_node' { 
            ext {
                split_jobs = params.nodes
                threads = params.threads
            }
            cpus = params.threads
        }
        withLabel: 'gpx_submitter' {
            ext {
                split_jobs = params.nodes
                threads = 1
            }
            cpus = 1
        }
    }
    
    profiles {
    
        stubrun {
            
            process {
                memory = 1.GB
                cpus = 1
                time = 1.h
    
                withLabel: 'big_job' {
                    memory = 1.GB
                    cpus = 1
                }
    
                withLabel: 'huge_job' {
                    memory = 1.GB
                    cpus = 1
                }
    
                withLabel: 'long_job' {
                    time = 1.h
                }
            }
        }
    
    }
    

    And for the test run I've used the small yaml with only 3 RNA-seq datasets. And used only 1 chromosome as a reference. The biggest of all three RNA-seq files is only 1.7 GB

    genome: /storage/replicated/projects/I2_gene_annotation/EG_chr1.fa 
    taxid: 51953
    
    trnascan:
      enabled: false
    
    cmsearch:
      enabled: false
    
    max_intron: 250000
    
    short_reads:
     - - AL3943-CNI-2
       - - /scratch/projects/01.output_cutadapt/AL3943-CNI-2_R1.fastq.gz
         - /scratch/projects/01.output_cutadapt/AL3943-CNI-2_R2.fastq.gz
     - - AL3943-RI-2
       - - /scratch/projects/01.output_cutadapt/AL3943-RI-2_R1.fastq.gz
         - /scratch/projects/01.output_cutadapt/AL3943-RI-2_R2.fastq.gz
     - - DRR016807
       - - /scratch/users/paniushevn/EG11_annotation_data/DRR016807_1.fastq.gz
         - /scratch/users/paniushevn/EG11_annotation_data/DRR016807_2.fastq.gz
    
    

    And the growth of the space occupied started well before the actual STAR run even started! As I've withnessed this on Friday it happened when the cmsearch job started to run, but maybe it's just a coincidence.

  6. Andy-B-123 commented on Oct 26, 2026

    @Andy-B-123

    Hi, just chiming in, I was trying to troubleshoot why I had some very long runs and I think I hit a similar thing (also on SLURM). In our case, this was mostly explained by large proportions of rRNA in some of the input RNA-Seq samples. Our assemblies contain rDNA tandem arrays on a few small contigs, and with --outFilterMultimapNmax 200 each rRNA read gets written many times. One 62 M pair library produced 1.26 billion alignments (half of them on three rDNA contigs totalling 0.26 Mb) and >1.4 TB of SAM in the work area. I tested the longest sample from an egapx run with and without filtering with sortmeRNA (table below). The time saving comes mostly from writing ~10x less SAM rather than from STAR mapping faster.

    I came across this from another project where we had problems with rRNA in input samples. I compared filtering all ~10x input RNA-Seqs with sortmeRNA and providing to egapx, and this resulted in a ~0.5-1% decrease in BUSCOs, so I would not suggest that filtering all input RNA-Seqs to remove rRNA is appropriate, since some of them do appear to be contributing to 'real' genes. But I thought I'd mention it in case people have some very very long running jobs. Identifying input RNA-Seqs that are very high rRNA proportion (samtools idxstats on a run_star BAM shows it quickly) and gently filtering those might improve overall run times. Capping how many STAR tasks run at once (maxForks on run_star) also helped keep peak disk use down for us.

    (Claude Code summary)

    Image
  7. murphyte commented on Oct 28, 2026

    @murphyte

    We're still discussing what we might do here, but our options are limited. According to Google's AI, even if we could use --outSAMtype BAM (which would require converting back to SAM before processing through compact_sam), the chunk files written to tmp would still be SAM. STAR is supposed to delete the tmp directory on successful completion, but it'll get left behind with a failed task. The parameters we use in order to enable the compact_sam processing are likely also contributing. I'd love to use a different aligner, but we've found STAR gives better results than other options.

    The rRNA observation is interesting and not surprising, especially as rDNA copy number has increased in modern assemblies. 31.6% or reads classified as rRNA is impressive(ly high), assuming the run wasn't supposed to be total RNA. We have occasionally seen long run times and/or high memory consumption for some chainer jobs associated with rDNA, and at times we've filtered out the alignments before rnaseq_collapse. We haven't implemented that option into EGAPx because it introduces a dependency on running Rfam. But with that caveat, we could use Rfam to hardmask rDNA arrays before STAR indexing, reducing multicopy arrays down to a single copy. That would leave a sink to align the rRNA reads while reducing the multimapper rate, and not require pre-filtering the reads (with some risk of over-filtering, as you found). We'll need to collect some more data on how often rRNA is such a culprit before going down that path.

    In the meantime, we'll add some documentation on how to reduce concurrent STAR jobs to help control tmp space usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions