예제 #1
0
 def test_fetch_objects_required_for_analyses_bad_workflow(self):
     with self.assertRaises(RuntimeError) as context:
         fetch_objects_required_for_analysis({
             "studyUuid": self.study.uuid,
             "user_id": self.user.id,
             "workflowUuid": "COFFEE"
         })
         self.assertIn("Couldn't fetch Workflow", context.exception.message)
예제 #2
0
 def test_fetch_objects_required_for_analyses_bad_user(self):
     with self.assertRaises(RuntimeError) as context:
         fetch_objects_required_for_analysis(
             {
                 "studyUuid": self.study.uuid,
                 "user_id": 400,
                 "workflowUuid": self.workflow.uuid
             }
         )
         self.assertIn("Couldn't fetch User", context.exception.message)
예제 #3
0
 def test_fetch_objects_required_for_analyses_bad_user(self):
     with self.assertRaises(RuntimeError) as context:
         fetch_objects_required_for_analysis(
             {
                 "study_uuid": self.study.uuid,
                 "user_id": 400,
                 "workflow_uuid": self.workflow.uuid
             }
         )
         self.assertIn("Couldn't fetch User", context.exception.message)
예제 #4
0
 def test_fetch_objects_required_for_analyses_bad_workflow(self):
     with self.assertRaises(RuntimeError) as context:
         fetch_objects_required_for_analysis(
             {
                 "study_uuid": self.study.uuid,
                 "user_id": self.user.id,
                 "workflow_uuid": "COFFEE"
             }
         )
         self.assertIn("Couldn't fetch Workflow", context.exception.message)
예제 #5
0
 def test_fetch_objects_required_for_analyses_bad_dataset(self):
     self.dataset.delete()
     with self.assertRaises(RuntimeError) as context:
         fetch_objects_required_for_analysis(
             {
                 "studyUuid": self.study.uuid,
                 "user_id": self.user.id,
                 "workflowUuid": self.workflow.uuid
             }
         )
         self.assertIn("Couldn't fetch DataSet", context.exception.message)
예제 #6
0
def create_tool_analysis(validated_analysis_config):
    """
    Create an Analysis instance from a validated analysis config with
    Tool information
    :param validated_analysis_config: a dict including the necessary
    information to create an Analysis that has been validated prior by
    `analysis_manager.utils.validate_analysis_config`
    :return: an Analysis instance
    :raises: RuntimeError
    """

    # Input list for running analysis
    common_analysis_objects = (
        fetch_objects_required_for_analysis(validated_analysis_config))
    name = validated_analysis_config["name"]
    current_workflow = common_analysis_objects["current_workflow"]
    data_set = common_analysis_objects["data_set"]
    user = common_analysis_objects["user"]

    try:
        tool = Tool.objects.get(uuid=validated_analysis_config["toolUuid"])
    except (Tool.DoesNotExist, Tool.MultipleObjectsReturned) as e:
        raise RuntimeError("Couldn't fetch Tool from UUID: {}".format(e))

    analysis = AnalysisFactory(summary="Analysis run for: {}".format(tool),
                               name=name,
                               project=user.profile.catch_all_project,
                               data_set=data_set,
                               workflow=current_workflow,
                               time_start=timezone.now())
    analysis.set_owner(user)
    return analysis
예제 #7
0
 def test_fetch_objects_required_for_analyses(self):
     self.assertEqual(
         fetch_objects_required_for_analysis({
             "studyUuid":
             self.study.uuid,
             "user_id":
             self.user.id,
             "workflowUuid":
             self.workflow.uuid
         }), {
             "user": self.user,
             "current_workflow": self.workflow,
             "data_set": self.dataset,
         })
예제 #8
0
 def test_fetch_objects_required_for_analyses(self):
     self.assertEqual(
         fetch_objects_required_for_analysis(
             {
                 "study_uuid": self.study.uuid,
                 "user_id": self.user.id,
                 "workflow_uuid": self.workflow.uuid
             }
         ),
         {
             "user": self.user,
             "current_workflow": self.workflow,
             "data_set": self.dataset,
         }
     )
예제 #9
0
def create_tool_analysis(validated_analysis_config):
    """
    Create an Analysis instance from a validated analysis config with
    Tool information
    :param validated_analysis_config: a dict including the necessary
    information to create an Analysis that has been validated prior by
    `analysis_manager.utils.validate_analysis_config`
    :return: an Analysis instance
    :raises: RuntimeError
    """
    common_analysis_objects = (
        fetch_objects_required_for_analysis(validated_analysis_config)
    )
    current_workflow = common_analysis_objects["current_workflow"]
    data_set = common_analysis_objects["data_set"]
    user = common_analysis_objects["user"]

    try:
        tool = WorkflowTool.objects.get(
            uuid=validated_analysis_config["toolUuid"]
        )
    except (WorkflowTool.DoesNotExist,
            WorkflowTool.MultipleObjectsReturned) as e:
        raise RuntimeError("Couldn't fetch Tool from UUID: {}".format(e))

    analysis = AnalysisFactory(
        uuid=str(uuid.uuid4()),
        summary="Galaxy workflow execution for: {}".format(tool.name),
        name="{} - {} - {}".format(
            tool.get_tool_name(),
            get_aware_local_time().strftime("%Y/%m/%d %H:%M:%S"),
            tool.get_owner_username().title()
        ),
        project=user.profile.catch_all_project,
        data_set=data_set,
        workflow=current_workflow,
        time_start=timezone.now()
    )
    analysis.set_owner(user)
    return analysis