diff --git a/FlywheelConnect/flywheel_connect.py b/FlywheelConnect/flywheel_connect.py index ebbad35..bf51acf 100644 --- a/FlywheelConnect/flywheel_connect.py +++ b/FlywheelConnect/flywheel_connect.py @@ -266,8 +266,6 @@ def onProjectSelected(self, item): self.tree_management.source_model.removeRows(0, tree_rows) self.loadFilesButton.enabled = False - self.segmentationButton.enabled = False - def is_compressed_dicom(self, file_path, file_type): """ Check file_path and file_type for a flywheel compressed dicom archive. diff --git a/FlywheelConnect/management/fw_container_items.py b/FlywheelConnect/management/fw_container_items.py index b6ec348..898175f 100644 --- a/FlywheelConnect/management/fw_container_items.py +++ b/FlywheelConnect/management/fw_container_items.py @@ -5,6 +5,11 @@ from PythonQt.QtCore import Qt from qt import QAbstractItemView +# Common paired file types +PAIRED_FILE_TYPES = { + "mhd": "raw", + "hdr": "img" +} class FolderItem(QtGui.QStandardItem): """ @@ -365,6 +370,33 @@ def _get_cache_path(self): file_path /= self.container.name return file_path + def _is_paired_type(self): + """ + Determine if this file is of a paired type. + + Returns: + bool: True or False of paired type. + """ + return self.container.name.split(".")[-1] in PAIRED_FILE_TYPES.keys() + + def _get_paired_file(self): + """ + Get the pair of current file, if exists + + Returns: + str: Name of paired file + """ + file_parent = self.parent_item.parent().container + fl_ext = self.container.name.split(".")[-1] + paired_ext = PAIRED_FILE_TYPES[fl_ext] + paired_file_name = self.container.name[:-len(fl_ext)] + paired_ext + + # file definition is retrieved or a None is returned. + if file_parent.get_file(paired_file_name): + return paired_file_name + else: + return None + def _is_cached(self): """ Check if file is cached. @@ -383,6 +415,7 @@ def _add_to_cache(self): """ file_path = self._get_cache_path() file_parent = self.parent_item.parent().container + if not file_path.exists(): if not file_path.parents[0].exists(): os.makedirs(file_path.parents[0]) @@ -390,4 +423,12 @@ def _add_to_cache(self): self.icon_path = "Resources/Icons/file_cached.png" self.setToolTip("File is cached.") self._set_icon() + # Check if this file is of a paired type + if self._is_paired_type(): + # attempt to find the paired type + paired_file_name = self._get_paired_file() + # if found, download the adjoining pair into original directory + if paired_file_name: + file_parent.download_file(paired_file_name, str(file_path.parents[0]/paired_file_name)) + return file_path, self.file_type diff --git a/INSTALLATION.md b/INSTALLATION.md index 4049789..fcb4240 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -11,3 +11,6 @@ Follow these steps to run a local copy of the extension: 1. Clone this github repository into a convenient location 2. Add the FlywheelConnect subfolder of the repository as an additional module path (in menu: Edit / Application settings -> Modules -> Additional module paths; either drag-and-drop the FlywheelConnect folder to the path list, or click the double-arrow button and then click Add and select the FlywheelConnect folder) 3. Restart the application + +## Bonus +In place of (2) above, install the DeveloperToolsForExtensions Extension and locate the FlywheelConnect folder in the Extension Wizard. diff --git a/README.md b/README.md index b45504b..3876b70 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A 3D Slicer Extension to view, select, and download images from a Flywheel insta Flywheel is a comprehensive data management solutions for life sciences and imaging research. More details at [https://flywheel.io/](https://flywheel.io/). -The Flywheel Connect 3D Slicer Extension is now in the [3D Slicer Extension Catalog](https://slicer.kitware.com/midas3/slicerappstore/extension/view?extensionId=460488) and available through the [3D Slicer Extensions Manager](https://slicer.readthedocs.io/en/latest/user_guide/extensions_manager.html) for direct installation. +The Flywheel Connect 3D Slicer Extension is now in the [3D Slicer Extension Catalog](https://extensions.slicer.org/view/flywheel_connect/30117/linux) and available through the [3D Slicer Extensions Manager](https://slicer.readthedocs.io/en/latest/user_guide/extensions_manager.html) for direct installation. ## Usage Instructions @@ -39,3 +39,6 @@ The interface is shown below. Notable areas are commented on: * H) Load all selected files. Files that are Slicer-supported data formats (Images and Models) will be loaded. This will only be enabled if files are selected. * I) Upload derived files to Flywheel Analysis or Container files. This will only be enabled if a single valid Flywheel Container is selected. * H) If checked, indicates that derived files should be uploaded to Flywheel as Analysis output under the selected Container. + +## ToDo +- [ ] Ensure that a created analysis downloads the necessary files to the cache if they are not already there.