Skip to content

Commit

Permalink
ROCrates for workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaskavouras committed Feb 4, 2021
1 parent 8f1a3c2 commit c26056e
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 52 deletions.
67 changes: 48 additions & 19 deletions components/RoCrateModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use app\models\SoftwareMpi;
use app\models\Workflow;
use app\models\SoftwareInput;
use app\models\WorkflowInput;
use app\models\RoCrate;
use yii\widgets\ActiveForm;

Expand All @@ -25,18 +26,40 @@ public static function addModal($jobid)
$download_icon='<i class="fas fa-question-circle" title="Download a local copy of the RO-Crate object to be produced"></i>';
$edit_icon='<i class="fas fa-pencil-alt"></i>';
$download_icon='<i class="fas fa-download"></i>';

$required='<span style="color:red">*</span>';

$history=RunHistory::find()->where(['jobid'=>$jobid])->one();
$software_id=$history->software_id;
$software=Software::find()->where(['id'=>$software_id])->one();

$public_url='';
$image_url='';

if($history->type=='job')
{
$software=Software::find()->where(['id'=>$software_id])->one();
$soft_type='Software';
$fields=SoftwareInput::find()->where(['softwareid'=>$software_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Software::getRerunFieldValues($jobid,$fields);
}
elseif ($history->type=='workflow')
{
$workflow=Workflow::find()->where(['id'=>$software_id])->one();
$soft_type='Workflow';
$fields=WorkflowInput::find()->where(['workflow_id'=>$software_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Workflow::getRerunFieldValues($jobid,$fields);

}


$model=RoCrate::find()->where(['jobid'=>$jobid])->one();

//print_r($history->jobid);
$disabled_fields=false;
if(!empty($model))
{
$disabled_fields=true;
}
$image_url='';

$disabled=false;
if ((!empty($software)) && (empty($model->software_url)))
{
Expand All @@ -46,16 +69,19 @@ public static function addModal($jobid)
$disabled=true;
$image=$software->original_image;
$image_url='https://hub.docker.com/r/'.$image;


}

}
elseif ((!empty($software)) && (!empty($model->software_url)))
elseif ((!empty($software) || (!empty($workflow))) && (!empty($model->software_url)))
{
$image_url=$model->software_url;
}

$fields=SoftwareInput::find()->where(['softwareid'=>$software_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Software::getRerunFieldValues($jobid,$fields);




$field_to_url=[];
if(empty($model))
Expand Down Expand Up @@ -92,19 +118,32 @@ public static function addModal($jobid)

echo Html::hiddenInput('softname',$history->softname);
echo Html::hiddenInput('softversion',$history->softversion);



echo "<div class='modal fade' tabindex='-1' role='dialog' id='experiment-modal-$jobid' aria-labelledby='experiment-modal' aria-hidden='true'>";
echo '<div class="modal-dialog modal-dialog-centered modal-lg modal-size" role="document">';
echo '<div class="modal-content" >';
echo '<div class="modal-header">';
echo "<div class='modal-title text-center size' id='exampleModalLongTitle'>RO-Crate object details</div>";
echo "<div class='modal-title text-center size' id='exampleModalLongTitle'>RO-Crate object details &nbsp; &nbsp;"
. Html::img('@web/img/ro-crate.svg', ['width'=>'15%'])."</div>";
echo '</div>';
echo '<div class="rocrate-description">RO-Crate is a community effort to establish a lightweight approach to packaging research data with their metadata. For more details please visit the official '. Html::a('RO-Crate webpage','http://www.researchobject.org/ro-crate/', ['target'=>'_blank']).'.</div>';
echo '<div class="inputs">';
echo '<div class="modal-body modal-size">';
echo '<div class="row body-row">';
echo "<span class='col-md-7 field-row'>Software public URL $required $software_icon : </span>";
echo "<span class='col-md-7 field-row'>$soft_type public URL $required $software_icon : </span>";
echo '<span class="col-md-5" >'.$form->field($model,'software_url')->label("")->textInput(['value'=>$image_url, 'disabled'=>$disabled, 'disabled'=>$disabled_fields]).'</span>
</div>';
echo '<div class="row body-row">
<span class="col-md-7 field-row"> Public URL of the output dataset:</span>
<span class="col-md-5">'. $form->field($model,'output')->label("")
->textInput(['value'=>$model->output, 'disabled'=>$disabled_fields]).'</span>';
echo '</div>';
echo "<div class='row body-row'>
<span class='col-md-7 field-row'> Publication DOI $publication_icon :</span>
<span class='col-md-5'>". $form->field($model,'publication')->label("")
->textInput(['value'=>$model->publication, 'disabled'=>$disabled_fields])."</span>
</div>";
echo "<div class='input-file-fields'>";
$i=0;

Expand All @@ -125,16 +164,6 @@ public static function addModal($jobid)
}
}
echo "</div>";
echo '<div class="row body-row">
<span class="col-md-7 field-row"> Public URL of the output dataset:</span>
<span class="col-md-5">'. $form->field($model,'output')->label("")
->textInput(['value'=>$model->output, 'disabled'=>$disabled_fields]).'</span>';
echo '</div>';
echo "<div class='row body-row'>
<span class='col-md-7 field-row'> Publication DOI $publication_icon :</span>
<span class='col-md-5'>". $form->field($model,'publication')->label("")
->textInput(['value'=>$model->publication, 'disabled'=>$disabled_fields])."</span>
</div>";
echo '</div>';
echo '</div>';
echo '<div class="modal-footer">';
Expand Down
46 changes: 36 additions & 10 deletions controllers/SoftwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use webvimark\modules\UserManagement\models\User;
use app\models\RunHistory;
use app\models\SoftwareInput;
use app\models\WorkflowInput;
use app\models\Workflow;
use yii\data\Pagination;

Expand Down Expand Up @@ -1653,10 +1654,21 @@ public function actionCreateExperiment($jobid)

$model=new RoCrate();
$history=RunHistory::find()->where(['jobid'=>$jobid])->one();
$software_id=$history->software_id;
$software=Software::find()->where(['id'=>$software_id])->one();
$fields=SoftwareInput::find()->where(['softwareid'=>$software_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Software::getRerunFieldValues($jobid,$fields);
if($history->type=='job')
{
$software_id=$history->software_id;
$software=Software::find()->where(['id'=>$software_id])->one();
$fields=SoftwareInput::find()->where(['softwareid'=>$software_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Software::getRerunFieldValues($jobid,$fields);
}
else
{
$workflow_id=$history->software_id;
$software=Workflow::find()->where(['id'=>$workflow_id])->one();
$fields=WorkflowInput::find()->where(['workflow_id'=>$workflow_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Workflow::getRerunFieldValues($jobid,$fields);

}


$input_data=[];
Expand All @@ -1682,18 +1694,32 @@ public function actionCreateExperiment($jobid)
$software_name=$_POST['softname'];
$software_version=$_POST['softversion'];
$software_url=$model->software_url;
foreach ($model->input as $input_name=>$input_url)

if($model->input)
{
$input_data[$input_name]['url']=$input_url;

foreach ($model->input as $input_name=>$input_url)
{
$input_data[$input_name]['url']=$input_url;

}
}


$output_data=$model->output;
$publication=$model->publication;

$result=ROCrate::CreateROObject($jobid, $software_name,$software_version,$software_url,$input_data,$output_data,$publication);
$software=$result[0];
if($history->type=='job')
{
$result=ROCrate::CreateROObjectSoftware($jobid, $software_name,$software_version,$software_url,$input_data,$output_data,$publication);
}
else
{
$result=ROCrate::CreateROObjectWorkflow($jobid, $software_name,$software_version,$software_url,$input_data,$output_data,$publication);
}

//$workflow=$result[0];

// print_r($workflow);
// exit(0);

Yii::$app->session->setFlash('success', "$result[1]");
}
Expand Down
100 changes: 92 additions & 8 deletions models/RoCrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Yii;
use yii\helpers\Html;
use yii\helpers\Url;
use webvimark\modules\UserManagement\models\User;
use app\models\SoftwareInput;
use app\models\Software;
Expand Down Expand Up @@ -60,20 +61,14 @@ public function attributeLabels()
];
}

public function CreateROObject($jobid, $software_name,$software_version,$software_url,$input_data,$output_data,$publication)
public function CreateROObjectSoftware($jobid, $software_name,$software_version,$software_url,$input_data,$output_data,$publication)
{

$software=Software::find()->where(['name'=>$software_name])->andWhere(['version'=>$software_version])->one();
$software_id=$software->id;
$docker=$software->docker_or_local;
if(empty($software))
{
$software=Workflow::find()->where(['name'=>$software_name])->andWhere(['version'=>$software_version])->one();

}

$software_description=$software->description;
$location=empty($software->location)?"$software->cwl_path":"$software->location";
$location=$software->cwl_path;
$creator=explode('@',$software->uploaded_by)[0];


Expand Down Expand Up @@ -142,8 +137,97 @@ public function CreateROObject($jobid, $software_name,$software_version,$softwar
Html::a('here', ['software/download-rocrate', 'jobid'=>$jobid]). ".";

exec($command,$out,$ret);

// print_r($out);
// exit(0);

return [$software, $success];

}

public function CreateROObjectWorkflow($jobid, $software_name,$software_version,$software_url,$input_data,$output_data,$publication)
{

$workflow=Workflow::find()->where(['name'=>$software_name])->andWhere(['version'=>$software_version])->one();
$workflow_id=$workflow->id;


$workflow_description=$workflow->description;
$location=$workflow->original_file;
$creator=explode('@',$workflow->uploaded_by)[0];
$url = Url::base('https');
$image=$url. "/img/workflows/$workflow->visualize";



$ROCratesFolder=Yii::$app->params['ROCratesFolder'];

if (!is_dir($ROCratesFolder))
{
exec("mkdir $ROCratesFolder");
}
exec("chmod 777 $ROCratesFolder -R 2>&1",$out,$ret);

$fields=WorkflowInput::find()->where(['workflow_id'=>$workflow_id])->orderBy(['position'=> SORT_ASC])->all();
$fields=Workflow::getRerunFieldValues($jobid,$fields);
$field_names=[];
foreach ($fields as $field)
{
$field_names[]=$field->name;
}

$arguments=['software_name'=>$software_name,
'software_version'=>$software_version,
'software_description'=>$workflow_description,
'software_url'=>$software_url,
'output_data'=>['id'=>uniqid(), 'data'=>$output_data],
'publication'=>$publication,
'ROCratesFolder'=>$ROCratesFolder,
'location'=>$location,
'creator'=>$creator,
'jobid'=>$jobid,
'input_data'=>$input_data,
'number_of_inputs'=>count($input_data),
'field_names'=>$field_names,
'image'=>$image


];


$username=User::getCurrentUser()['username'];

$query=Yii::$app->db->createCommand()->delete('ro_crate',["jobid" => $jobid])->execute();

$query=Yii::$app->db->createCommand()->insert('ro_crate',
[
"username"=>$username,
"jobid" => $jobid,
'date'=>'NOW()',
'output'=>$output_data,
'input'=>json_encode($input_data),
'publication'=>$publication,
'software_url'=>$software_url,
]
)->execute();


$filepath=Yii::$app->params['ROCratesFolder']. 'arguments.json';
$arguments_file = fopen($filepath, "w");
fwrite($arguments_file, json_encode($arguments));
fclose($arguments_file);

$command="sudo -u ". Yii::$app->params['systemUser'] . " " . Yii::$app->params['scriptsFolder'] .
"ro-crate.py ";
$command.= "2>&1";

$success="ROCrate object has been created. You can download the ROCrate object by clicking ".
Html::a('here', ['software/download-rocrate', 'jobid'=>$jobid]). ".";

exec($command,$out,$ret);


return [$workflow, $success];

}
}
8 changes: 3 additions & 5 deletions scheduler_files/ro-crate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
data = json.load(f)


# inputs=data['input_data']['0']
# print(data['input_data']['0'])


# print(data['software_description'])

wf_path = data['location']
files_list = []

Expand All @@ -43,6 +39,8 @@
wf_crate.name = data['software_name']
wf_crate.description=data['software_description']
wf_crate.creator=data['creator']
print(data['image'])
wf_crate.image = data['image']

main_entity = entity.Entity(wf_crate, data['software_url'],
properties={
Expand All @@ -52,7 +50,7 @@
"@type": ["File", "SoftwareSourceCode"],
"input": [ "{@id: #" + data['input_data']["%s"%x]['id']+"}" for x in data['field_names']],
"output": [{"@id": "#" + data['output_data']['id']}],
"version": data['version']
"version": data['software_version']
},
)

Expand Down
4 changes: 3 additions & 1 deletion views/layouts/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@
<footer class="footer bg-light">
<div class="container">
<p class="pull-left">&copy; Athena RC <?= date('Y') ?></p>
<p class="col-md-offset-4 col-md-3"><?=$footerImageLink?></p>
<p class="powered col-md-2">Powered by <?= Html::a('Schema', 'https://github.com/athenarc/schema',
['target'=>'_blank'])?></p>
<p class="col-md-offset-2 col-md-3"><?=$footerImageLink?></p>
<p class="col-md-offset-1 col-md-2"><?=Html::a('Privacy & cookie policy','https://egci-beta.imsi.athenarc.gr/index.php?r=site/privacy')?></p>
<p class="pull-right"><?=$twitter_link?>&nbsp;<?=$youtube_link?></p>
</div>
Expand Down
Loading

0 comments on commit c26056e

Please sign in to comment.