<p><code>echo $PATH</code> will show the directories in your search path. Either copy the samtools executable there or add its location to the $PATH variable. You would be well served with a unix command line course or tutorial.</p>

CC BY-SA 4.0
2020-06-17T06:35:53.990Z
2020-06-17T06:35:53.990Z
Devon Ryan
<p>you can add a directory to <code>$PATH</code> by executing following command in the terminal:</p>
<p><code>export PATH=&quot;$HOME/Documents/Software/bbmap:$PATH&quot;</code></p>
<p>In this example, all executable commands in the folder <code>bbmap</code> can be executed from any other directory in the terminal.</p>
<p>So you can install <code>samtools</code> in an appropriate directory and then execute <code>export PATH=&quot;$HOME/your/directory:$PATH&quot;</code>. Then check if it succeeded by running <code>echo $PATH</code>. This latter command will return a list of directories which are assigned to <code>$PATH</code> and your new directory (where <code>samtools</code> is located) should be included.</p>

CC BY-SA 4.0
2020-06-18T12:00:57.620Z
2020-06-18T12:00:57.620Z
RobH
<p>The clean way to do this is to make your own <code>bin</code> within your user directory</p>
<pre><code>cd ~
mkdir bin
vi .profile # or vi .profile_bash or for OS X using `csh` or `tcsh` vi .cshrc
</code></pre>
<p>For bash (Linux, or OS X) within vi type &quot;i&quot; then type,</p>
<pre><code>PATH=$PATH:~/bin
</code></pre>
<p>or</p>
<pre><code>PATH=~/bin:$PATH
</code></pre>
<p>... followed by <code>esc</code> key and &quot;wp&quot; <code>enter</code>
Then enter for <code>csh</code> or <code>tcsh</code> e.g. for OS X</p>
<pre><code>set path = ($path /Users/username/bin /Users/username/anaconda3/bin)
</code></pre>
<p>Same instructions for using <code>vi</code> as for <code>bash</code>. Dump bedtools into any directory (not the desktop) and connect the programs into the bin using <code>ln</code></p>
<pre><code>cd ~/progs/bedtools
ln -si $PWD/prog ~/bin
</code></pre>
<p>If you are using <code>csh</code> or <code>tcsh</code> you need to type <code>rehash</code> but <code>bash</code> does this automatically.</p>
<p>The programs will then be cleaning connect to your $PATH via <code>ln</code> without massive memory usage and visible anywhere within your home space. Its good practice for any Linux / OS X (time gone by UNIX) program or script and whilst you don't need it for this operation as you add more stuff its better.</p>

CC BY-SA 4.0
2020-06-18T19:38:14.773Z
2020-06-18T19:45:11.370Z
2020-06-18T19:45:11.370Z
M__
<p>You can run a piece of software by specifying exactly where it is, like <code>/home/usr/software/samtools_1.1.0/samtools</code></p>

<p>Or if that location is in your $PATH, you can run it with just <code>samtools</code>.  The software you downloaded needs to run those programs, but there's no way for you to give it the specific path for them; it's going to try and run them with just <code>samtools</code>.  So you need to make sure that will work, by putting their locations in your PATH.</p>

<p>It is not clear to me that running every command with sudo is wise.  If you don't understand what $PATH is, I'm pretty sure you should not be running everything with sudo.</p>

