CFSAN-Biostatistics / C-WAP

SC2 variant detection and composition pipeline
Other
16 stars 8 forks source link

`freyjaVariantCaller` terminated with an error exit status (2) #24

Closed rgn3210 closed 1 year ago

rgn3210 commented 1 year ago

Hello!

I am trying to use your pipeline, however I am having some trouble with Freyja. Below i have included my terminal input and output.

Input:

user@user:~/Desktop/SARS-Cov-2/wastewater$ /home/user/C-WAP-main/startWorkflowedit.nf --platform n --primers /home/user/.nextflow/assets/epi2me-labs/wf-artic/data/primer_schemes/SARS-CoV-2/Midnight-ONT/V1/SARS-CoV-2.scheme.bed --in /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/ --out /home/user/Desktop/SARS-Cov-2/wastewater/output/ -profile local_only
N E X T F L O W  ~  version 22.04.5
Launching `/home/user/C-WAP-main/startWorkflowedit.nf` [wise_leakey] DSL1 - revision: 7b831ce115
Nanopore mode
[barcode78, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode78_concatenated.fastq.gz, null]
[barcode73, /home/user/Desktop/SARS-Cov-2/wastewater/wconcat_fastq/barcode73_concatenated.fastq.gz, null]
[barcode72, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode72_concatenated.fastq.gz, null]
[barcode77, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode77_concatenated.fastq.gz, null]
[barcode71, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode71_concatenated.fastq.gz, null]
[barcode76, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode76_concatenated.fastq.gz, null]
[barcode70, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode70_concatenated.fastq.gz, null]
[barcode74, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode74_concatenated.fastq.gz, null]
[barcode69, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode69_concatenated.fastq.gz, null]
[barcode75, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode75_concatenated.fastq.gz, null]
[barcode79, /home/user/Desktop/SARS-Cov-2/wastewater/concat_fastq/barcode79_concatenated.fastq.gz, null]
executor >  local (71)
executor >  local (72)
executor >  local (202)
[94/365d9c] process > referenceAlignment (10)       [100%] 11 of 11 ✔
[d6/b516a0] process > trimming (11)                 [100%] 11 of 11 ✔
[29/2f6917] process > trimmedBam2Fastq (11)         [100%] 11 of 11 ✔
[4d/930b2d] process > generatePileup (11)           [100%] 11 of 11 ✔
[9d/e59ee2] process > variantCalling (11)           [100%] 11 of 11 ✔
[4b/47b9e6] process > k2stdDB (2)                   [100%] 11 of 11 ✔
[9e/f888bf] process > QCplots (11)                  [100%] 11 of 11 ✔
[c4/b96986] process > readLengthHist (2)            [100%] 11 of 11 ✔
[d8/55119f] process > krakenVariantCaller (11)      [100%] 11 of 11 ✔
[4a/97797d] process > consensusSequence (11)        [100%] 11 of 11 ✔
[76/70d0dc] process > pangolinVariantCaller (11)    [100%] 11 of 11 ✔
[04/7b4fca] process > linearDeconVariantCaller (11) [100%] 11 of 11 ✔
[4c/2f193d] process > kallistoVariantCaller (11)    [100%] 11 of 11 ✔
[0e/410d86] process > freyjaVariantCaller (9)       [100%] 35 of 35, failed: 24, retries: 24 ✔
[ca/c8dc28] process > getNCBImetadata (3)           [100%] 11 of 11 ✔
[cf/f5f87c] process > generateReport (11)           [100%] 11 of 11 ✔
[bb/497326] process > summaryPage                   [100%] 1 of 1 ✔
[d8/72c2f7] process > html2pdf                      [100%] 1 of 1 ✔

