Skip to content

Commit

Permalink
added resources path to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroMTQ committed Mar 2, 2022
1 parent d6ca38f commit 1a89a3b
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 77 deletions.
1 change: 1 addition & 0 deletions config/MANTIS.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#######DEFAULT PATHS#######
#You can add custom paths here, otherwise they will be set to default values
#default_ref_folder=
#resources_folder=
#####<custom_ref_folder> defines the folder where Mantis will look for MULTIPLE custom HMMs or DMND. Each HMM should be contained within a folder, such that the path will look something like this: /path/to/custom_ref_folder/custom1/custom1.hmm
#custom_ref_folder=
# dmnd or hmm
Expand Down
170 changes: 93 additions & 77 deletions mantis/Assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __str__(self):
if hasattr(self, 'output_folder'):
res.append(f'Output folder:\nself.output_folder')
res.append(f'Default references folder:\n{self.mantis_paths["default"]}')
res.append(f'Resources folder:\n{self.mantis_paths["resources"]}')
res.append(f'Custom references folder:\n{self.mantis_paths["custom"]}')
if self.mantis_paths['NOG'][0:2] != 'NA':
res.append(f'TAX NOG references folder:\n{self.mantis_paths["NOG"]}')
Expand Down Expand Up @@ -100,20 +101,6 @@ def check_internet_connection(self):
print("Could not connect to internet!\nIf you would like to run offline make sure you introduce organism NCBI IDs instead of synonyms!")
return False

def get_default_ref_path(self):
file = open(self.config_file, 'r')
line = file.readline()
while line:
line = line.strip('\n')
if '#' not in line:
# data sources configuration
if 'default_ref_folder=' in line:
line_path = add_slash(line.replace('default_ref_folder=', ''))
if line_path:
default_ref_path = line_path
return default_ref_path
line = file.readline()
file.close()

def set_nogt_line(self, line_path):
if line_path:
Expand All @@ -134,55 +121,100 @@ def set_nogt_line(self, line_path):
self.mantis_nogt_tax.add(str(i))

def setup_paths_config_file(self):
self.mantis_paths = {'default': None,
'resources': None,
'custom': None,
'NOG': None,
'pfam': None,
'kofam': None,
'NCBI': None,
'tcdb': None,
}


self.nog_db = 'dmnd'
file = open(self.config_file, 'r')
line = file.readline()
nogt_line=None
while line:
line = line.strip('\n')
if not line.startswith('#') and line:
# data sources configuration
if line.startswith('custom_ref_folder='):
line_path = add_slash(line.replace('custom_ref_folder=', ''))
if line_path: self.mantis_paths['custom'] = line_path

elif line.startswith('nog_ref_folder='):
line_path = add_slash(line.replace('nog_ref_folder=', ''))
if line_path: self.mantis_paths['NOG'] = line_path

# taxa ids list for only downloading nogt specific to lineage
elif line.startswith('nog_tax='):
nogt_line = line.replace('nog_tax=', '')

elif line.startswith('pfam_ref_folder='):
line_path = add_slash(line.replace('pfam_ref_folder=', ''))
if line_path: self.mantis_paths['pfam'] = line_path

elif line.startswith('kofam_ref_folder='):
line_path = add_slash(line.replace('kofam_ref_folder=', ''))
if line_path: self.mantis_paths['kofam'] = line_path

elif line.startswith('ncbi_ref_folder='):
line_path = add_slash(line.replace('ncbi_ref_folder=', ''))
if line_path: self.mantis_paths['NCBI'] = line_path

elif line.startswith('tcdb_ref_folder='):
line_path = add_slash(line.replace('tcdb_ref_folder=', ''))
if line_path: self.mantis_paths['tcdb'] = line_path


elif '_weight=' in line:
ref_source, weight = line.split('_weight=')
self.mantis_ref_weights[ref_source] = float(weight)

elif line.startswith('nog_ref='):
nog_db = line.replace('nog_ref=', '').split()[0]
if nog_db.lower() not in ['dmnd','hmm']:
kill_switch(InvalidNOGType)
else:
self.nog_db=nog_db
line = file.readline()
file.close()
with open(self.config_file) as file:
for line in file:
line = line.strip('\n')
if not line.startswith('#') and line:
# data sources configuration
if line.startswith('default_ref_folder='):
line_path = add_slash(line.replace('default_ref_folder=', ''))
if line_path: self.mantis_paths['default'] = line_path

