3

I have downloaded some software (called samtools) and it is stored in a folder on my desktop. Then I've added the path to the executable into the PATH environment variable. In other words my ~/.bashrc file has the following line:

export PATH="~/Desktop/samtools/samtools-1.1:$PATH".

The executable file named samtools is in this folder.

When I try to launch it from the command line by simply typing samtools, it works. It also works when I use the full path to the executable.

However, when I try to launch it from a shell script, it does not launch and reports either: No such file or Directory not found.

Can anyone help me to solve this problem?

EDIT: As some people requested.

The exact error message is:

Realigning using Bowtie2...
./RP_capture//realign/filter_long_inserts.sh: 29: ./RP_capture//realign/filter_long_inserts.sh: samtools: not found
./RP_capture//realign/filter_long_inserts.sh: 29: ./RP_capture//realign/filter_long_inserts.sh: samtools: not found
Could not locate a Bowtie index corresponding to basename "./aux/chr1.fa"

I have also added echo $PATH to my script and the output seems correct. Path to samtools is there.

this is example of one of many calls to samtools from the script.

samtools index $OUTPUT/realignments/$file.abnormal.realign.bowtie.bam

I have actually managed to solve the problem using

export set SAMTOOLS_DIR="/home/laba/Desktop/samtools/samtools-1.1"

within a script and then calling samtools like this:

$SAMTOOLS_DIR/samtools [parameters]

Strangely enough, another binary script calls works with just explicitly providing path to the executable. Without having to use set.

  • Please edit your question and insert a copy/paste of the relevant part(s) of your script. – BenjiWiebe Dec 27 '14 at 5:02
  • I have edited my post to answer your question. – YKY Dec 29 '14 at 10:30
1

Setting directory variable like this:

export set SAMTOOLS_DIR="/home/laba/Desktop/samtools/samtools-1.1"

And then calling the exacutable from the script like this:

$SAMTOOLS_DIR/samtools [parameters]

solves the problem

0

Try putting a echo $ PATH in the script, to ensure the path is what you think it is, and ensure the script itself can run (executable bit set, correct shebang #!/bin/sh or whatever in the first line). If nothing else works, you may try stracing the script invocation call.

Update

From the error message, it is clear that the problem arises in a sub-script, which invokes samtools on its own:

./RP_capture//realign/filter_long_inserts.sh at line 29

So the problem is that invocation of samtools, which is either missing a PATH or some other variable component.

As you found out, that component is in all likelihood SAMTOOLS_DIR.

Another possibility worth investigation is that the problem is in the user running the script (e.g. via sudo or the like). In that case, the value of PATH set to "~/Desktop...", where the "~" means "The home user of the current user", would end up meaning two different things for you and for the user running the script. In that case you ought to set PATH to

/home/laba/Desktop/samtools/samtools-1.1:$PATH

instead of

~/Desktop/samtools/samtools-1.1:$PATH

  • I have added echo $PATH to the script and it seems good. Path to samtools is there. Also I've changed shebang from #!/bin/sh to #!/bin/bash. Which was the output of 'which bash' command. – YKY Dec 29 '14 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.