0

I am using the program GTDBtk, a tool kit that uses other programs. When I ran GTDBtk using the terminal it gave me an error:

[2020-03-15 18:58:22] INFO: Using GTDB-Tk reference data version r89: /Users/Desktop/GTDB/gtdbtk/release89
hmmsearch is not on the system path.

I solved this problem by writing this code

PATH="/Users/monkiky/Desktop/Data/hmmer-3.3/src/hmmsearch:$PATH"

Now, due to I need to run this program several times, I am writing a script in Python. Writing this code I have found the same error and I do not know how to solve it.

[2020-03-21 11:26:37] INFO: Using GTDB-Tk reference data version r89: /Users/monkiky/Desktop/GTDB/gtdbtk/release89
hmmsearch is not on the system path.

How can I define the path using python? or what I am doing wrong.

I have tried this with not lucky:

os.system('PATH="/Users/monkiky/Desktop/Data/hmmer-3.3/src/hmmsearch:$PATH"')

Here my completed coded:

#Define directory
os.chdir('/Users/monkiky/Desktop/prueba/GTDBTk-1.0.1')

# We define the environment variable
os.environ['GTDBTK_DATA_PATH'] = "/Users/monkiky/Desktop/GTDB/gtdbtk/release89" 

# Add the path of prodigal (here the problem bust be)
sys.path.append("/Users/monkiky/Desktop/GTDB/GTDBTk-1.0.1/hmmsearch")


#Run the program
os.system('gtdbtk identify --genome_dir /Users/monkiky/Desktop/GTDB/input --out_dir /Users/monkiky/Desktop/GTDB/prueba')

output

2020-03-21 14:29:09] INFO: GTDB-Tk v1.0.2
[2020-03-21 14:29:09] INFO: gtdbtk identify --genome_dir /Users/monkiky/Desktop/GTDB/input --out_dir /Users/monkiky/Desktop/GTDB/prueba
[2020-03-21 14:29:09] INFO: Using GTDB-Tk reference data version r89: /Users/monkiky/Desktop/GTDB/gtdbtk/release89
hmmsearch is not on the system path.
[2020-03-21 14:29:09] ERROR: Controlled exit resulting from early termination.
<built-in function chdir>
  • `os.system` starts a new shell, executes the assignment in that shell, and then that shell exits. `PATH` in the *current* process isn't changed. – chepner Mar 21 '20 at 13:02

1 Answers1

0

If you want just to append your path to the PATH, then use

import os
path = '/Users/monkiky/Desktop/Data/hmmer-3.3/src/hmmsearch'
os.environ["PATH"] += os.pathsep + path

See here.

Alternatively, you can either:

Add /Users/monkiky/Desktop/Data/hmmer-3.3/src/hmmsearch to your system environment manually (let's call it HMM_SEARCH_PATH) and the call:

import os

path = os.getenv('HMM_SEARCH_PATH')

# Use path wherever you need, e.g.
print(path) 

or,

Create a .env file in your project folder and insert HMM_SEARCH_PATH = /Users/monkiky/Desktop/Data/hmmer-3.3/src/hmmsearch, then in your python script:

import os
from dotenv import load_dotenv

load_dotenv()
path = os.getenv('HMM_SEARCH_PATH')

# Use path wherever you need, e.g.
print(path) 

See this question and this article for more information.

s.dallapalma
  • 1,225
  • 1
  • 12
  • 35