Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from joshicola/GEAR-2399/load_paired_files
Browse files Browse the repository at this point in the history
Support for mhd:raw, hdr:img
  • Loading branch information
jiavila authored Jun 7, 2022
2 parents b31e162 + e910bad commit 81df655
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
2 changes: 0 additions & 2 deletions FlywheelConnect/flywheel_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
41 changes: 41 additions & 0 deletions FlywheelConnect/management/fw_container_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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.
Expand All @@ -383,11 +415,20 @@ 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])
file_parent.download_file(self.file.name, str(file_path))
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
3 changes: 3 additions & 0 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

0 comments on commit 81df655

Please sign in to comment.