Hi All,

I was able to solve this problem by replacing each variable in the template design.fsf file in it's original place using the 'sed' command (kudos to MH for the solution). This method produces a design.fsf that is identical to the one produced by the feat gui.

Here is an example in case anyone's interested:

(1) For each field in the template_design.fsf that I wanted to customize, I replaced it with a unique text string (can't appear anywhere else in the file):
set fmri(custom1) "EV1"
(2) Then I copied the template_design.fsf to a unique design.fsf file for that particular subject/run
cp <path to template_design.fsf> unique_design.fsf
(3) Then in my script, I assign <path to the EV file> to a variable (can be the same as in the template, I just didn't want to confuse things here), and replace the text string with the new variable using 'sed'
export EV_1=<path to the EV file>
sed -i "s@EV1@${EV_1}@g" unique_design.fsf
(4) Then after doing this for each variable, I simply point feat to the .fsf file
feat Unique_design.fsf

Works like a charm. Thanks to everyone for their help.

Cheers,
Pete

P.S. The usage of 'sed' is a bit confusing, especially with variables. Here's a good guide: http://unstableme.blogspot.com/2008/03/accessing-external-variable-in-awk-and.html
 



On Jun 19, 2012, at 11:20 AM, Michael Harms wrote:


Hi Peter,
I don't know what the glitch is, but could you modify your script to
"replace" (e.g., using 'sed') the lines in place, rather than appending
them to the end of the file?

Or, make a test case with just a single EV or two, and then run it
through your script.  In that case, 'diff'ing the files should be
manageable and you should be able to establish whether it is truly an
issue with the order, or if there is some hidden error/variable that
isn't being set correctly.

cheers,
-MH


On Jun 19, 2012, at 12:31 PM, Christine Zakrzewski wrote:

This is not exactly clear, where the problem is. The problem I still maintain is with your script.
How bout you try this?
(1) Set up everything in the FEAT gui and save it as MY_FEAT_TEMPLATE.fsf
(2) edit a single design matrix with the gui
(3) save as my_new_design_matrix
(3) cp /directory_to_my_new_design_matrix /directory_to_each_subjects_design.fsf/new_design_matrix
(4) echo -e "set fmri(outputdir) " '"'<path of my data directory>'"' >> <path to new design.fsf>
     it is not really clear what youre are doing here?
(5) mv new_design_matrix to same directory as design.fsf--if it isnt already
(6) feat new_design_matrix
Good luck.
CZ

Date: Tue, 19 Jun 2012 11:07:49 -0400
From: [log in to unmask]
Subject: Re: [FSL] FEAT: custom design.fsf fails with command-line, works in gui
To: [log in to unmask]

Hi Christine,

Thanks for your response. Unfortunately, my problem doesn't  stem from a difficulty in running the feat from the command line per se (I have done this in the past many times with success). The problem appear to be in the way the feat_model loads a design.fsf file which has custom EVs at the end of the file:

Feat main script
/bin/cp <path of new design.fsf> design.fsf
$FSLDIR/bin/feat_model design
Can't open "<the first custom EV file> for reading

The process I have been using is to: 
(1) Set up everything in the FEAT gui and save it as MY_FEAT_TEMPLATE.fsf

(2) Then edit the template and comment out those variables which are specific to the subject and task:

# Output directory
#*******Postpone until end*******

(3) Then my bash script copies the template to a unique deisgn.fsf file and adds the variables back in at the end of the file: 

echo -e "set fmri(outputdir) " '"'<path of my data directory>'"' >> <path to new design.fsf>

(4) And at the end of the script I simply point FEAT to the new design.fsf
feat <path to new design.fsf>

As I mentioned, FEAT (cmd line) loads the file but feat_model fails b/c it is unable to open the first custom EV file (even though it exists and FEAT is actually able to copy it just fine). However if I load the same design.fsf file into the FEAT (gui) everything is fine. Presumably this because the gui creates a tmp design.fsf file with all the commands/variables in their proper order.

In short, there seems to be something unique about EV files that prevents feat_model from loading them if they are called at the end of the file. This has not been the case with any other variable. The only work around I can think of is to separate MY_FEAT_TEMPLATE.fsf into multiple parts so that the bash script creates it with command,

set fmri(custom1) "<path to first EV file>"

in it's original order within the file.

Unless of course anyone has a different solution. Thanks.

Cheers,
Pete



For some reason though, t is failing to open the EV files even though it is copying them??
On Jun 18, 2012, at 8:02 PM, Christine Zakrzewski wrote:

I think I understand what may be going on.  When moving from using the command line to writing scripts, you need to first get the conception of flow statements.  It sounds like you may want to make use of a for loop. the script should read something like:
for subject1 subject2;
do 
    cd /directorytodata/
    feat new_design.fsf
done 
save the script. make the file executable for at least yourself chmod -744 myscript.sh. run in terminal where you saved script with ./myscript.sh 
 
I apologize for not being more clear.  The exact command line options for use with feat are not exactly clear.  Every scientist seems to be simplifying the process with guis and pre-written scripts.  Someone wise stays close to their data, especially since it insures reliability and quality control.  I quietly object to this practice of letting users circumvent having a knowledge of basic programming before analyzing data.  Do not get me wrong, though, they do this with kindness.  Becoming even moderately fluent with programming took me years, so in the end, they just save you the torture of having to do it yourself.  I view it more as an initiation ritual every scientist should endure.
Dear MJ and Steven, 
  Can you please make the command line options, for many of your gui based programs, easier to find?
Christine
 
 

 I created a bash script to generate custom design.fsf files for each subject and then run it in the command line:
feat <design.fsf>
> Date: Mon, 18 Jun 2012 09:55:11 -0400
> From: [log in to unmask]
> Subject: Re: [FSL] FEAT: custom design.fsf fails with command-line, works in gui
> To: [log in to unmask]
> 
> Thanks for the advice, unfortunately simply running diff won't work because the way the script is written, it adds the custom variables to the end of the design.fsf file so the same information is in a different place in the two files. In the past, constructing design.fsf files this way has worked fine. For some reason though it doesn't appear to work with EVs.
> 
> 
> On Jun 15, 2012, at 5:23 PM, Michael Harms wrote:
> 
> > Did you try 'diff'ing the original design.fsf file generated by your
> > bash script with the one that you get when you load it into the GUI and
> > then save it back out as new_design.fsf?
> > 
> > The GUI implements certain checks, and may have changed some of the
> > fields in your original design.fsf. 'diff'ing the two should establish
> > what the problem in the original was.
> > 
> > cheers,
> > -MH
> > 
> > 
> > On Fri, 2012-06-15 at 17:08 -0400, Peter Fried wrote:
> >> Dear FSL Experts & Community,
> >> 
> >> I created a bash script to generate custom design.fsf files for each subject and then run it in the command line:
> >> 
> >> feat <design.fsf>
> >> 
> >> When I do, the design.fsf file is created as it should, but feat fails to load the first custom EVs (with a "can't find <file> for reading" message and the whole thing fails because FILM ran out of memory.
> >> 
> >> The weird thing is that when I load the custom design.fsf file into Feat GUI, everything is as it should and it runs without error. I then saved it to a new design.fsf file without changing anything and it was able to run successfully from the command line.
> >> 
> >> Any ideas? Does feat need the other supporting files that are generated along with the .fsf? Is there anything else that is different between running it as a command line and through the gui?
> >> 
> >> Your help is always appreciated.
> >> 
> >> Cheers,
> >> Pete