elif line.startswith('resources_folder='):
line_path = add_slash(line.replace('resources_folder=', ''))
if line_path: self.mantis_paths['resources'] = line_path

elif line.startswith('custom_ref_folder='):
line_path = add_slash(line.replace('custom_ref_folder=', ''))
if line_path: self.mantis_paths['custom'] = line_path

elif line.startswith('nog_ref_folder='):
line_path = add_slash(line.replace('nog_ref_folder=', ''))
if line_path: self.mantis_paths['NOG'] = line_path

# taxa ids list for only downloading nogt specific to lineage
elif line.startswith('nog_tax='):
nogt_line = line.replace('nog_tax=', '')

elif line.startswith('pfam_ref_folder='):
line_path = add_slash(line.replace('pfam_ref_folder=', ''))
if line_path: self.mantis_paths['pfam'] = line_path

elif line.startswith('kofam_ref_folder='):
line_path = add_slash(line.replace('kofam_ref_folder=', ''))
if line_path: self.mantis_paths['kofam'] = line_path

elif line.startswith('ncbi_ref_folder='):
line_path = add_slash(line.replace('ncbi_ref_folder=', ''))
if line_path: self.mantis_paths['NCBI'] = line_path

elif line.startswith('tcdb_ref_folder='):
line_path = add_slash(line.replace('tcdb_ref_folder=', ''))
if line_path: self.mantis_paths['tcdb'] = line_path

elif '_weight=' in line:
ref_source, weight = line.split('_weight=')
self.mantis_ref_weights[ref_source] = float(weight)

elif line.startswith('nog_ref='):
nog_db = line.replace('nog_ref=', '').split()[0]
if nog_db.lower() not in ['dmnd','hmm']:
kill_switch(InvalidNOGType)
else:
self.nog_db=nog_db
if not self.mantis_paths['default']:
self.mantis_paths['default']=add_slash(MANTIS_FOLDER + 'References')
default_ref_path=self.mantis_paths['default']

if not self.mantis_paths['resources']:
self.mantis_paths['resources']=add_slash(MANTIS_FOLDER + 'Resources')

if not self.mantis_paths['custom']:
self.mantis_paths['custom']= add_slash(default_ref_path + 'Custom_references')

if not self.mantis_paths['NOG']:
self.mantis_paths['NOG']= add_slash(default_ref_path + 'NOG')

if not self.mantis_paths['pfam']:
self.mantis_paths['pfam']= add_slash(default_ref_path + 'pfam')

if not self.mantis_paths['kofam']:
self.mantis_paths['kofam']= add_slash(default_ref_path + 'kofam')

if not self.mantis_paths['NCBI']:
self.mantis_paths['NCBI']= add_slash(default_ref_path + 'NCBI')

if not self.mantis_paths['tcdb']:
self.mantis_paths['tcdb']= add_slash(default_ref_path + 'tcdb')




#setting up which taxa we need to have references for
Taxonomy_SQLITE_Connector.__init__(self,resources_folder=self.mantis_paths['resources'])
if self.use_taxonomy:
if nogt_line:
if self.launch_taxonomy_connector():
Expand Down Expand Up @@ -210,22 +242,6 @@ def read_config_file(self):
flush=True, file=self.redirect_verbose)
raise FileNotFoundError

default_ref_path = self.get_default_ref_path()

# if there's no path, we just assume its in the default folder
if not default_ref_path: default_ref_path = add_slash(MANTIS_FOLDER + 'References')
resources_path = add_slash(MANTIS_FOLDER + 'Resources')

self.mantis_paths = {'default': default_ref_path,
'resources': resources_path,
'custom': add_slash(default_ref_path + 'Custom_references'),
'NOG': add_slash(default_ref_path + 'NOG'),
'pfam': add_slash(default_ref_path + 'pfam'),
'kofam': add_slash(default_ref_path + 'kofam'),
'NCBI': add_slash(default_ref_path + 'NCBI'),
'tcdb': add_slash(default_ref_path + 'tcdb'),
}
Taxonomy_SQLITE_Connector.__init__(self,resources_folder=self.mantis_paths['resources'])

self.setup_paths_config_file()
if not self.use_taxonomy:
Expand Down

0 comments on commit 1a89a3b

Please sign in to comment.