etal / cnvkit

Copy number variant detection from targeted DNA sequencing
http://cnvkit.readthedocs.org
Other
547 stars 166 forks source link

subprocess.CalledProcessError when segmenting #881

Open sainsachiko opened 6 months ago

sainsachiko commented 6 months ago

I am trying to run segmentation on a cnr file with version 0.9.11 with this command: cnvkit.py segment HCC1395T.cnr -o HCC1395T.cns but got below error:

Segmenting with method 'cbs', significance threshold 0.0001, in 1 processes
Traceback (most recent call last):
  File "/opt/miniconda/envs/cnvkit/lib/python3.10/site-packages/cnvlib/core.py", line 23, in call_quiet
    proc = subprocess.run(args, check=True, capture_output=True)
  File "/opt/miniconda/envs/cnvkit/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('Rscript', '--no-restore', '--no-environ', '/tmp/tmpmy9rct8d')' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/miniconda/envs/cnvkit/bin/cnvkit.py", line 8, in <module>
    sys.exit(main())
  File "/opt/miniconda/envs/cnvkit/lib/python3.10/site-packages/cnvlib/cnvkit.py", line 10, in main
    args.func(args)
  File "/opt/miniconda/envs/cnvkit/lib/python3.10/site-packages/cnvlib/commands.py", line 1022, in _cmd_segment
    results = segmentation.do_segmentation(
  File "/opt/miniconda/envs/cnvkit/lib/python3.10/site-packages/cnvlib/segmentation/__init__.py", line 81, in do_segmentation
    rets = list(
  File "/opt/miniconda/envs/cnvkit/lib/python3.10/site-packages/cnvlib/segmentation/__init__.py", line 126, in _ds
    return _do_segmentation(*args)
  File "/opt/miniconda/envs/cnvkit/lib/python3.10/site-packages/cnvlib/segmentation/__init__.py", line 209, in _do_segmentation
    seg_out = core.call_quiet(
  File "/opt/miniconda/envs/cnvkit/lib/python3.10/site-packages/cnvlib/core.py", line 30, in call_quiet
    raise RuntimeError(
RuntimeError: Subprocess command failed:
$ Rscript --no-restore --no-environ /tmp/tmpmy9rct8d

Command '('Rscript', '--no-restore', '--no-environ', '/tmp/tmpmy9rct8d')' returned non-zero exit status 1.

My .cnr have NaN values, when I tried with version 0.9.10, it resulted in

Segmenting with method 'cbs', significance threshold 0.0001, in 1 processes
Traceback (most recent call last):
  File "/opt/miniconda/envs/cnvkit9/bin/cnvkit.py", line 8, in <module>
    sys.exit(main())
  File "/opt/miniconda/envs/cnvkit9/lib/python3.9/site-packages/cnvlib/cnvkit.py", line 10, in main
    args.func(args)
  File "/opt/miniconda/envs/cnvkit9/lib/python3.9/site-packages/cnvlib/commands.py", line 994, in _cmd_segment
    results = segmentation.do_segmentation(
  File "/opt/miniconda/envs/cnvkit9/lib/python3.9/site-packages/cnvlib/segmentation/__init__.py", line 79, in do_segmentation
    rets = list(
  File "/opt/miniconda/envs/cnvkit9/lib/python3.9/site-packages/cnvlib/segmentation/__init__.py", line 123, in _ds
    return _do_segmentation(*args)
  File "/opt/miniconda/envs/cnvkit9/lib/python3.9/site-packages/cnvlib/segmentation/__init__.py", line 205, in _do_segmentation
    seg_out = core.call_quiet(
  File "/opt/miniconda/envs/cnvkit9/lib/python3.9/site-packages/cnvlib/core.py", line 32, in call_quiet
    raise RuntimeError(
RuntimeError: Subprocess command failed:
$ Rscript --no-restore --no-environ /tmp/tmptqq453e7

b'Loading probe coverages into a data frame\nWarning message:\nIn CNA(cbind(tbl$log2), tbl$chromosome, tbl$start, data.type = "logratio",  :\n  markers with missing chrom and/or maploc removed\n\nSegmenting the probe data\nError in segment(cna, weights = tbl$weight, alpha = 1e-04) : \n  length of weights should be the same as the number of probes\nExecution halted\n'

Is there any solutions for this? Thank you in advance!

etal commented 6 months ago

Are there any blank fields in your .cnr file? Which columns do they occur in?

sainsachiko commented 6 months ago

Hi, thank you for replying. My cnr have NAs in weight columns. You can find the file here

Sanat-Mishra commented 4 months ago

Hi @sainsachiko, after spending hours trying to debug the same issue, I was able to get it to run. Theres's some issue with the R env that DNACopy needs to run segmentation. so you'll have to run CNVkit from within an environment. I kept running into a compatibility issue with Conda until I used the yaml file on the repo to make it.

There are two ways you get CNVkit to run - i) Using the docker image and running everything in that container ii) Build a Conda env with the yaml file (NOTE - This yaml will work on Mac OS only, further I am on an Apple Silicon M2 chip, so that could further nuance the dependency list).

name: cnvkit
channels:
    - conda-forge
    - bioconda
    - defaults
dependencies:
    - python>=3.8
    - biopython >=1.80
    - matplotlib >=3.5.2
    - numpy >=1.24.2
    - pandas >=1.5.3
    - pyfaidx >=0.7.1
    - pytest
    - reportlab >=3.6.12
    - ruff
    - scikit-learn >=1.1.0
    - scipy >=1.10.1
    - tox

Once set up, don't forget to pip install CNVkit!

bounlu commented 3 months ago

@Sanat-Mishra

I am using the Docker image but still get the same error.

@etal

In my .cnr file, the weights column are empty for antitarget regions.