首页 » 影像遗传学 数据分析 » 全文

“for” and “if” command for deep fsl users

2010 年 11 月 18 日 xuemei 浏览:1,594 最后更新:2010 年 12 月 17 日

在fsl数据分析中,被试很多,经常需要进行批处理或者让某一个处理过程不停的循环,这时候就需要用到for命令。其基本的格式:

For 判断
do
循环命令1 ;
循环命令2;
Done

举一个例子,在一个study中,有40个被试,每组被试20人,每个被试下面有behavior数据、brain数据。我们需要建立一个如下的文件夹系统:

其中sub后的第一个数字代表组编号,第三个数据代表被试编号,如sub101即第一组的第一个被试。要实现这个功能需要进行两次循环和判断,第一次循环是组循环(1到2),第二次是被试循环(1到20),并且被试编号从1到9时,组编号与被试编号之间需要用0占位,所以又引入了if判断。于是需要运行下面的代码:

For ((j=1;j<3;j++)) #从1循环到2,每次增加1,小于3为止。
do
for ((i=1;i<21;i++)) #从1循环到20,每次增加1,小于21为止。
do
if [ ${i} –lt 10 ]  # 如果i小于10为真,“lt”即 less than。大于用“gt”;不等于“ne”
then
mkdir   -p   sub${j}0${i}
mkdir   -p   sub${j}0${i}/brain
mkdir   -p   sub${j}0${i}/behavior
elif  [ ${i} –gt 9 ] #如果相等则用” = ”, 字符串相等也用这个,但是等号两边需要空格
then
mkdir   -p   sub${j}${i}
mkdir   -p   sub${j}${i}/brain
mkdir   -p   sub${j}${i}/behavior
fi
done

发现上面的文件夹系统建好后,假设现在我发现除了behavior数据、brain数据外,这40个被试还有基因数据,所以还需要建立一个基因数据的文件夹:

for  i  in  sub* #当前目录下所有以sub*开头的文件夹
do
mkdir  ${i}/gene
done

在这里就用了“*”通用匹配符。这也是常用的一种循环方式。

For循环经常和if判断语句联用,处理上面判断数字大小外,if还可以判断文件或者文件夹是否存在:

If  [  -d  sub101/behavior ] #如果这个文件夹存在为真,执行以下命令
If  [ !-d  sub101/behavior ] #如果这个文件夹不存在为真,执行以下命令
If  [  -f  sub101/behavior/test.txt ] #如果这个文件存在为真,执行以下命令

If判断常与逻辑判断结合,”-a”即and; “!”及not;”-o” 即 or如下:

If  [ -d  sub101/behavior –a -f  \sub101/brain/test.txt]  #这两个条件都要满足。

相关文章

  1. linux introductuon for fsl users
  2. 推荐一款学习脑结构的免费软件—BrainVoyager Tutor!

分类: 影像遗传学,数据分析

标签:, , ,

linux introductuon for fsl users 脑成像数据的格式转换

12 条评论 发表评论

  • 1. How to remove stretch marks  |  2011 年 05 月 26 日 于 05:06

    In this everyday activities, there are generally little things we can do to keep your a good a higher standard general well being for ourselves and friends and family. Obvious tips include a proper diet which involves meals which were properly balance using the food people, adequate variety of sleep, along with lower emotional tension. This article however might give information regarding 3 reduced popular, though impressive ways to manage our Our health and wellbeing.

  • 2. forex strategies  |  2011 年 05 月 29 日 于 13:21

    Awesome Post, Thank you

  • 3. grants for single mothers  |  2011 年 06 月 01 日 于 16:08

    Indeed but if this kind of do come about, whatrrrs your opinion would happen towards the earlier versions?

  • 4. bespoke kitchens  |  2011 年 06 月 02 日 于 02:38

    Hello there! I could have sworn I’ve been to this site before but after reading through some of the post I realized it’s new to me. Nonetheless, I’m definitely glad I found it and I’ll be bookmarking and checking back frequently!

  • 5. Google Apps  |  2011 年 06 月 02 日 于 05:19

    You completed various nice points there. I did a search on the subject and found a good number of folks will go along with with your blog.

  • 6. Jacqualine Hein  |  2011 年 06 月 02 日 于 13:22

    When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four e-mails with the same comment. Is there any way you can remove people from that service? Bless you!

  • 7. Acai Berries Diet  |  2011 年 06 月 02 日 于 17:46

    Stopping by your blog helped me to get what I was looking for.

  • 8. Immigration Lawyers  |  2011 年 06 月 02 日 于 21:37

    It’s really a great and useful piece of information. I am glad that you shared this helpful information with us. Please keep us informed like this. Thanks for sharing.

  • 9. ps3 3.61 downgrade  |  2011 年 06 月 03 日 于 00:05

    I got what you intend, appreciate it for putting up.Woh I am thankful to find this website through google.

  • 10. get rid of cellulite  |  2011 年 06 月 03 日 于 02:03

    Something else…… I’m impressed, I have to say. Really almost never do I face a blog that’s every different educative and thrilling, and let me show you, you have got hit the nail on the head. Your process is outstanding; the problem is something that not really sufficient persons tend to be speaking intelligently about. I’m very comfortable we stumbled across this at my search for starters regarding this.

  • 11. Creative Agency London  |  2011 年 06 月 03 日 于 17:23

    fourzerotwo? Portal 2 comes out in one week from today

  • 12. Property Solicitors  |  2011 年 06 月 04 日 于 22:49

    I have not checked in here for a while since I thought it was getting boring, but the last several posts are good quality so I guess I’ll add you back to my daily bloglist. You deserve it my friend :)

发表评论

(必填)

(必填), (隐藏)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

TrackBack URL  |  这篇文章上的评论的 RSS feed


最新文章

热门文章

近期评论

标签云

amygdala Analyze bat brain anatomy brain structure BrainVoyager call Cerebral Cortex choice dcm2nii del DICOM e-prime e-prime、gonogo e-prime、时间精确度 e-prime使用指南 e_prime for for循环 freesurfer fsl functional connectivity go-nogo GoldenHelix、gene、SVS gonogo、e-prime if if判断 linux MRI MRIconvert MRIcron NIfRI rd Rem rest rm spm spm5 spm8 start tutorial 命令管道符 批处理 文件定向符 文件通配符

链接表

站点管理