Skip to content

Commit

Permalink
refactor SampleSheetTableBuilder init (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Dec 12, 2022
1 parent 481b6e1 commit 4251014
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 24 deletions.
10 changes: 2 additions & 8 deletions irodsadmin/management/commands/irodsorphans.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


logger = ManagementCommandLogger(__name__)
table_builder = SampleSheetTableBuilder()


def get_assay_collections(assays, irods_backend):
Expand All @@ -30,12 +31,10 @@ def get_assay_collections(assays, irods_backend):

def get_assay_subcollections(studies, irods_backend):
"""Return a list of all assay row colletion names."""
tb = SampleSheetTableBuilder()
collections = []

for study in studies:
try:
study_tables = tb.get_study_tables(study)
study_tables = table_builder.get_study_tables(study)
except Exception as ex:
logger.error(
'Study table building exception for "{}" '
Expand All @@ -60,7 +59,6 @@ def get_assay_subcollections(studies, irods_backend):
)
if row_path not in collections:
collections.append(row_path)

shortcuts = assay_plugin.get_shortcuts(assay)
if shortcuts:
for shortcut in shortcuts:
Expand All @@ -70,7 +68,6 @@ def get_assay_subcollections(studies, irods_backend):
collections.append(assay_path + '/' + TRACK_HUBS_COLL)
collections.append(assay_path + '/' + RESULTS_COLL)
collections.append(assay_path + '/' + MISC_FILES_COLL)

return collections


Expand Down Expand Up @@ -154,7 +151,6 @@ def get_orphans(irods, irods_backend, expected, assays):
):
if collection.path not in expected:
orphans.append(collection.path)

return orphans


Expand All @@ -163,7 +159,6 @@ def get_output(orphans, irods_backend, irods):
for orphan in orphans:
stats = irods_backend.get_object_stats(irods, orphan)
m = re.search(r'/projects/([^/]{2})/(\1[^/]+)', orphan)

if m:
uuid = m.group(2)
try:
Expand All @@ -174,7 +169,6 @@ def get_output(orphans, irods_backend, irods):
else:
uuid = '<ERROR>'
title = '<ERROR>'

