0

I think it is an environment issue, but I am new to linux.

I try to run subprocess.run('multiqc .') in pycharm but it shows me the file is not found

FileNotFoundError: [Errno 2] No such file or directory: 'multiqc .'

and echo $PATH shows that anaconda path is exposed

$ echo $PATH /media/SSD1T/Software/anaconda3/bin:

I tried subprocess.run('multiqc', shell = True), it returns error: /bin/sh: 1: multiqc: not found

while in terminal, I can call multiqc no problem

$which multiqc /media/SSD1T/Software/anaconda3/bin/multiqc

tried run other commands in pycharm, no problem:

subprocess.run('ls')

In[11]: subprocess.run("ls")
loadSamples.py
venv
xFastqc.py
xTrim.py
Out[11]: CompletedProcess(args='ls', returncode=0)

The only way I can make it work is to add the whole path to subprocess.run

In[12]: subprocess.run("/media/SSD1T/Software/anaconda3/bin/multiqc")
Usage: multiqc [OPTIONS] <analysis directory>

Error: Missing argument "analysis_dir".

This is MultiQC v1.5

For more help, run 'multiqc --help' or visit http://multiqc.info

Out[12]: CompletedProcess(args='/media/SSD1T/Software/anaconda3/bin/multiqc', returncode=2)

My question is: how can I just call multiqc in subprocess.run without put in the whole path?

Thank you

Xp.L
  • 837
  • 1
  • 7
  • 13

2 Answers2

0

So I bypassed this problem by adding a link to /usr/bin. If you have a better solution, please let me know.

Thanks

Xp.L
  • 837
  • 1
  • 7
  • 13
0

This is an old question, but for the sake of future googlers I can try to help. I think the problem is that using subprocess opens up a new shell where the conda environment with MultiQC is not activated. Because of this, multiqc is not available on the PATH, and you have to specify the full absolute path to the binary.

If I'm right about this, the problem is not so much about MultiQC, but more about using conda within a subprocess call. There are several other Stack Overflow questions on this topic. The quick and dirty method is to just activate the relevant conda environment within the same subprocess call:

subprocess.run('source activate base && multiqc .', shell = True)

But, I have good news! As of MultiQC v1.8 (which should be released in a few days) and pull-request #1042, you can now import MultiQC into python scripts and run it as a function. This is much easier and more portable. You can see an example here: https://github.com/MultiQC/MultiQC_Notebook

Basic script:

import IPython
import multiqc

multiqc.run('./path/to/data/')

IPython.display.IFrame('./multiqc_report.html', '100%', 600)
ewels
  • 463
  • 7
  • 19