Update of Lin4Neuro (28 Dec 2013)

Lin4Neuro was updated. Some changes are…

  • Kernel was updated to 3.5.0-44-generic.
  • FSL was updated to 5.0.6.
  • Ginkgo CADx was updated to 3.6.0.
  • MINC toolkit was updated to 1.0.01
  • MITK was updated to 2013.12.00.
  • Slicer was updated to 4.3.1.
  • LibreOffice was updated to 4.1.4.2

You can download the latest Lin4Neuro from here.

Now I’m focusing on the 64bit version of Lin4Neuro, so I suspend updating 32bit version. One of the task is to make the UEFI-compatible L4N. I hope it will be possible to boot from UEFI on the next update.

JBL Flip on Xubuntu 12.04

Xubuntu 12.04からJBL FlipをBluetoothで接続しようとしたところ、すぐにはつながりませんでした。
ググったところ、このサイトが参考になりました。

pulseaudio-module-bluetoothがキモでした。

sudo apt-get install pulseaudio-module-bluetooth

これでPulseaudioの設定で音がきちんと出るようになりました。

VBM8の前処理のベンチマーク

VBMの前処理にはどのくらいの時間がかかりますか?という質問を受けましたので、様々なマシンで計測してみました。

3人の3D-T1 MRI画像(ボクセルサイズ 1x1x1mm)をVBM8でDARTELでノーマライズしています。
前処理の設定をvbm8_preproc.matという名前で保存して、以下のベンチマークスクリプトを用意しました。とても単純なMATLABのスクリプトで、処理の前後にtic, tocというコマンドを入れることで前処理にかかった時間を測定するというものです。

%vbm8_benchmark.m
tic
spm('defaults','pet');
spm_jobman('initcfg');
load vbm8_preproc.mat;
spm_jobman('run',matlabbatch);
toc

その結果は、以下のようになりました。

Machine CPU Core Thread Memory OS Matlab Processed time
Workstation BTO AMD Opteron Processor 2425HE x 2 12 12 24GB Xubuntu 12.04 R2013b 74m31s
Desktop BTO Core i7-960 3.2GHz 4 8 24GB Xubuntu 12.04 R2011b 34m47s
Desktop BTO Core i7-960 3.2GHz 4 8 24GB Xubuntu 12.04 R2013b 33m20s
Mac Book Pro (Late 2011) Core i7-2640M 2.8GHz 2 4 8GB Mac OSX 10.9 R2011b 30m29s
Thinkpad T430s Core i7-3520M 2.9GHz 2 4 16GB Windows 7 R2013a 35m0s
Thinkpad T430s Core i7-3520M 2.9GHz 2 4 16GB Xubuntu 12.04 R2013b 29m12s
Desktop BTO Core i7-3930K 3.2GHz 6 12 32GB Xubuntu 12.04 R2013b 26m52s

この結果をまとめると、以下のようになります。

  • CPUが一番影響します。新しいCPU、かつ1コアあたりの性能が高いCPUだとよい結果となります。
  • これはSPM全体に言えることですが、マルチコアは効果はたいしてありません。逆に言えば、SPMを複数立ち上げて処理させることで処理時間を短縮できる可能性があります。
  • メモリは8GB以上あれば、さほど変わりありません。
  • WindowsとLinuxを比べるとLinuxに軍配があがります。
  • Matlabもバージョンが最新の方が処理速度が改善されているようです。

ということで、SPM-VBMという観点からでは、1コアあたりの周波数ができるだけ速いCPUを入手することをお勧めします。

Thinkpad T430sでUbuntu 12.04ファミリーがフリーズする時

Thinkpad T430sにXubuntu 12.04を入れました。インストール自体は何の問題もなかったのですが、入れてから1日の間に10回以上システムがフリーズしました。マウスもキーボードも何の操作も受け付けなくなってしまうのです。

これでは、信頼できないマシンになってしまいます…。

いろいろ調べたところ、カーネルを3.4にアップデートしたところ、問題が解決したという記事をみつけました。

