FSL (tbss) randomise command makes none permutations - permutation

I'm working on TBSS FSL to make an ANOVA with 3 groups and ~20 subjects per groups. In order to analyze my sample, I have to perform a randomise command which basically make permutations inside my sample.
The command is the following :
randomise -i all_FA_skeletonised -o tbss -m mean_FA_skeleton_mask -d design.mat -t design.con -f design.fts –e design.grp --T2
where the design.mat matrix is the matrix which attributes subjects inside the different group, the design.con is the matrix of contrast which computes comparisons between the groups, whereas the .fts and .grp are the files needed to make the ANOVA and are given by the GLM interface inside fsl.
My problem is that fsl actually do none permutation...
Data loaded
1 permutations required for exhaustive test of f-test 1
Doing all 1 unique permutations
Starting permutation 1 (Unpermuted data)
Critical Value for: tbss_tfce_corrp_fstat1 is: 6.3312e+06
I just show you what I would expect when I was doing t-test without ANOVA, the command was the following :
randomise -i all_FA_skeletonised -o tbss -m mean_FA_skeleton_mask -d design.mat -t design.con -n 500 --T2
And the terminal answer was :
Data loaded
1.10355e+34 permutations required for exhaustive test of t-test 1
Doing 500 random permutations
Starting permutation 1 (Unpermuted data)
Starting permutation 2
Starting permutation 3
...
Starting permutation 500
Critical Value for: tbss_tfce_corrp_tstat1 is: 341255
It looks like if the program computed by itself the needed number of permutations and find 1. Though, I tried to force the number of permutations by adding the -n 500 command for the ANOVA without success.
I am not confident enough with fsl(tbss) and so I don't understand what the programm does and why it doesn't make the permutations. Does anyone have any idea ?
Thanks for your help.

I am not sure if you need design.grp. To my understanding, -e design.grp option is only needed for Within/Mixed group design (like paired T-test, or repeated ANOVA). Please see here about Exchangeability Blocks: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/PALM/ExchangeabilityBlocks

Related

How to call program with array values as arguments?