[0a/cba3a5] NOTE: Process `freyjaVariantCaller (1)` terminated with an error exit status (2) -- Execution is retried (2)
[32/af4580] NOTE: Process `freyjaVariantCaller (3)` terminated with an error exit status (2) -- Execution is retried (2)
[e7/a0c931] NOTE: Process `freyjaVariantCaller (4)` terminated with an error exit status (2) -- Execution is retried (2)
[6a/2ff91c] NOTE: Process `freyjaVariantCaller (6)` terminated with an error exit status (2) -- Execution is retried (2)
[49/b5fd01] NOTE: Process `freyjaVariantCaller (5)` terminated with an error exit status (2) -- Execution is retried (2)
[75/d2ff79] NOTE: Process `freyjaVariantCaller (7)` terminated with an error exit status (2) -- Execution is retried (2)
[56/9fe5f8] NOTE: Process `freyjaVariantCaller (8)` terminated with an error exit status (2) -- Execution is retried (2)
[e7/ba23db] NOTE: Process `freyjaVariantCaller (9)` terminated with an error exit status (2) -- Execution is retried (2)
[6b/c3d52f] NOTE: Process `freyjaVariantCaller (1)` terminated with an error exit status (2) -- Execution is retried (3)
[5d/a740ca] NOTE: Process `freyjaVariantCaller (3)` terminated with an error exit status (2) -- Execution is retried (3)
[d7/6096c6] NOTE: Process `freyjaVariantCaller (4)` terminated with an error exit status (2) -- Execution is retried (3)
[f8/88738c] NOTE: Process `freyjaVariantCaller (6)` terminated with an error exit status (2) -- Execution is retried (3)
[19/1a8c21] NOTE: Process `freyjaVariantCaller (5)` terminated with an error exit status (2) -- Execution is retried (3)
[fe/8e8544] NOTE: Process `freyjaVariantCaller (7)` terminated with an error exit status (2) -- Execution is retried (3)
[97/78c338] NOTE: Process `freyjaVariantCaller (8)` terminated with an error exit status (2) -- Execution is retried (3)

Pipeline execution complete. Thank you for choosing C-WAP
Completed at: 16-May-2023 13:47:05
Duration    : 4m 17s
CPU hours   : 0.5 (7.1% failed)
Succeeded   : 178
Failed      : 24

Below I have also included a part of the output of the nextflow log:

May-16 13:44:28.236 [Task submitter] DEBUG nextflow.executor.LocalTaskHandler - Launch cmd line: /bin/bash -ue .command.run
May-16 13:44:28.236 [Task submitter] INFO  nextflow.Session - [d0/674164] Re-submitted process > freyjaVariantCaller (6)
May-16 13:44:28.797 [Task monitor] DEBUG n.processor.TaskPollingMonitor - Task completed > TaskHandler[id: 186; name: freyjaVariantCaller (6); status: COMPLETED; exit: 0; error: -; workDir: /home/user/Desktop/SARS-Cov-2/wastewater/work/d0/674164b3d793734e280f8392acb043]
May-16 13:44:28.798 [Task submitter] DEBUG nextflow.executor.LocalTaskHandler - Launch cmd line: /bin/bash -ue .command.run
May-16 13:44:28.798 [Task submitter] INFO  nextflow.Session - [8e/d7a843] Re-submitted process > freyjaVariantCaller (5)
May-16 13:44:29.360 [Task monitor] DEBUG n.processor.TaskPollingMonitor - Task completed > TaskHandler[id: 187; name: freyjaVariantCaller (5); status: COMPLETED; exit: 0; error: -; workDir: /home/user/Desktop/SARS-Cov-2/wastewater/work/8e/d7a84338777711187552a82a117ff3]
May-16 13:44:29.361 [Task submitter] DEBUG nextflow.executor.LocalTaskHandler - Launch cmd line: /bin/bash -ue .command.run
May-16 13:44:29.361 [Task submitter] INFO  nextflow.Session - [75/21e468] Re-submitted process > freyjaVariantCaller (7)
May-16 13:44:29.925 [Task monitor] DEBUG n.processor.TaskPollingMonitor - Task completed > TaskHandler[id: 188; name: freyjaVariantCaller (7); status: COMPLETED; exit: 0; error: -; workDir: /home/user/Desktop/SARS-Cov-2/wastewater/work/75/21e468fb7bbc0c13aeb950d1ed6f75]
May-16 13:44:29.926 [Task submitter] DEBUG nextflow.executor.LocalTaskHandler - Launch cmd line: /bin/bash -ue .command.run
May-16 13:44:29.927 [Task submitter] INFO  nextflow.Session - [af/42f127] Re-submitted process > freyjaVariantCaller (8)
May-16 13:44:29.929 [Task submitter] DEBUG nextflow.executor.LocalTaskHandler - Launch cmd line: /bin/bash -ue .command.run
May-16 13:44:29.929 [Task submitter] INFO  nextflow.Session - [fe/6a4ebd] Submitted process > generateReport (2)
May-16 13:44:30.578 [Task monitor] DEBUG n.processor.TaskPollingMonitor - Task completed > TaskHandler[id: 189; name: freyjaVariantCaller (8); status: COMPLETED; exit: 0; error: -; workDir: /home/user/Desktop/SARS-Cov-2/wastewater/work/af/42f12751b5f66bef9d91fd9e1e8c91]
May-16 13:44:30.579 [Task submitter] DEBUG nextflow.executor.LocalTaskHandler - Launch cmd line: /bin/bash -ue .command.run
May-16 13:44:30.579 [Task submitter] INFO  nextflow.Session - [0e/410d86] Re-submitted process > freyjaVariantCaller (9)
May-16 13:44:31.188 [Task monitor] DEBUG n.processor.TaskPollingMonitor - Task completed > TaskHandler[id: 190; name: freyjaVariantCaller (9); status: COMPLETED; exit: 0; error: -; workDir: /home/user/Desktop/SARS-Cov-2/wastewater/work/0e/410d860232502a714c6bcc3038acea]