実際にやってみました。

  1. http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.4-precise/にアクセスします。
  2. 64bitの場合ここから3つのファイルをダウンロードします。
    • linux-headers-3.4.0-030400-generic_3.4.0-030400.201205210521_amd64.deb
    • linux-headers-3.4.0-030400_3.4.0-030400.201205210521_all.deb
    • linux-image-3.4.0-030400-generic_3.4.0-030400.201205210521_amd64.deb

    つまり、後ろにamd64.debとあるものとall.debとあるものです。32bitの場合でしたらi386.debとall.debになります。

  3. ダウンロードしたあとで、次のコマンドでカーネルをインストールします。
    sudo dpkg -i linux-*
    
  4. カーネルがインストールされたあと、古いカーネルを削除します。そのためには、apt-get autoremoveがよいと思います。
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get autoremove
    
  5. マシンを再起動します。
  6. ターミナルを立ち上げ、次のようにタイプします。
    uname -r
    

    これで3.4.0-030400-genericと表示されれば新しいカーネルになったことを確認できます。

こうしたところ、私のThinkpad T430sは全くフリーズしなくなりました。カーネルの問題だったということですね。これで安心して解析ができます。

Ubuntuのキーボードセッティング

Ubuntuではキーボードのレイアウトを簡単に変えることはできますが、「システムデフォルト」はコマンドラインでしか変えられないようです。

keyboard

変えたい時は以下をタイプすれば大丈夫です。

sudo dpkg-reconfigure keyboard-configuration

ちなみに、私はThinkapd 430sの英語キーボードを使っているので、Generic 101に変更しました。

TeX Live 2012 on Ubuntu 12.04

Windows 8.1を試しに使ってみたら、あまりにも不適応を起こしたので、この際、思い切ってメイン環境をLinuxに切り替えることにしました。

OSはXubuntu 12.04ベースのLin4Neuroです。自分が使いやすいようにカスタマイズしているので、一番自分にぴったりあっています。
Latexに関しては、TeX Live 2012を入れたいと思っていたのですが、検索したら、こちらのサイトに非常にわかりやすく解説されていました。やるべきことは下記のとおりです。

sudo apt-add-repository ppa:texlive-backports/ppa
sudo apt-get update; sudo apt-get upgrade; sudo apt-get install texlive-lang-cjk

こんなに簡単にできるのは感動ものです。

Ubuntu 12.04でLibreOfficeを3.xから4.xにアップグレードする方法

Ubuntu 12.04LTSを利用していると、LibreOfiiceは3.xのままです。
しかし、LibreOfficeは4.xにアップグレードされ、互換性なども高まっているようです。
以下の方法で、簡単にLibreOfficeを3.xから4.xにアップグレードできます。

sudo add-apt-repository ppa:libreoffice/ppa
sudo apt-get update
sudo apt-get dist-upgrade

ここでポイントは、apt-get updateの後にapt-get dist-upgradeを行うことです。

apt-get upgradeとapt-get dist-upgradeの違いは、man apt-getに以下の記載があります。

upgrade
upgrade は、現在システムにインストールされている全パッケージの最新バージョンを、/etc/apt/sources.list に列挙した取得元からインストールするのに使用します。現在インストール中のパッケージに新しいバージョンがあれば更新しますが、いかなる時も現在インストール中のパッケージの削除は行いません。対象のパッケージが、他のパッケージのインストール状態を変更せずに更新できない場合は、現在のバージョンのままとなります。最初に update を実行しておき、apt-get にパッケージの新しいバージョンがあることを知らせる必要があります。

dist-upgrade
dist-upgrade は、upgrade の機能に加え、新バージョンのパッケージに対する依存関係の変更を知的に操作します。apt-get は「洗練された」競合解決システムを持ち、必要とあらば比較的重要でないパッケージを犠牲にして、最重要パッケージの更新を試みます。そのため dist-upgradeは、いくつかのパッケージを削除する可能性があります。/etc/apt/sources.list ファイルには、必要なパッケージファイルを検索する場所のリストが含まれています。

upgradeは全く削除されることなく、dist-upgradeは必要あらばファイルを削除する可能性があるわけですね。今回、LibreOfficeの3.xから4.xへのアップグレードには、いくつかのファイルが削除される必要もあるので、dist-upgradeを利用することとなります。

