Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: add new files to BuscoDatabaseDirFmt #231

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions q2_annotate/busco/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import os
import subprocess
from q2_annotate._utils import colorify, run_command
from q2_annotate.busco.types import BuscoDatabaseDirFmt
Expand Down Expand Up @@ -37,6 +38,9 @@ def fetch_busco_db(
f"Error during BUSCO database download: {e.returncode}"
)

# There is a symlink in the BUSCO database that needs to be removed
delete_symlinks(str(busco_db))

# Let user know that the process is complete but it still needs
# some time to copy files over.
print(colorify(
Expand All @@ -45,3 +49,10 @@ def fetch_busco_db(
))

return busco_db


def delete_symlinks(root_dir):
for dirpath, dirnames, filenames in os.walk(root_dir, followlinks=False):
for file in filenames:
if os.path.islink(os.path.join(dirpath, file)):
os.unlink(os.path.join(dirpath, file))
19 changes: 18 additions & 1 deletion q2_annotate/busco/tests/test_fetch_busco.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
from q2_annotate.busco.database import fetch_busco_db
import os
from q2_annotate.busco.database import fetch_busco_db, delete_symlinks
from unittest.mock import patch
from qiime2.plugin.testing import TestPluginBase

Expand Down Expand Up @@ -36,3 +37,19 @@ def test_fetch_busco_db_all(self, subp_run):
# Check that command was called in the expected way
cmd = ["busco", "--download", "all"]
subp_run.assert_called_once_with(cmd, check=True, cwd=str(busco_db))

def test_delete_symlinks(self):
temp_dir = self.temp_dir.name
sub_dir = os.path.join(temp_dir, "subdir")
os.makedirs(sub_dir)

# Create symlinks
symlink1 = os.path.join(temp_dir, "symlink1")
symlink2 = os.path.join(sub_dir, "symlink2")

# Run delete function
delete_symlinks(temp_dir)

# Check that symlinks were deleted
self.assertFalse(os.path.exists(symlink1))
self.assertFalse(os.path.exists(symlink2))
15 changes: 15 additions & 0 deletions q2_annotate/busco/types/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ class BuscoDatabaseDirFmt(model.DirectoryFormat):
r'busco_downloads\/lineages\/.+refseq_db\.faa\.gz',
format=BuscoGenericBinaryFileFmt
)
information = model.FileCollection(
r'busco_downloads\/information\/.+\.txt$',
format=BuscoGenericTextFileFmt,
optional=True
)
missing_parasitic = model.File(
r'busco_downloads\/lineages\/.+\/missing_in_parasitic\.txt$',
format=BuscoGenericTextFileFmt,
optional=True
)
no_hits = model.File(
r'busco_downloads\/lineages\/.+\/no_hits$',
format=BuscoGenericTextFileFmt,
optional=True
)

def _path_maker(self, name):
return str(name)
Expand Down
Loading