Skip to content

Commit

Permalink
1.2, changed metadata format for custom references
Browse files Browse the repository at this point in the history
Former-commit-id: 22c957d
  • Loading branch information
PedroMTQ committed Sep 7, 2021
1 parent f618b71 commit ea02fac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 2 additions & 4 deletions source/MANTIS_DB.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ def compile_kofam_metadata(self):
remove_file(self.mantis_paths['kofam'] + 'ko2cog.xl')
remove_file(self.mantis_paths['kofam'] + 'ko2go.xl')
remove_file(self.mantis_paths['kofam'] + 'ko2tc.xl')
remove_file(self.mantis_paths['kofam'] + 'ko_to_path')

def get_link_kofam_ko_list(self, res):
file_path = self.mantis_paths['kofam'] + 'ko_list'
Expand Down Expand Up @@ -463,18 +462,16 @@ def download_kofam(self, force_download=False, stdout_file=None):
ko_to_go = 'https://www.kegg.jp/kegg/files/ko2go.xl'
ko_to_tc = 'https://www.kegg.jp/kegg/files/ko2tc.xl'
ko_to_cazy = 'https://www.kegg.jp/kegg/files/ko2cazy.xl'
ko_to_path = 'http://rest.kegg.jp/link/pathway/ko'
with open(self.mantis_paths['kofam'] + 'readme.md', 'w+') as file:
datetime_str = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
file.write(f'This hmm was downloaded on {datetime_str} from:\n{kofam_hmm}\nMetadata was downloaded from:\n{ko_list}\n{ko_to_cog}\n{ko_to_go}\n{ko_to_tc}\n{ko_to_cazy}')
print_cyan('Downloading and unzipping KOfam hmms ', flush=True, file=stdout_file)
for url in [kofam_hmm, ko_list, ko_to_cog, ko_to_go, ko_to_tc, ko_to_cazy, ko_to_path]:
for url in [kofam_hmm, ko_list, ko_to_cog, ko_to_go, ko_to_tc, ko_to_cazy]:
download_file(url, output_folder=self.mantis_paths['kofam'], stdout_file=stdout_file)
uncompress_archive(source_filepath=self.mantis_paths['kofam'] + 'profiles.tar.gz',
extract_path=self.mantis_paths['kofam'], stdout_file=stdout_file, remove_source=True)
uncompress_archive(source_filepath=self.mantis_paths['kofam'] + 'ko_list.gz', stdout_file=stdout_file,
remove_source=True)
move_file(self.mantis_paths['kofam'] + 'ko', self.mantis_paths['kofam'] + 'ko_to_path')
merge_profiles(self.mantis_paths['kofam'] + 'profiles/', self.mantis_paths['kofam'] + 'kofam_merged.hmm',stdout_file=stdout_file)
run_command('hmmpress ' + self.mantis_paths['kofam'] + 'kofam_merged.hmm', stdout_file=stdout_file)
self.compile_kofam_metadata()
Expand Down Expand Up @@ -1321,3 +1318,4 @@ def get_metadata_hmms(self, target_annotation_file, target_sql_file, taxon_id=No
print(f'Finished exporting metadata for NOGT {taxon_id}', flush=True, file=stdout_file)
stdout_file.close()


9 changes: 8 additions & 1 deletion source/MANTIS_Metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ def get_hit_links(self, dict_hits, ref_file):
self.get_link_compiled_metadata(dict_hits=dict_hits, ref_file_path=self.mantis_paths['tigrfam'] + 'metadata.tsv')
self.is_essential(dict_hits)
else:
self.get_link_custom_ref(dict_hits, self.get_target_custom_ref_paths(ref_file, folder=False))
custom_ref_path=self.get_target_custom_ref_paths(ref_file, folder=False)
if custom_ref_path:
if custom_ref_path.endswith('.hmm'):
file_path = custom_ref_path.replace('.hmm', '.tsv')
elif custom_ref_path.endswith('.dmnd'):
file_path = custom_ref_path.replace('.dmnd', '.tsv')
if file_exists(file_path):
self.get_link_compiled_metadata(dict_hits=dict_hits, ref_file_path=file_path)
for hit in dict_hits:
self.get_common_links(hit, dict_hits[hit])
if 'accession' in dict_hits[hit]['link']: self.get_common_links(dict_hits[hit]['link']['accession'], dict_hits[hit])
Expand Down

0 comments on commit ea02fac

Please sign in to comment.