lines.append(
';'.join(
[
Expand Down
4 changes: 2 additions & 2 deletions samplesheets/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

app_settings = AppSettingAPI()
logger = logging.getLogger(__name__)
table_builder = SampleSheetTableBuilder()


# SODAR constants
Expand Down Expand Up @@ -898,7 +899,6 @@ def _update_cache_rows(self, app_name, name=None, project=None, user=None):
if not cache_backend or not irods_backend:
return

tb = SampleSheetTableBuilder()
projects = (
[project]
if project
Expand All @@ -924,7 +924,7 @@ def _update_cache_rows(self, app_name, name=None, project=None, user=None):

# Get assay paths
for study in studies:
study_tables = tb.get_study_tables(study)
study_tables = table_builder.get_study_tables(study)
for assay in [a for a in study.assays.all() if a in config_assays]:
assay_table = study_tables['assays'][str(assay.sodar_uuid)]
assay_path = irods_backend.get_path(assay)
Expand Down
4 changes: 2 additions & 2 deletions samplesheets/sheet_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

app_settings = AppSettingAPI()
logger = logging.getLogger(__name__)
table_builder = SampleSheetTableBuilder()


# Local constants
Expand Down Expand Up @@ -106,8 +107,7 @@ def get_sheet_config(self, investigation, inv_tables=None):
if not sheet_ok:
logger.info(msg)
if not inv_tables:
tb = SampleSheetTableBuilder()
inv_tables = tb.build_inv_tables(
inv_tables = table_builder.build_inv_tables(
investigation, use_config=False
)
sheet_config = self.build_sheet_config(investigation, inv_tables)
Expand Down
5 changes: 2 additions & 3 deletions samplesheets/studyapps/cancer/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@


logger = logging.getLogger(__name__)
table_builder = SampleSheetTableBuilder()
User = auth.get_user_model()


# SODAR constants
PROJECT_TYPE_PROJECT = SODAR_CONSTANTS['PROJECT_TYPE_PROJECT']

# Local constants
APP_NAME = 'samplesheets.studyapps.cancer'

Expand Down Expand Up @@ -268,7 +268,6 @@ def update_cache(self, name=None, project=None, user=None):
if not cache_backend:
return

tb = SampleSheetTableBuilder()
projects = (
[project]
if project
Expand Down Expand Up @@ -301,7 +300,7 @@ def update_cache(self, name=None, project=None, user=None):
vcf_paths = {}

# Get/build render tables
study_tables = tb.get_study_tables(study)
study_tables = table_builder.get_study_tables(study)
for library in get_study_libraries(study, study_tables):
if not library.assay:
continue
Expand Down
6 changes: 4 additions & 2 deletions samplesheets/studyapps/cancer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from samplesheets.studyapps.cancer.utils import get_library_file_path


table_builder = SampleSheetTableBuilder()


class BaseCancerConfigView(
LoginRequiredMixin,
LoggedInPermissionMixin,
Expand Down Expand Up @@ -85,8 +88,7 @@ def get(self, request, *args, **kwargs):
return redirect(self.redirect_url)

# Get/build render tables
tb = SampleSheetTableBuilder()
study_tables = tb.get_study_tables(self.material.study)
study_tables = table_builder.get_study_tables(self.material.study)
# Get libraries
libraries = get_sample_libraries(samples, study_tables)
bam_urls = {}
Expand Down
4 changes: 2 additions & 2 deletions samplesheets/studyapps/germline/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)

logger = logging.getLogger(__name__)
table_builder = SampleSheetTableBuilder()
User = auth.get_user_model()


Expand Down Expand Up @@ -294,8 +295,7 @@ def _update_study_cache(cls, study, user, cache_backend, irods_backend):
bam_paths = {}
vcf_paths = {}
# Get/build render tables
tb = SampleSheetTableBuilder()
study_tables = tb.get_study_tables(study)
study_tables = table_builder.get_study_tables(study)

# Pre-fetch study objects to eliminate redundant queries
obj_len = 0
Expand Down
7 changes: 4 additions & 3 deletions samplesheets/studyapps/germline/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
from sodar.users.auth import fallback_to_auth_basic


table_builder = SampleSheetTableBuilder()


class BaseGermlineConfigView(
LoginRequiredMixin,
LoggedInPermissionMixin,
Expand Down Expand Up @@ -64,10 +67,8 @@ def get(self, request, *args, **kwargs):
if not settings.IRODS_WEBDAV_ENABLED or not settings.IRODS_WEBDAV_URL:
messages.error(self.request, 'iRODS WebDAV not available')
return redirect(self.redirect_url)

# Get/build render tables
tb = SampleSheetTableBuilder()
self.study_tables = tb.get_study_tables(self.source.study)
self.study_tables = table_builder.get_study_tables(self.source.study)


@fallback_to_auth_basic
Expand Down
4 changes: 2 additions & 2 deletions samplesheets/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

app_settings = AppSettingAPI()
logger = logging.getLogger(__name__)
table_builder = SampleSheetTableBuilder()


MD5_RE = re.compile(r'([a-fA-F\d]{32})')
Expand Down Expand Up @@ -399,11 +400,10 @@ def get(self, request, **kwargs):
# Rendered tables
if not isa or int(isa) != 1:
ret = {'studies': {}}
tb = SampleSheetTableBuilder()
# Get/build study tables
for study in investigation.studies.all():
try:
tables = tb.get_study_tables(study)
tables = table_builder.get_study_tables(study)
except Exception as ex:
return Response(str(ex), status=500)
ret['studies'][str(study.sodar_uuid)] = tables
Expand Down

0 comments on commit 4251014

Please sign in to comment.