Skip to content

Commit

Permalink
mri_glmfit. #NF. Can now handle perm sim with PVRs
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Greve committed Feb 21, 2022
1 parent ecb154f commit 64984b4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
48 changes: 45 additions & 3 deletions mri_glmfit/mri_glmfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,10 @@ double round(double x);
#include "dti.h"
#include "image.h"
#include "stats.h"
#include "evschutils.h"

int MRISmaskByLabel(MRI *y, MRIS *surf, LABEL *lb, int invflag);
int RandPermMatrixAndPVR(MATRIX *X, MRI **pvrs, int npvrs);

static int parse_commandline(int argc, char **argv);
static void check_options(void);
Expand Down Expand Up @@ -1738,11 +1740,11 @@ int main(int argc, char **argv) {
SmoothSurfOrVol(surf, mriglm->y, mriglm->mask, SmoothLevel);
}
if (!strcmp(csd->simtype,"perm")) {
if (!OneSamplePerm) MatrixRandPermRows(mriglm->Xg);
if (!OneSamplePerm) RandPermMatrixAndPVR(mriglm->Xg,mriglm->pvr,mriglm->npvr);
else {
for (n=0; n < mriglm->y->nframes; n++) {
if (drand48() > 0.5) m = +1;
else m = -1;
else m = -1;
mriglm->Xg->rptr[n+1][1] = m;
}
//MatrixPrint(stdout,mriglm->Xg);
Expand Down Expand Up @@ -3645,7 +3647,8 @@ static void check_options(void) {
exit(1);
}

if(DoSim && !strcmp(csd->simtype,"perm") && npvr != 0){
if(0 && DoSim && !strcmp(csd->simtype,"perm") && npvr != 0){
// Modified to allow for pvrs with sim
printf("ERROR: PVR is not supported with permutation simulations\n");
exit(1);
}
Expand Down Expand Up @@ -4140,6 +4143,45 @@ int MRIloganize(MATRIX **X, MRI **Ct, MRI **intCt, const MATRIX *t, const double
return(0);
}

/*!
\fn int RandPermMatrixAndPVR(MATRIX *X, MRI **pvrs, int npvrs)
\brief Permutes both the design matrix and any PVRs
*/
int RandPermMatrixAndPVR(MATRIX *X, MRI **pvrs, int npvrs)
{
int *NewRowOrder, r;
MATRIX *X0;

NewRowOrder = RandPerm(X->rows, NULL);
for (r = 0; r < X->rows; r++) {
NewRowOrder[r]++; // Make one-based
printf("%d\n",NewRowOrder[r]);
}
X0 = MatrixCopy(X, NULL);
MatrixReorderRows(X0, NewRowOrder, X);

int n;
for(n=0; n < npvrs; n++){
int c,r,f;
MRI *pvr = pvrs[n];
for(c=0; c < pvr->width; c++){
double *vect = (double *) calloc(sizeof(double),X->rows);
for(r=0; r < pvr->height; r++){
for(s=0; s < pvr->depth; s++){
for(f=0; f < X->rows; f++) vect[f] = MRIgetVoxVal(pvr,c,r,s,f);
for(f=0; f < X->rows; f++) {
int f2 = NewRowOrder[f] - 1;
MRIsetVoxVal(pvr,c,r,s,f, vect[f2]);
}
}
}
free(vect);
}
}

free(NewRowOrder);
return (0);
}



5 changes: 5 additions & 0 deletions scripts/mri_glmfit-sim
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ echo $glmfitcmd
set gd2mtx = dods
set UseTable = 0;
set label = ();
set pvrlist = ()
while($#glmfitcmd)
set flag = $glmfitcmd[1]; shift glmfitcmd;
#echo $flag
Expand Down Expand Up @@ -250,6 +251,7 @@ while($#glmfitcmd)
breaksw
case "--pvr"
set IsPVR = 1;
set pvrlist = ($pvrlist $glmfitcmd[1]);
shift glmfitcmd;
breaksw
# Ignore these options that have two args
Expand Down Expand Up @@ -457,6 +459,9 @@ if($DoSim) then
if($#X) set cmd = ($cmd --X $X)
if($#wls) set cmd = ($cmd --wls $wls)
if($#framemask) set cmd = ($cmd --frame-mask $framemask)
foreach pvr ($pvrlist)
set cmd = ($cmd --pvr $pvr)
end
# --y must go after --fsgd
if(! $UseTable) then
set cmd = ($cmd --mask $mask)
Expand Down

0 comments on commit 64984b4

Please sign in to comment.