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

Jkmarx/remove node group #1744

Merged
merged 18 commits into from
May 26, 2017
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
91 changes: 2 additions & 89 deletions refinery/analysis_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from .models import AnalysisStatus
from .tasks import run_analysis
from core.models import (Analysis, InvestigationLink, NodeGroup, NodePair,
from core.models import (Analysis, InvestigationLink, NodePair,
NodeRelationship, NodeSet, Workflow,
WorkflowDataInputMap, WorkflowEngine)
from core.utils import get_aware_local_time
Expand Down Expand Up @@ -177,103 +177,16 @@ def run(request):
workflow_uuid = analysis_config['workflowUuid']
study_uuid = analysis_config['studyUuid']
node_set_uuid = analysis_config['nodeSetUuid']
node_group_uuid = analysis_config['nodeGroupUuid']
node_relationship_uuid = analysis_config['nodeRelationshipUuid']
custom_name = analysis_config['name']
except KeyError:
return HttpResponseBadRequest() # 400
# must provide workflow and study UUIDs,
# and either node set UUID or node relationship UUID
if not (workflow_uuid and study_uuid and
(node_set_uuid or node_relationship_uuid or node_group_uuid)):
(node_set_uuid or node_relationship_uuid)):
return HttpResponseBadRequest() # 400

# single-input workflow based node group
if node_group_uuid:
try:
curr_node_group = NodeGroup.objects.get(uuid=node_group_uuid)
except NodeGroup.DoesNotExist:
logger.error("Node Group with UUID '{}' does not exist".format(
node_group_uuid))
return HttpResponse(status='404')
except NodeGroup.MultipleObjectsReturned:
logger.error("Node Group with UUID '{}' returned multiple "
"objects".format(node_group_uuid))
return HttpResponse(status='500')

try:
curr_workflow = Workflow.objects.get(uuid=workflow_uuid)
except Workflow.DoesNotExist:
logger.error("WorkFlow with UUID '{}' does not exist".format(
workflow_uuid))
return HttpResponse(status='404')
except Workflow.MultipleObjectsReturned:
logger.error("WorkFlow with UUID '{}' returns multiple objects"
.format(workflow_uuid))
return HttpResponse(status='500')

try:
study = Study.objects.get(uuid=study_uuid)
except Study.DoesNotExist:
logger.error("Study with UUID '{}' does not exist".format(
study_uuid))
return HttpResponse(status='404')
except Study.MultipleObjectsReturned:
logger.error("Study with UUID '{}' returns multiple objects"
.format(study_uuid))
return HttpResponse(status='500')

investigation_links = InvestigationLink.objects.filter(
investigation__uuid=study.investigation.uuid).order_by(
"version")
if not investigation_links:
logger.error("InvestigationLink with UUID '{}' with does not "
"exist".format(study.investigation.uuid))
return HttpResponse(status='404')

data_set = investigation_links.reverse()[0].data_set
logger.info("Associating analysis with data set %s (%s)",
data_set, data_set.uuid)

# ANALYSIS MODEL
# How to create a simple analysis object
if not custom_name:
temp_name = curr_workflow.name + " " + get_aware_local_time()\
.strftime("%Y-%m-%d @ %H:%M:%S")
else:
temp_name = custom_name

summary_name = "None provided."
analysis = Analysis.objects.create(
summary=summary_name,
name=temp_name,
project=request.user.profile.catch_all_project,
data_set=data_set,
workflow=curr_workflow,
time_start=timezone.now()
)
analysis.set_owner(request.user)

# getting distinct workflow inputs
try:
workflow_data_inputs = curr_workflow.data_inputs.all()[0]
except IndexError:
logger.error("Workflow with UUID '{}' has an index "
"error with inputs".format(workflow_uuid.uuid))
return HttpResponse(status='500')

# NEED TO GET LIST OF FILE_UUIDS from node_group_uuid fields
count = 0
for node_file in curr_node_group.nodes.all():
count += 1
temp_input = WorkflowDataInputMap.objects.create(
workflow_data_input_name=workflow_data_inputs.name,
data_uuid=node_file.uuid,
pair_id=count
)
analysis.workflow_data_input_maps.add(temp_input)
analysis.save()