I would like to call a program by filling in the argument values with varying amounts of array values as in:
myarray=("val1" "val2" val3" ... "valn")
program -t "${myarray[0]}" -t "${myarray[1]}" -t "${myarray[2]}" ... -t "${myarray[n-1]}"
I am essentially missing some way to expand the string "-t ${myarray[i]}" n times, where n is ${#myarray[#]}.
Thanks for showing me the light!
Background:
I extract base names of files from a tab-separated file using awk filtering and store them in an array. Now I would like to run a program using these specific filenames as individual arguments of the same option.

bash script to dynamically display array element based on user selection(s)

i have to task to write a bash script which can let user to choose which array element(s) to display.
for example, the array have these element
ARRAY=(zero one two three four five six)
i want the script to be able to print out the element after user enter the array index
let say the user entered(in one line) : 1 2 6 5
then the output will be : one two six five
the index entered can be single(input: 0 output: zero) or multiple(such as above) and the output will be correspond to the index(es) entered
any help is much appreciated.
thanks
ARRAY=(zero one two three four five six)
for i in $#; do
echo -n ${ARRAY[$i]}
done
echo
Then call this script like this:
script.sh 1 2 6 5
it will print:
one two six five
You would want to use associative arrays for a generic solution, i.e. assuming your keys aren't just integers:
# syntax for declaring an associative array
declare -A myArray
# to quickly assign key value store
myArray=([1]=one [2]=two [3]=three)
# or to assign them one by one
myArray[4]='four'
# you can use strings as key values
myArray[five]=5
# Using them is straightforward
echo ${myArray[3]} # three
# Assuming input in $#
for i in 1 2 3 4 five; do
echo -n ${myArray[$i]}
done
# one two three four 5
Also, make sure you're using Bash4 (version 3 doesn't support it). See this answer and comment for more details.

Find the most frequent entry in a file using unix

I have a file containing around 2,000,000 entries - just one column with that many entries, all numbers. I would like to quickly find out what the most frequent number in the file is.. Is there a way to do this using unix?
I know how to do it using gnuplot but it is a slightly tedious way and was wondering if there was a simpler way just by using some unix commands?
Like if my file is
1
1
1
2
3
4
Then I want it to read the file and give me the answer 1 because thats the most frequent.
You can do it like this:
$ cat file|sort -n|uniq -c|sort -n|tail -n 1|awk '{print $2}'
sort test.txt | uniq -c | sort -rn | head -n 1 should help. It prints the number of occurences and the number that is most used, so for your example file it would be: 3 1
My first answer to that would be building an histogram. It helps if the range of possible values is small enough.
Once the histogram is built, just look for the highest amount in it.

Sorting by unique values of multiple fields in UNIX shell script

I am new to unix and would like to be able to do the following but am unsure how.
Take a text file with lines like:
TR=P567;dir=o;day=su;TI=12:10;stn=westborough;Line=worcester
TR=P567;dir=o;day=su;TI=12:10;stn=westborough;Line=lowell
TR=P567;dir=o;day=su;TI=12:10;stn=westborough;Line=worcester
TR=P234;dir=o;day=su;TI=12:10;stn=westborough;Line=lowell
TR=P234;dir=o;day=su;TI=12:10;stn=westborough;Line=lowell
TR=P234;dir=o;day=su;TI=12:10;stn=westborough;Line=worcester
And output this:
TR=P567;dir=o;day=su;TI=12:10;stn=westborough;Line=worcester
TR=P567;dir=o;day=su;TI=12:10;stn=westborough;Line=lowell
TR=P234;dir=o;day=su;TI=12:10;stn=westborough;Line=lowell
TR=P234;dir=o;day=su;TI=12:10;stn=westborough;Line=worcester
I would like the script to be able to find all all the lines for each TR value that have a unique Line value.
Thanks
Since you are apparently O.K. with randomly choosing among the values for dir, day, TI, and stn, you can write:
sort -u -t ';' -k 1,1 -k 6,6 -s < input_file > output_file
Explanation:
The sort utility, "sort lines of text files", lets you sort/compare/merge lines from files. (See the GNU Coreutils documentation.)
The -u or --unique option, "output only the first of an equal run", tells sort that if two input-lines are equal, then you only want one of them.
The -k POS[,POS2] or --key=POS1[,POS2] option, "start a key at POS1 (origin 1), end it at POS2 (default end of line)", tells sort where the "keys" are that we want to sort by. In our case, -k 1,1 means that one key consists of the first field (from field 1 through field 1), and -k 6,6 means that one key consists of the sixth field (from field 6 through field 6).
The -t SEP or --field-separator=SEP option tells sort that we want to use SEP — in our case, ';' — to separate and count fields. (Otherwise, it would think that fields are separated by whitespace, and in our case, it would treat the entire line as a single field.)
The -s or --stabilize option, "stabilize sort by disabling last-resort comparison", tells sort that we only want to compare lines in the way that we've specified; if two lines have the same above-defined "keys", then they're considered equivalent, even if they differ in other respects. Since we're using -u, that means that means that one of them will be discarded. (If we weren't using -u, it would just mean that sort wouldn't reorder them with respect to each other.)

parsing the output of the 'w' command?

I'm writing a program which requires knowledge of the current load on the system, and the activity of any users (it's a load balancer).
This is a university assignment, and I am required to use the w command. I'm having a hard time parsing this command because it is very verbose. Any suggestions on what I can do would be appreciated. This is a small part of the program, and I am free to use whatever method i like.
The most condensed version of w which still has the information I require is `w -u -s -f' which produces this:
10:13:43 up 9:57, 2 users, load average: 0.00, 0.00, 0.00
USER TTY IDLE WHAT
fsm tty7 22:44m x-session-manager
fsm pts/0 0.00s w -u -s -f
So out of that, I am interested in the first number after load average and the smallest idle time (so i will need to parse them all).
My background process will call w, so the fact that w is the lowest idle time will not matter (all i will see is the tty time).
Do you have any ideas?
Thanks
(I am allowed to use alternative unix commands, like grep, if that helps).
Are you allowed to use other Unix commands? You could use grep, sed or head/tail to get the lines you need, and cut to split them up as needed.
Check out: http://www.gnu.org/s/libc/manual/html_node/Regexp-Subexpressions.html#Regexp-Subexpressions
Use regular expressions to match [0-9]+\.[0-9]{2} on the first line. You may have to fiddle with which characters are escaped. That will give you 3 load averages.
The remaining output is column-based, so if you count off the string positions from w, you'll be able to just strncpy the interesting bits.
Another possible theory (which sounds like it goes against the assignment, but I'd keep it in mind) is to go grab the source code of w and hack it up to just tell you the information via function calls. If you're feeling really hardcore, you can learn all the library api calls and do it directly that way.
I found i can use a combination of commands like so:
w -u -s -f | grep load | cut -d " " -f 11
and
w -u -s -f | grep tty | cut -d " " -f 13
the first takes the output of w, uses grep to only select the line with load, and then cuts everything except for the 11th chunk of data (delimiter is a space), which is the first load number with a comma.
the second does something similar, only for user load. And if there are multiple loads, its a list.
This is easy enough to parse, unless someone has an objection, or suggestion to improve it.

Resources