The reports I get as the output contain all the analysis besides the Freyja part.

Could you perhaps give me some guidance on how to fix this problem? I would be really grateful!

skunklem commented 1 year ago

In my experience, the freyja step is less likely to fail if you allot it more memory. My runs were failing when I had larger fastq files. In startWorkflow.nf, you can try adding memory '16 GB' (or however much memory you like, since the default is 8 GB) after the line process freyjaVariantCaller {.

rgn3210 commented 1 year ago

Thank you for your reply!

I have tried changing the memory to 16, 30 and 50 GB, but unfortunately I am still having the same issue (same errors). Is there anything else I could potentially try?

skunklem commented 1 year ago

If you go into the .nextflow.log file to where you're getting a line like this (where you see "exit: 1"):

May-15 17:42:29.937 [Task monitor] DEBUG n.processor.TaskPollingMonitor - Task completed > TaskHandler[jobId: 2695446; id: 156; name: freyjaVariantCaller (4); status: COMPLETED; exit: 1; error: -; workDir: /projects/enviro_lab/WW-UNCC/NCDHHS-05-11-23-A4-1-test3-fastqs/work/57/1cc5bbc34de8fbe15786651c7c981e started: 1684186916939; exited: 2023-05-15T21:42:12.439007427Z; ]

Go to that workDir and open up .command.log. Mine has a bunch of stack traces that all end with

joblib.externals.loky.process_executor.TerminatedWorkerError: A worker process managed by the executor was unexpectedly terminated. This could be caused by a segmentation fault while calling the function or by an excessive memory usage causing the Operating System to kill the worker.

That's how I knew my issue was insufficient memory. If you have a different problem going on, the solution would be different. Check out what sort of error message you're getting. It may be something with an input that you can resolve yourself. If not, post it and maybe someone can help.

rgn3210 commented 1 year ago

The error message I'm getting from my .command.log files are:

Pileup generation for Freyja...
ivar: invalid option -- 'r'
[mpileup] 1 samples in 1 input files
Demixing variants by Freyja and bootstrapping
Usage: freyja demix [OPTIONS] VARIANTS DEPTHS
Try 'freyja demix --help' for help.

Error: Invalid value for 'VARIANTS': Path 'freyja.variants.tsv' does not exist.
Usage: freyja boot [OPTIONS] VARIANTS DEPTHS
Try 'freyja boot --help' for help.

Error: Invalid value for 'VARIANTS': Path 'freyja.variants.tsv' does not exist.
skunklem commented 1 year ago

The freyja steps are as follows:

echo Pileup generation for Freyja...
freyja variants resorted.bam --variants freyja.variants.tsv --depths freyja.depths.tsv --ref /projects/enviro_lab/software/C-WAP/covidRefSequences/wuhan.fa

echo Demixing variants by Freyja and bootstrapping
freyja demix freyja.variants.tsv freyja.depths.tsv --output freyja.demix --confirmedonly &
freyja boot freyja.variants.tsv freyja.depths.tsv --nt $(nproc) --nb 1000 --output_base freyja_boot
wait

The ivar error must be from the freyja variants step. freyja variants is what produces 'freyja.variants.tsv', so it's not getting made for some reason. Maybe there's an issue with the inputs. I would verify that the bam file exists in that workDir. Ivar definitely has the option '-r', and the freyja command using ivar can be seen here. In startWorkflow.sh, the command looks like this:

freyja variants resorted.bam --variants freyja.variants.tsv --depths freyja.depths.tsv --ref $params.referenceSequence

Considering that the --ref variable is derived from the referenceSequence variable in your nextflow.config here and is the only non-explicit part of that command, maybe that variable is empty or incorrect in your config. In $workDir/.command.sh, does the freyja variants command look correct? Mine looks like this with the reference sequence expanded: freyja variants resorted.bam --variants freyja.variants.tsv --depths freyja.depths.tsv --ref /projects/enviro_lab/software/C-WAP/covidRefSequences/wuhan.fa

srnarum commented 1 year ago

I have the same issue and get the exact same error message from my .command.log file. The bam file does exist in my working directory and my freyja variants command looks like this: freyja variants resorted.bam --variants freyja.variants.tsv --depths freyja.depths.tsv --ref /mnt/ceph/srnarum/C-WAP/covidRefSequences/wuhan.fa. The path to the reference file looks correct.

Did you solve this issue @rgn3210 ?

skunklem commented 1 year ago

If resorted.bam and the reference file both exist, then I'm not sure what else the issue could be (unless you have a bad version of freyja or ivar). I would recommend going into your workDir and running just the freyja variants step to make sure that works, like this.:

cd $workDir
conda activate $cwap_dir/conda/env-freyja
freyja variants resorted.bam --variants freyja.variants.tsv --depths freyja.depths.tsv --ref /mnt/ceph/srnarum/C-WAP/covidRefSequences/wuhan.fa

If that works without the ivar error (ivar: invalid option -- 'r') and produces the expected outputs (variants and depths), you should be good. If not, that might at least give the developers more of an idea of the problem...

srnarum commented 1 year ago

Hm, that unfortunately does not work.

My version of ivar does not allow for a -r flag, this is the output of ivar variants:

Usage: samtools mpileup -A -d 0 --reference -B -Q 0 | ivar variants -p [-q ] [-t ]

Note : samtools mpileup output must be piped into ivar variants

Input Options Description -q Minimum quality score threshold to count base (Default: 20) -t Minimum frequency threshold(0 - 1) to call variants (Default: 0.03)

Output Options Description -p (Required) Prefix for the output tsv variant file

skunklem commented 1 year ago

That must be the issue. You'll need to update your version of ivar within the conda environment env-freyja. I have ivar version 1.3.1 and it has three additional Input Options (including -r). Ibelive that should be as simple as activating the env and running

conda update ivar

The current version is 1.4.2.

jasmine-amir commented 1 year ago

Hi, and thanks for choosing C-WAP!

Also, special thank you to @skunklem !!

Assuming you all installed ivar using the prepare_envs.sh, then the version should already be ivar 1.3.1, which is what we use.

We may have noticed a similar issue in-house and are discussing with the Freyja developers.

In order to determine if we are all dealing with the same issue, I am curious to see the output of a particular file, please and thank you in advance.

Here is how to find that file:

  1. Navigate to the work-<hash> directory: cd work-<hash>/. This may look something like cd cd work-cdcea7b210f41b6579f3c4c60c48b5f9/, but everyone will have a slightly different hash.
  2. Type find . -type f -name 'freyja.variants.tsv' -print
  3. Choose any of the outputs. If there are multiple, just choose one. Everyone's will look slightly different due to different hashes, but it will look something like this: ./dd/e86f512d8b17a42fa5dbc7d26e906c/freyja.variants.tsv.
  4. Navigate into that directory, for example: cd dd/e86f512d8b17a42fa5dbc7d26e906c/
  5. Then type cat -n .command.log, and please reply with the output of that.

Thanks again! Jasmine

srnarum commented 1 year ago

Hi, I did install all of the environments using prepare_envs.sh, but the ivar version is 1.0. Even after conda update ivar and rebooting, the version is still 1.0.

The output is: Pileup generation for Freyja... 2 ivar: invalid option -- 'r' 3 [mpileup] 1 samples in 1 input files 4 Demixing variants by Freyja and bootstrapping 5 Usage: freyja demix [OPTIONS] VARIANTS DEPTHS 6 Try 'freyja demix --help' for help. 7
8 Error: Invalid value for 'VARIANTS': Path 'freyja.variants.tsv' does not exist. 9 Usage: freyja boot [OPTIONS] VARIANTS DEPTHS 10 Try 'freyja boot --help' for help. 11
12 Error: Invalid value for 'VARIANTS': Path 'freyja.variants.tsv' does not exist.

jasmine-amir commented 1 year ago

Hello,

I have updated the repo with a new release, v1.0.0, a few moments ago.

I did adjust several configs in this latest update, and I am hopeful it will resolve this issue.

Please let me know how it goes.

All the best, Jasmine