何はともあれ、この3つのコマンドで、LibreOfficeを3.xから4.xにアップグレードできます。

Non-stationary correction for VBM on SPM8

Below is an excerpt from SPM-ML

(https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=SPM;72ea5d13.1109)

There is an option for the newest SPM8 releases (>=4010), which enables non-stationarity
correction on the cluster level. Please set in spm_defaults.m:
defaults.stats.rft.nonstat = 1;

However, this option will result in a much longer calculation if you print the results table.
This is maybe also the reason that this option is not set as default.

SPMで複数の群の比較を行いたい時のDesign Matrix

SPM-MLに勉強になる話題が流れていたので、共有します。

出典はこちら。
https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=SPM;a65dd354.1307

コントロールAと疾患B、疾患Cという3群がある時、Design Matrixに全部を入れてしまった方がいいのか、
もしくは、コントロールと疾患A、コントロールと疾患Bというように、別々にDesign Matrixを作った方がいいのかという質問です。

これに対し、Cyril Pernetが非常にわかりやすいたとえを使って説明をしています。
ただ、少しだけtypoがあったのでそこを補足して説明します。

続きを読む

VBMの観点からのSPMの理解(一般線型モデルの理解)

2013年9月に、包括脳MRIチュートリアルで、「VBMの観点からのSPMの理解」なる話をさせていただきました。
VBMに限らず、SPMで用いられる一般線形モデル(GLM)の基本をまとめてみました。
SPMユーザには多少はお役に立てる内容かと思いますので、講義の配布資料を公開させていただきます。

VBMの観点からのSPMの理解の配布資料をダウンロード

LaTeXで各章の最後に引用文献をいれる方法

引用文献は普通は最後に記載することが多いですが、時に章末に掲載したいときがあります。
しかし、普通に、\begin{thebibliography}とすると、見出しの大きさが章の大きさと同じになってしまってかっこわるくなります。
これを解決する方法を見つけました。

まず、chapterbib.styを入手します。
私はここから入手しました。

そして、これがポイントなのですが、jbookやjreportなどの場合に、章末に1セクションとして引用文献を掲載したい場合は、

プリアンプルに

\usepackage[sectionbib]{chapterbib}

と記載します。

また、jbookやjreportだとthebibliographyはデフォルトでは、「関連図書」となってしまいます。
「引用文献」としたい場合は、プリアンブルに

\renewcommand{\bibname}{引用文献}

と記載します。

これで、引用文献が各章末にきちんと表示されるようになります。
[sectionbib]を見つけるまでに相当時間がかかってしまいましたので、書いておきます。

Script to change images to 300dpi TIFF format

When we prepare research paper, many journals require the resolution of images to be 300dpi.
Below is the script to change various image files to 300dpi TIFF format.

#!/bin/bash
#A script which converts various image file formats into 300 dpi TIFF format.
#Usage: dpi300tiff.sh filename
#Wild card can be used.</code>

