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

Fix invocation of shapeworks commands #216

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion dev/django.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ RUN pip install -U pip && \
pip install --editable /opt/django-project[dev] && \
pip install --editable /opt/django-project/swcc

RUN curl -L -o /tmp/shapeworks.tgz https://api.github.com/repos/SCIInstitute/ShapeWorks/tarball/dev-linux
RUN export url=$(curl -s https://api.github.com/repos/SCIInstitute/ShapeWorks/releases | grep -o "http.*dev-linux.*${6:-tar.gz}"); \
curl -L -o /tmp/shapeworks.tgz $url
RUN mkdir /opt/shapeworks && \
tar -zxvf /tmp/shapeworks.tgz -C /opt/shapeworks --strip-components 1 && \
rm /tmp/shapeworks.tgz
Expand Down
41 changes: 29 additions & 12 deletions shapeworks_cloud/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from shapeworks_cloud.core import models
from swcc.api import swcc_session
from swcc.models import Project as SWCCProject
from swcc.models.constants import expected_key_prefixes
from swcc.models.project import ProjectFileIO


Expand All @@ -26,6 +27,9 @@ def edit_swproj_section(filename, section_name, new_df):
data[section_name]['shape'] = new_contents
else:
data[section_name] = new_contents
data['data'] = [
{k: v.replace('../', '').replace('./', '') for k, v in row.items()} for row in data['data']
]
with open(filename, 'w') as f:
json.dump(data, f)

Expand Down Expand Up @@ -133,9 +137,15 @@ def post_command_function(project, download_dir, result_data, project_filename):
subject__dataset__id=project.dataset.id
)
project_meshes = models.Mesh.objects.filter(subject__dataset__id=project.dataset.id)
for row in result_data['data']:
source_filename = row['shape_1'].split('/')[-1]
result_file = Path(download_dir, row['groomed_1'])
for entry in result_data['data']:
row = {}
for key in entry.keys():
prefixes = [p for p in expected_key_prefixes if key.startswith(p)]
if len(prefixes) > 0:
row[prefixes[0]] = entry[key].replace('../', '').replace('./', '')

source_filename = row['shape'].split('/')[-1]
result_file = Path(download_dir, row['groomed'])
try:
target_object = project_segmentations.get(
file__endswith=source_filename,
Expand All @@ -153,7 +163,7 @@ def post_command_function(project, download_dir, result_data, project_filename):
mesh=target_object,
)
result_object.file.save(
row['groomed_1'],
row['groomed'],
open(result_file, 'rb'),
)

Expand All @@ -178,8 +188,15 @@ def post_command_function(project, download_dir, result_data, project_filename):
# make new objects in database
project_groomed_segmentations = models.GroomedSegmentation.objects.filter(project=project)
project_groomed_meshes = models.GroomedMesh.objects.filter(project=project)
for row in result_data['data']:
groomed_filename = row['groomed_1'].split('/')[-1]

for entry in result_data['data']:
row = {}
for key in entry.keys():
prefixes = [p for p in expected_key_prefixes if key.startswith(p)]
if len(prefixes) > 0:
row[prefixes[0]] = entry[key].replace('../', '').replace('./', '')

groomed_filename = row['groomed'].split('/')[-1]
target_segmentation = project_groomed_segmentations.filter(
file__endswith=groomed_filename,
).first()
Expand All @@ -192,16 +209,16 @@ def post_command_function(project, download_dir, result_data, project_filename):
project=project,
)
result_particles_object.world.save(
row['world_particles_1'].split('/')[-1],
open(Path(download_dir, row['world_particles_1']), 'rb'),
row['world'].split('/')[-1],
open(Path(download_dir, row['world']), 'rb'),
)
result_particles_object.local.save(
row['local_particles_1'].split('/')[-1],
open(Path(download_dir, row['local_particles_1']), 'rb'),
row['local'].split('/')[-1],
open(Path(download_dir, row['local']), 'rb'),
)
result_particles_object.transform.save(
'.'.join(row['shape_1'].split('/')[-1].split('.')[:-1]) + '.transform',
ContentFile(str(row['alignment_1']).encode()),
'.'.join(row['shape'].split('/')[-1].split('.')[:-1]) + '.transform',
ContentFile(str(row['alignment']).encode()),
)

run_shapeworks_command(
Expand Down
1 change: 1 addition & 0 deletions swcc/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ envlist =
skipsdist = true
skip_install = true
deps =
flake8<6
flake8-black
flake8-bugbear
flake8-docstrings
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ envlist =
skipsdist = true
skip_install = true
deps =
flake8<6
flake8-black
flake8-bugbear
flake8-docstrings
Expand Down