<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p><span id="ms-rterangepaste-start"></span></p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
Hi everyone, I wrap a matlab script, in the matlab function, I didnt define the output, but I will save some output images to a specific folder, and I use the MatlabCommand in Nipype, so here is my NIpype code:</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
from nipype.interfaces.utility import Function<br style="box-sizing: border-box;">
import nipype.pipeline.engine as pe </p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
def runmatlab(ContrastLinearModel, Format, CSVFilenames, PATH_TO_RECON_ALL_OUTPUTS, a_required_path):<br style="box-sizing: border-box;">
    from nipype.interfaces.matlab import MatlabCommand<br style="box-sizing: border-box;">
    matlab = MatlabCommand()<br style="box-sizing: border-box;">
    matlab.inputs.paths = [a_required_path]# this is the path to add into matlab, addpath<br style="box-sizing: border-box;">
    matlab.inputs.script = """<br style="box-sizing: border-box;">
    NipypeSurfStat('%s', '%s', '%s', '%s')"""%(ContrastLinearModel, Format, <br style="box-sizing: border-box;">
                                 CSVFilenames, PATH_TO_RECON_ALL_OUTPUTS )  <br style="box-sizing: border-box;">
    matlab.inputs.mfile = True # this will create a file: pyscript.m , the pyscript.m is the default name<br style="box-sizing: border-box;">
    out = matlab.run()<br style="box-sizing: border-box;">
    return out</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<br style="box-sizing: border-box;">
a_required_path = '/aramis/dataARAMIS/users/junhao.wen/Data_AD_CN/Group_analysis/SurfStat/Junhao_script/Code/NipypeSurfStat'<br style="box-sizing: border-box;">
#output_dir = '/aramis/dataARAMIS/users/junhao.wen/Data_AD_CN/Group_analysis/SurfStat/Junhao_script/Figures'<br style="box-sizing: border-box;">
PATH_TO_RECON_ALL_OUTPUTS = '/aramis/dataARAMIS/users/junhao.wen/Data_AD_CN/ADNI_60_AD_CN_object_recon_all_output';<br style="box-sizing: border-box;">
CSVFilenames     = '/aramis/dataARAMIS/users/junhao.wen/Data_AD_CN/Group_analysis/SurfStat/Junhao_script/Database/GroupAnalysisDataAramis/60_AD_CN_GROUPT_ANALYSIS.csv';<br style="box-sizing: border-box;">
Format = '%s %s %s %f';<br style="box-sizing: border-box;">
ContrastLinearModel = '1 + Label';</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
SurfStat = pe.Node(name='SurfStat',<br style="box-sizing: border-box;">
               interface=Function(input_names=['ContrastLinearModel', 'Format', 'CSVFilenames', <br style="box-sizing: border-box;">
                                     'PATH_TO_RECON_ALL_OUTPUTS', 'a_required_path'],<br style="box-sizing: border-box;">
                                  output_names=['out_file'],<br style="box-sizing: border-box;">
                                  function=runmatlab))<br style="box-sizing: border-box;">
SurfStat.inputs.ContrastLinearModel = ContrastLinearModel<br style="box-sizing: border-box;">
SurfStat.inputs.Format = Format<br style="box-sizing: border-box;">
SurfStat.inputs.CSVFilenames = CSVFilenames<br style="box-sizing: border-box;">
SurfStat.inputs.PATH_TO_RECON_ALL_OUTPUTS = PATH_TO_RECON_ALL_OUTPUTS<br style="box-sizing: border-box;">
SurfStat.inputs.a_required_path = a_required_path</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
SurfStat.run()</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
 </p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
But I got some error, and I checked my matlab script, it is caused by this line, </p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<strong style="box-sizing: border-box; font-weight: bold;">save2jpeg(strcat('Figures/', fileName, '/ContrastPositive-TValue.jpg')); </strong></p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
The error from my nipype is :</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<strong style="box-sizing: border-box; font-weight: bold;">Standard error:<br style="box-sizing: border-box;">
Segmentation fault (core dumped)</strong></p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<strong style="box-sizing: border-box; font-weight: bold;">Return code: 139<br style="box-sizing: border-box;">
Interface MatlabCommand failed to run. <br style="box-sizing: border-box;">
Interface Function failed to run. </strong></p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
I googled, they give me this explaination:</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<strong style="box-sizing: border-box; font-weight: bold;"><span style="box-sizing: border-box;">1. Very basically, it means your program is trying to access a memory area it is not suposed to.</span></strong></p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<strong style="box-sizing: border-box; font-weight: bold;">2. To the current directoy.</strong></p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<strong style="box-sizing: border-box; font-weight: bold;">3. You need to make sure your program doesn't do 1.</strong>.</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
 </p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
I have been stucked by this for a long time, any advice will be appreciated:)</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
Good day! Bonne journée!</p>
<p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.5714302062988px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
Hao</p>
<span id="ms-rterangepaste-end"></span><br>
<p></p>
</div>
</body>
</html>