# single-input workflow
if node_set_uuid:
# TODO: handle DoesNotExist exception
Expand Down
33 changes: 33 additions & 0 deletions refinery/core/migrations/0006_auto_20170524_1554.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0005_ontology_data'),
]

operations = [
migrations.AlterUniqueTogether(
name='nodegroup',
unique_together=None,
),
migrations.RemoveField(
model_name='nodegroup',
name='assay',
),
migrations.RemoveField(
model_name='nodegroup',
name='nodes',
),
migrations.RemoveField(
model_name='nodegroup',
name='study',
),
migrations.DeleteModel(
name='NodeGroup',
),
]
34 changes: 0 additions & 34 deletions refinery/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,40 +1887,6 @@ def create_manager_group(sender, instance, created, **kwargs):
post_save.connect(create_manager_group, sender=ExtendedGroup)


class NodeGroup(SharableResource, TemporaryResource):
"""A collection of Nodes representing data files.
Used to save selection state between sessions and to map data files to
workflow inputs.
"""

#: Number of nodes in the NodeSet (provided in POST/PUT/PATCH requests)
node_count = models.IntegerField(default=0)
#: Implicit node is created "on the fly" to support an analysis while
#: explicit node is created by the user to store a particular selection
is_implicit = models.BooleanField(default=False)
study = models.ForeignKey(Study)
assay = models.ForeignKey(Assay)
# The "current selection" node set for the associated study/assay
is_current = models.BooleanField(default=False)
# Nodes in the group, using uuids are foreign-key
nodes = models.ManyToManyField(Node, blank=True,
null=True)

class Meta:
unique_together = ["assay", "name"]
verbose_name = "node group"
permissions = (
('read_%s' % verbose_name, 'Can read %s' % verbose_name),
('share_%s' % verbose_name, 'Can share %s' % verbose_name),
)

def __unicode__(self):
return (
self.name + ("*" if self.is_current else "") + " - " +
self.get_owner_username()
)


class NodeSet(SharableResource, TemporaryResource):
"""A collection of Nodes representing data files.
Used to save selection state between sessions and to map data files to
Expand Down
52 changes: 2 additions & 50 deletions refinery/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from rest_framework import serializers
from rest_framework.validators import UniqueValidator

from .models import DataSet, NodeGroup, Workflow
from data_set_manager.models import Assay, Node, Study
from .models import DataSet, Workflow
from data_set_manager.models import Node
from file_store.models import FileStoreItem


Expand Down Expand Up @@ -46,54 +46,6 @@ def partial_update(self, instance, validated_data):
return instance


class NodeGroupSerializer(serializers.ModelSerializer):
# Slug related field associated uuids with model
nodes = serializers.SlugRelatedField(
many=True, slug_field='uuid',
queryset=Node.objects.all(),
required=False, allow_null=True)
assay = serializers.SlugRelatedField(
queryset=Assay.objects.all(),
slug_field='uuid')
study = serializers.SlugRelatedField(
queryset=Study.objects.all(),
slug_field='uuid')

class Meta:
model = NodeGroup
fields = ('uuid', 'node_count', 'is_implicit', 'study',
'assay', 'is_current', 'nodes', 'name')

def create(self, validated_data):
node_group = NodeGroup.objects.create(
study=validated_data.get('study'),
assay=validated_data.get('assay'),
name=validated_data.get('name'),
is_current=validated_data.get('is_current', False),
)
# Add foreign keys after object is created
if validated_data.get('nodes'):
node_group.nodes.add(*validated_data.get('nodes'))
node_group.node_count = len(validated_data.get('nodes'))
node_group.save()

return node_group

def update(self, instance, validated_data):
"""
Update and return an existing `NodeGroup` instance, given the
validated data.
"""
if validated_data.get('nodes'):
instance.nodes = validated_data.get('nodes', instance.nodes)
instance.node_count = len(validated_data.get('nodes'))

instance.is_current = validated_data.get('is_current',
instance.is_current)
instance.save()
return instance


class WorkflowSerializer(serializers.HyperlinkedModelSerializer):
instance = serializers.HyperlinkedIdentityField(
view_name='workflow-detail')
Expand Down