CC BY-SA 4.0
2020-06-17T17:14:58.730Z
2020-06-17T17:14:58.730Z
swbarnes2
<p>I am trying to analyze my RNAseq reads for defective genomes and I use this program (<a href="http://www.di-tector.cyame.eu/" rel="nofollow noreferrer">http://www.di-tector.cyame.eu/</a>) that is suggested by Beauclair et al (<a href="https://pubmed.ncbi.nlm.nih.gov/30012569/" rel="nofollow noreferrer">https://pubmed.ncbi.nlm.nih.gov/30012569/</a>)  for that.</p>

<p>After downloading a .py script and running it with the following command: </p>

<pre><code>sudo python3 DI-tector_06.py /mnt/e/nastya/SLX066-02/sequence.fasta /mnt/e/nastya/SLX066-02/B-dVMV-RIG-1/B-dVMV-RIG-1_ACAGTG_L008_R1_001.rc.fastq.gz 
</code></pre>

<p>It says at the beginning that </p>

<pre><code>=================================
Program: DI-tector
Version: 0.6 - Last modified 25/05/2018
=================================
Requirement: (must be in your $PATH)
-bwa
-samtools

Optional: (must be in your $PATH)
-bedtools
</code></pre>

<p>I have tried to install bwa using:</p>

<pre><code>sudo apt-get update -y
sudo apt-get install -y bwa
</code></pre>

<p>and samtools using </p>

<pre><code>cd /usr/local/bin
sudo wget https://github.com/samtools/samtools/releases/download/1.9/samtools-1.9.tar.bz2
sudo tar -vxjf samtools-1.9.tar.bz2
cd samtools-1.9
sudo make
</code></pre>

<p>I did not get exactly what does that mean: <strong>(must be in your $PATH)</strong> but I have searched here and there and discovered that it might mean <code>/usr/local/bin</code></p>

<p>The program starts and, after some calculations it gives me the following error:</p>

<pre><code>Input file:               /mnt/e/nastya/SLX066-02/B-dVMV-RIG-1/B-dVMV-RIG-1_ACAGTG_L008_R1_001.rc.fastq.gz
Host reference:           None
Virus reference:          /mnt/e/nastya/SLX066-02/sequence.fasta
Remove segment:         &lt; 15 nt
Remove reads with MAPQ: &lt; 25
Allow InDel. length:    &gt; 1 nt

=================================
Reading gziped input file...
=================================
Number of reads in input file: 18,035,544
=================================

=================================
Step 1/5 : Alignment against Viral reference...Filtering...
=================================
[E::bwa_idx_load_from_disk] fail to locate the index files
Traceback (most recent call last):
  File "DI-tector_06.py", line 183, in &lt;module&gt;
    Popen(["samtools", "view", "-Sb", "-F", "4"], stdin=out_file_onVirus, stdout=out_file_Virus).communicate()[0]
  File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'samtools'
</code></pre>

<p>I have no idea how samtools must be accessed, I tried <code>sudo</code> command with python3 but it did not work.</p>

CC BY-SA 4.0
2020-06-17T10:24:16.697Z
generally, if you type ``sudo make install``, after you run ``sudo make``, it will install the binary in your $PATH and you won't need to worry about adding it there afterwards
user438383
CC BY-SA 4.0
2020-06-19T09:28:18.077Z
A piece of advice: Dont "over-sudo": You shouldn't need `sudo` to run a data analysis program. When installing samtools, avoid downloading stuff in `/usr/local/bin`: Do it in a local directory (I would recommend having a `$HOME/src` for that), and use sudo only to install the program to `/usr/local/bin`.
bli
CC BY-SA 4.0
2020-06-19T09:41:13.907Z
"Permission denied: 'samtools'" may mean that the samtools "executable" is actually not executable. This can be because it is on a disk that doesn't allow execution of files, but more likely it just needs a fix of the file permission (`chmod +x <path_to_samtools>`).
bli
<python><samtools><linux>
How to make work programs from the $PATH?
# How to make work programs from the $PATH?

(Asked by: username_0 on 2020-06-16)

I am trying to analyze my RNAseq reads for defective genomes and I use this program (http://www.di-tector.cyame.eu/) that is suggested by Beauclair et al (https://pubmed.ncbi.nlm.nih.gov/30012569/)  for that.
After downloading a .py script and running it with the following command: 
sudo python3 DI-tector_06.py /mnt/e/nastya/SLX066-02/sequence.fasta /mnt/e/nastya/SLX066-02/B-dVMV-RIG-1/B-dVMV-RIG-1_ACAGTG_L008_R1_001.rc.fastq.gz 

It says at the beginning that 
=================================
Program: DI-tector
Version: 0.6 - Last modified 25/05/2018
=================================
Requirement: (must be in your $PATH)
-bwa
-samtools

Optional: (must be in your $PATH)
-bedtools

I have tried to install bwa using:
sudo apt-get update -y
sudo apt-get install -y bwa

and samtools using 
cd /usr/local/bin
sudo wget https://github.com/samtools/samtools/releases/download/1.9/samtools-1.9.tar.bz2
sudo tar -vxjf samtools-1.9.tar.bz2
cd samtools-1.9
sudo make

I did not get exactly what does that mean: (must be in your $PATH) but I have searched here and there and discovered that it might mean /usr/local/bin
The program starts and, after some calculations it gives me the following error:
Input file:               /mnt/e/nastya/SLX066-02/B-dVMV-RIG-1/B-dVMV-RIG-1_ACAGTG_L008_R1_001.rc.fastq.gz
Host reference:           None
Virus reference:          /mnt/e/nastya/SLX066-02/sequence.fasta
Remove segment:         < 15 nt
Remove reads with MAPQ: < 25
Allow InDel. length:    > 1 nt

=================================
Reading gziped input file...
=================================
Number of reads in input file: 18,035,544
=================================

=================================
Step 1/5 : Alignment against Viral reference...Filtering...
=================================
[E::bwa_idx_load_from_disk] fail to locate the index files
Traceback (most recent call last):
  File "DI-tector_06.py", line 183, in 
    Popen(["samtools", "view", "-Sb", "-F", "4"], stdin=out_file_onVirus, stdout=out_file_Virus).communicate()[0]
  File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'samtools'

I have no idea how samtools must be accessed, I tried sudo command with python3 but it did not work.

**Tags:** python, samtools, linux
> **Comments:**
> **username_1**: generally, if you type ``sudo make install``, after you run ``sudo make``, it will install the binary in your $PATH and you won't need to worry about adding it there afterwards  
> **username_2**: A piece of advice: Dont "over-sudo": You shouldn't need `sudo` to run a data analysis program. When installing samtools, avoid downloading stuff in `/usr/local/bin`: Do it in a local directory (I would recommend having a `$HOME/src` for that), and use sudo only to install the program to `/usr/local/bin`.  
> **username_2**: "Permission denied: 'samtools'" may mean that the samtools "executable" is actually not executable. This can be because it is on a disk that doesn't allow execution of files, but more likely it just needs a fix of the file permission (`chmod +x <path_to_samtools>`).  

---

## 4 answers

### Answer by username_3 on 2020-06-17. Score: 3 | Accepted answer

`echo $PATH` will show the directories in your search path. Either copy the samtools executable there or add its location to the $PATH variable. You would be well served with a unix command line course or tutorial.


---

### Answer by username_4 on 2020-06-18. Score: 2

you can add a directory to `$PATH` by executing following command in the terminal:

`export PATH="$HOME/Documents/Software/bbmap:$PATH"`

In this example, all executable commands in the folder `bbmap` can be executed from any other directory in the terminal.

So you can install `samtools` in an appropriate directory and then execute `export PATH="$HOME/your/directory:$PATH"`. Then check if it succeeded by running `echo $PATH`. This latter command will return a list of directories which are assigned to `$PATH` and your new directory (where `samtools` is located) should be included.


---

### Answer by username_5 on 2020-06-18. Score: 1

The clean way to do this is to make your own bin within your user directory
cd ~
mkdir bin
vi .profile # or vi .profile_bash or for OS X using `csh` or `tcsh` vi .cshrc

For bash (Linux, or OS X) within vi type "i" then type,
PATH=$PATH:~/bin

or
PATH=~/bin:$PATH

... followed by esc key and "wp" enter
Then enter for csh or tcsh e.g. for OS X
set path = ($path /Users/username/bin /Users/username/anaconda3/bin)

Same instructions for using vi as for bash. Dump bedtools into any directory (not the desktop) and connect the programs into the bin using ln
cd ~/progs/bedtools
ln -si $PWD/prog ~/bin

If you are using csh or tcsh you need to type rehash but bash does this automatically.
The programs will then be cleaning connect to your $PATH via ln without massive memory usage and visible anywhere within your home space. Its good practice for any Linux / OS X (time gone by UNIX) program or script and whilst you don't need it for this operation as you add more stuff its better.


---

### Answer by username_6 on 2020-06-17. Score: 1

You can run a piece of software by specifying exactly where it is, like `/home/usr/software/samtools_1.1.0/samtools`

Or if that location is in your $PATH, you can run it with just `samtools`. The software you downloaded needs to run those programs, but there's no way for you to give it the specific path for them; it's going to try and run them with just `samtools`. So you need to make sure that will work, by putting their locations in your PATH.

It is not clear to me that running every command with sudo is wise. If you don't understand what $PATH is, I'm pretty sure you should not be running everything with sudo.


---