if [ $# = 0 ]
then
  echo "Please specify the files you want to convert!"
  echo "Usage: dpi300tiff.sh filename"
  exit 1
fi

for image in "$@"
do
  if [ -f $image ]
  then
  convert -units PixelsPerInch $image -density 300 `echo $image | sed 's/\..*$/.tiff/'`
else
  echo "$image: No such file"
fi
done

症例報告の抄録のポイント

(結構この投稿へのアクセスが多いので、具体例を追記しました)

後輩に学会発表の指導をしていて思いついたことですが…。

症例報告をして、それを抄録にする際には起承転結として、以下のポイントをおさえておくといいかと思います。

  • 【起】冒頭に症例を一言でいうとこんな感じということを書く。
  • 【承】次に、症例の病歴(自分たちが関わるまで)を簡潔にまとめる。
  • 【転】自分たちが行ったことの要点を書く。
  • 【結】そこから学んだことをTake home messageとしてまとめる。

こうすると、抄録を読む人に伝わりやすいんじゃないかなと思いました。
実際の例は、以下のようになります。起承転結がわかりやすいように、明示しておきます。○や△は適当なので、全く関連はありません。

【起】○○と診断されていたが、臨床症状および検査所見から△△と××の
   合併が疑われた症例を経験した。
【承】症例は○歳女性。X-○年から抑うつ状態となり、次第に常に強い
   不安・焦燥感を訴え、精神科を受診した。○○と診断され、様々な
   抗うつ薬が投与されたがいずれも無効で、抗精神病薬も少量で副
   作用を呈した。このような状態が消長したため、当院に紹介と
   なった。
【転】入院時、強い焦燥感と認知機能低下を認めた。また、※※も認め
   た。画像検査では、□□を認めた。焦燥感を主体とする臨床症状、
   認知機能低下、および画像所見から△△と××の合併が最も考えら
   れた。薬物療法としては、▽▽が有効であり、修正型電気けいれ
   ん療法により精神症状と運動機能が更に改善した。
【結】○○や△△を認める症例では、××を鑑別に挙げることの重要性が
   示唆された。

心理のためのMatlabチュートリアル (SPMユーザに役立つMatlab入門)

SPMを使う方々は必ずMatlabを使いますが、世の中のMatlab入門をうたった書籍は、たいていが工学向けで、SPMを使う人がこれを知っておいたらいいというようなMatlab入門はあまりありません。何かいい手引きがないかと探していたら、Antonia Hamilton女史の書いたMatlab for Psychologists: A Tutorialという手引きを見つけました。ざっと見たところ非常によい手引きと感じたので、Hamilton女史に連絡をとり、日本語訳の許可をいただきました。日本語訳ができましたので、公開します。「心理のため」となっていますが、SPMを使う方々には、とても有用だと思います。
 なお、翻訳にあたり、山口大学の松尾幸治先生に多くのアドバイスをいただきました。この場をお借りして深謝いたします。

心理のためのMatlabチュートリアルをダウンロード

チュートリアルで用いるデータは下からダウンロードしてください。
練習用データ

SPM switcher: Run different versions of SPM in one Matlab

I used to write an article, “Run SPM2, SPM5, and SPM8 concurrently.” Though this is a smart way to run different version of SPM, we need to prepare scripts separately. So I came up with another script, called “SPM switcher”. This script brings up a dialog and you can select the version of SPM you want to run.

  • Make a directory where you want to save scripts. (e.g. C:\Users\foo\Documents\MATLAB\)
  • Add the directory to the path in Matlab. (File -> Set Path -> Add path)
  • put spm_rmpath.m in SPM2 and SPM99 directory.
  • You find this file in SPM5 or SPM8 directory. You can just copy it from SPM5/8 to SPM2/99 directory.

  • save switchspm.m in the directory you prepared.
  • edit switchspm.m and change “spm_path=’C:\spm\'” according to your circumstance.

Typing switchspm in Matlab command window will bring up a dialog below and you can run different version of SPM easily.

switchspm_screenshot

Download switchspm.m (Right click –> Save as)

%switchspm: Run different version of SPM
%This tiny script prompts the dialog which SPM version you want to run.
%Prerequisites
%1. Each version of SPM is supporsed to be located under spm_path.
%2. Please copy spm_rmpath.m from SPM5 or later and put it into SPM99 and
%   SPM2 direcotry. Otherwise, Path removal won't work correctly.
%3. Please change the SPM path according to your environment

%%%Please change the path below according to your environment%%%
spm_path='C:\spm\';
%%%

%The path for each version of SPM
spm99_path=fullfile(spm_path,'spm99');
spm2_path=fullfile(spm_path,'spm2');
spm5_path=fullfile(spm_path,'spm5');
spm8_path=fullfile(spm_path,'spm8');
spm12_path=fullfile(spm_path,'spm12');

str = ['spm99 '; 'spm2  '; 'spm5  '; 'spm8  '; 'spm12'];
spmver = listdlg('PromptString','SPM ver you want to run...',...
                'SelectionMode','single',...
                'ListString',str);

switch spmver
    case 1, %spm99
    % remove spm path
    while true
      try
        spm_rmpath
        catch break;
      end;
    end;
    % add spm99 path
    addpath(spm99_path);
    % run spm99
    spm;
        
    case 2, %spm2
    % remove spm path
    while true
      try
        spm_rmpath
        catch break;
      end;
    end;
    % add spm2 path
    addpath(spm2_path);
    % run spm2
    spm;

    case 3, %spm5
    % remove spm path
    while true
      try
        spm_rmpath
        catch break;
      end;
    end;
    % add spm5 path
    addpath(spm5_path);
    % run spm5
    spm;
        
    case 4 %spm8
    % remove spm path
    while true
      try
        spm_rmpath;
        catch break;
      end;
    end;
    % add spm8 path
    addpath(spm8_path);
    % run spm8
    spm;

    case 5 %spm12
    % remove spm path
    while true
      try
        spm_rmpath;
        catch break;
      end;
    end;
    % add spm12 path
    addpath(spm12_path);
    % run spm12
    spm;
end

Xubuntuで用紙サイズがLetterになってしまうとき…

Xubuntuでいろいろ印刷するときに、用紙をA4と設定しても、プリンターの方で、「Letterになっています。強制印刷しますか?」のような警告が出ることがいつもでした。
原因は何だろうと思っていたら、次の変数でした。

/etc/environment
の中にLC_PAPERというものがあります。

これが、私の場合、

LC_PAPER="en_US.UTF-8"

となっていました。調べたところ、この設定だと用紙サイズのデフォルトは、Letterになること。
なので、これを

LC_PAPER="ja_JP.UTF-8"

と変えたところ、問題がなくなりました。
locale設定が用紙サイズにも影響しているんですね。
Xubuntuだけでなく、Ubuntuでも同じようなことが起こるのだと思います。

How to do Topological FDR

Many ask “how to do Topological FDR” in SPM ML. Below are the posts I found useful.

Originally Guillaume Flandin showed how to do that.
https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=SPM;44838216.0904

The height threshold you define during the Results procedure is the feature-inducing threshold (used to define local maxima and clusters).
For topological FDR, I would typically choose “none” and a small T-value, for example 3.
The MIP will display all voxels whose T-value is above 3 and the Results table will display all local maxima whose T-value is above 3 (actually, at most 3 local maxima per cluster, more than 8mm apart) and the corresponding FWE p-values and FDR q-values for peaks and clusters.

If you want to threshold the MIP to a particular significance level, go through the Results procedure again and enter the corresponding height and extent thresholds (the 0.05 critical thresholds are indicated at the bottom left of the Results table):
(height) FWEp and FDRp for peak-FWE and -FDR.
(extent) FWEc amd FDRc for cluster-FWE and -FDR.

Jonathan Peele also gave a detail instruction of how to do that. This time he focused more on cluster-thresholded FDR.
https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=SPM;6f4e0139.1110

> How can I see images with a threshold at the cluster-level instead of the peak level with the graphical user interface?

I’m not aware of a way to set a cluster-level threshold when running results the first time (i.e., “show everything that is cluster-level corrected p < .05").  What I would do is this: 1) Run results using some voxelwise threshold.  This threshold defines your clusters, and it's fine to use an uncorrected threshold (e.g., p< .001, uncorrected). 2) In the results table, for each cluster you will see the cluster extent (i.e. how many voxels) and the cluster-corrected p value.  In SPM8 you will see 2 cluster-corrected p values, one for topological FDR (Chumbley & Friston, 2009), one for random field theory (labeled FWE).  You can then look at the size of those clusters, and figure out the cluster extent  that divides p < .05 from the others.  For example, if a cluster of 300 voxels is p = .10, and a cluster of 400 voxels is p = .04, then you know that any cluster 400 voxels or larger would be p < .05. 3) Re-run the results, selecting the same voxelwise threshold. But now, in the minimum cluster extent, specify the cluster size you just figured out—in the above example, you could specify 400.

4) Now all of the displayed results should be cluster-level corrected.

5) If you want to save this thresholded image for displaying with another program, just click the “save” button, and you can write out a thresholded t map as a nifti file.

In practice this is actually fairly quick to do once you’ve done it a couple of times.

Note the difference between these two. Two-step approach is the same, but Guillaume’s way deals with peak and cluster threshold and Jonathan’s way deals with cluster threshold.