recon-all.local-copy 262 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587
  1. #! /bin/tcsh -f
  2. #
  3. # recon-all
  4. #
  5. # script to run all of the reconstruction routines
  6. #
  7. # Original Author: Doug Greve
  8. # CVS Revision Info:
  9. # $Author: nicks $
  10. # $Date: 2013/05/12 23:15:37 $
  11. # $Revision: 1.379.2.73 $
  12. #
  13. # Copyright © 2011-2013 The General Hospital Corporation (Boston, MA) "MGH"
  14. #
  15. # Terms and conditions for use, reproduction, distribution and contribution
  16. # are found in the 'FreeSurfer Software License Agreement' contained
  17. # in the file 'LICENSE' found in the FreeSurfer distribution, and here:
  18. #
  19. # https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense
  20. #
  21. # Reporting: freesurfer@nmr.mgh.harvard.edu
  22. #
  23. #
  24. #
  25. umask 002;
  26. set VERSION = '$Id: recon-all,v 1.379.2.73 2013/05/12 23:15:37 nicks Exp $';
  27. set ProgName = `basename $0`;
  28. set inputargs = ($argv);
  29. set subjid = ();
  30. set hemilist = (lh rh);
  31. set mailuser = ();
  32. set WaitForFile = ();
  33. set nWaitsMax = 1000;
  34. set WaitSleep = 1m;
  35. set NotifyFile = ();
  36. set PrintHelp = 0;
  37. set LF = ();
  38. set LF_DEFAULT_NAME = recon-all.log;
  39. set SF = ();
  40. set SF_DEFAULT_NAME = recon-all-status.log;
  41. set CF = ();
  42. set CF_DEFAULT_NAME = recon-all.cmd;
  43. set AppendLog = 1;
  44. set AppendStatus = 1;
  45. set DoTime = 0;
  46. set fs_time = "";
  47. set ErrorFile = /dev/null
  48. set cmd = ();
  49. set tcsh61706 = (`tcsh --version | grep "6\.17\.06"`)
  50. if ("$tcsh61706" != "") then
  51. echo ""
  52. echo "WARNING: tcsh v6.17.06 has an exit code bug! Please update tcsh!"
  53. echo ""
  54. # workaround to force expected behavior:
  55. set anyerror
  56. endif
  57. set Force = 0;
  58. set DoCleanCSDF = 0;
  59. set DoCleanCW256 = 0;
  60. set DoCleanTal = 0;
  61. set DoCleanLta = 0;
  62. set DoCleanCP = 0;
  63. set DoCleanSeed = 0;
  64. set DoCleanPFH = 0;
  65. set DoCleanBM = 0;
  66. set DoCleanBFSE = 0;
  67. set DoCleanASeg = 0;
  68. set DoCleanWM = 0;
  69. set DoCleanXopts = 0;
  70. set DoCleanT2 = 0;
  71. set DoCleanFLAIR = 0;
  72. set DoShowEdits = 0;
  73. set InputList = ();
  74. # Expert preferences
  75. set XOptsFile = ();
  76. set XOptsClean = 0; # Delete a pre-existing xopts file
  77. set XOptsUse = 1; # Use a pre-existing xopts file (default '1': always use)
  78. set XOptsOverwrite = 0; # Overwrite a pre-existing xopts file
  79. set ControlPointsFile = ();
  80. set PonsSeedCRS = (); # SeedCRS center of pons for mri_fill #
  81. set CCSeedCRS = (); # SeedCRS center of corpus callosum for mri_fill #
  82. set RHSeedCRS = (); # SeedCRS point in the right hemi wm for mri_fill #
  83. set LHSeedCRS = (); # SeedCRS point in the left hemi wm for mri_fill #
  84. set WaterShed = 1; # 0=no WS, 1= WS normal, 2 = WS only, 3 = WS+1st
  85. set WSLess = 0; # Shrinks skull surface
  86. set WSMore = 0; # Expands skull surface
  87. set WSPctPreFlood = (); # Pre-flooding height
  88. set WSSeedPoint = (); # C R S
  89. set WSAtlas = 0; # 0=don't use atlas, 1=use atlas (for skull strip)
  90. set WSGcaAtlas = 1; # 1=use GCA atlas and registration to do skull strip
  91. set WSUseTalXfm = 0; # 1=use talairach.xfm instead of talairach_with_skull
  92. # to do atlas alignment during mri_watershed
  93. set DoGcut = 0; # 1=run mri_gcut after mri_watershed
  94. set NuIterations = 2; # Number of iterations for nu intensity correction
  95. set ConformMin = 0; # 1=conformed to min dimension
  96. set HiRes = 0; # 1=hires option (conformed to min dimension)
  97. set Norm3dIters = (); # passed as -n to *both* mri_normalize runs
  98. set NormMaxGrad = 1; # passed as -g to *both* mri_normalize runs
  99. set Norm1_b = (); # passed as -b to the *first* mri_normalize only
  100. set Norm1_n = (); # passed as -n to the *first* mri_normalize only
  101. set Norm2_b = (); # passed as -b to the *second* mri_normalize only
  102. set Norm2_n = (); # passed as -n to the *second* mri_normalize only
  103. set WMSeg_wlo = (); # from -seg-ghi and -seg-wlo, passed to mri_segment
  104. set WMSeg_ghi = (); # and mris_make_surfaces
  105. set FixWithGA = 1; # for topology fixer
  106. set FixDiagOnly = 0; # for topology fixer
  107. set RmNeckRadius = 25; # used by mri_remove_neck
  108. set UseCAAlign = (-align); # flag added to mri_ca_label
  109. set UseCAAlignAfter = (-align-after); # flag added to mri_ca_register
  110. set UseAseg = 1 # when set to 0 (using -noaseg), then aseg.mgz is not used,
  111. # nor is ?h.cortex.label (which originates through the aseg)
  112. set NoAsegInorm2 = 0 # when set to 1 (using -noaseg-inorm2), then aseg.mgz
  113. # is not used during the 2nd mri_normalize step
  114. set UseNoNeg = 0 # if 1, add '-remove_negative 1' to mris_sphere,mris_register
  115. set NoThicken = 0 # if 1, add '-thicken 0' to mri_segment
  116. set UnCompress = 0 # if 1, add '-uncompress' to mri_ca_reg
  117. set BigVentricles = 0 # if 1, add '-bigventricles' to mri_ca_reg.
  118. # else, add '-nobigventricles'
  119. set DoSecondPassRenorm = 0 # if 1, add -secondpassrenorm to mri_ca_register
  120. set UseOldTopoFix = 1 # if 1, use mris_fix_topology instead of mris_topo_fixer
  121. set UseNewTopoFix = 0 # if 1, use mris_topo_fixer instead of mris_fix_topology
  122. set NoRandomness = 1 # if 1, seed critical binaries with identical seeds, to
  123. # ensure consistency in surface creation. otherwise, the
  124. # default is to seed with current time and date,
  125. # resulting in slightly different surfaces each run.
  126. # affects: mris_smooth, mris_sphere, mris_topology_fixer,
  127. # mris_topo_fixer, mris_ca_label,
  128. # mri_robust_template (1st-base-call-only)
  129. set RngSeed = 1234 # seed for random number generator, used only when
  130. # -norandomness flag is used, and can be overriden by
  131. # the flag -rng-seed <seed>
  132. set DoMultiStrip = 0 # if 1, then multiple instances of mri_watershed and
  133. # mri_em_register are run in order to determine the best
  134. # skull-strip
  135. set IsMPRAGE = 0 # if 1, then -mprage added to mri_normalize/segment
  136. set IsWashuMPRAGE = 0 # if 1, then -washu_mprage added to mri_normalize/segment
  137. set DoConformWidth256 = 0 # if 1, then conform to 256^3 during
  138. # the mri_convert -conform step
  139. set NoNormMGZ = 0; # set to 1 when -nosubcortseg or -noaseg flag is used,
  140. # which causes norm.mgz not to used during inorm2 step
  141. set NoWMSA = 0; # if 1, then -nowmsa flag is added to mri_ca_label
  142. set DoQdecCache = 0; # if 1, then create smoothed fsaverage surface files
  143. set measurelist = ( thickness area area.pial volume curv sulc white.K white.H jacobian_white w-g.pct.mgh )
  144. # ^ these are the files smoothed by DoQdecCache (-qcache)
  145. set UserMeasureList = 0; # if 1, then 'measurelist' gets additional -measure args
  146. set measuredir = (); # for specifying an alternate path to measure files
  147. set fwhmlist = ( 0 5 10 15 20 25 ) # see DoQdecCache
  148. set target = fsaverage # see DoQdecCache
  149. set SmoothCortexOnly = 1; # For -qcache. smooths only within ?h.cortex.label
  150. set UseMincMritotal = 0; # if 1, then use the BIC-MNI mritotal tal reg tools
  151. set UseYa3tTalAtlas = 0; # if 1, use 3T18yoSchwartz young-adult 3T atlas for tal_avi
  152. set CustomTalAtlas = ""; # -custom-tal-atlas <name of atlas in average dir>
  153. set DoMakefile = 0; # if 1, run make -f recon-all.makefile $(MakefileTarget)
  154. set MakefileTarget = () # argument to recon-all -make
  155. set DoAsegStatsDiff = 0; # if 1, then run asegstatsdiff
  156. set DoAparcStatsDiff = 0; # if 1, then run aparcstatsdiff
  157. set diffsubj = (); # the subject used by asegstatsdiff and aparcstatsdiff
  158. set DoLabelV1 = 0; # if 1, create V1 label from O.Hinds V1 prediction atlas
  159. set DoRobustMotionCor = 1; # if 1, then use mri_robust_template for motion cor
  160. set mc_robust_template_avg_arg = 1; # when using mri_robust_template for motion
  161. # correction, construct template from: 0 Mean, 1 Median
  162. set UseCuda = 0; # if 1 (-use-cuda), then use GPU versions of tools:
  163. # mri_em_register_cuda, mri_ca_register_cuda,
  164. # mris_inflate_cuda, mris_sphere_cuda
  165. # (future: mri_segstats_cuda)
  166. set GetCuda = 0; # if 1 (-get-cuda) then print cuda info and exit
  167. set PialNoAparc = 0; # if 1 (-pial-noaparc), then add -noaparc flag to
  168. # mris_make_surfaces to bypass usage of parcellation
  169. set DoNuMakeUchar = 1; # if 1, then run mri_nu_correct.mni using talairach.xfm
  170. # to run mri_make_uchar to correct histogram problem
  171. set DoTalairachUseNu = 0; # if 1, use nu.mgz as input to talairach stage
  172. setenv OMP_NUM_THREADS 1 # -openmp <num_threads> allows specifying more threads
  173. set UseCPsWithCaNorm = 0 # -canorm-usecps flag allows usage of control points with ca_norm
  174. # Longitudinal processing:
  175. set longitudinal = 0; # if 1, will run the longitudinal scheme
  176. set longbaseid = ();
  177. set tpNid = ();
  178. set longbasetotpN_regfile = (); # reg file to align longbase to current subj
  179. set UseConcatLtaTal = 0; # if 1, use mri_concatenate_lta during tal creation
  180. set UseLongbaseCtrlVol = 0; # if 1, use ctrl volume of longbase in norm step
  181. set UseLongbaseWMedits = 0; # if 1, use transfer wm edits from base (default from cross)
  182. set UseAsegFusion = 1; # if 0, dont create 'fused' asegs from timepoints
  183. set DoCreateBaseSubj = 0; # if 1, create the 'base' subject used in longitud
  184. set BaseSubjInvol = (orig.mgz); # -base-invol allows using some other file
  185. set BaseSubjsList = (); # subject set grabbed from -base-tp args
  186. set BaseSubjsListFname = (base-tps); # file containing BaseSubjsList
  187. set robust_template_avg_arg = 1; # construct template from: 0 Mean, 1 Median
  188. set DoNuIntensityCor3T = 0; # if 1, use Zheng, Chee, Zagorodnov params for 3T
  189. set DoAddTp = 0; # if 1, then 'fake'-add this timepoint to long subj set
  190. set DoAffineBase = 0; # if 1, allow affine when creating base (fix calibration)
  191. set UseCubic = 0; # if 1, use cubic spline when mri_convert does conform step
  192. set DoT2pial = 0; # if 1, mris_make_surfaces refines pial using T2
  193. set DoFLAIRpial = 0; # if 1, mris_make_surfaces refines pial using FLAIR
  194. # Hippocampal subfields:
  195. set DoGEMS = 0; # if 1, will run the hippocampal subfields processing
  196. # For defacing, as found in:
  197. # $FREESURFER_HOME/average/
  198. set brain_template = talairach_mixed_with_skull.gca
  199. set face_template = face.gca
  200. # For subcortical segmentation
  201. set GCA = RB_all_2008-03-26.gca
  202. set GCASkull = RB_all_withskull_2008-03-26.gca
  203. set GCADIR = "${FREESURFER_HOME}/average"
  204. # For cortical registration, as found in $AvgCurvTifPath/$hemi.$AvgCurvTif
  205. set AvgCurvTifPath = "${FREESURFER_HOME}/average"
  206. set AvgCurvTif = average.curvature.filled.buckner40.tif
  207. # Desikan-Killiany cortical parcellation atlas (-cortparc), as found in:
  208. # $FREESURFER_HOME/average/$hemi.$GCS
  209. # The 2009-03-04 atlas contains the insula label.
  210. # The 2010-03-25 atlas has a different color for temporalpole (the old
  211. # color was gray, which looked like the default tksurfer surface color).
  212. set OLD_OLD_GCS = curvature.buckner40.filled.desikan_killiany.2007-06-20.gcs
  213. set OLD_GCS = curvature.buckner40.filled.desikan_killiany.2009-03-04.gcs
  214. set GCS = curvature.buckner40.filled.desikan_killiany.2010-03-25.gcs
  215. set GCSDIR = "${FREESURFER_HOME}/average"
  216. # Christophe Destrieux cortical parcellation atlas (-cortparc2):
  217. set OLD_OLD_DESTRIEUX_GCS = atlas2002_simple.gcs
  218. set OLD_OLD_DESTRIEUX_NAME = a2002s
  219. set OLD_DESTRIEUX_GCS = atlas2005_simple.gcs
  220. set OLD_DESTRIEUX_NAME = a2005s
  221. set DESTRIEUX_GCS = destrieux.simple.2009-07-29.gcs
  222. set DESTRIEUX_NAME = a2009s
  223. # Mindboggle cortical parcellation atlas (-cortparc3):
  224. set DKTATLAS40_GCS = DKTatlas40.gcs
  225. set DKTATLAS40_NAME = DKTatlas40
  226. # Set this to 0 to do everything but run the command.
  227. # This is good for debugging.
  228. set RunIt = 1;
  229. # print versions and exit
  230. set DoVersionsOnly = 0;
  231. #----- Volume -----------#
  232. set DoConvertInput = 0;
  233. set DoConvertT2Input = 0;
  234. set DoConvertFlairInput = 0;
  235. set DoCreateBaseInput = 0;
  236. set DoMotionCor = 0;
  237. set DoDeface = 0;
  238. set DoNuIntensityCor = 0;
  239. set DoTalairach = 0;
  240. set DoTalCheck = 0;
  241. set DoNormalization = 0;
  242. set DoNormalization2 = 0;
  243. set DoMaskBFS = 0;
  244. set UseControlPoints = 0;
  245. set DoSkullStrip = 0;
  246. set DoSegmentation = 0;
  247. set DoGCAReg = 0;
  248. set DoCARegInv = 0;
  249. set DoCANormalize = 0;
  250. set DoCAReg = 0;
  251. set DoRemoveNeck = 0;
  252. set DoSkullLTA = 0;
  253. set DoCALabel = 0;
  254. set DoASegMerge = 0;
  255. set DoFill = 0;
  256. #----- Surface -----------#
  257. set DoTessellate = 0;
  258. set SvInitOrigSurf = 0;
  259. set DoSmooth1 = 0;
  260. set DoInflate1 = 0;
  261. set DoQSphere = 0;
  262. set DoFix = 0;
  263. set DoSmooth2 = 0;
  264. set DoInflate2 = 0;
  265. set DoSphere = 0;
  266. set DoSurfReg = 0;
  267. set SurfRegToSubj = ();
  268. set DoJacobianWhite = 0;
  269. set DoJacobianDist0 = 0;
  270. set DoContraSurfReg = 0;
  271. set DoContraSurfRegWithinSubject = 0;
  272. set DoAvgCurv = 0;
  273. set DoMorphRGB = 0;
  274. set DoWhiteSurfs = 0;
  275. set DoCortParc = 0;
  276. set DoCortParc2 = 0;
  277. set DoCortParc3 = 0;
  278. set DoPialSurfs = 0;
  279. set DoPctSurfCon = 0;
  280. set DoSurfVolume = 0;
  281. set DoParcStats = 0;
  282. set DoParcStats2 = 0;
  283. set DoParcStats3 = 0;
  284. set DoCurvStats = 0;
  285. set DoVnoMatchCheck = 0;
  286. set DoLocalGyriIndex = 0;
  287. set DoBaLabels = 0;
  288. set DoLabelExvivoEC = 0;
  289. # ----------- Surface and Volume ------------------#
  290. set DoSurfSegEdit = 0; # if 1, run mri_edit_segmentation_with_surfaces to
  291. # fixup aseg.mgz with info from surfaces
  292. # (this is the -surfsegedit flag)
  293. set DoCortRibbonVolMask = 0;
  294. set DoSegStats = 0;
  295. set DoAParc2ASeg = 0;
  296. set DoWMParc = 0;
  297. set DoAParcASegStats = 0;
  298. set DoIsRunning = 1;
  299. set IsRunningFile = ();
  300. setenv LANG C # Required by MNI tool
  301. # -------------------------------------------------- #
  302. set argv0 = ($argv); # make a copy
  303. set PWD = pwd;
  304. # better yet, make sure the real pwd is used:
  305. if ( -e /bin/pwd ) set PWD = /bin/pwd
  306. if($#argv == 0) goto usage_exit;
  307. set n = `echo $argv | egrep -e -help | wc -l`
  308. if($n != 0) then
  309. set PrintHelp = 1;
  310. goto usage_exit;
  311. endif
  312. set n = `echo $argv | egrep -e -version | wc -l`
  313. if($n != 0) then
  314. echo $VERSION
  315. exit 0;
  316. endif
  317. goto parse_args;
  318. parse_args_return:
  319. goto check_params;
  320. check_params_return:
  321. set StartTime = `date`;
  322. set tSecStart = `date '+%s'`;
  323. # This allows the user to require that the build stamp be
  324. # consistent from one recon-all invocation to the next.
  325. # Good for frozen versions.
  326. if($?REQUIRE_FS_MATCH == 0) setenv REQUIRE_FS_MATCH 0
  327. #echo "REQUIRE_FS_MATCH $REQUIRE_FS_MATCH"
  328. set bstampfile0 = $FREESURFER_HOME/build-stamp.txt
  329. mkdir -p $SUBJECTS_DIR/$subjid/scripts
  330. set bstampfile = $SUBJECTS_DIR/$subjid/scripts/build-stamp.txt
  331. if(-e $bstampfile0) then
  332. if(! -e $bstampfile) cp $bstampfile0 $bstampfile
  333. set bstamp0 = `cat $bstampfile0`
  334. set bstamp = `cat $bstampfile`
  335. if("$bstamp0" != "$bstamp") then
  336. if($REQUIRE_FS_MATCH) then
  337. echo "ERROR: FreeSurfer build stamps do not match"
  338. echo "Subject Stamp: $bstamp"
  339. echo "Current Stamp: $bstamp0"
  340. exit 1;
  341. else
  342. echo "INFO: FreeSurfer build stamps do not match"
  343. endif
  344. endif
  345. echo "Subject Stamp: $bstamp"
  346. echo "Current Stamp: $bstamp0"
  347. endif
  348. if ($DoMakefile) then
  349. setenv RECONALL_MAKE_SUBJECT $subjid
  350. set make_flags=( $MakefileTarget )
  351. if ( ! $RunIt) set make_flags=( -n $make_flags )
  352. echo "Subject '$subjid': make $make_flags"
  353. make -f $FREESURFER_HOME/bin/recon-all.makefile ${make_flags}
  354. set makestatus=($status)
  355. unsetenv RECONALL_MAKE_SUBJECT
  356. exit ($makestatus)
  357. endif
  358. if ($DoTime) then
  359. fs_time ls >& /dev/null
  360. if ( ! $status) set fs_time=(fs_time)
  361. endif
  362. echo "INFO: SUBJECTS_DIR is $SUBJECTS_DIR"
  363. # Get "True" FS HOME
  364. pushd $FREESURFER_HOME > /dev/null
  365. set freesurfer_home_true = `pwd`;
  366. popd > /dev/null
  367. echo "Actual FREESURFER_HOME $freesurfer_home_true"
  368. set DateString = "`date '+%y%m%d%H%M'`"
  369. cd $subjdir # This variable is set in check_params
  370. mkdir -p mri scripts surf tmp label touch stats touch src trash bem
  371. mkdir -p mri/transforms mri/transforms/bak mri/orig
  372. set touchdir = $subjdir/touch
  373. # Create cmd and env files from scratch
  374. if(! $DoVersionsOnly) then
  375. set CF = ($subjdir/scripts/$CF_DEFAULT_NAME)
  376. rm -f $CF
  377. # Create a separate file for the env
  378. set ENVF = $subjdir/scripts/recon-all.env
  379. if(-e $ENVF) mv $ENVF $ENVF.bak
  380. date >> $ENVF
  381. echo "FREESURFER_HOME $FREESURFER_HOME" >> $ENVF
  382. echo "Actual FREESURFER_HOME $freesurfer_home_true" >> $ENVF
  383. pwd >> $ENVF
  384. echo "setenv SUBJECTS_DIR $SUBJECTS_DIR" >> $ENVF
  385. echo $inputargs >> $ENVF
  386. uname -a >> $ENVF
  387. echo "" >> $ENVF
  388. limit >> $ENVF
  389. echo "" >> $ENVF
  390. printenv >> $ENVF
  391. endif
  392. if($DoVersionsOnly) then
  393. if (-e /dev/stdout) then
  394. set LF = /dev/stdout
  395. set SF = /dev/stdout
  396. else
  397. set LF = /dev/null
  398. set SF = /dev/null
  399. endif
  400. endif
  401. # ------------ Create the log file --------------- #
  402. if($#LF == 0) then
  403. set LF = ($subjdir/scripts/$LF_DEFAULT_NAME)
  404. if(-e $LF) then
  405. ls -l $LF
  406. if(! $AppendLog) then
  407. mv $LF $LF.old
  408. else
  409. # if running using -make, then dont bother with repeated info dumps
  410. if ($?RECONALL_MAKE_SUBJECT) goto skip_new_invo
  411. echo "\n\n" >> $LF
  412. echo "New invocation of recon-all " >> $LF
  413. echo "\n\n" >> $LF
  414. endif
  415. endif
  416. else
  417. if(-e $LF) then
  418. if ($?RECONALL_MAKE_SUBJECT) goto skip_new_invo
  419. echo "\n\n" >> $LF
  420. echo "New invocation of recon-all " >> $LF
  421. echo "\n\n" >> $LF
  422. endif
  423. endif
  424. skip_new_invo:
  425. date >> $LF
  426. $PWD >> $LF
  427. echo $0 >> $LF
  428. echo $inputargs >> $LF
  429. # if running using -make, then dont bother with repeated info dumps
  430. if ($?RECONALL_MAKE_SUBJECT) goto skip_all_info
  431. echo "subjid $subjid" >> $LF
  432. echo "setenv SUBJECTS_DIR $SUBJECTS_DIR" >> $LF
  433. echo "FREESURFER_HOME $FREESURFER_HOME" >> $LF
  434. echo "Actual FREESURFER_HOME $freesurfer_home_true" >> $LF
  435. if (-e $FREESURFER_HOME/build-stamp.txt) then
  436. echo "build-stamp.txt: `cat $FREESURFER_HOME/build-stamp.txt`" >> $LF
  437. endif
  438. uname -a | tee -a $LF
  439. limit >> $LF
  440. if (-e /usr/bin/free) then
  441. echo "" >> $LF
  442. /usr/bin/free >> $LF
  443. echo "" >> $LF
  444. endif
  445. if ("`uname -s`" == "Darwin") then
  446. echo "" >> $LF
  447. /usr/bin/top -l 1 | grep PhysMem >> $LF
  448. echo "" >> $LF
  449. endif
  450. ## gather all versions here
  451. echo "########################################" >> $LF
  452. echo "program versions used" >> $LF
  453. echo $VERSION >> $LF
  454. mri_motion_correct.fsl -version >> $LF
  455. if (-e $FREESURFER_HOME/bin/flirt.fsl) flirt.fsl -version >> $LF
  456. talairach_avi --version >> $LF
  457. tkregister2_cmdl --all-info >> $LF
  458. nu_correct -version >> $LF
  459. mri_make_uchar -all-info >> $LF
  460. mri_normalize -all-info >> $LF
  461. mri_watershed -all-info >> $LF
  462. mri_gcut -all-info >> $LF
  463. mri_segment -all-info >> $LF
  464. mri_label2label -all-info >> $LF
  465. mri_em_register -all-info >> $LF
  466. mri_ca_normalize -all-info >> $LF
  467. mri_ca_register -all-info >> $LF
  468. mri_ca_label -all-info >> $LF
  469. mri_pretess -all-info >> $LF
  470. mri_fill -all-info >> $LF
  471. mri_tessellate -all-info >> $LF
  472. mri_concatenate_lta -all-info >> $LF
  473. mri_normalize_tp2 -all-info >> $LF
  474. mris_smooth -all-info >> $LF
  475. mris_inflate -all-info >> $LF
  476. mris_curvature -all-info >> $LF
  477. mris_sphere -all-info >> $LF
  478. mris_fix_topology -all-info >> $LF
  479. mris_topo_fixer -all-info >> $LF
  480. mris_ca_label -all-info >> $LF
  481. mris_euler_number -all-info >> $LF
  482. mris_make_surfaces -all-info >> $LF
  483. mris_register -all-info >> $LF
  484. mris_volmask --all-info >> $LF
  485. mris_anatomical_stats -all-info >> $LF
  486. mrisp_paint -all-info >> $LF
  487. mris_curvature_stats -all-info >> $LF
  488. if(-e .xdebug_mris_curvature_stats) rm -f .xdebug_mris_curvature_stats
  489. mris_calc -all-info >> $LF
  490. if(-e .xdebug_mris_calc) rm -f .xdebug_mris_calc
  491. mri_robust_register -all-info >> $LF
  492. mri_robust_template -all-info >> $LF
  493. mri_and -all-info >> $LF
  494. mri_or -all-info >> $LF
  495. mri_fuse_segmentations -all-info >> $LF
  496. mri_segstats -all-info >> $LF
  497. echo "#######################################" >> $LF
  498. echo "GCADIR $GCADIR" >> $LF
  499. echo "GCA $GCA" >> $LF
  500. echo "GCASkull $GCASkull" >> $LF
  501. echo "AvgCurvTif $AvgCurvTif" >> $LF
  502. echo "GCSDIR $GCSDIR" >> $LF
  503. echo "GCS $GCS" >> $LF
  504. echo "#######################################" >> $LF
  505. skip_all_info:
  506. if($DoVersionsOnly) exit 0;
  507. # Delete the error file. This is created when error_exit is run.
  508. set ErrorFile = $subjdir/scripts/recon-all.error
  509. rm -f $ErrorFile
  510. # Delete the done file. This is created when recon-all exits normally
  511. set DoneFile = $subjdir/scripts/recon-all.done
  512. rm -f $DoneFile
  513. # ------------ Create the IsRunning File --------- #
  514. if($DoIsRunning) then
  515. set IsRunningLH = $subjdir/scripts/IsRunning.lh
  516. set IsRunningRH = $subjdir/scripts/IsRunning.rh
  517. set IsRunningLHRH = $subjdir/scripts/IsRunning.lh+rh
  518. set bailfile = ();
  519. if($#hemilist == 1) then
  520. set hemi = $hemilist;
  521. set IsRunningFile = $subjdir/scripts/IsRunning.$hemi
  522. if(-e $IsRunningLHRH) set bailfile = $IsRunningLHRH
  523. else
  524. set IsRunningFile = $subjdir/scripts/IsRunning.lh+rh
  525. if(-e $IsRunningLH) set bailfile = $IsRunningLH
  526. if(-e $IsRunningRH) set bailfile = $IsRunningRH
  527. endif
  528. if(-e $IsRunningFile) set bailfile = $IsRunningFile
  529. if($#bailfile) then
  530. echo ""
  531. echo "ERROR: it appears that recon-all is already running"
  532. echo "for $subjid based on the presence of $bailfile. It could"
  533. echo "also be that recon-all was running at one point but"
  534. echo "died in an unexpected way. If it is the case that there"
  535. echo "is a process running, you can kill it and start over or"
  536. echo "just let it run. If the process has died, you should type:"
  537. echo ""
  538. echo "rm $bailfile"
  539. echo ""
  540. echo "and re-run. Or you can add -no-isrunning to the recon-all"
  541. echo "command-line. The contents of this file are:"
  542. echo "----------------------------------------------------------"
  543. cat $bailfile
  544. echo "----------------------------------------------------------"
  545. exit 1;
  546. endif
  547. echo "------------------------------" > $IsRunningFile
  548. echo "SUBJECT $subjid" >> $IsRunningFile
  549. echo "HEMI $hemilist" >> $IsRunningFile
  550. echo "DATE `date`" >> $IsRunningFile
  551. echo "USER $user" >> $IsRunningFile
  552. echo "HOST `hostname`" >> $IsRunningFile
  553. echo "PROCESSID $$ " >> $IsRunningFile
  554. echo "PROCESSOR `uname -m`" >> $IsRunningFile
  555. echo "OS `uname -s`" >> $IsRunningFile
  556. uname -a >> $IsRunningFile
  557. echo $VERSION >> $IsRunningFile
  558. endif
  559. # ------- Check FREESURFER HOME consistency ---------------------#
  560. set CSDF = $subjdir/scripts/csurfdir
  561. if($DoCleanCSDF) rm -vf $CSDF
  562. if(-e $CSDF) then
  563. set tmp = `cat $CSDF`;
  564. if($tmp != $FREESURFER_HOME) then
  565. echo "INFO: current FREESURFER_HOME does not match that of previous processing." \
  566. | tee -a $LF
  567. echo " Current: $FREESURFER_HOME" | tee -a $LF
  568. echo " Previous: $tmp" | tee -a $LF
  569. sleep 1;
  570. endif
  571. else
  572. echo $FREESURFER_HOME > $CSDF
  573. endif
  574. # --------------- Create the status file ---------------- #
  575. if($#SF == 0) then
  576. set SF = ($subjdir/scripts/$SF_DEFAULT_NAME)
  577. if(-e $SF) then
  578. if(! $AppendStatus) then
  579. mv $SF $SF.old
  580. else
  581. echo "\n\n" >> $SF
  582. echo "New invocation of recon-all " >> $SF
  583. echo "\n\n" >> $SF
  584. endif
  585. endif
  586. else
  587. if(-e $SF) then
  588. echo "\n\n" >> $SF
  589. echo "New invocation of recon-all " >> $SF
  590. echo "\n\n" >> $SF
  591. endif
  592. endif
  593. echo "status file for recon-all" >> $SF
  594. date >> $SF
  595. # Put a copy of myself (this script) in the scripts dir
  596. cp $0 $subjdir/scripts/recon-all.local-copy
  597. # Wait for a file to appear #
  598. if($#WaitForFile != 0) then
  599. echo "Waiting for $WaitForFile" |& tee -a $SF |& tee -a $LF
  600. echo " WaitSleep $WaitSleep" |& tee -a $SF |& tee -a $LF
  601. echo " nWaitsMax $nWaitsMax" |& tee -a $SF |& tee -a $LF
  602. @ nWaits = 1;
  603. while(! -e $WaitForFile && $nWaits < $nWaitsMax)
  604. sleep $WaitSleep;
  605. @ nWaits = $nWaits + 1;
  606. end
  607. if(! -e $WaitForFile ) then
  608. echo "ERROR: timed out waiting for $WaitForFile"
  609. goto error_exit;
  610. endif
  611. echo "Finished Waiting `date`" |& tee -a $SF |& tee -a $LF
  612. endif
  613. if( ! $RunIt) then
  614. echo "INFO: -dontrun flag is in effect, so subsequent commands" |& tee -a $LF
  615. echo "may not have accurate arguments!" |& tee -a $LF
  616. endif
  617. #------------ Clean -----------------------------#
  618. if($DoCleanSeed) then
  619. set cmd = ("mv -f $subjdir/scripts/seed-*.crs.man.dat $subjdir/trash");
  620. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  621. if($RunIt) $cmd |& tee -a $LF
  622. endif
  623. if($DoCleanCW256) then
  624. set cmd = (mv -f $subjdir/tmp/cw256 $subjdir/trash)
  625. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  626. if($RunIt) $cmd |& tee -a $LF
  627. endif
  628. if($DoCleanTal) then
  629. set cmd = (mv -f $subjdir/mri/transforms/talairach.xfm $subjdir/trash)
  630. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  631. if($RunIt) $cmd |& tee -a $LF
  632. endif
  633. if($DoCleanLta) then
  634. set cmd = ("mv -f $subjdir/mri/transforms/*.lta $subjdir/trash")
  635. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  636. if($RunIt) $cmd |& tee -a $LF
  637. endif
  638. if($DoCleanPFH) then
  639. set cmd = (mv -f $subjdir/mri/optimal_preflood_height $subjdir/trash)
  640. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  641. if($RunIt) $cmd |& tee -a $LF
  642. set cmd = (mv -f $subjdir/mri/optimal_skullstrip_invol $subjdir/trash)
  643. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  644. if($RunIt) $cmd |& tee -a $LF
  645. endif
  646. if($DoCleanBM) then
  647. set cmd = (mv -f $subjdir/mri/brainmask.mgz $subjdir/trash)
  648. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  649. if($RunIt) $cmd |& tee -a $LF
  650. endif
  651. if($DoCleanASeg) then
  652. set cmd = (mv -f $subjdir/mri/aseg.mgz $subjdir/trash)
  653. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  654. if($RunIt) $cmd |& tee -a $LF
  655. set cmd = (mv -f $subjdir/mri/aseg.manedit.mgz $subjdir/trash)
  656. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  657. if($RunIt) $cmd |& tee -a $LF
  658. endif
  659. if($DoCleanWM) then
  660. set cmd = (mv -f $subjdir/mri/wm.mgz $subjdir/trash)
  661. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  662. if($RunIt) $cmd |& tee -a $LF
  663. set cmd = (mv -f $subjdir/mri/wm.seg.mgz $subjdir/trash)
  664. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  665. if($RunIt) $cmd |& tee -a $LF
  666. endif
  667. if($DoCleanCP) then
  668. set cmd = (mv -f $subjdir/tmp/control.dat $subjdir/trash)
  669. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  670. if($RunIt) $cmd |& tee -a $LF
  671. endif
  672. if($DoCleanBFSE) then
  673. set cmd = (mv -f $subjdir/mri/brain.finalsurfs.manedit.mgz $subjdir/trash)
  674. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  675. if($RunIt) $cmd |& tee -a $LF
  676. endif
  677. if($DoCleanXopts) then
  678. set cmd = (mv -f $subjdir/scripts/expert-options $subjdir/trash)
  679. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  680. if($RunIt) $cmd |& tee -a $LF
  681. endif
  682. if($DoCleanT2) then
  683. set cmd = (mv -f $subjdir/mri/T2.mgz $subjdir/trash)
  684. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  685. if($RunIt) $cmd |& tee -a $LF
  686. endif
  687. if($DoCleanFLAIR) then
  688. set cmd = (mv -f $subjdir/mri/FLAIR.mgz $subjdir/trash)
  689. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  690. if($RunIt) $cmd |& tee -a $LF
  691. endif
  692. #------------ Handle Seed Points for Fill/Cut, and Watershed ---------------#
  693. set seedfile = $subjdir/scripts/seed-pons.crs.man.dat
  694. if($#PonsSeedCRS) then
  695. echo "# Manually specified seed CRS for Pons" > $seedfile
  696. echo $PonsSeedCRS >> $seedfile
  697. endif
  698. if(-e $seedfile) set PonsSeedCRS = `cat $seedfile | grep -v \#`
  699. set seedfile = $subjdir/scripts/seed-cc.crs.man.dat
  700. if($#CCSeedCRS) then
  701. echo "# Manually specified seed CRS for CC" > $seedfile
  702. echo $CCSeedCRS >> $seedfile
  703. endif
  704. if(-e $seedfile) set CCSeedCRS = `cat $seedfile | grep -v \#`
  705. set seedfile = $subjdir/scripts/seed-lh.crs.man.dat
  706. if($#LHSeedCRS) then
  707. echo "# Manually specified seed CRS for LH" > $seedfile
  708. echo $LHSeedCRS >> $seedfile
  709. endif
  710. if(-e $seedfile) set LHSeedCRS = `cat $seedfile | grep -v \#`
  711. set seedfile = $subjdir/scripts/seed-rh.crs.man.dat
  712. if($#RHSeedCRS) then
  713. echo "# Manually specified seed CRS for RH" > $seedfile
  714. echo $RHSeedCRS >> $seedfile
  715. endif
  716. if(-e $seedfile) set RHSeedCRS = `cat $seedfile | grep -v \#`
  717. set seedfile = $subjdir/scripts/seed-ws.crs.man.dat
  718. if($#WSSeedPoint) then
  719. echo "# Manually specified seed CRS for watershed" > $seedfile
  720. echo $WSSeedPoint >> $seedfile
  721. endif
  722. if(-e $seedfile) set WSSeedPoint = `cat $seedfile | grep -v \#`
  723. #------------ Control Points for Intensity Normalization ------------------#
  724. set ControlPointsFile = $subjdir/tmp/control.dat
  725. if(-e $ControlPointsFile) then
  726. set UseControlPoints = 1;
  727. endif
  728. #---- Conform Width to 256 --------#
  729. if( $DoConformWidth256) then
  730. echo "-cw256 option is now persistent (remove with -clean-cw256)" \
  731. |& tee -a $LF
  732. touch $subjdir/tmp/cw256
  733. endif
  734. #---------------- Show Edits ------------------#
  735. # discover which edits a user has made, list them, and if volume edits were
  736. # made, create a file which shows them (using mri_compile_edits)
  737. if($DoShowEdits) then
  738. @ edit_count = 0;
  739. echo "-----------------------------------------------" |& tee -a $LF
  740. echo "Subject $subjid has the following edits..." |& tee -a $LF
  741. # control points
  742. if(-e $ControlPointsFile) then
  743. @ edit_count = $edit_count + 1;
  744. set num_cps = (`grep numpoints $ControlPointsFile | awk '{print $2}'`)
  745. echo "$num_cps control points declared in file $ControlPointsFile" |& tee -a $LF
  746. endif
  747. # seeds
  748. set seedfile = $subjdir/scripts/seed-pons.crs.man.dat
  749. if(-e $seedfile) then
  750. @ edit_count = $edit_count + 1;
  751. echo "Manually specified seed CRS for Pons in file $seedfile" |& tee -a $LF
  752. endif
  753. set seedfile = $subjdir/scripts/seed-cc.crs.man.dat
  754. if($#CCSeedCRS) then
  755. @ edit_count = $edit_count + 1;
  756. echo "Manually specified seed CRS for CC in file $seedfile" |& tee -a $LF
  757. endif
  758. set seedfile = $subjdir/scripts/seed-lh.crs.man.dat
  759. if($#LHSeedCRS) then
  760. @ edit_count = $edit_count + 1;
  761. echo "Manually specified seed CRS for LH in file $seedfile" |& tee -a $LF
  762. endif
  763. set seedfile = $subjdir/scripts/seed-rh.crs.man.dat
  764. if($#RHSeedCRS) then
  765. @ edit_count = $edit_count + 1;
  766. echo "Manually specified seed CRS for RH in file $seedfile" |& tee -a $LF
  767. endif
  768. set seedfile = $subjdir/scripts/seed-ws.crs.man.dat
  769. if($#WSSeedPoint) then
  770. @ edit_count = $edit_count + 1;
  771. echo "Manually specified seed CRS for watershed in file $seedfile" \
  772. |& tee -a $LF
  773. endif
  774. # expert opts
  775. if($#XOptsFile != 0) then
  776. if (-e $XOptsFile) then
  777. @ edit_count = $edit_count + 1;
  778. echo "Expert options declared in file $XOptsFile" |& tee -a $LF
  779. endif
  780. endif
  781. # talairach.xfm
  782. set xfm = $subjdir/mri/transforms/talairach.xfm
  783. set xfma = $subjdir/mri/transforms/talairach.auto.xfm
  784. if(-e $xfm && -e $xfma) then
  785. diff $xfm $xfma >& /dev/null
  786. if($status) then
  787. @ edit_count = $edit_count + 1;
  788. echo "The talairach.xfm file appears to have been edited" |& tee -a $LF
  789. endif
  790. endif
  791. # cw256
  792. if(-e $subjdir/tmp/cw256) then
  793. @ edit_count = $edit_count + 1;
  794. echo "Conform-width (reduce FOV) to 256 is enabled" |& tee -a $LF
  795. endif
  796. # volume edits, as determined by mri_compile_edits:
  797. # brainmask.mgz, aseg.mgz, brain.finalsurfs.mgz, wm.mgz, brain.mgz
  798. set compile_edits=($subjdir/tmp/compile_edits)
  799. set cmd = (mri_compile_edits ${subjid} $subjdir/mri/edits.mgz)
  800. if($RunIt) then
  801. if ( -e $compile_edits) rm -f $compile_edits
  802. $cmd |& tee -a $LF |& tee -a $compile_edits
  803. set vol_edits=(`grep mri_compile_edits_found $compile_edits | awk '{print $1}'`)
  804. if($#vol_edits != 0) then
  805. @ edit_count = $edit_count + $vol_edits;
  806. endif
  807. endif
  808. # summarize
  809. echo "$edit_count edits were found for subject $subjid" |& tee -a $LF
  810. endif
  811. #----------- Longitudinal ------------------#
  812. if($longitudinal) then
  813. # if adding a new timepoint was requested by -addtp flag
  814. if($DoAddTp) then
  815. echo "Adding $tpNid as timepoint to base $longbaseid" |& tee -a $LF
  816. set cmd=(mri_add_new_tp $longbaseid $tpNid)
  817. if($RunIt) $cmd |& tee -a $LF
  818. if($status) goto error_exit;
  819. endif
  820. # init regfile variable with map cross_tp to base:
  821. # used later in many places
  822. set tpNtobase_regfile = ${longbasedir}/mri/transforms/${tpNid}_to_${longbaseid}.lta
  823. # map control.dat file from the cross-sectional data for this subj
  824. if ( -e ${SUBJECTS_DIR}/${tpNid}/tmp/control.dat && ! $UseLongbaseCtrlVol ) then
  825. # only if it does not already exist:
  826. if ( ! -e ${subjdir}/tmp/control.dat ) then
  827. set cmd = (mkdir -p ${subjdir}/tmp)
  828. echo "\n $cmd"|& tee -a $LF |& tee -a $CF
  829. if($RunIt) $cmd |& tee -a $LF
  830. set cmd = (mri_map_cpdat -in ${SUBJECTS_DIR}/${tpNid}/tmp/control.dat)
  831. set cmd = ($cmd -out ${subjdir}/tmp/control.dat)
  832. set cmd = ($cmd -lta $tpNtobase_regfile)
  833. echo " $cmd \n"|& tee -a $LF |& tee -a $CF
  834. if($RunIt) $cmd |& tee -a $LF
  835. if($status) goto error_exit;
  836. endif
  837. endif
  838. endif
  839. #----------- Convert T1 Input ------------------#
  840. if($#InputList != 0) then
  841. @ nth = 1;
  842. foreach InputVol ($InputList)
  843. # sanity-check: make sure each input has the same dimensions
  844. if ($nth == 1) then
  845. # assume first input has 'correct' dimensions
  846. set firstInput = ($InputVol)
  847. set rows = `mri_info --nrows $InputVol |& tail -n 1`
  848. set cols = `mri_info --ncols $InputVol |& tail -n 1`
  849. set slices = `mri_info --nslices $InputVol |& tail -n 1`
  850. else
  851. # check subsequent against the first input
  852. set nrows = `mri_info --nrows $InputVol |& tail -n 1`
  853. set ncols = `mri_info --ncols $InputVol |& tail -n 1`
  854. set nslices = `mri_info --nslices $InputVol |& tail -n 1`
  855. if (($nrows != $rows) || \
  856. ($ncols != $cols) || \
  857. ($nslices != $slices)) then
  858. echo "ERROR: inputs have mismatched dimensions!" |& tee -a $LF
  859. echo "$firstInput is" |& tee -a $LF
  860. echo "$rows x $cols x $slices while" |& tee -a $LF
  861. echo "$InputVol is" |& tee -a $LF
  862. echo "$nrows x $ncols x $nslices" |& tee -a $LF
  863. goto error_exit;
  864. endif
  865. endif
  866. set nthid = `printf %03d.mgz $nth`
  867. set cmd = (mri_convert $InputVol $subjdir/mri/orig/$nthid)
  868. $PWD |& tee -a $LF
  869. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  870. if($RunIt) then
  871. $fs_time $cmd |& tee -a $LF
  872. if($status) goto error_exit;
  873. endif
  874. @ nth = $nth + 1;
  875. end
  876. endif
  877. #----------- Input T2 or FLAIR images ------------------#
  878. if ($DoConvertT2Input || $DoConvertFlairInput) then
  879. echo "#--------------------------------------------" \
  880. |& tee -a $LF |& tee -a $CF
  881. echo "#@# T2/FLAIR Input `date`" \
  882. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  883. if ($DoConvertT2Input) then
  884. set cmd = (mri_convert $InputT2Vol $subjdir/mri/orig/T2raw.mgz)
  885. $PWD |& tee -a $LF
  886. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  887. if($RunIt) then
  888. $fs_time $cmd |& tee -a $LF
  889. if($status) goto error_exit;
  890. endif
  891. endif
  892. if ($DoConvertFlairInput) then
  893. set cmd = (mri_convert $InputFlairVol $subjdir/mri/orig/FLAIRraw.mgz)
  894. $PWD |& tee -a $LF
  895. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  896. if($RunIt) then
  897. $fs_time $cmd |& tee -a $LF
  898. if($status) goto error_exit;
  899. endif
  900. endif
  901. endif
  902. #------------- Longitudinal 'base' subject input file creation ------------#
  903. if ($DoCreateBaseInput && $DoCreateBaseSubj) then
  904. echo "#--------------------------------------------" \
  905. |& tee -a $LF |& tee -a $CF
  906. echo "#@# Longitudinal Base Subject Creation `date`" \
  907. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  908. if ($#BaseSubjsList == 0) then
  909. echo "ERROR: must specify subjects for base subject using -base-tp" \
  910. |& tee -a $LF
  911. goto error_exit;
  912. endif
  913. cd $subjdir > /dev/null
  914. $PWD |& tee -a $LF
  915. if($RunIt) rm -f ${BaseSubjsListFname};
  916. set subjInVols=();
  917. set normInVols=();
  918. set ltaXforms=();
  919. set lta1forms=();
  920. set ltaAforms=();
  921. set headInVols=();
  922. set geodiff=0;
  923. foreach s ($BaseSubjsList)
  924. if($RunIt) echo "${s}" >> ${BaseSubjsListFname};
  925. set normInVols = ($normInVols ${SUBJECTS_DIR}/${s}/mri/norm.mgz)
  926. set headInVols = ($headInVols ${SUBJECTS_DIR}/${s}/mri/T1.mgz)
  927. set subjInVols = ($subjInVols ${SUBJECTS_DIR}/${s}/mri/${BaseSubjInvol})
  928. set ltaname = ${s}_to_${subjid}.lta
  929. set ltaXforms = ($ltaXforms ${subjdir}/mri/transforms/${ltaname})
  930. set lta1forms = ($lta1forms ${subjdir}/mri/transforms/${s}_to_${subjid}_norm.lta)
  931. set ltaAforms = ($ltaAforms ${subjdir}/mri/transforms/${s}_to_${subjid}_affine.lta)
  932. # check if geometry differs across time
  933. if ( "$s" != "$BaseSubjsList[1]" ) then
  934. set cmd = ( mri_diff --notallow-pix ${SUBJECTS_DIR}/$s/mri/rawavg.mgz \
  935. ${SUBJECTS_DIR}/$BaseSubjsList[1]/mri/rawavg.mgz )
  936. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  937. if($RunIt) then
  938. $fs_time $cmd |& tee -a $LF
  939. if($status) set geodiff = 1;
  940. endif
  941. endif
  942. end
  943. if ( "$geodiff" == "1" ) then
  944. echo "\n*******************************************************************************" |& tee -a $LF
  945. echo "WARNING: Image geometries differ across time, maybe due to aquisition changes?" |& tee -a $LF
  946. echo " This can potentially bias a longitudinal study! Will continue in 10s." |& tee -a $LF
  947. echo "*******************************************************************************\n" |& tee -a $LF
  948. sleep 10
  949. endif
  950. if ($#BaseSubjsList == 1) then
  951. # if only a single time point, create fake 'base' by making the image upright
  952. # this assures that also subjects with a single time point get processes as the other
  953. # subjects in the longitudinal stream
  954. # 1. make the norm upright (base space)
  955. set cmd = ( make_upright $normInVols[1] ${subjdir}/mri/norm_template.mgz $ltaXforms[1] )
  956. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  957. if($RunIt) then
  958. $fs_time $cmd |& tee -a $LF
  959. if($status) goto error_exit;
  960. endif
  961. # 2. create the upright orig volume
  962. set cmd = ( mri_convert -rt cubic -at $ltaXforms[1] $subjInVols[1] ${subjdir}/mri/orig.mgz )
  963. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  964. if($RunIt) then
  965. $fs_time $cmd |& tee -a $LF
  966. if($status) goto error_exit;
  967. endif
  968. else #more than 1 time point:
  969. # create the 'mean/median' norm volume:
  970. set cmd = (mri_robust_template --mov ${normInVols})
  971. if ($DoAffineBase) then
  972. # this is only initial rigid reg
  973. set cmd = ($cmd --lta ${lta1forms})
  974. set cmd = ($cmd --template ${subjdir}/mri/norm1_template.mgz)
  975. else
  976. # this is final rigid reg
  977. set cmd = ($cmd --lta ${ltaXforms})
  978. set cmd = ($cmd --template ${subjdir}/mri/norm_template.mgz)
  979. endif
  980. set cmd = ($cmd --average ${robust_template_avg_arg})
  981. set cmd = ($cmd --sat 4.685 )
  982. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  983. if($RunIt) then
  984. $fs_time $cmd |& tee -a $LF
  985. if($status) goto error_exit;
  986. endif
  987. if ($DoAffineBase) then
  988. # use registration on norm.mgz to initialize affine reg on full head imgs:
  989. set cmd = (mri_robust_template --mov ${headInVols})
  990. set cmd = ($cmd --lta ${ltaAforms})
  991. set cmd = ($cmd --average ${robust_template_avg_arg})
  992. set cmd = ($cmd --template ${subjdir}/mri/head_template.mgz)
  993. set cmd = ($cmd --sat 4.685 )
  994. set cmd = ($cmd --ixforms ${lta1forms})
  995. set cmd = ($cmd --affine)
  996. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  997. if($RunIt) then
  998. $fs_time $cmd |& tee -a $LF
  999. if($status) goto error_exit;
  1000. endif
  1001. # use affine reg to init rigid reg on norm,.mgz (fine tuning)
  1002. # not sure if it is really necessary
  1003. set cmd = (mri_robust_template --mov ${normInVols})
  1004. set cmd = ($cmd --lta ${ltaXforms})
  1005. set cmd = ($cmd --average ${robust_template_avg_arg})
  1006. set cmd = ($cmd --template ${subjdir}/mri/norm_template.mgz)
  1007. set cmd = ($cmd --sat 4.685 )
  1008. set cmd = ($cmd --ixforms ${ltaAforms})
  1009. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1010. if($RunIt) then
  1011. $fs_time $cmd |& tee -a $LF
  1012. if($status) goto error_exit;
  1013. endif
  1014. endif
  1015. # create the 'mean/median' input (orig) volume:
  1016. set cmd = (mri_robust_template --mov ${subjInVols})
  1017. set cmd = ($cmd --average ${robust_template_avg_arg})
  1018. set cmd = ($cmd --ixforms ${ltaXforms})
  1019. set cmd = ($cmd --noit)
  1020. set cmd = ($cmd --template ${subjdir}/mri/orig.mgz)
  1021. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1022. if($RunIt) then
  1023. $fs_time $cmd |& tee -a $LF
  1024. if($status) goto error_exit;
  1025. endif
  1026. endif # more than one time point
  1027. # now create the inverse transforms
  1028. cd $subjdir/mri/transforms > /dev/null
  1029. $PWD |& tee -a $LF
  1030. foreach s ($BaseSubjsList)
  1031. set cmd = (mri_concatenate_lta -invert1)
  1032. set cmd = ($cmd ${s}_to_${subjid}.lta)
  1033. set cmd = ($cmd identity.nofile)
  1034. set cmd = ($cmd ${subjid}_to_${s}.lta)
  1035. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1036. if($RunIt) then
  1037. $fs_time $cmd |& tee -a $LF
  1038. if($status) goto error_exit;
  1039. endif
  1040. end
  1041. touch $touchdir/base.touch
  1042. endif
  1043. #----------- Motion Correct and Average ------------------#
  1044. if($DoMotionCor) then
  1045. echo "#--------------------------------------------" \
  1046. |& tee -a $LF |& tee -a $CF
  1047. echo "#@# MotionCor `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1048. if ($longitudinal) then
  1049. # longitudinal processing to create orig.mgz:
  1050. # in order to create orig.mgz in LONG we need at least 001.mgz in CROSS:
  1051. if ( ! -e ${SUBJECTS_DIR}/${tpNid}/mri/orig/001.mgz ) then
  1052. echo "ERROR: no CROSS run data found in ${SUBJECTS_DIR}/${tpNid}/mri/orig/. Make sure to" \
  1053. |& tee -a $LF
  1054. echo "have a volume called 001.mgz there." |& tee -a $LF
  1055. echo "If you have a second run of data call it 002.mgz, etc." \
  1056. |& tee -a $LF
  1057. echo "See also: http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Conversion" \
  1058. |& tee -a $LF
  1059. goto error_exit;
  1060. endif
  1061. # use orig/00?.mgz from cross:
  1062. set CrossList = `ls ${SUBJECTS_DIR}/${tpNid}/mri/orig/[0-9][0-9][0-9].mgz`;
  1063. set origvol = $subjdir/mri/orig.mgz
  1064. set rawvol = $subjdir/mri/rawavg.mgz
  1065. if($#CrossList == 1) then
  1066. # if only single input, directly resample to base space
  1067. set cmd = (mri_convert -at $tpNtobase_regfile -odt uchar)
  1068. set cmd = ($cmd -rt cubic)
  1069. set cmd = ($cmd ${SUBJECTS_DIR}/${tpNid}/mri/orig/001.mgz)
  1070. set cmd = ($cmd ${origvol})
  1071. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1072. if($RunIt) $fs_time $cmd |& tee -a $LF
  1073. if($status) goto error_exit;
  1074. # also create rawavg (usually float) image
  1075. set cmd = (mri_convert -at $tpNtobase_regfile )
  1076. set cmd = ($cmd -rt cubic)
  1077. set cmd = ($cmd ${SUBJECTS_DIR}/${tpNid}/mri/orig/001.mgz)
  1078. set cmd = ($cmd ${rawvol})
  1079. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1080. if($RunIt) $fs_time $cmd |& tee -a $LF
  1081. if($status) goto error_exit;
  1082. goto motioncor_post_process
  1083. endif
  1084. # if ltas and iscales exist in cross, copy them over
  1085. set CrossLtas = `ls ${SUBJECTS_DIR}/${tpNid}/mri/orig/[0-9][0-9][0-9].lta`;
  1086. set CrossIscales = `ls ${SUBJECTS_DIR}/${tpNid}/mri/orig/[0-9][0-9][0-9]-iscale.txt`;
  1087. if ( $#CrossLtas > 0 ) then
  1088. # check if one lta for each mgz:
  1089. # here we could better check if really each 00?.mgz has its own 00?.lta in future
  1090. if ( $#CrossList != $#CrossLtas ) then
  1091. echo "ERROR: Orig 00?.mgz runs and number of 00?.lta files must agree in" \
  1092. |& tee -a $LF
  1093. echo "${SUBJECTS_DIR}/${tpNid}/mri/orig/" \
  1094. |& tee -a $LF
  1095. goto error_exit;
  1096. endif
  1097. #copy ltas:
  1098. cd $subjdir/mri/
  1099. set cmd = (cp -vf ${CrossLtas})
  1100. set cmd = ($cmd orig/)
  1101. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1102. if($RunIt) $fs_time $cmd |& tee -a $LF
  1103. if($status) goto error_exit;
  1104. #copy iscales if available:
  1105. if ($#CrossIscales > 0) then
  1106. # here we could better check if really each 00?.mgz has its own iscale file in future
  1107. if ( $#CrossList != $#CrossIscales ) then
  1108. echo "ERROR: Orig 00?.mgz runs and number of 00?-iscale.txt files must agree in" \
  1109. |& tee -a $LF
  1110. echo "${SUBJECTS_DIR}/${tpNid}/mri/orig/" \
  1111. |& tee -a $LF
  1112. goto error_exit;
  1113. endif
  1114. cd $subjdir/mri/
  1115. set cmd = (cp -vf ${CrossIscales})
  1116. set cmd = ($cmd orig/)
  1117. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1118. if($RunIt) $fs_time $cmd |& tee -a $LF
  1119. if($status) goto error_exit;
  1120. endif
  1121. else
  1122. # else the ltas don't exist (maybe because 5.0 or fsl was used,
  1123. # they are created by 5.1+ in cross sectional stream)
  1124. # if more than one input, re-receate the ltas:
  1125. if($#CrossList > 1) then
  1126. # set output names for ltas and iscales in long dir
  1127. set LongLtas = ""
  1128. set LongIscales = ""
  1129. foreach nthid ($CrossList)
  1130. set nthname=`basename $nthid .mgz`
  1131. set nthdir=$subjdir/mri/orig
  1132. set nthlta=${nthdir}/${nthname}.lta
  1133. set LongLtas=($LongLtas $nthlta)
  1134. set LongIscales=($LongIscales $nthdir/${nthname}-iscale.txt)
  1135. end
  1136. # perform motion correction again to obtain the ltas (but in long dir, don't touch cross):
  1137. set rawavg = $subjdir/mri/rawavg.mgz
  1138. # the output rawavg in long will be ignored and not used for anything
  1139. # except maybe debugging, we only need the ltas and iscales!
  1140. set cmd = (mri_robust_template)
  1141. set cmd = ($cmd --mov ${CrossList})
  1142. set cmd = ($cmd --average 1)
  1143. set cmd = ($cmd --template ${rawavg})
  1144. set cmd = ($cmd --satit)
  1145. set cmd = ($cmd --inittp 1)
  1146. set cmd = ($cmd --fixtp)
  1147. set cmd = ($cmd --noit)
  1148. set cmd = ($cmd --iscale)
  1149. set cmd = ($cmd --iscaleout $LongIscales)
  1150. set cmd = ($cmd --subsample 200)
  1151. set cmd = ($cmd --lta $LongLtas)
  1152. echo "#-----------------------------------------------"
  1153. $PWD |& tee -a $LF
  1154. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1155. if($RunIt) then
  1156. $fs_time $cmd |& tee -a $LF
  1157. if($status) goto error_exit;
  1158. endif
  1159. # better get rid of rawavg to avoid confusion
  1160. # as it is not in the base/long space, but in 001.mgz space
  1161. set cmd = (rm -f $rawavg )
  1162. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1163. if($RunIt) then
  1164. $fs_time $cmd |& tee -a $LF
  1165. if($status) goto error_exit;
  1166. endif
  1167. else
  1168. # we should never get here, this case hase been dealt with above
  1169. echo Only single run - should not get here
  1170. goto error_exit;
  1171. endif
  1172. endif
  1173. # now we have the ltas in long (current tp : subjdir)
  1174. set LongLtas = `ls $subjdir/mri/orig/[0-9][0-9][0-9].lta`;
  1175. set LongIscales = `ls $subjdir/mri/orig/[0-9][0-9][0-9]-iscale.txt`;
  1176. # concat ltas (e.g. 002 -> 001 -> base/orig.mgz)
  1177. set ConcatLtas = ""
  1178. foreach nthlta ($LongLtas)
  1179. set nthname=`basename $nthlta .lta`
  1180. set nthdir=$subjdir/mri/orig
  1181. set concatlta=${nthdir}/${nthname}-long.lta
  1182. set ConcatLtas=($ConcatLtas $nthdir/${nthname}-long.lta)
  1183. set cmd = (mri_concatenate_lta $nthlta $tpNtobase_regfile $concatlta)
  1184. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1185. if($RunIt) $fs_time $cmd |& tee -a $LF
  1186. if($status) goto error_exit;
  1187. end
  1188. # use mri_robust_template just to create the average in base orig space:
  1189. set cmd = (mri_robust_template)
  1190. set cmd = ($cmd --mov ${CrossList})
  1191. set cmd = ($cmd --average 1)
  1192. set cmd = ($cmd --ixforms ${ConcatLtas})
  1193. if ($#LongIscales > 0) then
  1194. set cmd = ($cmd --iscalein ${LongIscales})
  1195. endif
  1196. set cmd = ($cmd --noit)
  1197. set cmd = ($cmd --template ${rawvol})
  1198. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1199. if($RunIt) then
  1200. $fs_time $cmd |& tee -a $LF
  1201. if($status) goto error_exit;
  1202. endif
  1203. # make sure orig is uchar:
  1204. set cmd = (mri_convert -odt uchar ${rawvol} ${origvol})
  1205. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1206. if($RunIt) then
  1207. $fs_time $cmd |& tee -a $LF
  1208. if($status) goto error_exit;
  1209. endif
  1210. goto motioncor_post_process
  1211. endif #longitudinal
  1212. # base processing (we do not need to do anything,
  1213. # as orig should be there, rawavg is not there, due to difficulties of
  1214. # averaging different image geometries across time)
  1215. if ($DoCreateBaseSubj) then
  1216. set origvol = $subjdir/mri/orig.mgz
  1217. goto motioncor_post_process
  1218. endif
  1219. # default processing:
  1220. set cmd = ();
  1221. # Get list of input run directories #
  1222. set RunList = ();
  1223. ls $subjdir/mri/orig/[0-9][0-9][0-9].mgz >& /dev/null
  1224. if(! $status) then
  1225. set RunList = `ls $subjdir/mri/orig/[0-9][0-9][0-9].mgz`;
  1226. else
  1227. # No runs found
  1228. ls $subjdir/mri//[0-9][0-9][0-9].mgz >& /dev/null
  1229. if(! $status) then
  1230. set RunList = `ls $subjdir/mri//[0-9][0-9][0-9].mgz`;
  1231. else
  1232. ls $subjdir/src/[0-9][0-9][0-9].mgz >& /dev/null
  1233. if(! $status) then
  1234. set RunList = $subjdir/src/[0-9][0-9][0-9].mgz
  1235. endif
  1236. endif
  1237. endif
  1238. if($#RunList == 0 && $RunIt) then
  1239. echo "ERROR: no run data found in $subjdir/mri. Make sure to" \
  1240. |& tee -a $LF
  1241. echo "have a volume called 001.mgz in $subjdir/mri/orig." |& tee -a $LF
  1242. echo "If you have a second run of data call it 002.mgz, etc." \
  1243. |& tee -a $LF
  1244. echo "See also: http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Conversion" \
  1245. |& tee -a $LF
  1246. goto error_exit;
  1247. else
  1248. if ($RunIt) then
  1249. echo "Found $#RunList runs" |& tee -a $LF
  1250. foreach run ($RunList)
  1251. echo $run |& tee -a $LF
  1252. end
  1253. endif
  1254. endif
  1255. # sanity-check: check if the input contains multiple frames, which would
  1256. # be the case if a multi-echo frame mprage was accidently used as input.
  1257. # without this check, andre is unhappy
  1258. foreach RunVol ($RunList)
  1259. echo "Checking for (invalid) multi-frame inputs..." |& tee -a $LF
  1260. set nframes = `mri_info --nframes $RunVol |& tail -n 1`
  1261. if ($nframes != 1) then
  1262. echo "ERROR: input(s) cannot have multiple frames!" |& tee -a $LF
  1263. echo "$RunVol has $nframes frames" |& tee -a $LF
  1264. if ($nframes == 4) then
  1265. echo "If this is a multi-frame MEMPRAGE image," |& tee -a $LF
  1266. echo "use mri_concat --rms to combine echo frames." |& tee -a $LF
  1267. endif
  1268. goto error_exit;
  1269. endif
  1270. end
  1271. set origvol = $subjdir/mri/orig.mgz
  1272. set rawavg = $subjdir/mri/rawavg.mgz
  1273. # Only one run, copy to rawavg
  1274. if($#RunList == 1) then
  1275. echo "WARNING: only one run found. This is OK, but motion"|& tee -a $LF
  1276. echo "correction cannot be performed on one run, so I'll"|& tee -a $LF
  1277. echo "copy the run to rawavg and continue."|& tee -a $LF
  1278. sleep 2s;
  1279. set cmd = (cp $RunList $rawavg)
  1280. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1281. if($RunIt) then
  1282. sleep 1; # Sleep here to assure that they have diff time stamps
  1283. $cmd |& tee -a $LF
  1284. if($status) goto error_exit;
  1285. endif
  1286. endif
  1287. # Actually perform the motion correction -- creates rawavg
  1288. if($#RunList > 1) then
  1289. # set names for ltas
  1290. set RunLtas = ""
  1291. set RunIscales = ""
  1292. foreach nthid ($RunList)
  1293. set nthname=`basename $nthid .mgz`
  1294. set nthdir=`dirname $nthid`
  1295. set nthlta=${nthdir}/${nthname}.lta
  1296. set RunLtas=($RunLtas $nthlta)
  1297. set RunIscales=($RunIscales ${nthdir}/${nthname}-iscale.txt)
  1298. end
  1299. if($DoRobustMotionCor) then
  1300. set cmd = (mri_robust_template)
  1301. set cmd = ($cmd --mov ${RunList})
  1302. set cmd = ($cmd --average 1)
  1303. set cmd = ($cmd --template ${rawavg})
  1304. set cmd = ($cmd --satit)
  1305. set cmd = ($cmd --inittp 1)
  1306. set cmd = ($cmd --fixtp)
  1307. set cmd = ($cmd --noit)
  1308. set cmd = ($cmd --iscale)
  1309. set cmd = ($cmd --iscaleout $RunIscales)
  1310. set cmd = ($cmd --subsample 200)
  1311. set cmd = ($cmd --lta $RunLtas)
  1312. else
  1313. # use FSL's flirt to do motion correction (averaging of runs)
  1314. set cmd = (mri_motion_correct.fsl -o $rawavg -wild $RunList)
  1315. endif
  1316. echo "#-----------------------------------------------"
  1317. $PWD |& tee -a $LF
  1318. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1319. if($RunIt) then
  1320. $fs_time $cmd |& tee -a $LF
  1321. if($status) goto error_exit;
  1322. echo $cmd > $touchdir/motion_correct.touch
  1323. endif
  1324. endif
  1325. # At this point, rawavg.mgz exists. Use it to create orig.mgz,
  1326. # conform to COR FOV but keep mgz format.
  1327. set cmd = (mri_convert $rawavg $origvol)
  1328. if($UseCubic) set cmd = ($cmd -rt cubic)
  1329. if($ConformMin) then
  1330. set cmd = ($cmd --conform_min)
  1331. else
  1332. set cmd = ($cmd --conform)
  1333. if($DoConformWidth256 || -e $subjdir/tmp/cw256) then
  1334. # force conform width to 256
  1335. set cmd = ($cmd --cw256)
  1336. # see note just below on when -cw256 is necessary (ie, when FOV > 256)
  1337. endif
  1338. endif
  1339. $PWD |& tee -a $LF
  1340. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1341. if($RunIt) then
  1342. $fs_time $cmd |& tee -a $LF
  1343. if($status) goto error_exit;
  1344. echo $cmd > $touchdir/conform.touch
  1345. endif
  1346. # this is the goto target for longitudinal processing (from above):
  1347. motioncor_post_process:
  1348. # check if FOV > 256 and error exit if so
  1349. set FOV=`mri_info ${origvol} | grep fov: | awk '{print $2}'`
  1350. set FOV_gt_256=`echo "${FOV} > 256" | bc`
  1351. if ($FOV_gt_256) then
  1352. echo "\n****************************************" |& tee -a $LF
  1353. echo "ERROR! FOV=${FOV} > 256" |& tee -a $LF
  1354. echo "Include the flag -cw256 with recon-all!" |& tee -a $LF
  1355. echo "Inspect orig.mgz to ensure the head is fully visible." |& tee -a $LF
  1356. echo "****************************************\n" |& tee -a $LF
  1357. goto error_exit;
  1358. endif
  1359. # Add xfm to orig, even though it does not exist yet. This is a
  1360. # compromise to keep from having to change the time stamp of
  1361. # the orig volume after talairaching.
  1362. set cmd = (mri_add_xform_to_header -c \
  1363. $subjdir/mri/transforms/talairach.xfm \
  1364. $origvol $origvol)
  1365. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1366. if($RunIt) then
  1367. $fs_time $cmd |& tee -a $LF
  1368. if($status) goto error_exit;
  1369. endif
  1370. endif # Motion Correction
  1371. #----------- Talairach ------------------#
  1372. if($DoTalairach) then
  1373. talairach:
  1374. echo "#--------------------------------------------" \
  1375. |& tee -a $LF |& tee -a $CF
  1376. echo "#@# Talairach `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1377. cd $subjdir/mri > /dev/null
  1378. $PWD |& tee -a $LF
  1379. set xfm = transforms/talairach.xfm
  1380. set xfma = transforms/talairach.auto.xfm
  1381. if ($longitudinal) then
  1382. # longitudinal processing:
  1383. if( -e $longbasedir/mri/$xfm) then
  1384. set tal_xfm = $xfm
  1385. else
  1386. set tal_xfm = $xfma
  1387. endif
  1388. # copy from the base (as we are now in same space)
  1389. # if edits were made to base, they will be also in long
  1390. set cmd = (cp $longbasedir/mri/$tal_xfm $subjdir/mri/$xfma)
  1391. else
  1392. # default processing:
  1393. if ($DoTalairachUseNu) then
  1394. # note that this only works if nu exists
  1395. # this is used as an alternative if tal is giving bad results
  1396. set tal_input = nu.mgz
  1397. else
  1398. # default: run one pass of nu_correct, as its been found that scans
  1399. # with strong bias fields can cause talairach_avi to fail. note that
  1400. # this orig_nu doesnt do as much correction as
  1401. # the nuintensitycor stage (which does more passes and uses talairach.xfm
  1402. # to find the wm ball so as to do histogramming).
  1403. set tal_input = orig_nu.mgz
  1404. set cmd = (mri_nu_correct.mni \
  1405. --n 1 --proto-iters 1000 --distance 50 --no-rescale \
  1406. --i orig.mgz --o orig_nu.mgz)
  1407. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1408. if($RunIt) $fs_time $cmd >& orig_nu.log
  1409. if($status) goto error_exit;
  1410. endif
  1411. if ($UseMincMritotal) then
  1412. # use the MINC mritotal utility
  1413. set xopts = `fsr-getxopts talairach $XOptsFile`;
  1414. set cmd = (talairach --i $tal_input --xfm $xfma $xopts)
  1415. else
  1416. # Avi Snyder's registration tools
  1417. set xopts = `fsr-getxopts talairach_avi $XOptsFile`;
  1418. set cmd = (talairach_avi --i $tal_input --xfm $xfma)
  1419. if($?CustomTalAtlas && "$CustomTalAtlas" != "") then
  1420. # use user-specified atlas found in average dir
  1421. set cmd = ($cmd --atlas "$CustomTalAtlas")
  1422. else
  1423. if($UseYa3tTalAtlas) then
  1424. # special atlas composed of young adults scanned at 3T
  1425. set cmd = ($cmd --atlas 3T18yoSchwartzReactN32_as_orig)
  1426. endif
  1427. endif
  1428. set cmd = ($cmd $xopts)
  1429. endif
  1430. endif
  1431. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1432. if($RunIt) $fs_time $cmd |& tee -a $LF
  1433. if($status) goto error_exit;
  1434. if( -e $xfm && ! $DoCleanTal) then
  1435. echo "\nINFO: $xfm already exists!" \
  1436. |& tee -a $LF |& tee -a $CF
  1437. echo "The new $xfma will not be copied to $xfm" \
  1438. |& tee -a $LF |& tee -a $CF
  1439. echo "This is done to retain any edits made to $xfm" \
  1440. |& tee -a $LF |& tee -a $CF
  1441. echo "Add the -clean-tal flag to recon-all to overwrite $xfm\n" \
  1442. |& tee -a $LF |& tee -a $CF
  1443. endif
  1444. if($DoCleanTal || ! -e $xfm) then
  1445. if(-e $xfm) cp $xfm transforms/bak/talairach.xfm.$DateString
  1446. set cmd = (cp $xfma $xfm)
  1447. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1448. if($RunIt) then
  1449. sleep 1; # Sleep here to assure that they have diff time stamps
  1450. $cmd |& tee -a $LF
  1451. if($status) goto error_exit;
  1452. endif
  1453. endif
  1454. echo $cmd > $touchdir/talairach.touch
  1455. endif
  1456. # perform the failure detection scheme
  1457. if($DoTalCheck) then
  1458. echo "#--------------------------------------------" \
  1459. |& tee -a $LF |& tee -a $CF
  1460. echo "#@# Talairach Failure Detection `date`" \
  1461. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1462. cd $subjdir/mri > /dev/null
  1463. # first run Laurence's AFD tool:
  1464. set xopts = `fsr-getxopts talairach_afd $XOptsFile`;
  1465. set xfm = transforms/talairach.xfm
  1466. set cmd = (talairach_afd -T 0.005 -xfm $xfm $xopts)
  1467. $PWD |& tee -a $LF
  1468. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1469. if($RunIt) then
  1470. $fs_time $cmd |& tee -a $LF
  1471. if($status) then
  1472. # IF Talairach alignment was run
  1473. # AND it was using the avi synder method
  1474. # AND this check failed,
  1475. # THEN try Talairach alignment using MINC mritotal tool
  1476. # ELSE error exit
  1477. if($DoTalairach && ! $UseMincMritotal && ! $longitudinal) then
  1478. echo "INFO: Attempting MINC mritotal to perform Talairach align" \
  1479. |& tee -a $LF
  1480. set UseMincMritotal = 1;
  1481. set DoCleanTal = 1;
  1482. goto talairach;
  1483. else
  1484. echo "Manual Talairach alignment may be necessary, or" |& tee -a $LF
  1485. echo "include the -notal-check flag to skip this test," |& tee -a $LF
  1486. echo "making sure the -notal-check flag follows -all" |& tee -a $LF
  1487. echo "or -autorecon1 in the command string." |& tee -a $LF
  1488. echo "See http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Talairach" |& tee -a $LF
  1489. goto error_exit;
  1490. endif
  1491. endif
  1492. endif
  1493. # now run Avi's QA check on the results found in talairach_avi.log
  1494. # see document RLB700_preprocessing_statistics.pdf for details
  1495. set avilog = ($subjdir/mri/transforms/talairach_avi.log)
  1496. if ( ! $UseMincMritotal && -e $avilog) then
  1497. set cmd = (awk -f $FREESURFER_HOME/bin/extract_talairach_avi_QA.awk)
  1498. set cmd = ($cmd $avilog)
  1499. set qalog = ($subjdir/mri/transforms/talairach_avi_QA.log)
  1500. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1501. set cmd2 = (tal_QC_AZS $avilog)
  1502. set qalog2 = ($subjdir/mri/transforms/talairach_avi_QA2.log)
  1503. echo "\n $cmd2 \n"|& tee -a $LF |& tee -a $CF
  1504. if($RunIt) then
  1505. rm -f $qalog $qalog2
  1506. $fs_time $cmd >& $qalog
  1507. if($status) then
  1508. echo "ERROR: ${cmd} failed! See logfile ${qalog}" |& tee -a $LF
  1509. goto error_exit;
  1510. endif
  1511. # tal_QC_AZS disabled. failing in weird ways. getting caught in infinite 'test' loops.
  1512. if (0) then
  1513. $fs_time $cmd2 >& $qalog2
  1514. set tal_QC_AZS_status = $status
  1515. if($tal_QC_AZS_status) then
  1516. echo "INFO: ${cmd2} failed! See logfile ${qalog2}" |& tee -a $LF
  1517. echo " skipping tal_QC_AZS test" |& tee -a $LF
  1518. #NJS: skip instead of exit because tal_QC_AZS doesnt work on centos5.4
  1519. #goto error_exit;
  1520. endif
  1521. endif
  1522. # first set of QA data:
  1523. set talAviQA=`grep "TalAviQA" ${qalog} | awk '{print $2}'`
  1524. echo "TalAviQA: ${talAviQA}" |& tee -a $LF
  1525. set mean=(0.9781) # buckner40 mean TalAviQA
  1526. set std=(0.0044) # buckner40 std TalAviQA
  1527. set zscore=`echo "scale=0;(${talAviQA} - ${mean}) / ${std}" | bc`
  1528. echo "z-score: ${zscore}" |& tee -a $LF
  1529. set zscoreThreshold=(-9) # conservative value, but catches M.Harms subjs.
  1530. if (0) then
  1531. # second set:
  1532. if ( ! $tal_QC_AZS_status ) then
  1533. set talAviQA2=`grep "atlas_transform_error" ${qalog2} | awk '{print $6}'`
  1534. echo "TalAviQA2: ${talAviQA2}" |& tee -a $LF
  1535. set atlaserrhi=`echo "${talAviQA2} > 24" | bc`
  1536. set atlaserrlo=`echo "${talAviQA2} < -60" | bc`
  1537. else
  1538. set talAviQA2=0
  1539. set atlaserrhi=0
  1540. set atlaserrlo=0
  1541. endif
  1542. else
  1543. set talAviQA2=0
  1544. set atlaserrhi=0
  1545. set atlaserrlo=0
  1546. endif
  1547. # check both:
  1548. if (($zscore < $zscoreThreshold) || $atlaserrhi || $atlaserrlo) then
  1549. echo "ERROR: Talairach QA check failed!" |& tee -a $LF
  1550. echo " z-score = ${zscore} <= ${zscoreThreshold} = threshold\n" \
  1551. " atlas xform error = $talAviQA2 < -60 | > 24" \
  1552. |& tee -a $LF
  1553. echo "Manual Talairach alignment may be necessary, or" |& tee -a $LF
  1554. echo "include the -notal-check flag to skip this test," |& tee -a $LF
  1555. echo "making sure the -notal-check flag follows -all" |& tee -a $LF
  1556. echo "or -autorecon1 in the command string." |& tee -a $LF
  1557. echo "See http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Talairach" |& tee -a $LF
  1558. # IF Talairach alignment was run
  1559. # AND it was using the avi synder method
  1560. # AND this check failed,
  1561. # THEN try Talairach alignment using MINC mritotal tool
  1562. # ELSE error exit
  1563. if($DoTalairach && ! $UseMincMritotal && ! $longitudinal) then
  1564. echo "INFO: Attempting MINC mritotal to perform Talairach align" \
  1565. |& tee -a $LF
  1566. set UseMincMritotal = 1;
  1567. set DoCleanTal = 1;
  1568. goto talairach;
  1569. else
  1570. goto error_exit;
  1571. endif
  1572. endif
  1573. endif
  1574. endif
  1575. endif
  1576. #----------- Nu Intensity Correction ------------------#
  1577. if($DoNuIntensityCor) then
  1578. echo "#--------------------------------------------" \
  1579. |& tee -a $LF |& tee -a $CF
  1580. echo "#@# Nu Intensity Correction `date`" \
  1581. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1582. cd $subjdir/mri > /dev/null
  1583. set xopts = `fsr-getxopts mri_nu_correct.mni $XOptsFile`;
  1584. set cmd = (mri_nu_correct.mni --i orig.mgz --o nu.mgz )
  1585. # to fix a problem with mri_nu_correct.mni messing with the histogramming
  1586. # in some odd subjects (due to voxels outside the brain, which has the
  1587. # effect of altering white matter intensity interpretation downstream),
  1588. # the inclusion of talairach.xfm with mri_nu_correct.mni causes
  1589. # mri_make_uchar to run, which uses the Tal xform to find a ball of voxels
  1590. # that are mostly brain. The top of the intensity histogram in this ball
  1591. # will then be white matter, which allows us to center it at the desired
  1592. # value, approximately (110).
  1593. if ($DoNuMakeUchar) then
  1594. if ( ! -e transforms/talairach.xfm) then
  1595. echo "WARNING: transforms/talairach.xfm does not exist!" \
  1596. |& tee -a $LF
  1597. echo "It will not be used by mri_nu_correct.mni." \
  1598. |& tee -a $LF
  1599. else
  1600. set cmd = ($cmd --uchar transforms/talairach.xfm)
  1601. endif
  1602. endif
  1603. # --cm for hi-res support:
  1604. if ($ConformMin) set cmd = ($cmd --cm)
  1605. if ($DoNuIntensityCor3T) then
  1606. # params from Zheng, Chee, Zagorodnov 2009 NeuroImage paper
  1607. # "Improvement of brain segmentation accuracy by optimizing
  1608. # non-uniformity correction using N3"
  1609. set NuIterations = 1;
  1610. set cmd = ($cmd --proto-iters 1000 --distance 50)
  1611. endif
  1612. set cmd = ($cmd --n $NuIterations $xopts)
  1613. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1614. if($RunIt) $fs_time $cmd |& tee -a $LF
  1615. if($status) goto error_exit;
  1616. # Add xfm to nu
  1617. set cmd = (mri_add_xform_to_header -c \
  1618. $subjdir/mri/transforms/talairach.xfm \
  1619. nu.mgz nu.mgz)
  1620. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1621. if($RunIt) then
  1622. $fs_time $cmd |& tee -a $LF
  1623. if($status) goto error_exit;
  1624. endif
  1625. touch $touchdir/nu.touch
  1626. endif
  1627. #----------- Defacing ------------------#
  1628. if($DoDeface) then
  1629. echo "#--------------------------------------------" \
  1630. |& tee -a $LF |& tee -a $CF
  1631. echo "#@# Deface `date`" \
  1632. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1633. cd $subjdir/mri > /dev/null
  1634. set cmd = (mri_deface orig.mgz \
  1635. $FREESURFER_HOME/average/$brain_template \
  1636. $FREESURFER_HOME/average/$face_template \
  1637. orig_defaced.mgz)
  1638. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1639. if($RunIt) $fs_time $cmd |& tee -a $LF
  1640. if($status) goto error_exit;
  1641. touch $touchdir/deface.touch
  1642. endif
  1643. #----------- Intensity Normalization1 ------------------#
  1644. if($DoNormalization) then
  1645. echo "#--------------------------------------------" \
  1646. |& tee -a $LF |& tee -a $CF
  1647. echo "#@# Intensity Normalization `date`" \
  1648. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1649. cd $subjdir/mri > /dev/null
  1650. $PWD |& tee -a $LF
  1651. set xopts = `fsr-getxopts mri_normalize $XOptsFile`;
  1652. if ( $longitudinal && $UseLongbaseCtrlVol) then
  1653. # longitudinal processing stream AND using ctrl_vol.mgz from base:
  1654. if( ! -e $longbasedir/mri/ctrl_vol.mgz || ! -e $longbasedir/mri/bias_vol.mgz ) then
  1655. echo "Recompute intensity norm to create $longbaseid ctrl_vol.mgz" \
  1656. |& tee -a $LF
  1657. set cmd = (mri_normalize)
  1658. if($#Norm3dIters) set cmd = ($cmd -n $Norm3dIters)
  1659. if($#Norm1_b) set cmd = ($cmd -b $Norm1_b)
  1660. if($#Norm1_n) set cmd = ($cmd -n $Norm1_n)
  1661. if($IsMPRAGE) set cmd = ($cmd -mprage)
  1662. if($IsWashuMPRAGE) set cmd = ($cmd -washu_mprage)
  1663. set cmd = ($cmd \
  1664. -mask $longbasedir/mri/brain.mgz \
  1665. -W $longbasedir/mri/ctrl_vol.mgz $longbasedir/mri/bias_vol.mgz \
  1666. $longbasedir/mri/nu.mgz \
  1667. $longbasedir/mri/T1_tmp.mgz)
  1668. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1669. if($RunIt) $fs_time $cmd |& tee -a $LF
  1670. if($status) goto error_exit;
  1671. if( ! -e $longbasedir/mri/ctrl_vol.mgz ) then
  1672. echo "ERROR: unable to generate cntl-point volume for longbase" \
  1673. |& tee -a $LF
  1674. goto error_exit;
  1675. endif
  1676. rm -f $longbasedir/mri/T1_tmp.mgz
  1677. endif
  1678. # use ctrl_vol.mgz from base for normalization:
  1679. set cmd = (mri_normalize \
  1680. -w $subjdir/mri/ctrl_vol.mgz $subjdir/mri/bias_vol.mgz \
  1681. -l $longbasedir/mri/ctrl_vol.mgz $longbasedir/mri/bias_vol.mgz \
  1682. $subjdir/mri/nu.mgz \
  1683. $subjdir/mri/T1.mgz)
  1684. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1685. if($RunIt) $fs_time $cmd |& tee -a $LF
  1686. if($status) goto error_exit;
  1687. else
  1688. # for cross, base (and long if not useLongBaseCtrlVol) processing streams:
  1689. set cmd = (mri_normalize -g $NormMaxGrad);
  1690. if($UseControlPoints) set cmd = ($cmd -f $ControlPointsFile)
  1691. if($#Norm3dIters) set cmd = ($cmd -n $Norm3dIters)
  1692. if($#Norm1_b) set cmd = ($cmd -b $Norm1_b)
  1693. if($#Norm1_n) set cmd = ($cmd -n $Norm1_n)
  1694. if($IsMPRAGE) set cmd = ($cmd -mprage)
  1695. if($IsWashuMPRAGE) set cmd = ($cmd -washu_mprage)
  1696. if($ConformMin) set cmd = ($cmd -noconform)
  1697. # in base create the ctrl_vol.mgz for init longs later:
  1698. if($DoCreateBaseSubj) set cmd = ($cmd -W ctrl_vol.mgz bias_vol.mgz)
  1699. set cmd = ($cmd $xopts nu.mgz T1.mgz)
  1700. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1701. if($RunIt) $fs_time $cmd |& tee -a $LF
  1702. if($status) goto error_exit;
  1703. endif
  1704. echo $cmd > $touchdir/inorm1.touch
  1705. endif
  1706. #----------- Skull Stripping ------------------#
  1707. if($DoSkullStrip) then
  1708. skullstrip:
  1709. echo "#--------------------------------------------" \
  1710. |& tee -a $LF |& tee -a $CF
  1711. echo "#@# Skull Stripping `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1712. cd $subjdir/mri > /dev/null
  1713. $PWD |& tee -a $LF
  1714. if ($longitudinal) then
  1715. # longitudinal processing stream (copy from base):
  1716. set BM = brainmask.mgz
  1717. set BMA = brainmask.auto.mgz
  1718. set bmbase = brainmask_${longbaseid}.mgz
  1719. set cmd = (cp -vf ${longbasedir}/mri/${BM} ./${bmbase})
  1720. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1721. if($RunIt) $fs_time $cmd |& tee -a $LF
  1722. if($status) goto error_exit;
  1723. # first apply mask and keep deletion edits (1)
  1724. set cmd = (mri_mask -keep_mask_deletion_edits)
  1725. set cmd = ($cmd T1.mgz ${bmbase} ${BMA})
  1726. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1727. if($RunIt) $fs_time $cmd |& tee -a $LF
  1728. if($status) goto error_exit;
  1729. # then transfer the 255 edits (still keep deletions)
  1730. set cmd = (mri_mask -transfer 255)
  1731. set cmd = ($cmd -keep_mask_deletion_edits)
  1732. set cmd = ($cmd $BMA ${bmbase} $BMA)
  1733. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1734. if($RunIt) $fs_time $cmd |& tee -a $LF
  1735. if($status) goto error_exit;
  1736. goto skipped_skullstrip;
  1737. endif
  1738. # base subject stream:
  1739. if($DoCreateBaseSubj) then
  1740. set BMA = brainmask.auto.mgz
  1741. set BM = brainmask.mgz #used later
  1742. # create lists with all cross brainmasks and all ltas:
  1743. set bmInVols=""
  1744. set ltaXforms=""
  1745. foreach s ($BaseSubjsList)
  1746. set bmInVols = ($bmInVols ${SUBJECTS_DIR}/${s}/mri/brainmask.mgz)
  1747. set ltaname = ${s}_to_${subjid}.lta
  1748. set ltaXforms = ($ltaXforms ${subjdir}/mri/transforms/${ltaname})
  1749. end
  1750. if ($#bmInVols == 1) then
  1751. # only a single time point in base
  1752. set cmd = (mri_convert -at $ltaXforms[1] -rt nearest $bmInVols[1] brainmask_template.mgz )
  1753. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1754. if($RunIt) then
  1755. $fs_time $cmd |& tee -a $LF
  1756. if($status) goto error_exit;
  1757. endif
  1758. else
  1759. # map all brainmask with nearest neighbor and average 0=mean=logicalOR:
  1760. set cmd = (mri_robust_template --mov ${bmInVols})
  1761. set cmd = ($cmd --average 0)
  1762. set cmd = ($cmd --ixforms ${ltaXforms})
  1763. set cmd = ($cmd --noit)
  1764. set cmd = ($cmd --finalnearest)
  1765. set cmd = ($cmd --template brainmask_template.mgz)
  1766. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1767. if($RunIt) then
  1768. $fs_time $cmd |& tee -a $LF
  1769. if($status) goto error_exit;
  1770. endif
  1771. endif # more than 1 tp
  1772. # create brainmask.auto by applying brainmask_template to T1
  1773. # first apply mask and keep deletion edits (1)
  1774. set cmd = (mri_mask -keep_mask_deletion_edits)
  1775. set cmd = ($cmd T1.mgz brainmask_template.mgz $BMA)
  1776. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1777. if($RunIt) $fs_time $cmd |& tee -a $LF
  1778. if($status) goto error_exit;
  1779. # then copy over the 255 (edits) and still keep deletions (1)
  1780. set cmd = (mri_mask -transfer 255)
  1781. set cmd = ($cmd -keep_mask_deletion_edits)
  1782. set cmd = ($cmd $BMA brainmask_template.mgz $BMA)
  1783. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1784. if($RunIt) $fs_time $cmd |& tee -a $LF
  1785. if($status) goto error_exit;
  1786. goto skipped_skullstrip;
  1787. endif
  1788. # default stream...
  1789. set xopts = `fsr-getxopts mri_watershed $XOptsFile`;
  1790. set opts = ();
  1791. if($WaterShed == 0) set opts = ($opts -n);
  1792. if($WaterShed == 2) set opts = ($opts -wat);
  1793. if($WaterShed == 3) set opts = ($opts -wat+temp);
  1794. if($WaterShed == 4) set opts = ($opts -atlas);
  1795. if($WSLess) set opts = ($opts -less);
  1796. if($WSMore) set opts = ($opts -more);
  1797. if($WSAtlas) set opts = ($opts -atlas);
  1798. if($#WSSeedPoint != 0) set opts = ($opts -s $WSSeedPoint);
  1799. if($#WSPctPreFlood != 0) then
  1800. set opts = ($opts -h $WSPctPreFlood);
  1801. set DoMultiStrip = 0
  1802. else if( -e optimal_preflood_height) then
  1803. set WSPctPreFlood = `cat optimal_preflood_height`
  1804. set opts = ($opts -h $WSPctPreFlood);
  1805. set DoMultiStrip = 0
  1806. echo "Using optimal preflood height of $WSPctPreFlood" |& tee -a $LF
  1807. endif
  1808. set cmd = (mri_watershed)
  1809. set BM = brainmask.mgz
  1810. if ($WSGcaAtlas || $DoMultiStrip) then
  1811. if ( ! $WSUseTalXfm) then # dont bother if using talairach.xfm
  1812. # if using the GCA atlas to help with the skull-strip, then run the
  1813. # GCA registration (mri_em_register) to align to an atlas with a skull,
  1814. # unless that file already exists
  1815. if ( ! -e transforms/talairach_with_skull.lta || $DoCleanLta ) then
  1816. set xopts2 = `fsr-getxopts mri_em_register $XOptsFile`;
  1817. set cmd2 = (mri_em_register)
  1818. if($UseCuda) set cmd2 = (mri_em_register_cuda)
  1819. set cmd2 = ($cmd2 -skull)
  1820. set cmd2 = ($cmd2 $xopts2 nu.mgz ${GCADIR}/$GCASkull)
  1821. set cmd2 = ($cmd2 transforms/talairach_with_skull.lta)
  1822. echo "\n $cmd2 \n"|& tee -a $LF |& tee -a $CF
  1823. if($RunIt) $fs_time $cmd2 |& tee -a $LF
  1824. if($status) goto error_exit;
  1825. echo $cmd2 > $touchdir/skull.lta.touch
  1826. endif
  1827. endif
  1828. if ($WSGcaAtlas) then
  1829. # if just using -brain_atlas flag, then include necessary options
  1830. if ($WSUseTalXfm) then
  1831. set opts = (-brain_atlas ${GCADIR}/$GCASkull \
  1832. transforms/talairach.xfm $opts)
  1833. else
  1834. set opts = (-brain_atlas ${GCADIR}/$GCASkull \
  1835. transforms/talairach_with_skull.lta $opts)
  1836. endif
  1837. endif
  1838. endif
  1839. if($DoMultiStrip) then
  1840. # when DoMultiStrip is enabled, multiple instances of mri_watershed are
  1841. # run each using the following preflood height parameters
  1842. if ( $?WATERSHED_PREFLOOD_HEIGHTS ) then
  1843. # externally specified in the environment
  1844. set PREFLOOD_HEIGHTS = ( $WATERSHED_PREFLOOD_HEIGHTS )
  1845. else
  1846. # defaults:
  1847. set PREFLOOD_HEIGHTS = ( 5 10 20 30 )
  1848. endif
  1849. set SS_VOLUMES = ( orig nu T1 )
  1850. if ( $?GOTO_LL_CALC ) goto ll_calc
  1851. # create command files, one job for each volume type and preflood height...
  1852. set CMDFS = ()
  1853. foreach vol ( $SS_VOLUMES )
  1854. foreach pfh ( $PREFLOOD_HEIGHTS )
  1855. set cmd = (mri_watershed)
  1856. set BMA_OLD = brainmask.auto.mgz
  1857. set BMA = brainmask_${vol}_PFH${pfh}.auto.mgz
  1858. if(-e $BMA_OLD && -e $BM && ! $DoCleanBM) then
  1859. set cmd = ($cmd -keep $BMA_OLD $BM $BMA)
  1860. endif
  1861. set cmd = ($cmd $opts -h ${pfh} $xopts ${vol}.mgz $BMA)
  1862. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1863. set CMDF = mri_watershed_${vol}_PFH${pfh}.cmd
  1864. echo "$cmd" > $CMDF
  1865. set CMDFS = ( $CMDFS $CMDF )
  1866. end
  1867. end
  1868. # and launch parallel jobs and wait for completion.
  1869. # the batchjobs script will append each job output to $LF
  1870. if($RunIt) then
  1871. batchjobs $LF $CMDFS
  1872. if($status) goto error_exit;
  1873. endif
  1874. # brainmask volumes actually need to be T1 volumes, because while
  1875. # mri_watershed may run best in some cases using orig.mgz as input,
  1876. # we really want the brainmask to be from T1.mgz (post normalization)
  1877. set CMDFS = ()
  1878. foreach pfh ( $PREFLOOD_HEIGHTS )
  1879. set BMA_ORIG = brainmask_orig_PFH${pfh}.auto.mgz
  1880. if ( -e $BMA_ORIG ) then
  1881. set cmd = (mri_mask T1.mgz $BMA_ORIG $BMA_ORIG)
  1882. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1883. set CMDF = mri_mask_PFH${pfh}.cmd
  1884. echo "$cmd" > $CMDF
  1885. set CMDFS = ( $CMDFS $CMDF )
  1886. endif
  1887. end
  1888. # and launch parallel jobs and wait for completion.
  1889. # the batchjobs script will append each job output to $LF
  1890. if($RunIt) then
  1891. if($#CMDFS != 0) then
  1892. batchjobs $LF $CMDFS
  1893. if($status) goto error_exit;
  1894. endif
  1895. endif
  1896. echo $cmd > $touchdir/skull_strip.touch
  1897. # calculate a measure of skull-strip performance (mri_log_likelihood):
  1898. ll_calc:
  1899. set max_ll = -9999999999;
  1900. set best_pfh = 0;
  1901. set best_vol = ();
  1902. set xopts = `fsr-getxopts mri_log_likelihood $XOptsFile`;
  1903. foreach vol ( $SS_VOLUMES )
  1904. foreach pfh ( $PREFLOOD_HEIGHTS )
  1905. set BMA = brainmask_${vol}_PFH${pfh}.auto.mgz
  1906. set LTA = transforms/talairach_with_skull.lta
  1907. set cmd = (mri_log_likelihood -orig T1.mgz $BMA)
  1908. set cmd = ($cmd $xopts ${GCADIR}/$GCA $LTA)
  1909. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1910. if($RunIt) then
  1911. $cmd |& tee -a $LF |& tee -a ll_tmp
  1912. # extract the last line of output, containing the result
  1913. set ll = `tail -n 1 ll_tmp`
  1914. rm -f ll_tmp
  1915. endif
  1916. if($status) goto error_exit;
  1917. # and make the best result the brainmask.auto.mgz
  1918. if($RunIt) then
  1919. echo "$BMA log_likelihood= $ll" |& tee -a $LF
  1920. if ("$ll" == "nan") continue
  1921. if ($ll > $max_ll) then
  1922. set max_ll = $ll;
  1923. set best_pfh = $pfh;
  1924. set best_vol = $vol;
  1925. rm -f brainmask.auto.mgz
  1926. cp $BMA brainmask.auto.mgz
  1927. if($status) goto error_exit;
  1928. endif
  1929. endif
  1930. end
  1931. end
  1932. if($RunIt) then
  1933. if ($best_pfh == 0) then
  1934. echo "ERROR: failure in calculating best preflood height param." \
  1935. |& tee -a $LF
  1936. goto error_exit;
  1937. endif
  1938. echo ""
  1939. echo "Optimal input vol: $best_vol, pre-flood height= $best_pfh, results in log_likelihood= $max_ll" \
  1940. |& tee -a $LF
  1941. #rm -f *_PFH*.auto.*
  1942. #rm -f *_PFH*.*
  1943. # save this result, so that it is used next time, negating the need
  1944. # to run mulitstrip (parallel jobs) again
  1945. echo "$best_vol" > optimal_skullstrip_invol
  1946. echo "$best_pfh" > optimal_preflood_height
  1947. endif
  1948. echo $cmd > $touchdir/log_likelihood.touch
  1949. # make sure this is set properly:
  1950. set BMA = brainmask.auto.mgz
  1951. else
  1952. # single-job skull-strip (default)
  1953. set BMA = brainmask.auto.mgz
  1954. if(-e $BMA && -e $BM && ! $DoCleanBM) set cmd = ($cmd -keep $BMA $BM $BM)
  1955. set INVOL = T1
  1956. if( -e optimal_skullstrip_invol) set INVOL = `cat optimal_skullstrip_invol`
  1957. if("$INVOL" == "T1") set opts = ( -T1 $opts )
  1958. set cmd = ($cmd $opts $xopts $INVOL.mgz $BMA)
  1959. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1960. if($RunIt) $fs_time $cmd |& tee -a $LF
  1961. if($status) goto error_exit;
  1962. if("$INVOL" == "orig") then
  1963. # while mri_watershed may run best in some cases using orig.mgz as input,
  1964. # we really want the brainmask to be from T1.mgz (post normalization)
  1965. set cmd = (mri_mask T1.mgz $BMA $BMA)
  1966. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1967. if($RunIt) $fs_time $cmd |& tee -a $LF
  1968. if($status) goto error_exit;
  1969. endif
  1970. echo $cmd > $touchdir/skull_strip.touch
  1971. endif
  1972. # Gcut:
  1973. # Nanyang Technological University's skull-stripper, which is intended to
  1974. # work best running after watershed. it further removes dura. see:
  1975. # 'Skull Stripping Using Graph Cuts', Neuroimage, 2009
  1976. # brainmask.gcuts.mgz is a debug file showing voxels that were cut.
  1977. if($DoGcut) then
  1978. set BMA = brainmask.auto.mgz
  1979. set BGC = brainmask.gcuts.mgz
  1980. set cmd = (rm -f $BGC)
  1981. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1982. if($RunIt) $cmd |& tee -a $LF
  1983. set xopts = `fsr-getxopts mri_gcut $XOptsFile`;
  1984. set cmd = (mri_gcut $xopts -110 -mult $BMA T1.mgz $BMA $BGC)
  1985. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1986. echo "" |& tee -a $LF
  1987. echo "INFO: Care must be taken to thoroughly inspect your data" \
  1988. |& tee -a $LF
  1989. echo " when using mri_gcut. In particular, inspect the edges of" \
  1990. |& tee -a $LF
  1991. echo " gm and cerebellum for over-aggressive cutting." |& tee -a $LF
  1992. echo " Add -segmentation brainmask.gcuts.mgz to the tkmedit" |& tee -a $LF
  1993. echo " command string to view the voxels which gcut has removed." |& tee -a $LF
  1994. echo "" |& tee -a $LF
  1995. if($RunIt) $fs_time $cmd |& tee -a $LF
  1996. if($status) goto error_exit;
  1997. # binarize the gcuts file, setting vals to label 999 which appears as red
  1998. # when loaded as a segmentation
  1999. if ( -e $BGC) then
  2000. set cmd = (mri_binarize --i $BGC --o $BGC --binval 999 --min 1)
  2001. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2002. if($RunIt) $fs_time $cmd |& tee -a $LF
  2003. if($status) goto error_exit;
  2004. endif
  2005. endif
  2006. skipped_skullstrip:
  2007. if( -e $BM && ! $DoCleanBM) then
  2008. echo "\nINFO: brainmask.mgz already exists!" \
  2009. |& tee -a $LF |& tee -a $CF
  2010. echo "The new brainmask.auto.mgz will not be copied to brainmask.mgz." \
  2011. |& tee -a $LF |& tee -a $CF
  2012. echo "This is done to retain any edits made to brainmask.mgz." \
  2013. |& tee -a $LF |& tee -a $CF
  2014. echo "Add the -clean-bm flag to recon-all to overwrite brainmask.mgz.\n" \
  2015. |& tee -a $LF |& tee -a $CF
  2016. endif
  2017. if(! -e $BM || $DoCleanBM) then
  2018. set cmd = (cp $BMA $BM)
  2019. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2020. if($RunIt) then
  2021. sleep 1; # Sleep here to assure that they have diff time stamps
  2022. $cmd |& tee -a $LF
  2023. if($status) goto error_exit;
  2024. endif
  2025. endif
  2026. endif
  2027. #-------------- GCA Registration -------------------------#
  2028. if($DoGCAReg) then
  2029. echo "#-------------------------------------"|& tee -a $LF |& tee -a $CF
  2030. echo "#@# EM Registration `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2031. cd $subjdir/mri > /dev/null
  2032. $PWD |& tee -a $LF
  2033. set xopts = `fsr-getxopts mri_em_register $XOptsFile`;
  2034. if($longitudinal) then
  2035. # longitudinal processing:
  2036. set cmd = (cp -vf $longbasedir/mri/transforms/talairach.lta \
  2037. transforms/talairach.lta )
  2038. else
  2039. set cmd = (mri_em_register)
  2040. if($UseCuda) set cmd = (mri_em_register_cuda)
  2041. if($DoCreateBaseSubj) then
  2042. # base subj processing (norm_template instead of nu, and no mask needed):
  2043. set cmd = ($cmd -mask brainmask.mgz $xopts \
  2044. norm_template.mgz ${GCADIR}/$GCA \
  2045. transforms/talairach.lta)
  2046. else
  2047. # default processing:
  2048. set cmd = ($cmd -uns 3 -mask brainmask.mgz $xopts \
  2049. nu.mgz ${GCADIR}/$GCA \
  2050. transforms/talairach.lta)
  2051. endif
  2052. endif
  2053. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2054. if($RunIt) $fs_time $cmd |& tee -a $LF
  2055. if($status) goto error_exit;
  2056. echo $cmd > $touchdir/em_register.touch
  2057. endif
  2058. #------------ Canonical Normalization --------------#
  2059. if($DoCANormalize) then
  2060. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2061. echo "#@# CA Normalize `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2062. cd $subjdir/mri > /dev/null
  2063. $PWD |& tee -a $LF
  2064. if ($longitudinal) then
  2065. # longitudinal processing:
  2066. # cp aseg from base to current TP:
  2067. set cmd = (cp -vf ${longbasedir}/mri/aseg.mgz aseg_${longbaseid}.mgz)
  2068. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2069. if ($RunIt) $fs_time $cmd |& tee -a $LF
  2070. if ($status) goto error_exit;
  2071. endif
  2072. set xopts = `fsr-getxopts mri_ca_normalize $XOptsFile`;
  2073. set cmd = (mri_ca_normalize)
  2074. if($UseCPsWithCaNorm) set cmd = ($cmd -f $ControlPointsFile)
  2075. if ($longitudinal) then
  2076. # longitudinal processing:
  2077. # use the aseg_base (just created) as initialization of the current TP:
  2078. set cmd = ($cmd -long aseg_${longbaseid}.mgz)
  2079. else
  2080. # default stream
  2081. set cmd = ($cmd -c ctrl_pts.mgz)
  2082. endif
  2083. set cmd = ($cmd -mask brainmask.mgz $xopts)
  2084. if($DoCreateBaseSubj) then
  2085. # base subject stream
  2086. # (use norm vol created during -base-init, no mask needed)
  2087. set cmd = ($cmd norm_template.mgz)
  2088. else
  2089. # default stream
  2090. set cmd = ($cmd nu.mgz)
  2091. endif
  2092. set cmd = ($cmd ${GCADIR}/$GCA)
  2093. set cmd = ($cmd transforms/talairach.lta norm.mgz)
  2094. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2095. if($RunIt) $fs_time $cmd |& tee -a $LF
  2096. if($status) goto error_exit;
  2097. echo $cmd > $touchdir/ca_normalize.touch
  2098. endif # DoCANormalize
  2099. #------------ Canonical Registration --------------#
  2100. if($DoCAReg) then
  2101. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2102. echo "#@# CA Reg `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2103. cd $subjdir/mri > /dev/null
  2104. $PWD |& tee -a $LF
  2105. set xopts = `fsr-getxopts mri_ca_register $XOptsFile`;
  2106. set cmd = (mri_ca_register)
  2107. if($UseCuda) set cmd = (mri_ca_register_cuda)
  2108. if($UnCompress) set cmd = ($cmd -uncompress)
  2109. if($BigVentricles) set cmd = ($cmd -bigventricles)
  2110. if( ! $BigVentricles) set cmd = ($cmd -nobigventricles)
  2111. if($DoSecondPassRenorm) set cmd = ($cmd -secondpassrenorm)
  2112. if( ! $longitudinal) set cmd = ($cmd -T transforms/talairach.lta)
  2113. if ( $longitudinal ) then
  2114. # here is tpN's longitudinal command
  2115. # init with warp (m3z) from base
  2116. # no need to concatenate, as we are in same space now
  2117. set cmd = ($cmd -levels 2 -A 1 \
  2118. -l $longbasedir/mri/transforms/talairach.m3z \
  2119. identity.nofile)
  2120. endif
  2121. set cmd = ($cmd $UseCAAlignAfter)
  2122. set cmd = ($cmd -mask brainmask.mgz)
  2123. set cmd = ($cmd $xopts norm.mgz \
  2124. ${GCADIR}/$GCA \
  2125. transforms/talairach.m3z)
  2126. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2127. if($RunIt) $fs_time $cmd |& tee -a $LF
  2128. set st = $status
  2129. if($st) then
  2130. echo "ERROR: mri_ca_register with non-zero status $st" |& tee -a $LF
  2131. echo "but continuing despite the error" |& tee -a $LF
  2132. #goto error_exit;
  2133. endif
  2134. echo $cmd > $touchdir/ca_register.touch
  2135. endif
  2136. #------------ Inverse of Canonical Registration --------------#
  2137. if($DoCARegInv) then
  2138. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2139. echo "#@# CA Reg Inv `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2140. cd $subjdir/mri > /dev/null
  2141. $PWD |& tee -a $LF
  2142. # set xopts = `fsr-getxopts mri_ca_register $XOptsFile`; # careful here
  2143. set cmd = (mri_ca_register)
  2144. #NJS: cuda version doesnt work will -invert-and-save:
  2145. #if($UseCuda) set cmd = (mri_ca_register_cuda)
  2146. set cmd = ($cmd -invert-and-save transforms/talairach.m3z)
  2147. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2148. if($RunIt) $fs_time $cmd |& tee -a $LF
  2149. if($status) then
  2150. echo "ERROR: mri_ca_register with non-zero status $status" |& tee -a $LF
  2151. goto error_exit;
  2152. endif
  2153. echo $cmd > $touchdir/ca_register_inv.touch
  2154. endif
  2155. #------------ Removes neck and part of the face --------------#
  2156. if($DoRemoveNeck) then
  2157. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2158. echo "#@# Remove Neck `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2159. cd $subjdir/mri > /dev/null
  2160. set xopts = `fsr-getxopts mri_remove_neck $XOptsFile`;
  2161. set xform = (transforms/talairach.m3z)
  2162. if ( ! -e $xform) then
  2163. echo "INFO: $xform not found, using talairach.lta instead" \
  2164. |& tee -a $LF |& tee -a $CF
  2165. set xform = (transforms/talairach.lta)
  2166. endif
  2167. set cmd = (mri_remove_neck -radius $RmNeckRadius $xopts \
  2168. nu.mgz $xform \
  2169. ${GCADIR}/$GCA nu_noneck.mgz)
  2170. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2171. if($RunIt) $fs_time $cmd |& tee -a $LF
  2172. if($status) goto error_exit;
  2173. echo $cmd > $touchdir/mri_remove_neck.touch
  2174. endif
  2175. #------------ Recompute lta with skull but no neck --------------#
  2176. if($DoSkullLTA) then
  2177. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2178. echo "#@# SkullLTA `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2179. cd $subjdir/mri > /dev/null
  2180. set xopts = `fsr-getxopts mri_em_register $XOptsFile`;
  2181. set cmd = (mri_em_register)
  2182. if ($UseCuda) set cmd = (mri_em_register_cuda)
  2183. set cmd = ($cmd -skull -t transforms/talairach.lta \
  2184. $xopts nu_noneck.mgz ${GCADIR}/$GCASkull \
  2185. transforms/talairach_with_skull_2.lta)
  2186. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2187. if($RunIt) $fs_time $cmd |& tee -a $LF
  2188. if($status) goto error_exit;
  2189. echo $cmd > $touchdir/skull_2.lta.touch
  2190. endif
  2191. #-------------- SubCort Segmentation --------------#
  2192. if($DoCALabel) then
  2193. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2194. echo "#@# SubCort Seg `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2195. cd $subjdir/mri > /dev/null
  2196. set DoASegMerge = 1; # Force
  2197. if($DoCleanASeg) then
  2198. set cmd = (rm -f aseg.mgz aseg.manedit.mgz)
  2199. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2200. if($RunIt) $cmd |& tee -a $LF
  2201. if($status) goto error_exit;
  2202. endif
  2203. # ----------- Prior to changing aseg.auto.mgz -------------------#
  2204. if( -e aseg.mgz && -e aseg.auto.mgz) then
  2205. # aseg.mgz and aseg.auto.mgz DO exist (at least 2nd pass)
  2206. if(! -e aseg.manedit.mgz) then
  2207. # aseg.manedit.mgz does NOT exist
  2208. # Check for diffs between aseg.auto and aseg
  2209. # Note: if there are no diffs, then aseg.manedit.mgz is not created
  2210. set cmd = (mri_seg_diff --seg1 aseg.auto.mgz \
  2211. --seg2 aseg.mgz --diff aseg.manedit.mgz)
  2212. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2213. if( ! $RunIt) then
  2214. echo "INFO: mri_seg_diff was not actually executed," |& tee -a $LF
  2215. echo "so subsequent commands (shown with -dontrun)" |& tee -a $LF
  2216. echo "may not have accurate arguments!" |& tee -a $LF
  2217. endif
  2218. if($RunIt) $cmd |& tee -a $LF
  2219. if($status) goto error_exit;
  2220. else
  2221. # aseg.manedit.mgz DOES exist
  2222. # This has to be handled in two stages in case manedit itself has
  2223. # been edited.
  2224. # 1. Check for diffs bettween aseg.auto and aseg (new and old edits)
  2225. set cmd = (mri_seg_diff --seg1 aseg.auto.mgz \
  2226. --seg2 aseg.mgz --diff aseg.manedit.tmp.mgz)
  2227. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2228. if( ! $RunIt) then
  2229. echo "INFO: mri_seg_diff was not actually executed," |& tee -a $LF
  2230. echo "so subsequent commands (shown with -dontrun)" |& tee -a $LF
  2231. echo "may not have accurate arguments!" |& tee -a $LF
  2232. endif
  2233. if($RunIt) $cmd |& tee -a $LF
  2234. if($status) goto error_exit;
  2235. # 2. Merge new and old edits with manedit. If manedit has not
  2236. # been edited, then there will be no change.
  2237. if(-e aseg.manedit.tmp.mgz) then
  2238. set cmd = (mri_seg_diff --seg aseg.manedit.mgz \
  2239. --diff-in aseg.manedit.tmp.mgz --merged aseg.manedit.mgz)
  2240. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2241. if($RunIt) $cmd |& tee -a $LF
  2242. if($status) goto error_exit;
  2243. rm aseg.manedit.tmp.mgz
  2244. endif
  2245. endif
  2246. endif
  2247. # ------------ longitudinal (pre)processing ----------------#
  2248. # fuse segmentations of subjects composing the 'longbase' subject
  2249. if ($longitudinal && $UseAsegFusion) then
  2250. cd $subjdir/mri > /dev/null
  2251. $PWD |& tee -a $LF
  2252. set BaseSubjsList = (`cat ${longbasedir}/${BaseSubjsListFname}`)
  2253. # first create lta's of basesubjs to longsubj
  2254. foreach s (${BaseSubjsList})
  2255. # copy the transform (tpi cross to base) to local transform dir
  2256. # where mri_fuse_segmentations is looking for it:
  2257. set cmd = (cp -vf ${longbasedir}/mri/transforms/${s}_to_${longbaseid}.lta \
  2258. ${subjdir}/mri/transforms/${s}_to_${subjid}.lta)
  2259. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2260. if($RunIt) then
  2261. $fs_time $cmd |& tee -a $LF
  2262. if($status) goto error_exit;
  2263. endif
  2264. end
  2265. # now create the fused aseg
  2266. set cmd = (mri_fuse_segmentations)
  2267. set cmd = ($cmd -a aseg.mgz -c aseg.auto_noCCseg.mgz -n norm.mgz)
  2268. set cmd = ($cmd ${subjid} ${BaseSubjsList} aseg.fused.mgz)
  2269. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2270. if($RunIt) then
  2271. $fs_time $cmd |& tee -a $LF
  2272. if($status) goto error_exit;
  2273. endif
  2274. endif
  2275. #------------------- mri_ca_label -------------------------------#
  2276. # Run mri_ca_label to create aseg.auto_noCCseg.mgz
  2277. set xopts = `fsr-getxopts mri_ca_label $XOptsFile`;
  2278. set cmd = (mri_ca_label)
  2279. set cmd = ($cmd $UseCAAlign)
  2280. if($NoWMSA) set cmd = ($cmd -nowmsa)
  2281. set asegbasename=(aseg.auto_noCCseg)
  2282. if($longitudinal && $UseAsegFusion) then
  2283. # longitudinal processing: use 'fused' aseg just created
  2284. set cmd=($cmd -r $subjdir/mri/aseg.fused.mgz)
  2285. set cmd=($cmd -ri $longbasedir/mri/${asegbasename}.label_intensities.txt)
  2286. endif
  2287. set cmd = ($cmd $xopts norm.mgz)
  2288. set cmd = ($cmd transforms/talairach.m3z)
  2289. set cmd = ($cmd ${GCADIR}/$GCA)
  2290. set cmd = ($cmd ${asegbasename}.mgz)
  2291. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2292. if($RunIt) $fs_time $cmd |& tee -a $LF
  2293. if($status) goto error_exit;
  2294. #--- Corpus Callosum Segmentation ---#
  2295. # Run mri_cc to create aseg.auto.mgz
  2296. set xopts = `fsr-getxopts mri_cc $XOptsFile`;
  2297. set cmd = (mri_cc -aseg aseg.auto_noCCseg.mgz -o aseg.auto.mgz \
  2298. -lta ${subjdir}/mri/transforms/cc_up.lta $xopts $subjid);
  2299. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2300. if($RunIt) $fs_time $cmd |& tee -a $LF
  2301. if($status) goto error_exit;
  2302. echo $cmd > $touchdir/ca_label.touch
  2303. endif
  2304. # --------- Incorporate Manual ASeg Changes ----------------------
  2305. # Allow it to be done outside of CALabel. Note that DoASegMerge
  2306. # will be 1 if CALabel is run. This just allows the user to
  2307. # merge with Man Edits even if CALabel was not run, which will
  2308. # only have an effect if the user has actually changed aseg.manedit
  2309. if($DoASegMerge) then
  2310. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2311. echo "#@# Merge ASeg `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2312. cd $subjdir/mri > /dev/null
  2313. if(-e aseg.manedit.mgz ) then
  2314. set cmd = (mri_seg_diff --seg aseg.auto.mgz \
  2315. --diff-in aseg.manedit.mgz --merged aseg.mgz)
  2316. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2317. if( ! $RunIt) then
  2318. echo "INFO: mri_seg_diff was not actually executed," |& tee -a $LF
  2319. echo "so subsequent commands (shown with -dontrun)" |& tee -a $LF
  2320. echo "may not have accurate arguments!" |& tee -a $LF
  2321. endif
  2322. if($RunIt) $cmd |& tee -a $LF
  2323. if($status) goto error_exit;
  2324. else
  2325. set cmd = (cp aseg.auto.mgz aseg.mgz)
  2326. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2327. if($RunIt) $cmd |& tee -a $LF
  2328. if($status) goto error_exit;
  2329. endif
  2330. echo $cmd > $touchdir/asegmerge.touch
  2331. endif
  2332. # ----------- Intensity Normalization2 ------------------------#
  2333. if($DoNormalization2) then
  2334. echo "#--------------------------------------------" \
  2335. |& tee -a $LF |& tee -a $CF
  2336. echo "#@# Intensity Normalization2 `date`" \
  2337. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2338. cd $subjdir/mri > /dev/null
  2339. set xopts = `fsr-getxopts mri_normalize $XOptsFile`;
  2340. set cmd = (mri_normalize);
  2341. if($UseControlPoints) set cmd = ($cmd -f $ControlPointsFile)
  2342. if($#Norm3dIters) set cmd = ($cmd -n $Norm3dIters)
  2343. if($#Norm2_b) set cmd = ($cmd -b $Norm2_b)
  2344. if($#Norm2_n) set cmd = ($cmd -n $Norm2_n)
  2345. if($IsMPRAGE) set cmd = ($cmd -mprage)
  2346. if($IsWashuMPRAGE) set cmd = ($cmd -washu_mprage)
  2347. if($ConformMin) set cmd = ($cmd -noconform)
  2348. if($UseAseg && ! $NoAsegInorm2) set cmd = ($cmd -aseg aseg.mgz)
  2349. if($NoNormMGZ) then
  2350. # norm.mgz doesnt exist with -noaseg or -nosubcortseg, so use brainmask.mgz
  2351. set cmd = ($cmd $xopts brainmask.mgz brain.mgz)
  2352. else
  2353. set cmd = ($cmd -mask brainmask.mgz $xopts norm.mgz brain.mgz)
  2354. endif
  2355. $PWD |& tee -a $LF
  2356. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2357. if($RunIt) $fs_time $cmd |& tee -a $LF
  2358. if($status) goto error_exit;
  2359. echo $cmd > $touchdir/inorm2.touch
  2360. endif
  2361. # -------------- Mask BFS ----------------------#
  2362. if($DoMaskBFS) then
  2363. echo "#--------------------------------------------" \
  2364. |& tee -a $LF |& tee -a $CF
  2365. echo "#@# Mask BFS `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2366. cd $subjdir/mri > /dev/null
  2367. set xopts = `fsr-getxopts mri_mask $XOptsFile`;
  2368. # Set threshold to WM_MIN_VAL=5
  2369. set cmd = (mri_mask -T 5 $xopts brain.mgz brainmask.mgz brain.finalsurfs.mgz)
  2370. $PWD |& tee -a $LF
  2371. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2372. if($RunIt) $fs_time $cmd |& tee -a $LF
  2373. if($status) goto error_exit;
  2374. # if they exist, transfer finalsurfs edits (voxels=255 and voxels=1)
  2375. if( -e brain.finalsurfs.manedit.mgz ) then
  2376. set cmd = (mri_mask -transfer 255)
  2377. set cmd = ($cmd -keep_mask_deletion_edits)
  2378. set cmd = ($cmd brain.finalsurfs.mgz brain.finalsurfs.manedit.mgz \
  2379. brain.finalsurfs.mgz)
  2380. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2381. if($RunIt) $fs_time $cmd |& tee -a $LF
  2382. if($status) goto error_exit;
  2383. else
  2384. if ( $longitudinal && -e ${SUBJECTS_DIR}/${tpNid}/mri/brain.finalsurfs.manedit.mgz ) then
  2385. # transfer edits from cross
  2386. set cmd = (mri_mask -transfer 255)
  2387. set cmd = ($cmd -keep_mask_deletion_edits)
  2388. set cmd = ($cmd -xform $tpNtobase_regfile)
  2389. set cmd = ($cmd brain.finalsurfs.mgz)
  2390. set cmd = ($cmd ${SUBJECTS_DIR}/${tpNid}/mri/brain.finalsurfs.manedit.mgz)
  2391. set cmd = ($cmd brain.finalsurfs.mgz)
  2392. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2393. if($RunIt) $fs_time $cmd |& tee -a $LF
  2394. if($status) goto error_exit;
  2395. endif
  2396. endif
  2397. endif
  2398. #---------------- WM Segmentation --------------------------#
  2399. if($DoSegmentation) then
  2400. echo "#--------------------------------------------" \
  2401. |& tee -a $LF |& tee -a $CF
  2402. echo "#@# WM Segmentation `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2403. cd $subjdir/mri > /dev/null
  2404. set AllowLongWMtransfers = "1"
  2405. if(! $DoCleanWM && -e wm.mgz) then
  2406. # test if edits were made
  2407. # count 255 edits:
  2408. set cmd = (mri_binarize --i wm.mgz --min 255 --max 255 \
  2409. --o wm255.mgz --count wm255.txt)
  2410. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2411. if($RunIt) $cmd |& tee -a $LF
  2412. if($status) goto error_exit;
  2413. # count 1 edits:
  2414. set cmd = (mri_binarize --i wm.mgz --min 1 --max 1 \
  2415. --o wm1.mgz --count wm1.txt)
  2416. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2417. if($RunIt) $cmd |& tee -a $LF
  2418. if($status) goto error_exit;
  2419. # remove unnecessary mgz's
  2420. set cmd = (rm wm1.mgz wm255.mgz)
  2421. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2422. if($RunIt) $cmd |& tee -a $LF
  2423. if($status) goto error_exit;
  2424. # get number of edits:
  2425. set wm255=""
  2426. if ( -e wm255.txt ) then
  2427. set wm255 = `cat wm255.txt | awk ' { print $1 } '`
  2428. endif
  2429. set wm1=""
  2430. if ( -e wm1.txt ) then
  2431. set wm1 = `cat wm1.txt | awk ' { print $1 } '`
  2432. endif
  2433. # if edits exist:
  2434. if ( "$wm1" != "0" || "$wm255" != "0" ) then
  2435. echo "Found wm edits: $wm1 deletes, $wm255 fills" |& tee -a $LF
  2436. set cmd = (cp wm.mgz wm.seg.mgz)
  2437. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2438. if($RunIt) $cmd |& tee -a $LF
  2439. if($status) goto error_exit;
  2440. # wm.mgz was available (probably edited):
  2441. # don't allow transfers in long below
  2442. set AllowLongWMtransfers = "0"
  2443. endif
  2444. endif
  2445. # ----------- Segment -------------------------
  2446. set xopts = `fsr-getxopts mri_segment $XOptsFile`;
  2447. set cmd = (mri_segment);
  2448. if ($NoThicken) set cmd = ($cmd -thicken 0)
  2449. # note: check for wm.mgz happens so that -dontrun output is correct
  2450. if(! $DoCleanWM && -e wm.mgz && -e wm.seg.mgz) set cmd = ($cmd -keep)
  2451. if($IsMPRAGE) set cmd = ($cmd -mprage)
  2452. if($IsWashuMPRAGE) set cmd = ($cmd -washu_mprage)
  2453. set cmd = ($cmd $WMSeg_wlo $WMSeg_ghi $xopts brain.mgz wm.seg.mgz)
  2454. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2455. if($RunIt) $fs_time $cmd |& tee -a $LF
  2456. if($status) goto error_exit;
  2457. # ----------- Edit with ASeg -------------------------
  2458. if($UseAseg) then
  2459. set xopts = `fsr-getxopts mri_edit_wm_with_aseg $XOptsFile`;
  2460. set cmd = (mri_edit_wm_with_aseg)
  2461. if(! $DoCleanWM) set cmd = ($cmd -keep-in)
  2462. set cmd = ($cmd $xopts wm.seg.mgz brain.mgz aseg.mgz wm.asegedit.mgz)
  2463. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2464. if($RunIt) $fs_time $cmd |& tee -a $LF
  2465. if($status) goto error_exit;
  2466. endif
  2467. # ----------- PreTess -------------------------
  2468. set xopts = `fsr-getxopts mri_pretess $XOptsFile`;
  2469. set wmlabelstring = "wm"
  2470. if($UseAseg) then
  2471. set WM_vol = wm.asegedit.mgz
  2472. else
  2473. set WM_vol = wm.seg.mgz
  2474. endif
  2475. if($NoNormMGZ) then
  2476. set norm_vol = brain.mgz
  2477. else
  2478. set norm_vol = norm.mgz
  2479. endif
  2480. set cmd = (mri_pretess )
  2481. if(! $DoCleanWM && -e wm.mgz) set cmd = ($cmd -keep)
  2482. set cmd = ($cmd $xopts $WM_vol $wmlabelstring $norm_vol wm.mgz)
  2483. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2484. if($RunIt) $fs_time $cmd |& tee -a $LF
  2485. if($status) goto error_exit;
  2486. if($longitudinal && $AllowLongWMtransfers) then
  2487. if ($UseLongbaseWMedits) then
  2488. # transfer wm edits (voxels=255) from longbase wm.mgz to long tpN wm.mgz
  2489. # and -keep_mask_deletion_edits transfers voxel-deletion (voxels=1) edits
  2490. set cmd = (mri_mask -transfer 255)
  2491. set cmd = ($cmd -keep_mask_deletion_edits)
  2492. set cmd = ($cmd wm.mgz $longbasedir/mri/wm.mgz wm.mgz)
  2493. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2494. if($RunIt) $fs_time $cmd |& tee -a $LF
  2495. if($status) goto error_exit;
  2496. else #default in -long:
  2497. # transfer wm matter edits (voxels=255) from cross wm.mgz to long tpN wm.mgz
  2498. # and -keep_mask_deletion_edits transfers voxel-deletion (voxels=1) edits
  2499. set cmd = (mri_mask -transfer 255)
  2500. set cmd = ($cmd -keep_mask_deletion_edits)
  2501. set cmd = ($cmd -xform $tpNtobase_regfile)
  2502. set cmd = ($cmd wm.mgz ${SUBJECTS_DIR}/${tpNid}/mri/wm.mgz wm.mgz)
  2503. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2504. if($RunIt) $fs_time $cmd |& tee -a $LF
  2505. if($status) goto error_exit;
  2506. endif
  2507. endif
  2508. echo $cmd > $touchdir/wmsegment.touch
  2509. endif
  2510. #---------------- Fill --------------------------#
  2511. if($DoFill) then
  2512. echo "#--------------------------------------------" \
  2513. |& tee -a $LF |& tee -a $CF
  2514. echo "#@# Fill `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2515. cd $subjdir/mri > /dev/null
  2516. set xopts = `fsr-getxopts mri_fill $XOptsFile`;
  2517. set seedopts = ();
  2518. if($#PonsSeedCRS) set seedopts = ($seedopts -Pv $PonsSeedCRS);
  2519. if($#CCSeedCRS) set seedopts = ($seedopts -Cv $CCSeedCRS);
  2520. if($#LHSeedCRS) set seedopts = ($seedopts -lhv $LHSeedCRS);
  2521. if($#RHSeedCRS) set seedopts = ($seedopts -rhv $RHSeedCRS);
  2522. set cmd = (mri_fill -a ../scripts/ponscc.cut.log $seedopts)
  2523. if(-e transforms/talairach.lta) then
  2524. set cmd = ($cmd -xform transforms/talairach.lta)
  2525. endif
  2526. if($UseAseg) set cmd = ($cmd -segmentation aseg.auto_noCCseg.mgz);
  2527. if(! $UseOldTopoFix && ! $NoNormMGZ) set cmd = ($cmd -topofix norm.mgz);
  2528. set cmd = ($cmd $xopts wm.mgz filled.mgz)
  2529. $PWD |& tee -a $LF
  2530. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2531. if($RunIt) $fs_time $cmd |& tee -a $LF
  2532. if($status) goto error_exit;
  2533. echo $cmd > $touchdir/fill.touch
  2534. endif
  2535. #########################################################
  2536. # Per-Hemisphere #
  2537. #########################################################
  2538. foreach hemi ($hemilist)
  2539. #---------------- Tessellate --------------------------#
  2540. if($DoTessellate && ( ! $longitudinal )) then
  2541. if($hemi == "lh") then
  2542. set hemivalue = 255;
  2543. else
  2544. set hemivalue = 127;
  2545. endif
  2546. echo "#--------------------------------------------" \
  2547. |& tee -a $LF |& tee -a $CF
  2548. echo "#@# Tessellate $hemi `date`" \
  2549. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2550. cd $subjdir/scripts > /dev/null
  2551. $PWD |& tee -a $LF
  2552. # necessary second pretess, per f.segonne
  2553. set xopts = `fsr-getxopts mri_pretess $XOptsFile`;
  2554. if($NoNormMGZ) then
  2555. set norm_vol = brain.mgz
  2556. else
  2557. set norm_vol = norm.mgz
  2558. endif
  2559. set cmd = (mri_pretess $xopts ../mri/filled.mgz $hemivalue \
  2560. ../mri/$norm_vol ../mri/filled-pretess$hemivalue.mgz)
  2561. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2562. if($RunIt) $fs_time $cmd |& tee -a $LF
  2563. if($status) goto error_exit;
  2564. set xopts = `fsr-getxopts mri_tessellate $XOptsFile`;
  2565. set cmd = (mri_tessellate $xopts ../mri/filled-pretess$hemivalue.mgz \
  2566. $hemivalue ../surf/$hemi.orig.nofix)
  2567. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2568. if($RunIt) $fs_time $cmd |& tee -a $LF
  2569. if($status) goto error_exit;
  2570. set cmd = (rm -f ../mri/filled-pretess$hemivalue.mgz)
  2571. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2572. if($RunIt) $cmd |& tee -a $LF
  2573. # remove possible extra components, per f.segonne
  2574. set xopts = `fsr-getxopts mris_extract_main_component $XOptsFile`;
  2575. set cmd = (mris_extract_main_component $xopts ../surf/$hemi.orig.nofix \
  2576. ../surf/$hemi.orig.nofix)
  2577. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2578. if($RunIt) $fs_time $cmd |& tee -a $LF
  2579. if($status) goto error_exit;
  2580. echo $cmd > $touchdir/$hemi.tessellate.touch
  2581. endif
  2582. #---------------- Smooth1 --------------------------#
  2583. if($DoSmooth1 && ( ! $longitudinal )) then
  2584. echo "#--------------------------------------------" \
  2585. |& tee -a $LF |& tee -a $CF
  2586. echo "#@# Smooth1 $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2587. cd $subjdir/scripts > /dev/null
  2588. set xopts = `fsr-getxopts mris_smooth $XOptsFile`;
  2589. # -nw prevents it from writing curv and area
  2590. set cmd = (mris_smooth -nw)
  2591. if ($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  2592. set cmd = ($cmd $xopts \
  2593. ../surf/$hemi.orig.nofix ../surf/$hemi.smoothwm.nofix)
  2594. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2595. $PWD |& tee -a $LF
  2596. if($RunIt) $fs_time $cmd |& tee -a $LF
  2597. if($status) goto error_exit;
  2598. echo $cmd > $touchdir/$hemi.smoothwm1.touch
  2599. endif
  2600. #---------------- Inflate1 --------------------------#
  2601. if($DoInflate1 && ( ! $longitudinal )) then
  2602. echo "#--------------------------------------------" \
  2603. |& tee -a $LF |& tee -a $CF
  2604. echo "#@# Inflation1 $hemi `date`" \
  2605. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2606. cd $subjdir/scripts > /dev/null
  2607. set xopts = `fsr-getxopts mris_inflate $XOptsFile`;
  2608. set cmd = (mris_inflate)
  2609. if($UseCuda) set cmd = (mris_inflate_cuda)
  2610. set cmd = ($cmd -no-save-sulc $xopts \
  2611. ../surf/$hemi.smoothwm.nofix ../surf/$hemi.inflated.nofix)
  2612. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2613. $PWD |& tee -a $LF
  2614. if($RunIt) $fs_time $cmd |& tee -a $LF
  2615. if($status) goto error_exit;
  2616. echo $cmd > $touchdir/$hemi.inflate1.touch
  2617. endif
  2618. #---------------- QSphere --------------------------#
  2619. if($DoQSphere && ( ! $longitudinal )) then
  2620. echo "#--------------------------------------------" \
  2621. |& tee -a $LF |& tee -a $CF
  2622. echo "#@# QSphere $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2623. cd $subjdir/scripts > /dev/null
  2624. set xopts = `fsr-getxopts mris_sphere $XOptsFile`;
  2625. set cmd = (mris_sphere -q)
  2626. if($UseCuda) set cmd = (mris_sphere_cuda -q)
  2627. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  2628. set cmd = ($cmd $xopts)
  2629. set cmd = ($cmd ../surf/$hemi.inflated.nofix ../surf/$hemi.qsphere.nofix)
  2630. $PWD |& tee -a $LF
  2631. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2632. if($RunIt) $fs_time $cmd |& tee -a $LF
  2633. if($status) goto error_exit;
  2634. echo $cmd > $touchdir/$hemi.qsphere.touch
  2635. endif
  2636. #---------------- Fix Topology --------------------------#
  2637. if($DoFix && ( ! $longitudinal )) then
  2638. echo "#--------------------------------------------" \
  2639. |& tee -a $LF |& tee -a $CF
  2640. echo "#@# Fix Topology $hemi `date`" \
  2641. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2642. cd $subjdir/scripts > /dev/null
  2643. # Must copy unfixed to fixed
  2644. set cmd = (cp ../surf/$hemi.orig.nofix ../surf/$hemi.orig)
  2645. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2646. if($RunIt) $cmd |& tee -a $LF
  2647. if($status) goto error_exit;
  2648. set cmd = (cp ../surf/$hemi.inflated.nofix ../surf/$hemi.inflated)
  2649. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2650. if($RunIt) $cmd |& tee -a $LF
  2651. if($status) goto error_exit;
  2652. # Now can run fixer
  2653. if($UseOldTopoFix) then
  2654. set xopts = `fsr-getxopts mris_fix_topology $XOptsFile`;
  2655. set cmd = (mris_fix_topology)
  2656. set cmd = ($cmd -mgz -sphere qsphere.nofix)
  2657. if($FixWithGA) set cmd = ($cmd -ga)
  2658. if($FixDiagOnly) set cmd = ($cmd -diagonly)
  2659. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  2660. set cmd = ($cmd $xopts $subjid $hemi)
  2661. $PWD |& tee -a $LF
  2662. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2663. if($RunIt) $fs_time $cmd |& tee -a $LF
  2664. if($status) goto error_exit;
  2665. # check if total defect index != 0, meaning, euler # != 2 (surface bad)
  2666. set cmd = (mris_euler_number ../surf/$hemi.orig)
  2667. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2668. if($RunIt) then
  2669. $cmd >& mris_euler_number.log
  2670. if($status) goto error_exit;
  2671. set defect_idx=`grep "total defect index" mris_euler_number.log | awk '{print $5}'`
  2672. if("$defect_idx" != "0") then
  2673. echo "mris_fix_topology failed! (euler number != 2)" |& tee -a $LF
  2674. echo "Trying mris_topo_fixer..." |& tee -a $LF
  2675. set UseNewTopoFix = 1
  2676. set UseOldTopoFix = 0
  2677. # cannot use the failed ?h.orig surface, must revert to ?.orig.nofix
  2678. set cmd = (cp ../surf/$hemi.orig.nofix ../surf/$hemi.orig)
  2679. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2680. if($RunIt) $cmd |& tee -a $LF
  2681. if($status) goto error_exit;
  2682. endif
  2683. cat mris_euler_number.log |& tee -a $LF
  2684. rm -f mris_euler_number.log
  2685. endif
  2686. endif
  2687. if($UseNewTopoFix) then
  2688. set cmd = (cp ../surf/$hemi.qsphere.nofix ../surf/$hemi.qsphere)
  2689. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2690. if($RunIt) $cmd |& tee -a $LF
  2691. if($status) goto error_exit;
  2692. set cmd = (cp ../surf/$hemi.smoothwm.nofix ../surf/$hemi.smoothwm)
  2693. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2694. if($RunIt) $cmd |& tee -a $LF
  2695. if($status) goto error_exit;
  2696. set xopts = `fsr-getxopts mris_topo_fixer $XOptsFile`;
  2697. set cmd = (mris_topo_fixer -mgz -warnings)
  2698. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  2699. set cmd = ($cmd $xopts $subjid $hemi)
  2700. $PWD |& tee -a $LF
  2701. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2702. if($RunIt) $fs_time $cmd |& tee -a $LF
  2703. if($status) goto error_exit;
  2704. endif
  2705. # run surface intersection checker/fixer
  2706. set xopts = `fsr-getxopts mris_remove_intersection $XOptsFile`;
  2707. set cmd = (mris_remove_intersection)
  2708. set cmd = ($cmd $xopts ../surf/$hemi.orig ../surf/$hemi.orig)
  2709. $PWD |& tee -a $LF
  2710. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2711. if($RunIt) $fs_time $cmd |& tee -a $LF
  2712. if($status) goto error_exit;
  2713. # Remove hemi.inflated, real one created after mris_make_surfaces
  2714. set cmd = (rm ../surf/$hemi.inflated)
  2715. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2716. if($RunIt) $cmd
  2717. if($UseNewTopoFix) then
  2718. # Copy *h.orig_corrected to *h.orig
  2719. set cmd = (cp ../surf/$hemi.orig_corrected ../surf/$hemi.orig )
  2720. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2721. if($RunIt) $cmd
  2722. if($status) goto error_exit;
  2723. endif
  2724. echo $cmd > $touchdir/$hemi.topofix.touch
  2725. endif
  2726. # Smooth2 and Inflate2 moved to after make white surfs
  2727. #---------------- Make White Surfaces --------------------------#
  2728. if($DoWhiteSurfs) then
  2729. echo "#--------------------------------------------" \
  2730. |& tee -a $LF |& tee -a $CF
  2731. echo "#@# Make White Surf $hemi `date`" \
  2732. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2733. cd $subjdir/scripts > /dev/null
  2734. if( $longitudinal ) then
  2735. set cmd = (cp -vf $longbasedir/surf/${hemi}.white \
  2736. $subjdir/surf/${hemi}.orig)
  2737. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2738. if($RunIt) $fs_time $cmd |& tee -a $LF
  2739. if($status) goto error_exit;
  2740. set cmd = (cp -vf $longbasedir/surf/${hemi}.white \
  2741. $subjdir/surf/${hemi}.orig_white)
  2742. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2743. if($RunIt) $fs_time $cmd |& tee -a $LF
  2744. if($status) goto error_exit;
  2745. # also copy pial just in case (needed if $DoPialSurf == 0 below)
  2746. set cmd = (cp -vf $longbasedir/surf/${hemi}.pial \
  2747. $subjdir/surf/${hemi}.orig_pial)
  2748. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2749. if($RunIt) $fs_time $cmd |& tee -a $LF
  2750. if($status) goto error_exit;
  2751. endif
  2752. # Note mris_make_surfaces uses filled.mgz implicitly
  2753. set xopts = `fsr-getxopts mris_make_surfaces $XOptsFile`;
  2754. if($longitudinal) then
  2755. # longitudinal processing:
  2756. set cmd = (mris_make_surfaces \
  2757. -orig_white orig_white \
  2758. -orig orig_white \
  2759. -long \
  2760. -max 3.5)
  2761. else
  2762. # default stream:
  2763. set cmd = (mris_make_surfaces)
  2764. endif
  2765. if ( ! $UseAseg) set cmd = ($cmd -noaseg)
  2766. set cmd = ($cmd -noaparc)
  2767. if($DoPialSurfs) then
  2768. # if creating pial downstream, then only do white surface now
  2769. set cmd = ($cmd -whiteonly)
  2770. else
  2771. # else old-style single-run -finalsurfs is emulated
  2772. if($longitudinal) set cmd = ($cmd -orig_pial orig_pial)
  2773. endif
  2774. set cmd = ($cmd -mgz -T1 brain.finalsurfs)
  2775. set cmd = ($cmd $WMSeg_wlo $WMSeg_ghi $xopts $subjid $hemi)
  2776. $PWD |& tee -a $LF
  2777. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2778. if($RunIt) $fs_time $cmd |& tee -a $LF
  2779. if($status) goto error_exit;
  2780. echo $cmd > $touchdir/$hemi.white_surface.touch
  2781. if( ! $DoPialSurfs) echo $cmd > $touchdir/$hemi.final_surfaces.touch
  2782. endif
  2783. #---------------- Smooth2 --------------------------#
  2784. if($DoSmooth2) then
  2785. echo "#--------------------------------------------" \
  2786. |& tee -a $LF |& tee -a $CF
  2787. echo "#@# Smooth2 $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2788. cd $subjdir/scripts > /dev/null
  2789. set xopts = `fsr-getxopts mris_smooth $XOptsFile`;
  2790. # Use -nw to keep from writing out curv and area
  2791. # Default number of iterations is 10, but use 3 here
  2792. set cmd = (mris_smooth -n 3 -nw)
  2793. if ($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  2794. set cmd = ($cmd $xopts)
  2795. set cmd = ($cmd ../surf/$hemi.white ../surf/$hemi.smoothwm)
  2796. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2797. $PWD |& tee -a $LF
  2798. if($RunIt) $fs_time $cmd |& tee -a $LF
  2799. if($status) goto error_exit;
  2800. echo $cmd > $touchdir/$hemi.smoothwm2.touch
  2801. endif
  2802. #---------------- Inflate2 --------------------------#
  2803. if($DoInflate2) then
  2804. echo "#--------------------------------------------" \
  2805. |& tee -a $LF |& tee -a $CF
  2806. echo "#@# Inflation2 $hemi `date`" \
  2807. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2808. cd $subjdir/scripts > /dev/null
  2809. set xopts = `fsr-getxopts mris_inflate $XOptsFile`;
  2810. set cmd = (mris_inflate)
  2811. if($UseCuda) set cmd = (mris_inflate_cuda)
  2812. set cmd = ($cmd $xopts ../surf/$hemi.smoothwm \
  2813. ../surf/$hemi.inflated)
  2814. $PWD |& tee -a $LF
  2815. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2816. if($RunIt) $fs_time $cmd |& tee -a $LF
  2817. if($status) goto error_exit;
  2818. # create curvature files ?h.inflated.H and ?h.inflated.K
  2819. set xopts = `fsr-getxopts mris_curatvure $XOptsFile`;
  2820. set cmd = (mris_curvature -thresh .999 -n -a 5 -w -distances 10 10)
  2821. set cmd = ($cmd $xopts ../surf/$hemi.inflated)
  2822. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2823. if($RunIt) $fs_time $cmd |& tee -a $LF
  2824. if($status) goto error_exit;
  2825. echo $cmd > $touchdir/$hemi.inflate2.touch
  2826. endif
  2827. # ---------- Curvature Anatomical Stats ---------------------------
  2828. if($DoCurvStats) then
  2829. echo "\n#-----------------------------------------" \
  2830. |& tee -a $LF |& tee -a $CF
  2831. echo "#@# Curvature Stats $hemi `date`" \
  2832. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2833. cd $subjdir/surf > /dev/null
  2834. set stats = ../stats/$hemi.curv.stats
  2835. set xopts = `fsr-getxopts mris_curvature_stats $XOptsFile`;
  2836. set cmd = (mris_curvature_stats -m --writeCurvatureFiles -G \
  2837. -o $stats -F smoothwm \
  2838. $xopts $subjid $hemi curv sulc);
  2839. $PWD |& tee -a $LF
  2840. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2841. if($RunIt) $fs_time $cmd |& tee -a $LF
  2842. #if($status) goto error_exit;
  2843. if(-e .xdebug_mris_curvature_stats) rm -f .xdebug_mris_curvature_stats
  2844. echo $cmd > $touchdir/$hemi.curvstats.touch
  2845. endif
  2846. #---------------Begin Morph --------------------------------#
  2847. #---------------- Sphere --------------------------#
  2848. if($DoSphere) then
  2849. echo "#--------------------------------------------" \
  2850. |& tee -a $LF |& tee -a $CF
  2851. echo "#@# Sphere $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2852. cd $subjdir/scripts > /dev/null
  2853. if($longitudinal) then
  2854. # longitudinal processing:
  2855. set cmd = (cp $longbasedir/surf/$hemi.sphere $subjdir/surf/$hemi.sphere)
  2856. else
  2857. # default stream:
  2858. set xopts = `fsr-getxopts mris_sphere $XOptsFile`;
  2859. set cmd = (mris_sphere)
  2860. if($UseCuda) set cmd = (mris_sphere_cuda)
  2861. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  2862. if($UseNoNeg) set cmd = ($cmd -remove_negative 1)
  2863. set cmd = ($cmd $xopts)
  2864. set cmd = ($cmd ../surf/$hemi.inflated ../surf/$hemi.sphere)
  2865. endif
  2866. $PWD |& tee -a $LF
  2867. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2868. if($RunIt) $fs_time $cmd |& tee -a $LF
  2869. if($status) goto error_exit;
  2870. echo $cmd > $touchdir/$hemi.sphmorph.touch
  2871. endif
  2872. #---------------- Surface Registration --------------------------#
  2873. if($DoSurfReg) then
  2874. echo "#--------------------------------------------" \
  2875. |& tee -a $LF |& tee -a $CF
  2876. echo "#@# Surf Reg $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2877. cd $subjdir/scripts > /dev/null
  2878. set AvgTif = ${AvgCurvTifPath}/$hemi.${AvgCurvTif}
  2879. set xopts = `fsr-getxopts mris_register $XOptsFile`;
  2880. set cmd = (mris_register -curv)
  2881. if($UseNoNeg) set cmd = ($cmd -remove_negative 1)
  2882. set cmd = ($cmd $xopts)
  2883. if($longitudinal) then
  2884. # longitudinal processing:
  2885. set cmd = ($cmd -nosulc -norot \
  2886. $longbasedir/surf/$hemi.sphere.reg \
  2887. $AvgTif \
  2888. ../surf/$hemi.sphere.reg)
  2889. else
  2890. # default stream:
  2891. set cmd = ($cmd ../surf/$hemi.sphere $AvgTif ../surf/$hemi.sphere.reg)
  2892. endif
  2893. $PWD |& tee -a $LF
  2894. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2895. if($RunIt) $fs_time $cmd |& tee -a $LF
  2896. if($status) goto error_exit;
  2897. echo $cmd > $touchdir/$hemi.sphreg.touch
  2898. endif
  2899. #---------- Surface Registration to Average Subject ----------------#
  2900. if($#SurfRegToSubj) then
  2901. echo "#--------------------------------------------" \
  2902. |& tee -a $LF |& tee -a $CF
  2903. echo "#@# Surf RegTo $SurfRegToSubj $hemi `date`" \
  2904. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2905. cd $subjdir/scripts > /dev/null
  2906. set AvgTif = $SUBJECTS_DIR/$SurfRegToSubj/$hemi.reg.template.tif
  2907. set outreg = ../surf/$hemi.sphere.$SurfRegToSubj.reg
  2908. set cmd = (mris_register -curv)
  2909. if($UseNoNeg) set cmd = ($cmd -remove_negative 1)
  2910. set cmd = ($cmd ../surf/$hemi.sphere $AvgTif $outreg);
  2911. $PWD |& tee -a $LF
  2912. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2913. if($RunIt) $fs_time $cmd |& tee -a $LF
  2914. if($status) goto error_exit;
  2915. echo $cmd > $touchdir/$hemi.sphreg.$SurfRegToSubj.touch
  2916. endif
  2917. #---------------- Jacobian white --------------------------#
  2918. if($DoJacobianWhite) then
  2919. echo "#--------------------------------------------" \
  2920. |& tee -a $LF |& tee -a $CF
  2921. echo "#@# Jacobian white $hemi `date`" \
  2922. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2923. cd $subjdir/scripts > /dev/null
  2924. # produce the jacobian, from the white surface to the sphere
  2925. set cmd = (mris_jacobian \
  2926. ../surf/$hemi.white \
  2927. ../surf/$hemi.sphere.reg \
  2928. ../surf/$hemi.jacobian_white)
  2929. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2930. if($RunIt) $fs_time $cmd |& tee -a $LF
  2931. if($status) goto error_exit;
  2932. echo $cmd > $touchdir/$hemi.jacobian_white.touch
  2933. endif
  2934. #--- Surface Registration, allow maximal distortion, produce Jacobian ---#
  2935. if($DoJacobianDist0) then
  2936. echo "#--------------------------------------------" \
  2937. |& tee -a $LF |& tee -a $CF
  2938. echo "#@# Jacobian dist0 $hemi `date`" \
  2939. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2940. cd $subjdir/scripts > /dev/null
  2941. set AvgTif = ${AvgCurvTifPath}/$hemi.${AvgCurvTif}
  2942. set xopts = `fsr-getxopts mris_register $XOptsFile`;
  2943. set cmd = (mris_register -curv -norot -jacobian \
  2944. ../surf/$hemi.jacobian_dist0 -dist 0)
  2945. set cmd = ($cmd $xopts)
  2946. set cmd = ($cmd ../surf/$hemi.sphere.reg $AvgTif \
  2947. ../surf/$hemi.sphere.dist0.jacobian.reg)
  2948. $PWD |& tee -a $LF
  2949. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2950. if($RunIt) $fs_time $cmd |& tee -a $LF
  2951. if($status) goto error_exit;
  2952. echo $cmd > $touchdir/$hemi.jacobian_dist0.touch
  2953. endif
  2954. #---------------- Average Curv for Display----------------------#
  2955. if($DoAvgCurv) then
  2956. echo "#--------------------------------------------" \
  2957. |& tee -a $LF |& tee -a $CF
  2958. echo "#@# AvgCurv $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2959. cd $subjdir/scripts > /dev/null
  2960. set AvgTif = ${AvgCurvTifPath}/$hemi.${AvgCurvTif}
  2961. set xopts = `fsr-getxopts mrisp_paint $XOptsFile`;
  2962. # -a 5 means to smooth 5 iterations
  2963. set cmd = (mrisp_paint -a 5 $xopts "$AvgTif#6" \
  2964. ../surf/$hemi.sphere.reg ../surf/$hemi.avg_curv)
  2965. $PWD |& tee -a $LF
  2966. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2967. if($RunIt) $fs_time $cmd |& tee -a $LF
  2968. if($status) goto error_exit;
  2969. echo $cmd > $touchdir/$hemi.avgcurv.touch
  2970. endif
  2971. #---------------- Cortical Parcellation------------------------#
  2972. if($DoCortParc) then
  2973. echo "#-----------------------------------------" \
  2974. |& tee -a $LF |& tee -a $CF
  2975. echo "#@# Cortical Parc $hemi `date`" \
  2976. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2977. cd $subjdir/scripts > /dev/null
  2978. set xopts = `fsr-getxopts mris_ca_label $XOptsFile`;
  2979. set CPAtlas = ${GCSDIR}/$hemi.$GCS
  2980. set annot = ../label/$hemi.aparc.annot
  2981. set cmd = (mris_ca_label)
  2982. if($UseAseg) set cmd = ($cmd -l ../label/$hemi.cortex.label)
  2983. if($UseAseg) set cmd = ($cmd -aseg ../mri/aseg.mgz)
  2984. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  2985. set cmd = ($cmd $xopts)
  2986. if($longitudinal) then
  2987. # longitudinal:
  2988. set cmd = ($cmd -long -R $longbasedir/label/${hemi}.aparc.annot)
  2989. endif
  2990. set cmd = ($cmd $subjid $hemi ../surf/$hemi.sphere.reg $CPAtlas $annot)
  2991. $PWD |& tee -a $LF
  2992. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2993. if($RunIt) $fs_time $cmd |& tee -a $LF
  2994. if($status) goto error_exit;
  2995. echo $cmd > $touchdir/$hemi.aparc.touch
  2996. endif
  2997. #---------------- Make Pial Surfaces --------------------------#
  2998. if($DoPialSurfs) then
  2999. echo "#--------------------------------------------" \
  3000. |& tee -a $LF |& tee -a $CF
  3001. echo "#@# Make Pial Surf $hemi `date`" \
  3002. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3003. cd $subjdir/scripts > /dev/null
  3004. if( $longitudinal && ! -e $subjdir/surf/${hemi}.orig_pial ) then
  3005. # should rarely get here as this is copied above in Make White Surfaces
  3006. set cmd = (cp -vf $longbasedir/surf/${hemi}.pial\
  3007. $subjdir/surf/${hemi}.orig_pial)
  3008. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3009. if($RunIt) $fs_time $cmd |& tee -a $LF
  3010. if($status) goto error_exit;
  3011. endif
  3012. # Note mris_make_surfaces uses filled.mgz implicitly
  3013. set xopts = `fsr-getxopts mris_make_surfaces $XOptsFile`;
  3014. if($longitudinal) then
  3015. # longitudinal processing:
  3016. set cmd = (mris_make_surfaces \
  3017. -orig orig_white \
  3018. -orig_white orig_white \
  3019. -orig_pial orig_pial \
  3020. -long -max 3.5)
  3021. else
  3022. # default stream:
  3023. set cmd = (mris_make_surfaces)
  3024. endif
  3025. if ( ! $UseAseg) set cmd = ($cmd -noaseg)
  3026. if ($PialNoAparc) set cmd = ($cmd -noaparc)
  3027. # -white NOWRITE: dont overwrite white, curv, area, and cortex.label files
  3028. set cmd = ($cmd -white NOWRITE)
  3029. set cmd = ($cmd -mgz -T1 brain.finalsurfs)
  3030. set cmd = ($cmd $WMSeg_wlo $WMSeg_ghi $xopts $subjid $hemi);
  3031. $PWD |& tee -a $LF
  3032. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3033. if($RunIt) $fs_time $cmd |& tee -a $LF
  3034. if($status) goto error_exit;
  3035. echo $cmd > $touchdir/$hemi.pial_surface.touch
  3036. echo $cmd > $touchdir/$hemi.final_surfaces.touch
  3037. endif
  3038. if($DoPialSurfs || $DoSurfVolume) then
  3039. echo "#--------------------------------------------" \
  3040. |& tee -a $LF |& tee -a $CF
  3041. echo "#@# Surf Volume $hemi `date`" \
  3042. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3043. cd $subjdir/surf > /dev/null
  3044. $PWD |& tee -a $LF
  3045. set cmd=(mris_calc -o ${hemi}.area.mid ${hemi}.area add ${hemi}.area.pial)
  3046. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3047. if($RunIt) $fs_time $cmd |& tee -a $LF
  3048. if($status) goto error_exit;
  3049. set cmd=(mris_calc -o ${hemi}.area.mid ${hemi}.area.mid div 2)
  3050. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3051. if($RunIt) $fs_time $cmd |& tee -a $LF
  3052. if($status) goto error_exit;
  3053. set cmd=(mris_calc -o ${hemi}.volume)
  3054. set cmd=($cmd ${hemi}.area.mid mul ${hemi}.thickness)
  3055. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3056. if($RunIt) $fs_time $cmd |& tee -a $LF
  3057. if($status) goto error_exit;
  3058. if(-e .xdebug_mris_calc) rm -f .xdebug_mris_calc
  3059. echo $cmd > $touchdir/$hemi.surfvolume.touch
  3060. endif
  3061. # ---------- WM/GM Contrast (pctsurfcon) ---------------------------
  3062. # skip in base (as rawavg does not exist)
  3063. if($DoPctSurfCon && ( ! $DoCreateBaseSubj )) then
  3064. echo "#-----------------------------------------" \
  3065. |& tee -a $LF |& tee -a $CF
  3066. echo "#@# WM/GM Contrast $hemi `date`" \
  3067. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3068. cd $subjdir/scripts > /dev/null
  3069. set xopts = `fsr-getxopts pctsurfcon $XOptsFile`;
  3070. set cmd = (pctsurfcon --s $subjid)
  3071. if($hemi == lh) set cmd = ($cmd --lh-only)
  3072. if($hemi == rh) set cmd = ($cmd --rh-only)
  3073. $PWD |& tee -a $LF
  3074. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3075. if($RunIt) $fs_time $cmd |& tee -a $LF
  3076. if($status) goto error_exit;
  3077. echo $cmd > $touchdir/$hemi.pctsurfcon.touch
  3078. endif
  3079. # ---------- Surface Anatomical Stats ---------------------------
  3080. if($DoParcStats) then
  3081. echo "#-----------------------------------------" \
  3082. |& tee -a $LF |& tee -a $CF
  3083. echo "#@# Parcellation Stats $hemi `date`" \
  3084. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3085. cd $subjdir/scripts > /dev/null
  3086. set annot = ../label/$hemi.aparc.annot
  3087. set stats = ../stats/$hemi.aparc.stats
  3088. set ctab = ../label/aparc.annot.ctab
  3089. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  3090. set cmd = (mris_anatomical_stats -mgz)
  3091. if($UseAseg) set cmd = ($cmd -cortex ../label/$hemi.cortex.label)
  3092. set cmd = ($cmd -f $stats -b -a $annot -c $ctab $xopts $subjid $hemi white);
  3093. $PWD |& tee -a $LF
  3094. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3095. if($RunIt) $fs_time $cmd |& tee -a $LF
  3096. if($status) goto error_exit;
  3097. echo $cmd > $touchdir/$hemi.aparcstats.touch
  3098. endif
  3099. #---------------- Cortical Parcellation 2------------------------#
  3100. if($DoCortParc2) then
  3101. echo "#-----------------------------------------"\
  3102. |& tee -a $LF |& tee -a $CF
  3103. echo "#@# Cortical Parc 2 $hemi `date`" \
  3104. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3105. cd $subjdir/scripts > /dev/null
  3106. set xopts = `fsr-getxopts mris_ca_label $XOptsFile`;
  3107. set CPAtlas = ${GCSDIR}/${hemi}.${DESTRIEUX_GCS}
  3108. set annot = ../label/$hemi.aparc.${DESTRIEUX_NAME}.annot
  3109. set cmd = (mris_ca_label)
  3110. if($UseAseg) set cmd = ($cmd -l ../label/$hemi.cortex.label)
  3111. if($UseAseg) set cmd = ($cmd -aseg ../mri/aseg.mgz)
  3112. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  3113. set cmd = ($cmd $xopts)
  3114. if($longitudinal) then
  3115. # longitudinal:
  3116. set cmd = ($cmd -long -R \
  3117. $longbasedir/label/${hemi}.aparc.${DESTRIEUX_NAME}.annot)
  3118. endif
  3119. set cmd = ($cmd $subjid $hemi ../surf/$hemi.sphere.reg $CPAtlas $annot)
  3120. $PWD |& tee -a $LF
  3121. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  3122. if($RunIt) $fs_time $cmd |& tee -a $LF
  3123. if($status) goto error_exit;
  3124. echo $cmd > $touchdir/$hemi.aparc2.touch
  3125. endif
  3126. # ---------- Surface Anatomical Stats 2 ---------------------------
  3127. if($DoParcStats2) then
  3128. echo "#-----------------------------------------" \
  3129. |& tee -a $LF |& tee -a $CF
  3130. echo "#@# Parcellation Stats 2 $hemi `date`" \
  3131. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3132. cd $subjdir/scripts > /dev/null
  3133. set annot = ../label/$hemi.aparc.${DESTRIEUX_NAME}.annot
  3134. set stats = ../stats/$hemi.aparc.${DESTRIEUX_NAME}.stats
  3135. set ctab = ../label/aparc.annot.${DESTRIEUX_NAME}.ctab
  3136. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  3137. set cmd = (mris_anatomical_stats -mgz)
  3138. if($UseAseg) set cmd = ($cmd -cortex ../label/$hemi.cortex.label)
  3139. set cmd = ($cmd -f $stats -b -a $annot -c $ctab $xopts $subjid $hemi white);
  3140. $PWD |& tee -a $LF
  3141. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3142. if($RunIt) $fs_time $cmd |& tee -a $LF
  3143. if($status) goto error_exit;
  3144. echo $cmd > $touchdir/$hemi.aparcstats2.touch
  3145. endif
  3146. #---------------- Cortical Parcellation 3 ------------------------#
  3147. if($DoCortParc3) then
  3148. echo "#-----------------------------------------"\
  3149. |& tee -a $LF |& tee -a $CF
  3150. echo "#@# Cortical Parc 3 $hemi `date`" \
  3151. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3152. cd $subjdir/scripts > /dev/null
  3153. set xopts = `fsr-getxopts mris_ca_label $XOptsFile`;
  3154. set CPAtlas = ${GCSDIR}/${hemi}.${DKTATLAS40_GCS}
  3155. set annot = ../label/$hemi.aparc.${DKTATLAS40_NAME}.annot
  3156. set cmd = (mris_ca_label)
  3157. if($UseAseg) set cmd = ($cmd -l ../label/$hemi.cortex.label)
  3158. if($UseAseg) set cmd = ($cmd -aseg ../mri/aseg.mgz)
  3159. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  3160. set cmd = ($cmd $xopts)
  3161. if($longitudinal) then
  3162. # longitudinal:
  3163. set cmd = ($cmd -long -R \
  3164. $longbasedir/label/${hemi}.aparc.${DKTATLAS40_NAME}.annot)
  3165. endif
  3166. set cmd = ($cmd $subjid $hemi ../surf/$hemi.sphere.reg $CPAtlas $annot)
  3167. $PWD |& tee -a $LF
  3168. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  3169. if($RunIt) $fs_time $cmd |& tee -a $LF
  3170. if($status) goto error_exit;
  3171. echo $cmd > $touchdir/$hemi.aparc2.touch
  3172. endif
  3173. # ---------- Surface Anatomical Stats 3 ---------------------------
  3174. if($DoParcStats3) then
  3175. echo "#-----------------------------------------" \
  3176. |& tee -a $LF |& tee -a $CF
  3177. echo "#@# Parcellation Stats 3 $hemi `date`" \
  3178. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3179. cd $subjdir/scripts > /dev/null
  3180. set annot = ../label/$hemi.aparc.${DKTATLAS40_NAME}.annot
  3181. set stats = ../stats/$hemi.aparc.${DKTATLAS40_NAME}.stats
  3182. set ctab = ../label/aparc.annot.${DKTATLAS40_NAME}.ctab
  3183. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  3184. set cmd = (mris_anatomical_stats -mgz)
  3185. if($UseAseg) set cmd = ($cmd -cortex ../label/$hemi.cortex.label)
  3186. set cmd = ($cmd -f $stats -b -a $annot -c $ctab $xopts $subjid $hemi white);
  3187. $PWD |& tee -a $LF
  3188. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3189. if($RunIt) $fs_time $cmd |& tee -a $LF
  3190. if($status) goto error_exit;
  3191. echo $cmd > $touchdir/$hemi.aparcstats3.touch
  3192. endif
  3193. # ---------- Surface Vertices Number Match Check --------------
  3194. if($DoVnoMatchCheck) then
  3195. echo "#-----------------------------------------" \
  3196. |& tee -a $LF |& tee -a $CF
  3197. echo "#@# Vno Match Check $hemi `date`" \
  3198. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3199. cd $subjdir/scripts > /dev/null
  3200. set cmd = (vno_match_check $subjid $hemi);
  3201. $PWD |& tee -a $LF
  3202. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3203. if($RunIt) $fs_time $cmd |& tee -a $LF
  3204. if($status) goto error_exit;
  3205. echo $cmd > $touchdir/$hemi.vnomatchcheck.touch
  3206. endif
  3207. # ------ Compare aseg stats of two subjects ------
  3208. if ($DoAparcStatsDiff) then
  3209. echo "#--------------------------------------------" \
  3210. |& tee -a $LF |& tee -a $CF
  3211. echo "#@# AParc Stats Diff `date`" \
  3212. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3213. cd $SUBJECTS_DIR > /dev/null
  3214. $PWD |& tee -a $LF
  3215. foreach parc (aparc)
  3216. foreach meas (area volume thickness)
  3217. set subj1=($diffsubj)
  3218. if ( "x$subj1" == "x$subjid" ) then
  3219. # aparcstats2table doesnt accept identical subject names, so fake it
  3220. ln -s $subj1 ${diffsubj}_tmp
  3221. set subj1=(${diffsubj}_tmp)
  3222. endif
  3223. set cmd=(aparcstatsdiff $subj1 $subjid $hemi $parc $meas)
  3224. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3225. if($RunIt) $fs_time $cmd |& tee -a $LF
  3226. if (-e ${diffsubj}_tmp) rm ${diffsubj}_tmp
  3227. end
  3228. end
  3229. echo $cmd > $touchdir/aparcstatsdiff.touch
  3230. endif
  3231. # ---------- Label V1 ----------------
  3232. if($DoLabelV1) then
  3233. echo "#-----------------------------------------" \
  3234. |& tee -a $LF |& tee -a $CF
  3235. echo "#@# Label V1 $hemi `date`" \
  3236. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3237. if ( ! -e $SUBJECTS_DIR/V1_average) then
  3238. echo "ERROR: V1_average subject does not exist in SUBJECTS_DIR!"
  3239. goto error_exit;
  3240. endif
  3241. cd $subjdir/label > /dev/null
  3242. $PWD |& tee -a $LF
  3243. set cmd=(predict_v1.sh)
  3244. if( ! $RunIt) set cmd=($cmd -p)
  3245. set cmd = ($cmd -h $hemi $subjid);
  3246. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3247. $fs_time $cmd |& tee -a $LF
  3248. if($status) goto error_exit;
  3249. echo $cmd > $touchdir/$hemi.label_v1.touch
  3250. endif
  3251. end # Loop over hemilist
  3252. #---------------- Refine Pial Surfaces Using T2/FLAIR -----------------------#
  3253. if($DoT2pial || $DoFLAIRpial) then
  3254. echo "#--------------------------------------------" \
  3255. |& tee -a $LF |& tee -a $CF
  3256. echo "#@# Refine Pial Surfs w/ T2/FLAIR `date`" \
  3257. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3258. cd $subjdir/scripts > /dev/null
  3259. # should be one or the other. check params checks for this.
  3260. if($DoT2pial) set t2flair=(T2)
  3261. if($DoFLAIRpial) set t2flair=(FLAIR)
  3262. set mdir=$SUBJECTS_DIR/${subjid}/mri
  3263. set sdir=$SUBJECTS_DIR/${subjid}/surf
  3264. if (! -e $mdir/${t2flair}.mgz) then
  3265. set t2flairraw = $mdir/orig/${t2flair}raw.mgz
  3266. # Longitudinal processing
  3267. if ($longitudinal) then
  3268. # use T2/FLAIR raw from cross if missing in long
  3269. if (! -e $t2flairraw) then
  3270. set t2flairraw = ${SUBJECTS_DIR}/${tpNid}/mri/orig/${t2flair}raw.mgz
  3271. endif
  3272. if (! -e $t2flairraw) then
  3273. echo "ERROR: mri/orig/${t2flair}raw.mgz missing in long and cross." \
  3274. |& tee -a $LF
  3275. goto error_exit;
  3276. endif
  3277. # concatenate lta if created in cross (T2cross->T1cross->longspace)
  3278. # this avoids registering again if already done in cross
  3279. if ( -e ${SUBJECTS_DIR}/${tpNid}/mri/transforms/${t2flair}raw.lta ) then
  3280. set cmd = (mri_concatenate_lta )
  3281. set cmd = ($cmd ${SUBJECTS_DIR}/${tpNid}/mri/transforms/${t2flair}raw.lta )
  3282. set cmd = ($cmd $tpNtobase_regfile $mdir/transforms/${t2flair}raw.lta)
  3283. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  3284. if($RunIt) $fs_time $cmd |& tee -a $LF
  3285. if($status) goto error_exit;
  3286. else
  3287. # if t2flairraw.lta does not exist in cross, register T2raw to longspace
  3288. set bbcmd = (bbregister \
  3289. --s $subjid \
  3290. --mov $t2flairraw \
  3291. --lta $mdir/transforms/${t2flair}raw.lta \
  3292. --init-fsl \
  3293. --T2 )
  3294. echo "\n $bbcmd \n"|& tee -a $LF |& tee -a $CF
  3295. if($RunIt) $fs_time $bbcmd |& tee -a $LF
  3296. if($status) goto error_exit;
  3297. endif
  3298. else #regular processing, register T2flairraw to T1 and create lta
  3299. # first create a T2/FLAIR that is registered to the T1s
  3300. set bbcmd = (bbregister \
  3301. --s $subjid \
  3302. --mov $t2flairraw \
  3303. --lta $mdir/transforms/${t2flair}raw.lta \
  3304. --init-fsl \
  3305. --T2 )
  3306. echo "\n $bbcmd \n"|& tee -a $LF |& tee -a $CF
  3307. if($RunIt) $fs_time $bbcmd |& tee -a $LF
  3308. if($status) goto error_exit;
  3309. endif
  3310. # both regular and long processing:
  3311. # actually map the input (and make conform as the T1 target)
  3312. set mapcmd = ( mri_convert -at $mdir/transforms/${t2flair}raw.lta )
  3313. if($UseCubic) set mapcmd = ($mapcmd -rt cubic )
  3314. set mapcmd = ($mapcmd -rl $mdir/orig.mgz )
  3315. set mapcmd = ($mapcmd $t2flairraw )
  3316. set mapcmd = ($mapcmd $mdir/${t2flair}.mgz )
  3317. echo "\n $mapcmd \n"|& tee -a $LF |& tee -a $CF
  3318. if($RunIt) $fs_time $mapcmd |& tee -a $LF
  3319. if($status) goto error_exit;
  3320. # then give the T2/FLAIR a little normalizing
  3321. set normcmd = (mri_normalize \
  3322. -aseg $mdir/aseg.mgz \
  3323. -sigma 4 \
  3324. -surface $sdir/rh.white identity.nofile \
  3325. -surface $sdir/lh.white identity.nofile \
  3326. $mdir/${t2flair}.mgz \
  3327. $mdir/${t2flair}.mgz)
  3328. echo "\n $normcmd \n"|& tee -a $LF |& tee -a $CF
  3329. if($RunIt) $fs_time $normcmd |& tee -a $LF
  3330. if($status) goto error_exit;
  3331. endif
  3332. foreach hemi ($hemilist)
  3333. $PWD |& tee -a $LF
  3334. set xopts = `fsr-getxopts mris_make_surfaces $XOptsFile`;
  3335. set nv1=(`mris_info $sdir/${hemi}.pial |& grep nvertices`)
  3336. set nv2=(`mris_info $sdir/${hemi}.wo${t2flair}.pial |& grep nvertices`)
  3337. if ( (! -e $sdir/${hemi}.wo${t2flair}.pial) || \
  3338. ("$nv1" != "$nv2") ) then
  3339. set cmd = (cp -v $sdir/${hemi}.pial $sdir/${hemi}.wo${t2flair}.pial)
  3340. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3341. if($RunIt) $fs_time $cmd |& tee -a $LF
  3342. if($status) goto error_exit;
  3343. endif
  3344. set cmd = (mris_make_surfaces \
  3345. -orig_white white \
  3346. -orig_pial wo${t2flair}.pial)
  3347. if ( ! $UseAseg) set cmd = ($cmd -noaseg)
  3348. if ($PialNoAparc) set cmd = ($cmd -noaparc)
  3349. # -white NOWRITE: dont overwrite white, curv, area, and cortex.label files
  3350. set cmd = ($cmd -white NOWRITE)
  3351. set cmd = ($cmd -mgz -T1 brain.finalsurfs)
  3352. # if using a T2 or FLAIR to remove dura that might be confused with pial...
  3353. if ($DoT2pial) set cmd = ($cmd -T2 ../mri/T2)
  3354. if ($DoFLAIRpial) set cmd = ($cmd -FLAIR ../mri/FLAIR)
  3355. set cmd = ($cmd $WMSeg_wlo $WMSeg_ghi $xopts $subjid $hemi);
  3356. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3357. if($RunIt) $fs_time $cmd |& tee -a $LF
  3358. if($status) goto error_exit;
  3359. echo $cmd > $touchdir/$hemi.pial_refine.touch
  3360. end # for each hemi
  3361. # redo ?h.volume files
  3362. if(-e $subjdir/surf/rh.volume || -e $subjdir/surf/lh.volume) then
  3363. foreach hemi ($hemilist)
  3364. echo "#--------------------------------------------" \
  3365. |& tee -a $LF |& tee -a $CF
  3366. echo "#@# Surf Volume $hemi `date`" \
  3367. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3368. cd $subjdir/surf > /dev/null
  3369. $PWD |& tee -a $LF
  3370. set cmd=(mris_calc -o ${hemi}.area.mid ${hemi}.area add ${hemi}.area.pial)
  3371. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3372. if($RunIt) $fs_time $cmd |& tee -a $LF
  3373. if($status) goto error_exit;
  3374. set cmd=(mris_calc -o ${hemi}.area.mid ${hemi}.area.mid div 2)
  3375. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3376. if($RunIt) $fs_time $cmd |& tee -a $LF
  3377. if($status) goto error_exit;
  3378. set cmd=(mris_calc -o ${hemi}.volume)
  3379. set cmd=($cmd ${hemi}.area.mid mul ${hemi}.thickness)
  3380. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3381. if($RunIt) $fs_time $cmd |& tee -a $LF
  3382. if($status) goto error_exit;
  3383. if(-e .xdebug_mris_calc) rm -f .xdebug_mris_calc
  3384. echo $cmd > $touchdir/$hemi.surfvolume.touch
  3385. end # Loop over hemilist
  3386. endif
  3387. endif # if correct pial w/ T2/FLAIR
  3388. #-------Edit Aseg with Surfaces -------------#
  3389. if($DoSurfSegEdit) then
  3390. echo "#--------------------------------------------" \
  3391. |& tee -a $LF |& tee -a $CF
  3392. echo "#@# SurfSegEdit `date`" \
  3393. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3394. cd $subjdir/mri > /dev/null
  3395. set xopts = `fsr-getxopts mri_edit_segmentation_with_surfaces $XOptsFile`;
  3396. set cmd = (mri_edit_segmentation_with_surfaces $xopts)
  3397. set cmd = ($cmd aseg.auto.mgz ../surf norm.mgz aseg.surfedit.mgz)
  3398. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3399. $PWD |& tee -a $LF
  3400. if($RunIt) $fs_time $cmd |& tee -a $LF
  3401. if($status) goto error_exit;
  3402. # now merge any manual edits that user might have made
  3403. if(-e aseg.manedit.mgz ) then
  3404. set cmd = (mri_seg_diff --seg aseg.surfedit.mgz \
  3405. --diff-in aseg.manedit.mgz --merged aseg.mgz)
  3406. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3407. if( ! $RunIt) then
  3408. echo "INFO: mri_seg_diff was not actually executed," |& tee -a $LF
  3409. echo "so subsequent commands (shown with -dontrun)" |& tee -a $LF
  3410. echo "may not have accurate arguments!" |& tee -a $LF
  3411. endif
  3412. if($RunIt) $cmd |& tee -a $LF
  3413. if($status) goto error_exit;
  3414. # if no manual edits, then copy to aseg.mgz
  3415. else
  3416. set cmd = (cp aseg.surfedit.mgz aseg.mgz)
  3417. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3418. if($RunIt) $cmd |& tee -a $LF
  3419. if($status) goto error_exit;
  3420. endif
  3421. echo $cmd > $touchdir/surfsegedit.touch
  3422. endif
  3423. #---------------- Cortical Ribbon -------------------------#
  3424. if($DoCortRibbonVolMask) then
  3425. echo "#--------------------------------------------" \
  3426. |& tee -a $LF |& tee -a $CF
  3427. echo "#@# Cortical ribbon mask `date`" \
  3428. |& tee -a $SF|& tee -a $LF|& tee -a $CF
  3429. cd $subjdir/mri > /dev/null
  3430. set xopts = `fsr-getxopts mris_volmask $XOptsFile`;
  3431. set cmd = (mris_volmask \
  3432. --label_left_white 2 --label_left_ribbon 3 \
  3433. --label_right_white 41 --label_right_ribbon 42 \
  3434. --save_ribbon $subjid)
  3435. $PWD |& tee -a $LF
  3436. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3437. if($RunIt) $fs_time $cmd |& tee -a $LF
  3438. if($status) goto error_exit;
  3439. echo $cmd > $touchdir/cortical_ribbon.touch
  3440. endif
  3441. #-------------- ASeg Stats --------------#
  3442. if($DoSegStats) then
  3443. # Stats on the automatic segmentation
  3444. echo "#--------------------------------------------" \
  3445. |& tee -a $LF |& tee -a $CF
  3446. echo "#@# ASeg Stats `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3447. cd $subjdir > /dev/null
  3448. set xopts = `fsr-getxopts mri_segstats $XOptsFile`;
  3449. set cmd = (mri_segstats --seg mri/aseg.mgz --sum stats/aseg.stats)
  3450. # if($UseCuda) set cmd = (mri_segstats_cuda --seg mri/aseg.mgz --sum stats/aseg.stats)
  3451. set cmd = ($cmd --pv mri/norm.mgz --empty)
  3452. set cmd = ($cmd --brainmask mri/brainmask.mgz --brain-vol-from-seg)
  3453. set cmd = ($cmd --excludeid 0 --excl-ctxgmwm)
  3454. if ( -e mri/ribbon.mgz ) then
  3455. set cmd = ($cmd --supratent)
  3456. else
  3457. echo "\nINFO: mri_segstats will not calculate Supratentorial" |& tee -a $LF
  3458. echo " due to missing ribbon.mgz file" |& tee -a $LF
  3459. endif
  3460. set cmd = ($cmd --subcortgray)
  3461. set cmd = ($cmd --in mri/norm.mgz --in-intensity-name norm)
  3462. set cmd = ($cmd --in-intensity-units MR)
  3463. if ( -e mri/transforms/talairach.xfm ) then
  3464. set cmd = ($cmd --etiv);
  3465. else
  3466. echo "\nINFO: mri_segstats will not calculate eTIV" |& tee -a $LF
  3467. echo " due to missing talairach.xfm file" |& tee -a $LF
  3468. endif
  3469. if ( ( -e surf/lh.white ) && ( -e surf/rh.white ) ) then
  3470. set cmd = ($cmd --surf-wm-vol)
  3471. if ( ( -e surf/lh.pial ) && ( -e surf/rh.pial ) ) then
  3472. set cmd = ($cmd --surf-ctx-vol --totalgray)
  3473. else
  3474. echo "\nINFO: ?h.pial surfaces not available to mri_segstats.\n"\
  3475. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3476. endif
  3477. else
  3478. echo "\nINFO: ?h.white surfaces not available to mri_segstats.\n"\
  3479. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3480. endif
  3481. if( ( -e surf/lh.orig.nofix ) && ( -e surf/rh.orig.nofix ) ) then
  3482. set cmd = ($cmd --euler)
  3483. endif
  3484. set cmd = ($cmd --ctab $FREESURFER_HOME/ASegStatsLUT.txt)
  3485. set cmd = ($cmd --subject $subjid $xopts);
  3486. $PWD |& tee -a $LF
  3487. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3488. if($RunIt) $fs_time $cmd |& tee -a $LF
  3489. if($status) goto error_exit;
  3490. echo $cmd > $touchdir/segstats.touch
  3491. endif
  3492. if ($DoAsegStatsDiff) then
  3493. # Compare aseg stats of two subjects
  3494. echo "#--------------------------------------------" \
  3495. |& tee -a $LF |& tee -a $CF
  3496. echo "#@# ASeg Stats Diff `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3497. cd $SUBJECTS_DIR > /dev/null
  3498. set subj1=($diffsubj)
  3499. if ( "x$subj1" == "x$subjid" ) then
  3500. # asegstats2table doesnt accept identical subject names, so fake it
  3501. ln -s $subj1 ${diffsubj}_tmp
  3502. set subj1=(${diffsubj}_tmp)
  3503. endif
  3504. set cmd=(asegstatsdiff $subj1 $subjid)
  3505. $PWD |& tee -a $LF
  3506. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3507. if($RunIt) $fs_time $cmd |& tee -a $LF
  3508. if (-e ${diffsubj}_tmp) rm ${diffsubj}_tmp
  3509. echo $cmd > $touchdir/asegstatsdiff.touch
  3510. endif
  3511. # ----------------- AParc2ASeg ---------------------------------------- #
  3512. if($DoAParc2ASeg) then
  3513. echo "#-----------------------------------------"|& tee -a $LF |& tee -a $CF
  3514. echo "#@# AParc-to-ASeg `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3515. cd $subjdir > /dev/null
  3516. set xopts = `fsr-getxopts mri_aparc2aseg $XOptsFile`;
  3517. # Desikan (or whatever was specified by -gcs)
  3518. set cmd = (mri_aparc2aseg --s $subjid --volmask $xopts)
  3519. $PWD |& tee -a $LF
  3520. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3521. if($RunIt) $fs_time $cmd |& tee -a $LF
  3522. if($status) goto error_exit;
  3523. echo $cmd > $touchdir/aparc2aseg.touch
  3524. # Now do Christophe's (if exist, which they may not, if -nocortparc2 used)
  3525. if( -e ${subjdir}/label/lh.aparc.${DESTRIEUX_NAME}.annot && \
  3526. -e ${subjdir}/label/rh.aparc.${DESTRIEUX_NAME}.annot ) then
  3527. set xopts = `fsr-getxopts mri_aparc2aseg $XOptsFile`;
  3528. set cmd = (mri_aparc2aseg --s $subjid --volmask --${DESTRIEUX_NAME} $xopts)
  3529. $PWD |& tee -a $LF
  3530. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3531. if($RunIt) $fs_time $cmd |& tee -a $LF
  3532. if($status) goto error_exit;
  3533. echo $cmd > $touchdir/aparc.${DESTRIEUX_NAME}2aseg.touch
  3534. else
  3535. echo "INFO: skipping ${DESTRIEUX_NAME} aparc2aseg" \
  3536. |& tee -a $LF |& tee -a $CF
  3537. endif
  3538. endif
  3539. # ----------------- WMParc ---------------------------------------- #
  3540. if($DoWMParc) then
  3541. echo "#-----------------------------------------"|& tee -a $LF |& tee -a $CF
  3542. echo "#@# WMParc `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3543. cd $subjdir > /dev/null
  3544. set xopts = `fsr-getxopts mri_aparc2aseg $XOptsFile`;
  3545. set cmd = (mri_aparc2aseg --s $subjid --labelwm --hypo-as-wm --rip-unknown \
  3546. --volmask --o mri/wmparc.mgz --ctxseg aparc+aseg.mgz $xopts )
  3547. $PWD |& tee -a $LF
  3548. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3549. if($RunIt) $fs_time $cmd |& tee -a $LF
  3550. if($status) goto error_exit;
  3551. echo $cmd > $touchdir/wmaparc.touch
  3552. # Do segstats while we're here
  3553. set cmd = (mri_segstats)
  3554. # if($UseCuda) set cmd = (mri_segstats_cuda)
  3555. set cmd = ($cmd --seg mri/wmparc.mgz --sum stats/wmparc.stats \
  3556. --pv mri/norm.mgz --excludeid 0 \
  3557. --brainmask mri/brainmask.mgz --in mri/norm.mgz --in-intensity-name norm \
  3558. --in-intensity-units MR --subject $subjid --surf-wm-vol \
  3559. --ctab $FREESURFER_HOME/WMParcStatsLUT.txt )
  3560. if ( -e mri/transforms/talairach.xfm ) then
  3561. set cmd = ($cmd --etiv);
  3562. else
  3563. echo "INFO: mri_segstats will not calculate eTIV" |& tee -a $LF
  3564. echo " due to missing talairach.xfm file" |& tee -a $LF
  3565. endif
  3566. $PWD |& tee -a $LF
  3567. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3568. if($RunIt) $fs_time $cmd |& tee -a $LF
  3569. if($status) goto error_exit;
  3570. echo $cmd > $touchdir/wmaparc.stats.touch
  3571. endif
  3572. # -----------------------------------------------------------
  3573. # Do Contra Surface Registration here so don't have
  3574. # to wait for other results
  3575. foreach hemi ($hemilist)
  3576. # Registers ipsi and contra
  3577. if($DoContraSurfReg) then
  3578. if($hemi == lh) then
  3579. set nothemi = rh;
  3580. else
  3581. set nothemi = lh;
  3582. endif
  3583. echo "#--------------------------------------------" \
  3584. |& tee -a $LF |& tee -a $CF
  3585. echo "#@# Contra Surf Reg $hemi `date`" \
  3586. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3587. cd $subjdir/scripts > /dev/null
  3588. set AvgTif = ${AvgCurvTifPath}/$nothemi.${AvgCurvTif}
  3589. set xopts = `fsr-getxopts mris_register $XOptsFile`;
  3590. set cmd = (mris_register -curv -reverse ../surf/$hemi.sphere)
  3591. if($UseNoNeg) set cmd = ($cmd -remove_negative 1)
  3592. set cmd = ($cmd $xopts)
  3593. set cmd = ($cmd $AvgTif ../surf/$hemi.$nothemi.sphere.reg)
  3594. $PWD |& tee -a $LF
  3595. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3596. if($RunIt) $fs_time $cmd |& tee -a $LF
  3597. if($status) goto error_exit;
  3598. echo $cmd > $touchdir/$hemi.sphreg.contra.touch
  3599. endif
  3600. # Register ipsi to contra directly (instead of thru sphere)
  3601. # Creates lh.rh.sphere (note that there is no .reg)
  3602. if($DoContraSurfRegWithinSubject) then
  3603. cd $subjdir/surf
  3604. if($hemi == lh) then
  3605. set nothemi = rh;
  3606. else
  3607. set nothemi = lh;
  3608. endif
  3609. if(! -e $nothemi.inflated.H) then
  3610. echo "ERROR: cannot find $nothemi.inflated.H, try running -inflate2" \
  3611. |& tee -a $LF
  3612. goto error_exit;
  3613. endif
  3614. echo "#--------------------------------------------" \
  3615. |& tee -a $LF |& tee -a $CF
  3616. echo "#@# Contra Surf Reg Within Subject $hemi `date`" \
  3617. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3618. set cmd = (mris_register -dist 0.3 -reverse -1 \
  3619. ./$hemi.sphere ./$nothemi.sphere ./$hemi.$nothemi.sphere)
  3620. $PWD |& tee -a $LF
  3621. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3622. if($RunIt) $fs_time $cmd |& tee -a $LF
  3623. if($status) goto error_exit;
  3624. echo $cmd > $touchdir/$hemi.sphere.contra.touch
  3625. endif
  3626. end # hemi
  3627. # ---------------------------------------------------------------
  3628. # Create the smoothed surfaces to fsaverage target needed by Qdec.
  3629. if ($DoQdecCache) then
  3630. if ("${measuredir}" != "") then
  3631. cd ${measuredir}
  3632. else
  3633. cd $subjdir/surf
  3634. endif
  3635. $PWD |& tee -a $LF
  3636. foreach hemi ($hemilist)
  3637. foreach measure ($measurelist)
  3638. echo "#--------------------------------------------" \
  3639. |& tee -a $LF |& tee -a $CF
  3640. echo "#@# Qdec Cache $hemi $measure $target `date`" \
  3641. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3642. # check for the target subject 'fsaverage' (if using as default target)
  3643. # and create symlink from distribution dir if not found in subjects dir
  3644. if (("${target}" == "fsaverage") && ( ! -e $SUBJECTS_DIR/fsaverage)) then
  3645. echo "INFO: fsaverage subject does not exist in SUBJECTS_DIR" \
  3646. |& tee -a $LF |& tee -a $CF
  3647. echo "INFO: Creating symlink to fsaverage subject..." \
  3648. |& tee -a $LF |& tee -a $CF
  3649. set cmd=(ln -s $FREESURFER_HOME/subjects/fsaverage)
  3650. echo "\n cd $SUBJECTS_DIR; $cmd; cd - \n"|& tee -a $LF |& tee -a $CF
  3651. cd $SUBJECTS_DIR
  3652. if($RunIt && ! -e fsaverage) $fs_time $cmd |& tee -a $LF
  3653. cd -
  3654. endif
  3655. # now check that the measure file exists, print only warning if not
  3656. if ( ! -e ${hemi}.${measure} ) then
  3657. echo "INFO: File ${hemi}.${measure} does not exist!" \
  3658. |& tee -a $LF |& tee -a $CF
  3659. echo "Skipping creation of smoothed data for ${hemi}.${measure}" \
  3660. |& tee -a $LF |& tee -a $CF
  3661. else
  3662. set MeasFile=(${hemi}.${measure})
  3663. # strip .mgz from filename (does nothing if not .mgz extension):
  3664. set MeasFile=`basename ${MeasFile} .mgz`
  3665. set MeasFile=(${MeasFile}.${target})
  3666. set cmd=(mris_preproc \
  3667. --s ${subjid} \
  3668. --hemi ${hemi} \
  3669. --meas ${measure} \
  3670. --target ${target} \
  3671. --out ${MeasFile}.mgh)
  3672. if ("${measuredir}" != "") set cmd = ($cmd --surfdir ${measuredir})
  3673. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3674. if($RunIt) $fs_time $cmd |& tee -a $LF
  3675. if($status) goto error_exit;
  3676. if($RunIt) rm -Rf tmp.mris_preproc.*
  3677. foreach fwhm ($fwhmlist)
  3678. set OutFile=(${hemi}.${measure})
  3679. # strip .mgz from filename (does nothing if not .mgz extension):
  3680. set OutFile=`basename ${OutFile} .mgz`
  3681. set OutFile=(${OutFile}.fwhm${fwhm}.${target})
  3682. set cmd=(mri_surf2surf \
  3683. --s ${target} \
  3684. --hemi ${hemi} \
  3685. --fwhm ${fwhm} \
  3686. --sval ${MeasFile}.mgh \
  3687. --tval ${OutFile}.mgh)
  3688. if($SmoothCortexOnly) set cmd = ($cmd --cortex)
  3689. if(! $SmoothCortexOnly) set cmd = ($cmd --no-cortex)
  3690. echo "#--------------------------------------------" \
  3691. |& tee -a $LF |& tee -a $CF
  3692. echo "#@# Qdec Cache $hemi $measure fwhm$fwhm $target `date`" \
  3693. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3694. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3695. if($RunIt) $fs_time $cmd |& tee -a $LF
  3696. if($status) goto error_exit;
  3697. if($RunIt) rm -Rf tmp.mris_preproc.*
  3698. if($RunIt) then
  3699. if ("${measuredir}" != "") then
  3700. mv -v ${OutFile}.mgh $subjdir/surf
  3701. endif
  3702. endif
  3703. echo $cmd > $touchdir/$hemi.$measure.$fwhm.qcache.touch
  3704. end # fwhm
  3705. endif # if ( ! -e ${hemi}.${measure} )
  3706. end # measure
  3707. end # hemi
  3708. endif # DoQdecCache
  3709. # ---------------------------------------------------------------
  3710. # Compute local gyrification index measurements
  3711. if ($DoLocalGyriIndex) then
  3712. cd $subjdir/surf
  3713. $PWD |& tee -a $LF
  3714. foreach hemi ($hemilist)
  3715. echo "#--------------------------------------------" \
  3716. |& tee -a $LF |& tee -a $CF
  3717. echo "#@# Local Gyrification Index $hemi `date`" \
  3718. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3719. set cmd=(mris_compute_lgi --i ${hemi}.pial)
  3720. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3721. if($RunIt) $fs_time $cmd |& tee -a $LF
  3722. if($status) goto error_exit;
  3723. end # hemi
  3724. endif # DoLocalGyriIndex
  3725. # --------------------------------------------------------------------
  3726. # Create Brodmann area labels by mapping from fsaverage,
  3727. # then create the ?h.BA.annot file from these labels,
  3728. # then generate a ?h.BA.stats file from that annot.
  3729. if ($DoBaLabels) then
  3730. cd $subjdir/label
  3731. $PWD |& tee -a $LF
  3732. foreach hemi ($hemilist)
  3733. echo "#--------------------------------------------" \
  3734. |& tee -a $LF |& tee -a $CF
  3735. echo "#@# BA Labels $hemi `date`" \
  3736. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3737. set HaveFsAverage=1;
  3738. if ( ! -e $SUBJECTS_DIR/fsaverage) then
  3739. echo "INFO: fsaverage subject does not exist in SUBJECTS_DIR" \
  3740. |& tee -a $LF |& tee -a $CF
  3741. set HaveFsAverage=0;
  3742. else
  3743. # check if the latest-greatest fsaverage is here (which would not be
  3744. # the case if running on subjects processed by an older version)
  3745. if ( ! -e $SUBJECTS_DIR/fsaverage/label/lh.perirhinal.label) then
  3746. echo "INFO: fsaverage subject does not have perirhinal labels!" \
  3747. |& tee -a $LF |& tee -a $CF
  3748. set HaveFsAverage=0;
  3749. set cmd=(rm -Rf fsaverage)
  3750. echo "\n cd $SUBJECTS_DIR; $cmd; cd - \n"|& tee -a $LF |& tee -a $CF
  3751. cd $SUBJECTS_DIR
  3752. if($RunIt && -e fsaverage) $fs_time $cmd |& tee -a $LF
  3753. cd -
  3754. endif
  3755. endif
  3756. if ( ! $HaveFsAverage ) then
  3757. echo "INFO: Creating symlink to fsaverage subject..." \
  3758. |& tee -a $LF |& tee -a $CF
  3759. set cmd=(ln -s $FREESURFER_HOME/subjects/fsaverage)
  3760. echo "\n cd $SUBJECTS_DIR; $cmd; cd - \n"|& tee -a $LF |& tee -a $CF
  3761. cd $SUBJECTS_DIR
  3762. if($RunIt && ! -e fsaverage) $fs_time $cmd |& tee -a $LF
  3763. cd -
  3764. endif
  3765. # generate labels
  3766. foreach balabel (BA1 BA2 BA3a BA3b BA4a BA4p BA6 BA44 BA45 V1 V2 MT \
  3767. perirhinal)
  3768. set cmd=(mri_label2label \
  3769. --srcsubject fsaverage \
  3770. --srclabel $SUBJECTS_DIR/fsaverage/label/${hemi}.${balabel}.label \
  3771. --trgsubject $subjid \
  3772. --trglabel ./${hemi}.${balabel}.label \
  3773. --hemi ${hemi} \
  3774. --regmethod surface)
  3775. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3776. if($RunIt) $fs_time $cmd |& tee -a $LF
  3777. if($status) goto error_exit;
  3778. end # balabel
  3779. # generate .thresh labels
  3780. foreach balabel (BA1 BA2 BA3a BA3b BA4a BA4p BA6 BA44 BA45 V1 V2 MT)
  3781. set cmd=(mri_label2label \
  3782. --srcsubject fsaverage \
  3783. --srclabel $SUBJECTS_DIR/fsaverage/label/${hemi}.${balabel}.thresh.label \
  3784. --trgsubject $subjid \
  3785. --trglabel ./${hemi}.${balabel}.thresh.label \
  3786. --hemi ${hemi} \
  3787. --regmethod surface)
  3788. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3789. if($RunIt) $fs_time $cmd |& tee -a $LF
  3790. if($status) goto error_exit;
  3791. end # balabel
  3792. # create .annot
  3793. set cmd=(mris_label2annot \
  3794. --s $subjid \
  3795. --hemi $hemi \
  3796. --ctab $FREESURFER_HOME/average/colortable_BA.txt \
  3797. --l $hemi.BA1.label \
  3798. --l $hemi.BA2.label \
  3799. --l $hemi.BA3a.label \
  3800. --l $hemi.BA3b.label \
  3801. --l $hemi.BA4a.label \
  3802. --l $hemi.BA4p.label \
  3803. --l $hemi.BA6.label \
  3804. --l $hemi.BA44.label \
  3805. --l $hemi.BA45.label \
  3806. --l $hemi.V1.label \
  3807. --l $hemi.V2.label \
  3808. --l $hemi.MT.label \
  3809. --l $hemi.perirhinal.label \
  3810. --a BA \
  3811. --maxstatwinner \
  3812. --noverbose )
  3813. if($RunIt) if ( -e ./$hemi.BA.annot) rm -fv ./$hemi.BA.annot
  3814. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3815. if($RunIt) $fs_time $cmd |& tee -a $LF
  3816. if($status) goto error_exit;
  3817. # create .thresh.annot
  3818. set cmd=(mris_label2annot \
  3819. --s $subjid \
  3820. --hemi $hemi \
  3821. --ctab $FREESURFER_HOME/average/colortable_BA.txt \
  3822. --l $hemi.BA1.thresh.label \
  3823. --l $hemi.BA2.thresh.label \
  3824. --l $hemi.BA3a.thresh.label \
  3825. --l $hemi.BA3b.thresh.label \
  3826. --l $hemi.BA4a.thresh.label \
  3827. --l $hemi.BA4p.thresh.label \
  3828. --l $hemi.BA6.thresh.label \
  3829. --l $hemi.BA44.thresh.label \
  3830. --l $hemi.BA45.thresh.label \
  3831. --l $hemi.V1.thresh.label \
  3832. --l $hemi.V2.thresh.label \
  3833. --l $hemi.MT.thresh.label \
  3834. --a BA.thresh \
  3835. --maxstatwinner \
  3836. --noverbose )
  3837. if($RunIt) if ( -e ./$hemi.BA.thresh.annot) rm -fv ./$hemi.BA.thresh.annot
  3838. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3839. if($RunIt) $fs_time $cmd |& tee -a $LF
  3840. if($status) goto error_exit;
  3841. # generate stats
  3842. set annot = ./$hemi.BA.annot
  3843. set stats = ../stats/$hemi.BA.stats
  3844. set ctab = ./BA.ctab
  3845. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  3846. set cmd = (mris_anatomical_stats -mgz -f $stats \
  3847. -b -a $annot -c $ctab $xopts $subjid $hemi white);
  3848. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3849. if($RunIt) $fs_time $cmd |& tee -a $LF
  3850. if($status) goto error_exit;
  3851. # generate .thresh stats
  3852. set annot = ./$hemi.BA.thresh.annot
  3853. set stats = ../stats/$hemi.BA.thresh.stats
  3854. set ctab = ./BA.thresh.ctab
  3855. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  3856. set cmd = (mris_anatomical_stats -mgz -f $stats \
  3857. -b -a $annot -c $ctab $xopts $subjid $hemi white);
  3858. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3859. if($RunIt) $fs_time $cmd |& tee -a $LF
  3860. if($status) goto error_exit;
  3861. end # hemi
  3862. endif # DoBaLabels
  3863. # --------------------------------------------------------------------
  3864. # Create entorhinal cortex labels by mapping from exvivo subjects,
  3865. # then generate ?h.entorhinal_exvivo.stats files
  3866. if ($DoLabelExvivoEC) then
  3867. cd $subjdir/label
  3868. $PWD |& tee -a $LF
  3869. foreach hemi ($hemilist)
  3870. echo "#--------------------------------------------" \
  3871. |& tee -a $LF |& tee -a $CF
  3872. echo "#@# Ex-vivo Entorhinal Cortex Label $hemi `date`" \
  3873. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3874. if ( ! -e $SUBJECTS_DIR/${hemi}.EC_average) then
  3875. echo "INFO: ${hemi}.EC_average subject does not exist in SUBJECTS_DIR" \
  3876. |& tee -a $LF |& tee -a $CF
  3877. echo "INFO: Creating symlink to ${hemi}.EC_average subject..." \
  3878. |& tee -a $LF |& tee -a $CF
  3879. set cmd=(ln -s $FREESURFER_HOME/subjects/${hemi}.EC_average)
  3880. echo "\n cd $SUBJECTS_DIR; $cmd; cd - \n"|& tee -a $LF |& tee -a $CF
  3881. cd $SUBJECTS_DIR
  3882. if($RunIt && ! -e ${hemi}.EC_average) $fs_time $cmd |& tee -a $LF
  3883. cd -
  3884. endif
  3885. # generate label
  3886. set cmd = (mris_spherical_average \
  3887. -erode 1 \
  3888. -orig white \
  3889. -t 0.4 \
  3890. -o ${subjid} \
  3891. label ${hemi}.entorhinal \
  3892. $hemi sphere.reg \
  3893. ${hemi}.EC_average \
  3894. ${hemi}.entorhinal_exvivo.label)
  3895. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3896. if($RunIt) $fs_time $cmd |& tee -a $LF
  3897. if($status) goto error_exit;
  3898. # generate stats
  3899. set label = ./$hemi.entorhinal_exvivo.label
  3900. set stats = ../stats/$hemi.entorhinal_exvivo.stats
  3901. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  3902. set cmd = (mris_anatomical_stats -mgz -f $stats \
  3903. -b -l $label $xopts $subjid $hemi white);
  3904. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3905. if($RunIt) $fs_time $cmd |& tee -a $LF
  3906. if($status) goto error_exit;
  3907. end # hemi
  3908. endif # DoLabelExvivoEC
  3909. #-------------- AParc+ASeg Stats -----------------#
  3910. # This is not something you want to do in general. The volumes
  3911. # of cortical structures should be obtained from the aparc.stats,
  3912. # but getting the intensity means and stddevs can be useful.
  3913. if($DoAParcASegStats) then
  3914. echo "#--------------------------------------------" \
  3915. |& tee -a $LF |& tee -a $CF
  3916. echo "#@# AParcASeg Stats `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3917. cd $subjdir > /dev/null
  3918. set xopts = `fsr-getxopts mri_segstats $XOptsFile`;
  3919. set cmd = (mri_segstats)
  3920. # if($UseCuda) set cmd = (mri_segstats_cuda)
  3921. set cmd = ($cmd --seg mri/aparc+aseg.mgz --sum stats/aparc+aseg.stats)
  3922. set cmd = ($cmd --pv mri/norm.mgz )
  3923. set cmd = ($cmd --excludeid 0 --ctab-default --empty)
  3924. set cmd = ($cmd --brain-vol-from-seg --brainmask mri/brainmask.mgz)
  3925. set cmd = ($cmd --in mri/norm.mgz --in-intensity-name norm)
  3926. set cmd = ($cmd --in-intensity-units MR)
  3927. set cmd = ($cmd --subject $subjid);
  3928. if ( -e mri/transforms/talairach.xfm ) then
  3929. set cmd = ($cmd --etiv);
  3930. else
  3931. echo "INFO: mri_segstats will not calculate eTIV" |& tee -a $LF
  3932. echo " due to missing talairach.xfm file" |& tee -a $LF
  3933. endif
  3934. set cmd = ($cmd $xopts);
  3935. $PWD |& tee -a $LF
  3936. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3937. if($RunIt) $fs_time $cmd |& tee -a $LF
  3938. if($status) goto error_exit;
  3939. echo $cmd > $touchdir/aparc+aseg.stats.touch
  3940. endif
  3941. #-------------- Hippocampal Subfields -----------------#
  3942. if($DoGEMS) then
  3943. set GEMSF = ($subjdir/scripts/hippo-subfields.log)
  3944. rm -f $GEMSF
  3945. echo "#--------------------------------------------" \
  3946. |& tee -a $LF |& tee -a $CF |& tee -a $GEMSF
  3947. echo "#@# Hippocampal Subfields processing `date`" \
  3948. |& tee -a $SF |& tee -a $LF |& tee -a $CF |& tee -a $GEMSF
  3949. if (-e ${subjdir}/mri/aseg.mgz && -e ${subjdir}/mri/nu.mgz && -e ${subjdir}/mri/transforms/talairach.xfm ) then
  3950. # create a tmp directory if it doesn't exist
  3951. set cmd = (mkdir -p ${subjdir}/tmp/subfieldResults)
  3952. echo "\n $cmd"|& tee -a $LF |& tee -a $CF
  3953. if($RunIt) $cmd |& tee -a $GEMSF
  3954. set kvltmpd = (${subjdir}/tmp/subfieldResults)
  3955. # do hippocampal processing
  3956. set cmd = (kvlSegmentHippocampalSubfields.sh $subjid left $SUBJECTS_DIR ${kvltmpd} )
  3957. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3958. if($RunIt) $fs_time $cmd |& tee -a $GEMSF
  3959. if($status) goto error_exit;
  3960. set cmd = (kvlSegmentHippocampalSubfields.sh $subjid right $SUBJECTS_DIR ${kvltmpd} )
  3961. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3962. if($RunIt) $fs_time $cmd |& tee -a $GEMSF
  3963. if($status) goto error_exit;
  3964. # copy results back to mri directory
  3965. set cmd = ("cp ${kvltmpd}/${subjid}/left/segmentationWithoutPartialVolumingLog/posterior_left* ${subjdir}/mri" )
  3966. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3967. if($RunIt) $fs_time $cmd |& tee -a $GEMSF
  3968. if($status) goto error_exit;
  3969. set cmd = ("cp ${kvltmpd}/${subjid}/left/segmentationWithoutPartialVolumingLog/posterior_Left* ${subjdir}/mri" )
  3970. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3971. if($RunIt) $fs_time $cmd |& tee -a $GEMSF
  3972. if($status) goto error_exit;
  3973. set cmd = ("cp ${kvltmpd}/${subjid}/right/segmentationWithoutPartialVolumingLog/posterior_right* ${subjdir}/mri" )
  3974. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3975. if($RunIt) $fs_time $cmd |& tee -a $GEMSF
  3976. if($status) goto error_exit;
  3977. set cmd = ("cp ${kvltmpd}/${subjid}/right/segmentationWithoutPartialVolumingLog/posterior_Right* ${subjdir}/mri" )
  3978. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3979. if($RunIt) $fs_time $cmd |& tee -a $GEMSF
  3980. if($status) goto error_exit;
  3981. # delete the tmp directory
  3982. set cmd = (rm -rf ${kvltmpd} )
  3983. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3984. if($RunIt) $fs_time $cmd |& tee -a $GEMSF
  3985. echo $cmd > $touchdir/hippocampal_subfield.touch
  3986. else
  3987. echo "ERROR: cannot find aseg.mgz or nu.mgz or talairach.xfm for the subject."
  3988. echo "ERROR: Maybe, run recon-all again or disable hippocampal subfields processing."
  3989. goto error_exit;
  3990. endif #checking of aseg.mgz, nu.mgz and talairach.xfm
  3991. endif
  3992. echo "" |& tee -a $LF
  3993. echo "#------------------------------------------" |& tee -a $LF
  3994. echo "" |& tee -a $LF
  3995. set EndTime = `date`;
  3996. set tSecEnd = `date '+%s'`;
  3997. @ tSecRun = $tSecEnd - $tSecStart;
  3998. set tRunHours = `echo $tSecRun/3600|bc -l`
  3999. set tRunHours = `printf %6.3f $tRunHours`
  4000. echo "Started at $StartTime " |& tee -a $LF
  4001. echo "Ended at $EndTime" |& tee -a $LF
  4002. echo "#@#%# recon-all-run-time-hours $tRunHours" |& tee -a $LF
  4003. if($#NotifyFile != 0) then
  4004. echo "INFO: touching notification file $NotifyFile" |& tee -a $LF
  4005. touch $NotifyFile
  4006. endif
  4007. if($DoIsRunning && $#IsRunningFile) rm -f $IsRunningFile
  4008. # Create the Done File
  4009. echo "------------------------------" > $DoneFile
  4010. echo "SUBJECT $subjid" >> $DoneFile
  4011. echo "START_TIME $StartTime" >> $DoneFile
  4012. echo "END_TIME $EndTime" >> $DoneFile
  4013. echo "RUNTIME_HOURS $tRunHours" >> $DoneFile
  4014. echo "USER $user" >> $DoneFile
  4015. echo "HOST `hostname`" >> $DoneFile
  4016. echo "PROCESSOR `uname -m`" >> $DoneFile
  4017. echo "OS `uname -s`" >> $DoneFile
  4018. echo "UNAME `uname -a`" >> $DoneFile
  4019. echo "VERSION $VERSION" >> $DoneFile
  4020. echo "CMDPATH $0" >> $DoneFile
  4021. echo "CMDARGS $argv0" >> $DoneFile
  4022. echo "recon-all -s $subjid finished without error at `date`" \
  4023. |& tee -a $LF |& tee -a $SF
  4024. if($#mailuser != 0) then
  4025. echo "recon-all -s $subjid finished without error at `date`" | \
  4026. mail -s "$subjid DONE `date`" $mailuser
  4027. endif
  4028. echo "done"
  4029. # add to usage tracking file, if configured and writable
  4030. # a sysadmin would need to have users set the environment var
  4031. # RECONALL_USAGE_FILE to a world-writable file. example:
  4032. # setenv RECONALL_USAGE_FILE /space/freesurfer/recon-all_run_log
  4033. if($?RECONALL_USAGE_FILE) then
  4034. if(-e $RECONALL_USAGE_FILE) then
  4035. if(-w $RECONALL_USAGE_FILE) then
  4036. if ($RunIt) then
  4037. echo "`date` `cat $FREESURFER_HOME/build-stamp.txt`" \
  4038. >> $RECONALL_USAGE_FILE
  4039. endif
  4040. endif
  4041. endif
  4042. endif
  4043. exit 0
  4044. #############------------------------------------#######################
  4045. ##################>>>>>>>>>>>>>.<<<<<<<<<<<<<<<<<#######################
  4046. #############------------------------------------#######################
  4047. ############--------------##################
  4048. error_exit:
  4049. uname -a | tee -a $LF | tee -a $SF
  4050. echo "" |& tee -a $LF |& tee -a $SF
  4051. echo "recon-all -s $subjid exited with ERRORS at `date`" \
  4052. |& tee -a $LF |& tee -a $SF
  4053. echo "" |& tee -a $LF |& tee -a $SF
  4054. echo "For more details, see the log file $LF"
  4055. echo "To report a problem, see http://surfer.nmr.mgh.harvard.edu/fswiki/BugReporting"|& tee -a $LF
  4056. echo ""
  4057. # Handle IsRunningFile
  4058. if($DoIsRunning && $#IsRunningFile) rm -f $IsRunningFile
  4059. # Mail the user
  4060. if($#mailuser != 0) then
  4061. echo "recon-all -s $subjid finished with errors at `date`" | \
  4062. mail -s "$subjid ERROR `date`" $mailuser
  4063. endif
  4064. # Create an error file with date, cmd, etc of error
  4065. if ( $?ErrorFile ) then
  4066. echo "------------------------------" > $ErrorFile
  4067. echo "SUBJECT $subjid" >> $ErrorFile
  4068. echo "DATE `date`" >> $ErrorFile
  4069. echo "USER $user" >> $ErrorFile
  4070. echo "HOST `hostname`" >> $ErrorFile
  4071. echo "PROCESSOR `uname -m`" >> $ErrorFile
  4072. echo "OS `uname -s`" >> $ErrorFile
  4073. uname -a >> $ErrorFile
  4074. echo $VERSION >> $ErrorFile
  4075. echo $0 >> $ErrorFile
  4076. echo "PWD `pwd`" >> $ErrorFile
  4077. echo "CMD $cmd" >> $ErrorFile
  4078. endif
  4079. # Finally exit
  4080. exit 1;
  4081. endif
  4082. ############--------------##################
  4083. parse_args:
  4084. set cmdline = ($argv);
  4085. while( $#argv != 0 )
  4086. set flag = $argv[1]; shift;
  4087. switch($flag)
  4088. # This is a temporary flag to test how changing the way the vertex
  4089. # area is computed in mrisurf.c affects a recon. It is set by default!
  4090. case "-fixvertexarea"
  4091. setenv FIX_VERTEX_AREA;
  4092. breaksw
  4093. case "-nofixvertexarea"
  4094. unsetenv FIX_VERTEX_AREA;
  4095. breaksw
  4096. case "-subject":
  4097. case "-subjid":
  4098. case "-sid":
  4099. case "-s":
  4100. if ( $#argv < 1) goto arg1err;
  4101. set subjid = $argv[1]; shift;
  4102. set subjid = `basename $subjid`; # removes trailing /
  4103. breaksw
  4104. case "-sb":
  4105. # Hidden option: same as -s but no basename;
  4106. # needed when passing a subdir of a subject
  4107. # as a subject.
  4108. if( $#argv < 1) goto arg1err;
  4109. set subjid = $argv[1]; shift;
  4110. breaksw
  4111. case "-sd":
  4112. if ( $#argv < 1) goto arg1err;
  4113. setenv SUBJECTS_DIR $argv[1]; shift;
  4114. breaksw
  4115. case "-i"
  4116. if( $#argv < 1) goto arg1err;
  4117. set InputVol = "$argv[1]"; shift;
  4118. if(! -e "$InputVol") then
  4119. echo "ERROR: cannot find $InputVol"
  4120. goto error_exit;
  4121. endif
  4122. if (-d "$InputVol") then
  4123. echo "ERROR: You cannot give recon-all a folder as input. It must be an image file."
  4124. echo "If you have multiple files, you need multiple -i flags."
  4125. goto error_exit;
  4126. endif
  4127. if(! -r "$InputVol") then
  4128. echo "ERROR: $InputVol exists but is not readable"
  4129. goto error_exit;
  4130. endif
  4131. set InVolDir = `dirname "$InputVol"`;
  4132. set InVolBase = `basename "$InputVol"`;
  4133. pushd $InVolDir > /dev/null
  4134. set InVolDir = `pwd`;
  4135. popd > /dev/null
  4136. set InputVol = "$InVolDir/$InVolBase";
  4137. set InputList = ($InputList "$InputVol");
  4138. set DoConvertInput = 1;
  4139. breaksw
  4140. case "-T2"
  4141. case "-t2"
  4142. if( $#argv < 1) goto arg1err;
  4143. set InputT2Vol = "$argv[1]"; shift;
  4144. if(! -e "$InputT2Vol") then
  4145. echo "ERROR: cannot find $InputT2Vol"
  4146. goto error_exit;
  4147. endif
  4148. if(! -r "$InputT2Vol") then
  4149. echo "ERROR: $InputT2Vol exists but is not readable"
  4150. goto error_exit;
  4151. endif
  4152. set T2InVolDir = `dirname "$InputT2Vol"`;
  4153. set T2InVolBase = `basename "$InputT2Vol"`;
  4154. pushd $T2InVolDir > /dev/null
  4155. set T2InVolDir = `pwd`;
  4156. popd > /dev/null
  4157. set InputT2Vol = "$T2InVolDir/$T2InVolBase";
  4158. set DoConvertT2Input = 1;
  4159. breaksw
  4160. case "-FLAIR"
  4161. case "-flair"
  4162. if( $#argv < 1) goto arg1err;
  4163. set InputFlairVol = "$argv[1]"; shift;
  4164. if(! -e "$InputFlairVol") then
  4165. echo "ERROR: cannot find $InputFlairVol"
  4166. goto error_exit;
  4167. endif
  4168. if(! -r "$InputFlairVol") then
  4169. echo "ERROR: $InputFlairVol exists but is not readable"
  4170. goto error_exit;
  4171. endif
  4172. set FlairInVolDir = `dirname "$InputFlairVol"`;
  4173. set FlairInVolBase = `basename "$InputFlairVol"`;
  4174. pushd $FlairInVolDir > /dev/null
  4175. set FlairInVolDir = `pwd`;
  4176. popd > /dev/null
  4177. set InputFlairVol = "$FlairInVolDir/$FlairInVolBase";
  4178. set DoConvertFlairInput = 1;
  4179. breaksw
  4180. case "-base-affine":
  4181. set DoAffineBase = 1;
  4182. # don't break here, but also switch on -base:
  4183. case "-base":
  4184. if ( $#argv < 1) goto arg1err;
  4185. set subjid = $argv[1]; shift;
  4186. set subjid = `basename $subjid`; # removes trailing /
  4187. set DoCreateBaseSubj = 1;
  4188. set NoRandomness = 1;
  4189. breaksw
  4190. case "-base-init":
  4191. set DoCreateBaseInput = 1;
  4192. breaksw
  4193. case "-nobase-init":
  4194. set DoCreateBaseInput = 0;
  4195. breaksw
  4196. case "-base-tp":
  4197. case "-tp":
  4198. if ( $#argv < 1) goto arg1err;
  4199. set basetpid = $argv[1]; shift;
  4200. set basetpid = `basename $basetpid`; # removes trailing /
  4201. set BaseSubjsList = ($BaseSubjsList $basetpid);
  4202. if($DoCreateBaseSubj) then
  4203. if ("$basetpid" == "$subjid") then
  4204. echo "ERROR: you need to specify a new ID for the base/template. "
  4205. echo "It cannot be one of the time points."
  4206. echo "Find more info at:"
  4207. echo "http://surfer.nmr.mgh.harvard.edu/fswiki/LongitudinalProcessing"
  4208. exit 1;
  4209. endif
  4210. endif
  4211. breaksw
  4212. case "-base-invol":
  4213. if ( $#argv < 1) goto arg1err;
  4214. set BaseSubjInvol = $argv[1]; shift;
  4215. breaksw
  4216. case "-hemi":
  4217. if ( $#argv < 1) goto arg1err;
  4218. set hemilist = $argv[1]; shift;
  4219. if($hemilist != lh && $hemilist != rh) then
  4220. echo "ERROR: hemi = $hemilist, must be either lh or rh"
  4221. goto error_exit;
  4222. endif
  4223. breaksw
  4224. case "-mail":
  4225. if ( $#argv < 1) goto arg1err;
  4226. set mailuser = $argv[1]; shift;
  4227. breaksw
  4228. case "-motioncor":
  4229. case "-mc":
  4230. set DoMotionCor = 1;
  4231. breaksw
  4232. case "-nomotioncor":
  4233. case "-nomc":
  4234. set DoMotionCor = 0;
  4235. breaksw
  4236. case "-robust-motioncor":
  4237. case "-motioncor-robust":
  4238. set DoMotionCor = 1;
  4239. set DoRobustMotionCor = 1;
  4240. breaksw
  4241. case "-norobust-motioncor":
  4242. case "-nomotioncor-robust":
  4243. set DoRobustMotionCor = 0;
  4244. breaksw
  4245. case "-flirt-motioncor":
  4246. case "-motioncor-flirt":
  4247. set DoMotionCor = 1;
  4248. set DoRobustMotionCor = 0;
  4249. breaksw
  4250. case "-talairach":
  4251. set DoTalairach = 1;
  4252. breaksw
  4253. case "-talairach-nu":
  4254. set DoTalairach = 1;
  4255. set DoTalairachUseNu = 1;
  4256. breaksw
  4257. case "-notalairach":
  4258. set DoTalairach = 0;
  4259. set DoTalCheck = 0;
  4260. breaksw
  4261. case "-use-mritotal":
  4262. set UseMincMritotal = 1;
  4263. breaksw
  4264. case "-schwartzya3t-atlas":
  4265. set UseYa3tTalAtlas = 1;
  4266. breaksw
  4267. case "-custom-tal-atlas":
  4268. if ( $#argv < 1) goto arg1err;
  4269. set CustomTalAtlas = $argv[1]; shift;
  4270. breaksw
  4271. case "-deface":
  4272. set DoDeface = 1;
  4273. breaksw
  4274. case "-nodeface":
  4275. set DoDeface = 0;
  4276. breaksw
  4277. case "-nuintensitycor":
  4278. case "-nu_correct":
  4279. set DoNuIntensityCor = 1;
  4280. breaksw
  4281. case "-nonuintensitycor":
  4282. set DoNuIntensityCor = 0;
  4283. breaksw
  4284. case "-nuintensitycor-3T":
  4285. case "-nuintensitycor-3t":
  4286. set DoNuIntensityCor = 1;
  4287. set DoNuIntensityCor3T = 1;
  4288. breaksw
  4289. case "-3T":
  4290. case "-3t":
  4291. set UseYa3tTalAtlas = 1;
  4292. set DoNuIntensityCor3T = 1;
  4293. breaksw
  4294. case "-nuiterations":
  4295. if ( $#argv < 1) goto arg1err;
  4296. set NuIterations = $argv[1]; shift;
  4297. breaksw
  4298. case "-numakeuchar":
  4299. set DoNuMakeUchar = 1;
  4300. breaksw
  4301. case "-no-numakeuchar":
  4302. case "-nonumakeuchar":
  4303. set DoNuMakeUchar = 0;
  4304. breaksw
  4305. # note: norm3diters and normmaxgrads is applied to both runs of
  4306. # mri_normalize. use -norm1-b, -norm1-n, -norm2-b, -norm2-n to
  4307. # distinguish -b and -n of the two mri_normalize runs
  4308. case "-norm3diters":
  4309. if ( $#argv < 1) goto arg1err;
  4310. set Norm3dIters = $argv[1]; shift;
  4311. breaksw
  4312. case "-normmaxgrad":
  4313. if ( $#argv < 1) goto arg1err;
  4314. set NormMaxGrad = $argv[1]; shift;
  4315. breaksw
  4316. case "-norm1-b":
  4317. if ( $#argv < 1) goto arg1err;
  4318. set Norm1_b = $argv[1]; shift;
  4319. breaksw
  4320. case "-norm1-n":
  4321. if ( $#argv < 1) goto arg1err;
  4322. set Norm1_n = $argv[1]; shift;
  4323. breaksw
  4324. case "-norm2-b":
  4325. if ( $#argv < 1) goto arg1err;
  4326. set Norm2_b = $argv[1]; shift;
  4327. breaksw
  4328. case "-norm2-n":
  4329. if ( $#argv < 1) goto arg1err;
  4330. set Norm2_n = $argv[1]; shift;
  4331. breaksw
  4332. case "-normalization":
  4333. set DoNormalization = 1;
  4334. breaksw
  4335. case "-nonormalization":
  4336. set DoNormalization = 0;
  4337. breaksw
  4338. case "-normalization2":
  4339. set DoNormalization2 = 1;
  4340. breaksw
  4341. case "-nonormalization2":
  4342. set DoNormalization2 = 0;
  4343. breaksw
  4344. case "-usecontrolpoints":
  4345. set UseControlPoints = 1;
  4346. breaksw
  4347. case "-maskbfs":
  4348. set DoMaskBFS = 1;
  4349. breaksw
  4350. case "-nomaskbfs":
  4351. set DoMaskBFS = 0;
  4352. breaksw
  4353. case "-skullstrip":
  4354. set DoSkullStrip = 1;
  4355. breaksw
  4356. case "-noskullstrip":
  4357. set DoSkullStrip = 0;
  4358. breaksw
  4359. case "-multistrip":
  4360. set DoMultiStrip = 1;
  4361. set DoSkullStrip = 1;
  4362. set DoCleanPFH = 1;
  4363. breaksw
  4364. case "-nomultistrip":
  4365. set DoMultiStrip = 0;
  4366. breaksw
  4367. case "-segmentation":
  4368. set DoSegmentation = 1;
  4369. breaksw
  4370. case "-nosegmentation":
  4371. set DoSegmentation = 0;
  4372. breaksw
  4373. case "-gcareg":
  4374. set DoGCAReg = 1;
  4375. breaksw
  4376. case "-nogcareg":
  4377. set DoGCAReg = 0;
  4378. breaksw
  4379. case "-careginv":
  4380. set DoCARegInv = 1;
  4381. breaksw
  4382. case "-nocareginv":
  4383. set DoCARegInv = 0;
  4384. breaksw
  4385. case "-canorm":
  4386. set DoCANormalize = 1;
  4387. breaksw
  4388. case "-nocanorm":
  4389. set DoCANormalize = 0;
  4390. breaksw
  4391. case "-canorm-usecps":
  4392. set DoCANormalize = 1;
  4393. set UseCPsWithCaNorm = 1;
  4394. breaksw
  4395. case "-careg":
  4396. set DoCAReg = 1;
  4397. breaksw
  4398. case "-nocareg":
  4399. set DoCAReg = 0;
  4400. breaksw
  4401. case "-rmneck":
  4402. set DoRemoveNeck = 1;
  4403. breaksw
  4404. case "-normneck":
  4405. set DoRemoveNeck = 0;
  4406. breaksw
  4407. case "-skull-lta":
  4408. set DoSkullLTA = 1;
  4409. breaksw
  4410. case "-noskull-lta":
  4411. set DoSkullLTA = 0;
  4412. breaksw
  4413. case "-calabel":
  4414. set DoCALabel = 1;
  4415. breaksw
  4416. case "-nocalabel":
  4417. set DoCALabel = 0;
  4418. breaksw
  4419. case "-asegmerge":
  4420. set DoASegMerge = 1;
  4421. breaksw
  4422. case "-no-asegmerge":
  4423. # Note: this will be overriden if DoCALabel=1
  4424. set DoASegMerge = 0;
  4425. breaksw
  4426. case "-subcortseg":
  4427. set DoGCAReg = 1;
  4428. set DoCARegInv = 1;
  4429. set DoRemoveNeck = 1;
  4430. set DoSkullLTA = 1;
  4431. set DoCANormalize = 1;
  4432. set DoCAReg = 1;
  4433. set DoCALabel = 1;
  4434. set DoSegStats = 1;
  4435. breaksw
  4436. case "-nosubcortseg":
  4437. set DoGCAReg = 0;
  4438. set DoCARegInv = 0;
  4439. set DoRemoveNeck = 0;
  4440. set DoSkullLTA = 0;
  4441. set DoCANormalize = 0;
  4442. set DoCAReg = 0;
  4443. set DoCALabel = 0;
  4444. set DoSegStats = 0;
  4445. set NoNormMGZ = 1;
  4446. breaksw
  4447. case "-noaseg":
  4448. set UseAseg = 0;
  4449. set DoGCAReg = 0;
  4450. set DoCARegInv = 0;
  4451. set DoRemoveNeck = 0;
  4452. set DoSkullLTA = 0;
  4453. set DoCANormalize = 0;
  4454. set DoCAReg = 0;
  4455. set DoCALabel = 0;
  4456. set DoSegStats = 0;
  4457. set NoNormMGZ = 1;
  4458. set DoAParc2ASeg = 0;
  4459. set DoWMParc = 0;
  4460. set DoCortRibbonVolMask = 0;
  4461. breaksw
  4462. case "-noaseg-inorm2":
  4463. set NoAsegInorm2 = 1;
  4464. breaksw
  4465. case "-gca":
  4466. if ( $#argv < 1) goto arg1err;
  4467. set GCA = $argv[1]; shift;
  4468. breaksw
  4469. case "-gca-skull":
  4470. if ( $#argv < 1) goto arg1err;
  4471. set GCASkull = $argv[1]; shift;
  4472. breaksw
  4473. case "-gca-dir":
  4474. if ( $#argv < 1) goto arg1err;
  4475. set GCADIR = $argv[1]; shift;
  4476. breaksw
  4477. case "-gcs":
  4478. if ( $#argv < 1) goto arg1err;
  4479. set GCS = $argv[1]; shift;
  4480. breaksw
  4481. case "-gcs-dir":
  4482. if ( $#argv < 1) goto arg1err;
  4483. set GCSDIR = $argv[1]; shift;
  4484. breaksw
  4485. case "-fill":
  4486. set DoFill = 1;
  4487. breaksw
  4488. case "-nofill":
  4489. set DoFill = 0;
  4490. breaksw
  4491. case "-pons-crs":
  4492. if ( $#argv < 3) goto arg3err;
  4493. set PonsSeedCRS = ($argv[1] $argv[2] $argv[3]);
  4494. shift;shift;shift;
  4495. breaksw
  4496. case "-cc-crs":
  4497. if ( $#argv < 3) goto arg3err;
  4498. set CCSeedCRS = ($argv[1] $argv[2] $argv[3]);
  4499. shift;shift;shift;
  4500. breaksw
  4501. case "-lh-crs":
  4502. if ( $#argv < 3) goto arg3err;
  4503. set LHSeedCRS = ($argv[1] $argv[2] $argv[3]);
  4504. shift;shift;shift;
  4505. breaksw
  4506. case "-rh-crs":
  4507. if ( $#argv < 3) goto arg3err;
  4508. set RHSeedCRS = ($argv[1] $argv[2] $argv[3]);
  4509. shift;shift;shift;
  4510. breaksw
  4511. case "-watershed":
  4512. echo $argv[1];
  4513. if ( $#argv < 1 ) goto arg1err;
  4514. switch($argv[1])
  4515. case "nowatershed":
  4516. set WaterShed = 0; breaksw;
  4517. case "normal":
  4518. set WaterShed = 1; breaksw;
  4519. case "watershedonly":
  4520. set WaterShed = 2; breaksw;
  4521. case "watershedtemplate":
  4522. set WaterShed = 3; breaksw;
  4523. case "atlas":
  4524. set WaterShed = 4; breaksw;
  4525. default:
  4526. echo "ERROR: -watershed argument $argv[1] unrecognized."
  4527. echo "Valid arguments are: atlas, nowatershed, normal, watershedonly,"
  4528. echo "and watershedtemplate."
  4529. goto error_exit;
  4530. breaksw;
  4531. endsw
  4532. shift;
  4533. breaksw
  4534. case "-wsless":
  4535. set WSLess = 1; breaksw
  4536. case "-wsmore":
  4537. set WSMore = 1; breaksw
  4538. case "-wsatlas":
  4539. set WSAtlas = 1; breaksw
  4540. case "-no-wsatlas":
  4541. set WSAtlas = 0; breaksw
  4542. case "-wsthresh":
  4543. if ( $#argv < 1) goto arg1err;
  4544. set WSPctPreFlood = $argv[1]; shift;
  4545. breaksw
  4546. case "-wsseed":
  4547. if ( $#argv < 3) goto arg3err;
  4548. set WSSeedPoint = ($argv[1] $argv[2] $argv[3]);
  4549. shift;shift;shift;
  4550. breaksw
  4551. case "-wsgcaatlas":
  4552. set WSGcaAtlas = 1; breaksw
  4553. case "-nowsgcaatlas":
  4554. case "-no-wsgcaatlas":
  4555. set WSGcaAtlas = 0; breaksw
  4556. case "-wstalxfm":
  4557. set WSUseTalXfm = 1; breaksw
  4558. case "-no-wstalxfm":
  4559. set WSUseTalXfm = 0; breaksw
  4560. case "-gcut":
  4561. set DoGcut = 1;
  4562. breaksw
  4563. case "-no-gcut":
  4564. case "-nogcut":
  4565. set DoGcut = 0;
  4566. breaksw
  4567. case "-seg-wlo"
  4568. if( $#argv < 1) goto arg1err;
  4569. set WMSeg_wlo = (-wlo $argv[1]); shift;
  4570. breaksw
  4571. case "-seg-ghi"
  4572. if( $#argv < 1) goto arg1err;
  4573. set WMSeg_ghi = (-ghi $argv[1]); shift;
  4574. breaksw
  4575. case "-ca-align":
  4576. set UseCAAlign = (-align);
  4577. breaksw
  4578. case "-no-ca-align":
  4579. set UseCAAlign = ();
  4580. breaksw
  4581. case "-ca-align-after":
  4582. set UseCAAlignAfter = (-align-after);
  4583. breaksw
  4584. case "-no-ca-align-after":
  4585. set UseCAAlignAfter = ();
  4586. breaksw
  4587. case "-tessellate":
  4588. case "-tess":
  4589. set DoTessellate = 1;
  4590. breaksw
  4591. case "-notessellate":
  4592. case "-notess":
  4593. set DoTessellate = 0;
  4594. breaksw
  4595. case "-smooth1":
  4596. set DoSmooth1 = 1;
  4597. breaksw
  4598. case "-nosmooth1":
  4599. set DoSmooth1 = 0;
  4600. breaksw
  4601. case "-inflate1":
  4602. set DoInflate1 = 1;
  4603. breaksw
  4604. case "-noinflate1":
  4605. set DoInflate1 = 0;
  4606. breaksw
  4607. case "-svinitinflated":
  4608. set SvInitInflated = 1;
  4609. breaksw
  4610. case "-nosvinitinflated":
  4611. set SvInitInflated = 0;
  4612. breaksw
  4613. case "-qsphere":
  4614. set DoQSphere = 1;
  4615. breaksw
  4616. case "-noqsphere":
  4617. set DoQSphere = 0;
  4618. breaksw
  4619. case "-fix":
  4620. set DoFix = 1;
  4621. breaksw
  4622. case "-nofix":
  4623. set DoFix = 0;
  4624. breaksw
  4625. case "-fix-with-ga":
  4626. set FixWithGA = 1;
  4627. breaksw
  4628. case "-fix-with-ga-errflag":
  4629. set DoFix = 1;
  4630. set FixWithGA = 1;
  4631. set FixWithErrFlag = 1;
  4632. breaksw
  4633. case "-no-fix-with-ga":
  4634. set FixWithGA = 0;
  4635. breaksw
  4636. case "-fix-diag-only":
  4637. set DoFix = 1;
  4638. set FixWithGA = 1;
  4639. set FixDiagOnly = 1;
  4640. breaksw
  4641. case "-use-old-fixer":
  4642. set UseOldTopoFix = 1;
  4643. set UseNewTopoFix = 0;
  4644. breaksw
  4645. case "-use-new-fixer":
  4646. set UseOldTopoFix = 0;
  4647. set UseNewTopoFix = 1;
  4648. breaksw
  4649. case "-norandomness":
  4650. set NoRandomness = 1;
  4651. breaksw
  4652. case "-randomness":
  4653. set NoRandomness = 0;
  4654. breaksw
  4655. case "-rng-seed":
  4656. set NoRandomness = 1;
  4657. set RngSeed = $argv[1]; shift;
  4658. breaksw
  4659. case "-smooth2":
  4660. set DoSmooth2 = 1;
  4661. breaksw
  4662. case "-nosmooth2":
  4663. set DoSmooth2 = 0;
  4664. breaksw
  4665. case "-inflate2":
  4666. set DoInflate2 = 1;
  4667. breaksw
  4668. case "-noinflate2":
  4669. set DoInflate2 = 0;
  4670. breaksw
  4671. case "-cortribbon":
  4672. set DoCortRibbonVolMask = 1;
  4673. breaksw
  4674. case "-nocortribbon":
  4675. set DoCortRibbonVolMask = 0;
  4676. breaksw
  4677. case "-sphere":
  4678. set DoSphere = 1;
  4679. breaksw
  4680. case "-nosphere":
  4681. set DoSphere = 0;
  4682. breaksw
  4683. case "-surfreg":
  4684. set DoSurfReg = 1;
  4685. breaksw
  4686. case "-nosurfreg":
  4687. set DoSurfReg = 0;
  4688. breaksw
  4689. # Specify an average subject, which will have a tif
  4690. # in its directory. Output will be hemi.sphere.avgsubj.reg
  4691. case "-surfreg-to-subject":
  4692. if( $#argv < 1) goto arg1err;
  4693. set SurfRegToSubj = $argv[1]; shift;
  4694. breaksw
  4695. case "-no-surfreg-to-subject":
  4696. set SurfRegToSubj = ();
  4697. breaksw
  4698. case "-jacobian_white":
  4699. set DoJacobianWhite = 1;
  4700. breaksw
  4701. case "-nojacobian_white":
  4702. set DoJacobianWhite = 0;
  4703. breaksw
  4704. case "-jacobian_dist0":
  4705. set DoJacobianDist0 = 1;
  4706. breaksw
  4707. case "-nojacobian_dist0":
  4708. set DoJacobianDist0 = 0;
  4709. breaksw
  4710. case "-contrasurfreg":
  4711. set DoContraSurfReg = 1;
  4712. breaksw
  4713. case "-nocontrasurfreg":
  4714. set DoContraSurfReg = 0;
  4715. breaksw
  4716. case "-contrasurfreg-subj":
  4717. set DoContraSurfRegWithinSubject = 1;
  4718. breaksw
  4719. case "-nocontrasurfreg-subj":
  4720. set DoContraSurfRegWithinSubject = 0;
  4721. breaksw
  4722. case "-avgcurv":
  4723. set DoAvgCurv = 1;
  4724. breaksw
  4725. case "-noavgcurv":
  4726. set DoAvgCurv = 0;
  4727. breaksw
  4728. case "-whitesurfs":
  4729. case "-white":
  4730. set DoWhiteSurfs = 1;
  4731. breaksw
  4732. case "-nowhitesurfs":
  4733. case "-nowhite":
  4734. set DoWhiteSurfs = 0;
  4735. breaksw
  4736. case "-pialsurfs":
  4737. case "-pial":
  4738. set DoPialSurfs = 1;
  4739. breaksw
  4740. case "-nopialsurfs":
  4741. case "-nopial":
  4742. set DoPialSurfs = 0;
  4743. breaksw
  4744. case "-pial-noaparc":
  4745. case "-pial_noaparc":
  4746. set DoPialSurfs = 1;
  4747. set PialNoAparc = 1;
  4748. breaksw
  4749. # backward compatibility with single-run mris_make_surfaces:
  4750. case "-finalsurfs":
  4751. set DoWhiteSurfs = 1;
  4752. set DoPialSurfs = 0;
  4753. set DoSurfVolume = 1;
  4754. breaksw
  4755. case "-nofinalsurfs":
  4756. set DoWhiteSurfs = 0;
  4757. set DoPialSurfs = 0;
  4758. breaksw
  4759. case "-pctsurfcon":
  4760. set DoPctSurfCon = 1;
  4761. breaksw
  4762. case "-nopctsurfcon":
  4763. case "-no-pctsurfcon":
  4764. set DoPctSurfCon = 0;
  4765. breaksw
  4766. case "-cortparc":
  4767. set DoCortParc = 1;
  4768. breaksw
  4769. case "-nocortparc":
  4770. set DoCortParc = 0;
  4771. breaksw
  4772. case "-cortparc2":
  4773. set DoCortParc2 = 1;
  4774. breaksw
  4775. case "-nocortparc2":
  4776. set DoCortParc2 = 0;
  4777. breaksw
  4778. case "-cortparc3":
  4779. set DoCortParc3 = 1;
  4780. breaksw
  4781. case "-nocortparc3":
  4782. set DoCortParc3 = 0;
  4783. breaksw
  4784. case "-parcstats":
  4785. set DoParcStats = 1;
  4786. breaksw
  4787. case "-noparcstats":
  4788. set DoParcStats = 0;
  4789. breaksw
  4790. case "-parcstats2":
  4791. set DoParcStats2 = 1;
  4792. breaksw
  4793. case "-noparcstats2":
  4794. set DoParcStats2 = 0;
  4795. breaksw
  4796. case "-parcstats3":
  4797. set DoParcStats3 = 1;
  4798. breaksw
  4799. case "-noparcstats3":
  4800. set DoParcStats3 = 0;
  4801. breaksw
  4802. case "-surfsegedit":
  4803. case "-edit-aseg-with-surfs":
  4804. set DoSurfSegEdit = 1;
  4805. breaksw
  4806. case "-nosurfsegedit":
  4807. set DoSurfSegEdit = 0;
  4808. breaksw
  4809. case "-segstats":
  4810. set DoSegStats = 1;
  4811. breaksw
  4812. case "-nosegstats":
  4813. set DoSegStats = 0;
  4814. breaksw
  4815. case "-curvstats":
  4816. set DoCurvStats = 1;
  4817. breaksw
  4818. case "-nocurvstats":
  4819. set DoCurvStats = 0;
  4820. breaksw
  4821. case "-aparc2aseg":
  4822. set DoAParc2ASeg = 1;
  4823. breaksw
  4824. case "-noaparc2aseg":
  4825. set DoAParc2ASeg = 0;
  4826. breaksw
  4827. case "-aparc+aseg-stats":
  4828. set DoAParcASegStats = 1;
  4829. breaksw
  4830. case "-no-aparc+aseg-stats":
  4831. set DoAParcASegStats = 0;
  4832. breaksw
  4833. case "-wmparc":
  4834. set DoWMParc = 1;
  4835. breaksw
  4836. case "-nowmparc":
  4837. set DoWMParc = 0;
  4838. breaksw
  4839. case "-expert":
  4840. if( $#argv < 1) goto arg1err;
  4841. set XOptsFile = $argv[1]; shift;
  4842. fsr-checkxopts $XOptsFile
  4843. if($status) goto error_exit;
  4844. set XOptsFile = `getfullpath $XOptsFile`
  4845. breaksw
  4846. case "-xopts-use"
  4847. set XOptsUse = 1; # Use pre-existing xopts
  4848. breaksw
  4849. case "-xopts-clean"
  4850. set XOptsClean = 1; # Delete pre-existing xopts
  4851. breaksw
  4852. case "-xopts-overwrite"
  4853. set XOptsOverwrite = 1; # Overwrite pre-existing xopts
  4854. breaksw
  4855. case "-clean":
  4856. set DoCleanCSDF = 1;
  4857. set DoCleanCW256 = 1;
  4858. set DoCleanTal = 1;
  4859. set DoCleanLta = 1;
  4860. set DoCleanCP = 1;
  4861. set DoCleanSeed = 1;
  4862. set DoCleanPFH = 1;
  4863. set DoCleanBM = 1;
  4864. set DoCleanASeg = 1;
  4865. set DoCleanWM = 1;
  4866. set DoCleanBFSE = 1;
  4867. set DoCleanXopts = 1;
  4868. set DoCleanT2 = 1;
  4869. set DoCleanFLAIR = 1;
  4870. breaksw
  4871. case "-clean-xopts":
  4872. set DoCleanXopts = 1;
  4873. breaksw
  4874. case "-clean-cw256":
  4875. set DoCleanCW256 = 1;
  4876. breaksw
  4877. case "-clean-cp":
  4878. set DoCleanCP = 1;
  4879. breaksw
  4880. case "-clean-wm":
  4881. set DoCleanWM = 1;
  4882. breaksw
  4883. case "-clean-cpwm":
  4884. case "-clean-wmcp":
  4885. set DoCleanWM = 1;
  4886. set DoCleanCP = 1;
  4887. breaksw
  4888. case "-clean-seed":
  4889. set DoCleanSeed = 1;
  4890. breaksw
  4891. case "-clean-tal":
  4892. set DoCleanTal = 1;
  4893. breaksw
  4894. case "-clean-lta":
  4895. set DoCleanLta = 1;
  4896. breaksw
  4897. case "-clean-pfh":
  4898. set DoCleanPFH = 1;
  4899. breaksw
  4900. case "-clean-bm":
  4901. set DoCleanBM = 1;
  4902. breaksw
  4903. case "-clean-aseg":
  4904. set DoCleanASeg = 1;
  4905. breaksw
  4906. case "-clean-bfse":
  4907. set DoCleanBFSE = 1;
  4908. breaksw
  4909. case "-clean-T2":
  4910. set DoCleanT2 = 1;
  4911. breaksw
  4912. case "-clean-FLAIR":
  4913. set DoCleanFLAIR = 1;
  4914. breaksw
  4915. case "-all":
  4916. case "-autorecon-all":
  4917. set DoCreateBaseInput = 1;
  4918. set DoMotionCor = 1;
  4919. set DoTalairach = 1;
  4920. set DoTalCheck = 1;
  4921. set DoNuIntensityCor = 1;
  4922. set DoNormalization = 1;
  4923. set DoSkullStrip = 1;
  4924. set DoGCAReg = 1;
  4925. set DoCARegInv = 1;
  4926. set DoRemoveNeck = 1;
  4927. set DoSkullLTA = 1;
  4928. set DoCANormalize = 1;
  4929. set DoCAReg = 1;
  4930. set DoCALabel = 1;
  4931. set DoNormalization2 = 1;
  4932. set DoMaskBFS = 1;
  4933. set DoSegmentation = 1;
  4934. set DoFill = 1;
  4935. set DoTessellate = 1;
  4936. set DoSmooth1 = 1;
  4937. set DoInflate1 = 1;
  4938. set DoQSphere = 1;
  4939. set DoFix = 1;
  4940. set DoSmooth2 = 1;
  4941. set DoInflate2 = 1;
  4942. set DoWhiteSurfs = 1;
  4943. set DoSphere = 1;
  4944. set DoSurfReg = 1;
  4945. set DoContraSurfReg = 0;
  4946. set DoAvgCurv = 1;
  4947. set DoJacobianWhite = 1;
  4948. set DoCortParc = 1;
  4949. set DoPialSurfs = 1;
  4950. set DoPctSurfCon = 1;
  4951. set DoParcStats = 1;
  4952. set DoCortParc2 = 1;
  4953. set DoParcStats2 = 1;
  4954. set DoCortParc3 = 1;
  4955. set DoParcStats3 = 1;
  4956. set DoCortRibbonVolMask = 1;
  4957. set DoSegStats = 1;
  4958. set DoAParc2ASeg = 1;
  4959. set DoWMParc = 1;
  4960. set DoCurvStats = 1;
  4961. set DoBaLabels = 1;
  4962. set DoLabelExvivoEC = 1;
  4963. breaksw
  4964. case "-autorecon1":
  4965. set DoCreateBaseInput = 1;
  4966. set DoMotionCor = 1;
  4967. set DoTalairach = 1;
  4968. set DoTalCheck = 1;
  4969. set DoNuIntensityCor = 1;
  4970. set DoNormalization = 1;
  4971. set DoSkullStrip = 1;
  4972. breaksw
  4973. case "-autorecon2":
  4974. set DoGCAReg = 1;
  4975. set DoCARegInv = 1;
  4976. set DoRemoveNeck = 1;
  4977. set DoSkullLTA = 1;
  4978. set DoCANormalize = 1;
  4979. set DoCAReg = 1;
  4980. set DoCALabel = 1;
  4981. set DoSegStats = 1;
  4982. set DoNormalization2 = 1;
  4983. set DoMaskBFS = 1;
  4984. set DoSegmentation = 1;
  4985. set DoFill = 1;
  4986. set DoTessellate = 1;
  4987. set DoSmooth1 = 1;
  4988. set DoInflate1 = 1;
  4989. set DoQSphere = 1;
  4990. set DoFix = 1;
  4991. set DoSmooth2 = 1;
  4992. set DoInflate2 = 1;
  4993. set DoWhiteSurfs = 1;
  4994. set DoCurvStats = 1;
  4995. breaksw
  4996. case "-autorecon2-volonly":
  4997. set DoGCAReg = 1;
  4998. set DoCARegInv = 1;
  4999. set DoRemoveNeck = 1;
  5000. set DoSkullLTA = 1;
  5001. set DoCANormalize = 1;
  5002. set DoCAReg = 1;
  5003. set DoCALabel = 1;
  5004. set DoSegStats = 1;
  5005. set DoNormalization2 = 1;
  5006. set DoMaskBFS = 1;
  5007. set DoSegmentation = 1;
  5008. set DoFill = 1;
  5009. breaksw
  5010. case "-autorecon2-perhemi":
  5011. case "-autorecon2-surfonly":
  5012. case "-autorecon2-surfsonly":
  5013. set DoTessellate = 1;
  5014. set DoSmooth1 = 1;
  5015. set DoInflate1 = 1;
  5016. set DoQSphere = 1;
  5017. set DoFix = 1;
  5018. set DoSmooth2 = 1;
  5019. set DoInflate2 = 1;
  5020. set DoWhiteSurfs = 1;
  5021. set DoSegStats = 1;
  5022. set DoCurvStats = 1;
  5023. breaksw
  5024. case "-autorecon2-inflate1":
  5025. set DoGCAReg = 1;
  5026. set DoCARegInv = 1;
  5027. set DoRemoveNeck = 1;
  5028. set DoSkullLTA = 1;
  5029. set DoCANormalize = 1;
  5030. set DoCAReg = 1;
  5031. set DoCALabel = 1;
  5032. set DoSegStats = 1;
  5033. set DoNormalization2 = 1;
  5034. set DoMaskBFS = 1;
  5035. set DoSegmentation = 1;
  5036. set DoFill = 1;
  5037. set DoTessellate = 1;
  5038. set DoSmooth1 = 1;
  5039. set DoInflate1 = 1;
  5040. breaksw
  5041. case "-autorecon2-cp":
  5042. case "-autorecon2-noaseg":
  5043. case "-autorecon2-wm":
  5044. set DoNormalization2 = 1;
  5045. set DoSegmentation = 1;
  5046. set DoFill = 1;
  5047. set DoTessellate = 1;
  5048. set DoSmooth1 = 1;
  5049. set DoInflate1 = 1;
  5050. set DoQSphere = 1;
  5051. set DoFix = 1;
  5052. set DoMaskBFS = 1;
  5053. set DoWhiteSurfs = 1;
  5054. set DoSmooth2 = 1;
  5055. set DoInflate2 = 1;
  5056. set DoSegStats = 1;
  5057. set DoCurvStats = 1;
  5058. breaksw
  5059. case "-autorecon-pial":
  5060. set DoMaskBFS = 1;
  5061. set DoWhiteSurfs = 1;
  5062. set DoSmooth2 = 1;
  5063. set DoInflate2 = 1;
  5064. set DoSegStats = 1;
  5065. set DoCurvStats = 1;
  5066. set DoSphere = 1;
  5067. set DoSurfReg = 1;
  5068. set DoContraSurfReg = 0;
  5069. set DoAvgCurv = 1;
  5070. set DoJacobianWhite = 1;
  5071. set DoCortParc = 1;
  5072. set DoPialSurfs = 1;
  5073. set DoPctSurfCon = 1;
  5074. set DoParcStats = 1;
  5075. set DoCortParc2 = 1;
  5076. set DoParcStats2 = 1;
  5077. set DoCortParc3 = 1;
  5078. set DoParcStats3 = 1;
  5079. set DoCortRibbonVolMask = 1;
  5080. set DoAParc2ASeg = 1;
  5081. set DoWMParc = 1;
  5082. set DoCurvStats = 1;
  5083. set DoBaLabels = 1;
  5084. set DoLabelExvivoEC = 1;
  5085. breaksw
  5086. case "-autorecon3":
  5087. set DoSphere = 1;
  5088. set DoSurfReg = 1;
  5089. set DoContraSurfReg = 0;
  5090. set DoAvgCurv = 1;
  5091. set DoJacobianWhite = 1;
  5092. set DoCortParc = 1;
  5093. set DoPialSurfs = 1;
  5094. set DoPctSurfCon = 1;
  5095. set DoParcStats = 1;
  5096. set DoCortParc2 = 1;
  5097. set DoParcStats2 = 1;
  5098. set DoCortParc3 = 1;
  5099. set DoParcStats3 = 1;
  5100. set DoSegStats = 1;
  5101. set DoCortRibbonVolMask = 1;
  5102. set DoAParc2ASeg = 1;
  5103. set DoWMParc = 1;
  5104. set DoCurvStats = 1;
  5105. set DoBaLabels = 1;
  5106. set DoLabelExvivoEC = 1;
  5107. breaksw
  5108. case "-autorecon-hemi":
  5109. if ( $#argv < 1) goto arg1err;
  5110. set hemilist = $argv[1]; shift;
  5111. if($hemilist != lh && $hemilist != rh) then
  5112. echo "ERROR: hemi = $hemilist, must be either lh or rh"
  5113. goto error_exit;
  5114. endif
  5115. set LF_DEFAULT_NAME = "recon-all-${hemilist}.log"
  5116. set SF_DEFAULT_NAME = "recon-all-status-${hemilist}.log"
  5117. set CF_DEFAULT_NAME = "recon-all-${hemilist}.cmd"
  5118. set DoTessellate = 1;
  5119. set DoSmooth1 = 1;
  5120. set DoInflate1 = 1;
  5121. set DoQSphere = 1;
  5122. set DoFix = 1;
  5123. set DoSmooth2 = 1;
  5124. set DoInflate2 = 1;
  5125. set DoWhiteSurfs = 1;
  5126. set DoSphere = 1;
  5127. set DoSurfReg = 1;
  5128. set DoContraSurfReg = 0;
  5129. set DoAvgCurv = 1;
  5130. set DoJacobianWhite = 1;
  5131. set DoCortParc = 1;
  5132. set DoPialSurfs = 1;
  5133. set DoPctSurfCon = 1;
  5134. set DoParcStats = 1;
  5135. set DoCortParc2 = 1;
  5136. set DoParcStats2 = 1;
  5137. set DoCortParc3 = 1;
  5138. set DoParcStats3 = 1;
  5139. set DoCortRibbonVolMask = 0;
  5140. set DoAParc2ASeg = 0;
  5141. set DoWMParc = 0;
  5142. set DoSegStats = 1;
  5143. set DoCurvStats = 1;
  5144. set DoBaLabels = 1;
  5145. set DoLabelExvivoEC = 1;
  5146. breaksw
  5147. case "-waitfor":
  5148. if ( $#argv < 1) goto arg1err;
  5149. set WaitForFile = $argv[1]; shift;
  5150. breaksw
  5151. case "-notify":
  5152. if ( $#argv < 1) goto arg1err;
  5153. set NotifyFile = $argv[1]; shift;
  5154. breaksw
  5155. case "-status":
  5156. if ( $#argv < 1) goto arg1err;
  5157. set SF = $argv[1]; shift;
  5158. breaksw
  5159. case "-noappendlog":
  5160. set AppendLog = 0;
  5161. breaksw
  5162. case "-noappendstatus":
  5163. set AppendStatus = 0;
  5164. breaksw
  5165. case "-noappend":
  5166. set AppendLog = 0;
  5167. set AppendStatus = 0;
  5168. breaksw
  5169. case "-log":
  5170. if ( $#argv < 1) goto arg1err;
  5171. set LF = $argv[1]; shift;
  5172. breaksw
  5173. case "-nolog":
  5174. set LF = /dev/null
  5175. breaksw
  5176. case "-csurfdir":
  5177. if ( $#argv < 1) goto arg1err;
  5178. setenv FREESURFER_HOME $argv[1]; shift;
  5179. if(! -e $FREESURFER_HOME) then
  5180. echo "ERROR: cannot find $FREESURFER_HOME"
  5181. goto error_exit;
  5182. endif
  5183. pushd $FREESURFER_HOME > /dev/null
  5184. setenv FREESURFER_HOME `pwd`;
  5185. breaksw
  5186. case "-dontrun":
  5187. set RunIt = 0;
  5188. breaksw
  5189. case "-onlyversions":
  5190. set DoVersionsOnly = 1;
  5191. breaksw
  5192. case "-allowcoredump":
  5193. limit coredumpsize unlimited
  5194. breaksw
  5195. case "-no-isrunning":
  5196. set DoIsRunning = 0;
  5197. breaksw
  5198. case "-force":
  5199. echo "ERROR: -force is no longer used. You can continue an analysis on an"
  5200. echo " existing subject by omitting -force AND all -i flags."
  5201. exit 1;
  5202. set Force = 1;
  5203. breaksw
  5204. case "-verbose":
  5205. set verbose = 1;
  5206. breaksw
  5207. case "-echo":
  5208. set echo = 1;
  5209. breaksw
  5210. case "-debug":
  5211. set verbose = 1;
  5212. set echo = 1;
  5213. breaksw
  5214. case "-umask":
  5215. if ( $#argv < 1) goto arg1err;
  5216. umask $1; shift;
  5217. breaksw
  5218. case "-grp":
  5219. if ( $#argv < 1) goto arg1err;
  5220. set grp = $argv[1];
  5221. set curgrp = `id -gn`;
  5222. if($grp != $curgrp) then
  5223. echo "ERROR: current group ($curgrp) does not equal specified group $grp"
  5224. goto error_exit;
  5225. endif
  5226. breaksw
  5227. case "-cm":
  5228. set ConformMin = 1;
  5229. echo "INFO: all volumes are conformed to the min voxel size"
  5230. breaksw
  5231. case "-hires":
  5232. set HiRes = 1;
  5233. set ConformMin = 1;
  5234. echo "INFO: hi-res volumes are conformed to the min voxel size"
  5235. # dont use atlas for skull strip:
  5236. set WSAtlas = 0;
  5237. set WSGcaAtlas = 0;
  5238. # -noaseg flags:
  5239. set UseAseg = 0;
  5240. set DoGCAReg = 0;
  5241. set DoCARegInv = 0;
  5242. set DoRemoveNeck = 0;
  5243. set DoSkullLTA = 0;
  5244. set DoCANormalize = 0;
  5245. set DoCAReg = 0;
  5246. set DoCALabel = 0;
  5247. set DoSegStats = 0;
  5248. set NoNormMGZ = 1;
  5249. set DoAParc2ASeg = 0;
  5250. set DoWMParc = 0;
  5251. set DoCortRibbonVolMask = 0;
  5252. breaksw
  5253. case "-noneg":
  5254. set UseNoNeg = 1;
  5255. breaksw
  5256. case "-nothicken":
  5257. set NoThicken = 1;
  5258. breaksw
  5259. case "-uncompress":
  5260. set UnCompress = 1;
  5261. breaksw
  5262. case "-bigventricles":
  5263. set BigVentricles = 1;
  5264. breaksw
  5265. case "-nobigventricles":
  5266. set BigVentricles = 0;
  5267. breaksw
  5268. case "-secondpassrenorm":
  5269. set DoSecondPassRenorm = 1;
  5270. breaksw
  5271. case "-diffsubj":
  5272. if ( $#argv < 1) goto arg1err;
  5273. set diffsubj = $argv[1]; shift;
  5274. set diffsujb = `basename $diffsubj`; # remove trailing /
  5275. breaksw
  5276. # flags -long, -no-orig-pial and -uselongbasectrlvol are all associated
  5277. # with longitudinal processing
  5278. case "-long":
  5279. case "-longitudinal":
  5280. set longitudinal = 1;
  5281. set NoRandomness = 1;
  5282. if ( $#argv < 2) goto arg1err;
  5283. # get the subject name to use for timepoint
  5284. set tpNid = $argv[1]; shift;
  5285. set tpNid = `basename $tpNid`; # remove trailing /
  5286. # get the subject to use for the base subject
  5287. set longbaseid = $argv[1]; shift;
  5288. set longbaseid = `basename $longbaseid`; # remove trailing /
  5289. # and create subjid to reflect its longitudinal relation to longbaseid
  5290. set subjid = ${tpNid}.long.${longbaseid}
  5291. breaksw
  5292. case "-addtp":
  5293. # 'fake'-add a new timepoint
  5294. set DoAddTp = 1;
  5295. breaksw
  5296. case "-noasegfusion":
  5297. set UseAsegFusion = 0;
  5298. breaksw
  5299. case "-uselongbasectrlvol":
  5300. set UseLongbaseCtrlVol = 1;
  5301. breaksw
  5302. case "-uselongbasewmedits":
  5303. set UseLongbaseWMedits = 1;
  5304. breaksw
  5305. case "-mprage":
  5306. set IsMPRAGE = 1;
  5307. breaksw;
  5308. case "-washu_mprage":
  5309. set IsWashuMPRAGE = 1;
  5310. breaksw;
  5311. case "-cw256":
  5312. set DoConformWidth256 = 1;
  5313. breaksw;
  5314. case "-nowmsa":
  5315. set NoWMSA = 1;
  5316. breaksw;
  5317. case "-tal-check":
  5318. case "-talcheck":
  5319. set DoTalCheck = 1;
  5320. breaksw;
  5321. case "-notal-check":
  5322. case "-no-tal-check":
  5323. case "-notalcheck":
  5324. case "-no-talcheck":
  5325. set DoTalCheck = 0;
  5326. breaksw;
  5327. case "-avgcurvtifpath":
  5328. if ( $#argv < 1) goto arg1err;
  5329. set AvgCurvTifPath = $argv[1]; shift;
  5330. breaksw
  5331. case "-avgcurvtif":
  5332. if ( $#argv < 1) goto arg1err;
  5333. set AvgCurvTif = $argv[1]; shift;
  5334. breaksw
  5335. case "-qcache":
  5336. set DoQdecCache = 1;
  5337. breaksw;
  5338. case "-smooth-cortex-only"
  5339. set SmoothCortexOnly = 1;
  5340. breaksw;
  5341. case "-no-smooth-cortex-only"
  5342. set SmoothCortexOnly = 0;
  5343. breaksw;
  5344. case "-measure":
  5345. if ( $#argv < 1) goto arg1err;
  5346. if ( $UserMeasureList ) then
  5347. set measurelist = ($measurelist $argv[1]); shift;
  5348. else
  5349. set measurelist = $argv[1]; shift;
  5350. set UserMeasureList = 1; # allow for multiple instances of -measure
  5351. endif
  5352. breaksw
  5353. case "-measuredir":
  5354. if ( $#argv < 1) goto arg1err;
  5355. set measuredir = $argv[1]; shift;
  5356. breaksw
  5357. case "-fwhm":
  5358. if ( $#argv < 1) goto arg1err;
  5359. set fwhmlist = $argv[1]; shift;
  5360. breaksw
  5361. case "-target":
  5362. if ( $#argv < 1) goto arg1err;
  5363. set target = $argv[1]; shift;
  5364. breaksw
  5365. case "-vno_match_check":
  5366. case "-vno_check":
  5367. case "-vno-check":
  5368. set DoVnoMatchCheck = 1;
  5369. breaksw;
  5370. case "-make"
  5371. if ( $#argv < 1) goto arg1err;
  5372. set DoMakefile = 1;
  5373. set MakefileTarget = $argv[1]; shift;
  5374. breaksw;
  5375. case "-asegstatsdiff":
  5376. set DoAsegStatsDiff = 1;
  5377. breaksw;
  5378. case "-aparcstatsdiff":
  5379. set DoAparcStatsDiff = 1;
  5380. breaksw;
  5381. case "-time":
  5382. set DoTime = 1;
  5383. breaksw;
  5384. case "-notime":
  5385. set DoTime = 0;
  5386. breaksw;
  5387. case "-lgi":
  5388. case "-lGI":
  5389. case "-localGI":
  5390. set DoLocalGyriIndex = 1;
  5391. breaksw;
  5392. case "-balabels":
  5393. case "-ba_labels":
  5394. case "-ba-labels":
  5395. case "-label_ba":
  5396. case "-label_BA":
  5397. set DoBaLabels = 1;
  5398. breaksw;
  5399. case "-nobalabels":
  5400. case "-noba_labels":
  5401. case "-noba-labels":
  5402. case "-nolabel_ba":
  5403. case "-nolabel_BA":
  5404. case "-no_ba_labels":
  5405. case "-no-ba-labels":
  5406. case "-no_label_ba":
  5407. case "-no_label_BA":
  5408. set DoBaLabels = 0;
  5409. breaksw;
  5410. case "-surfvolume":
  5411. set DoSurfVolume = 1;
  5412. breaksw;
  5413. case "-label_v1":
  5414. case "-label_V1":
  5415. case "-label-v1":
  5416. case "-label-V1":
  5417. set DoLabelV1 = 1;
  5418. breaksw;
  5419. case "-label_exvivo_ec":
  5420. case "-label-exvivo-ec":
  5421. case "-label_exvivo_EC":
  5422. case "-label-exvivo-EC":
  5423. set DoLabelExvivoEC = 1;
  5424. breaksw;
  5425. case "-nolabel_exvivo_ec":
  5426. case "-nolabel-exvivo-ec":
  5427. case "-nolabel_exvivo_EC":
  5428. case "-nolabel-exvivo-EC":
  5429. case "-no_label_exvivo_ec":
  5430. case "-no-label-exvivo-ec":
  5431. case "-no_label_exvivo_EC":
  5432. case "-no-label-exvivo-EC":
  5433. set DoLabelExvivoEC = 0;
  5434. breaksw;
  5435. case "-use-concat-lta-tal":
  5436. set UseConcatLtaTal = 1;
  5437. breaksw;
  5438. case "-show-edits":
  5439. case "-show_edits":
  5440. case "-showedits":
  5441. set DoShowEdits = 1;
  5442. breaksw;
  5443. case "-use-cuda":
  5444. case "-use_cuda":
  5445. case "-use-gpu":
  5446. case "-use_gpu":
  5447. set UseCuda = 1;
  5448. # then set LD_LIBRARY_PATH to distributed cuda libs
  5449. source $FREESURFER_HOME/bin/cuda_setup
  5450. breaksw;
  5451. case "-get-cuda":
  5452. case "-get-gpu":
  5453. case "-show-cuda":
  5454. case "-show-gpu":
  5455. set GetCuda = 1; # info dump in check_params section below
  5456. # then set LD_LIBRARY_PATH to distributed cuda libs
  5457. source $FREESURFER_HOME/bin/cuda_setup
  5458. breaksw;
  5459. case "-openmp":
  5460. if ( $#argv < 1) goto arg1err;
  5461. setenv OMP_NUM_THREADS $argv[1]; shift;
  5462. breaksw;
  5463. # hippocampal subfield processing
  5464. case "-hippo-subfields":
  5465. set DoGEMS = 1;
  5466. breaksw;
  5467. case "-cubic":
  5468. set UseCubic = 1;
  5469. breaksw
  5470. case "-nocubic":
  5471. case "-no-cubic":
  5472. case "-no_cubic":
  5473. set UseCubic = 0;
  5474. breaksw
  5475. case "-T2pial":
  5476. case "-t2pial":
  5477. set DoT2pial = 1;
  5478. breaksw
  5479. case "-noT2pial":
  5480. case "-no-T2pial":
  5481. case "-no_T2pial":
  5482. case "-no-t2pial":
  5483. case "-no_t2pial":
  5484. set DoT2pial = 0;
  5485. breaksw
  5486. case "-FLAIRpial":
  5487. case "-flairpial":
  5488. set DoFLAIRpial = 1;
  5489. breaksw
  5490. case "-noFLAIRpial":
  5491. case "-no-FLAIRpial":
  5492. case "-no_FLAIRpial":
  5493. case "-no-flairpial":
  5494. case "-no_flairpial":
  5495. set DoFLAIRpial = 0;
  5496. breaksw
  5497. default:
  5498. echo ERROR: Flag $flag unrecognized.
  5499. echo $cmdline
  5500. goto error_exit;
  5501. breaksw
  5502. endsw
  5503. end
  5504. goto parse_args_return;
  5505. ############--------------##################
  5506. ############--------------##################
  5507. arg1err:
  5508. echo "ERROR: flag $flag requires one argument"
  5509. exit 1
  5510. ############--------------##################
  5511. ############--------------##################
  5512. arg3err:
  5513. echo "ERROR: flag $flag requires three arguments"
  5514. exit 1
  5515. ############--------------##################
  5516. ############--------------##################
  5517. check_params:
  5518. if($DoT2pial && $DoFLAIRpial) then
  5519. echo "Cannot specify both T2 and FLAIR for pial correction."
  5520. goto error_exit;
  5521. endif
  5522. if($UseCuda || $GetCuda) then
  5523. # test a binary
  5524. echo "Testing for CUDA device:"
  5525. $FREESURFER_HOME/bin/mri_em_register_cuda --version \
  5526. | grep -v "\-\-all\-info"
  5527. if ($status) goto error_exit;
  5528. echo ""
  5529. # print version of installed driver
  5530. if ( -e /proc/driver/nvidia/version) then
  5531. echo "NVIDIA driver version info:"
  5532. cat /proc/driver/nvidia/version | grep NVIDIA
  5533. echo ""
  5534. endif
  5535. if ($GetCuda) then
  5536. $FREESURFER_HOME/bin/cudadetect
  5537. if ($status) goto error_exit;
  5538. exit 0;
  5539. endif
  5540. endif
  5541. if(! $DoVersionsOnly) then
  5542. if($#subjid != 1) then
  5543. echo "ERROR: must specify a subject id"
  5544. exit 1;
  5545. endif
  5546. if(! $?SUBJECTS_DIR ) then
  5547. echo "ERROR: environment variable SUBJECTS_DIR not set"
  5548. echo " this can be done by setting it in the shell before"
  5549. echo " executing recon-all or by using the -sd flag"
  5550. exit 1;
  5551. endif
  5552. if(! -e $SUBJECTS_DIR ) then
  5553. echo "ERROR: SUBJECTS_DIR $SUBJECTS_DIR does not exist."
  5554. exit 1;
  5555. endif
  5556. # Get the full path #
  5557. pushd $SUBJECTS_DIR > /dev/null
  5558. setenv SUBJECTS_DIR `$PWD`;
  5559. popd > /dev/null
  5560. set subjdir = $SUBJECTS_DIR/$subjid
  5561. #------------ Longitudinal -----------------------------------#
  5562. if($longitudinal) then
  5563. # assert that $tpNid does not contain .long.
  5564. set haslong = `echo $tpNid | grep "\.long\."`
  5565. if ( "$haslong" != "" ) then
  5566. echo ""
  5567. echo "ERROR: Detected \'.long.\' in a subject id!
  5568. echo ""
  5569. echo " If you are trying to run or re-run a longitudinal time point"
  5570. echo " please specify the following parameters:"
  5571. echo ""
  5572. echo " \' -long <tpNid> <templateid> \'"
  5573. echo ""
  5574. echo " where <tpNid> is the time point id (SAME as cross sectional"
  5575. echo " ID) and <templateid> is the ID created in the -base run."
  5576. echo " The directory <tpNid>.long.<templateid> will be created"
  5577. echo " automatically or used for output, if it already exists."
  5578. echo ""
  5579. echo " If you are running a \'-base\' please specify a different name."
  5580. echo " Usage of \'.long.\' is reserved for the automatically created"
  5581. echo " longitudinal output."
  5582. echo ""
  5583. exit 1;
  5584. endif
  5585. #make sure cross sectional tpNid exists:
  5586. if ( ! -e ${SUBJECTS_DIR}/${tpNid} ) then
  5587. echo ""
  5588. echo "ERROR: Cross sectional tpNid: ${SUBJECTS_DIR}/${tpNid}"
  5589. echo " does not exist!"
  5590. echo ""
  5591. exit 1;
  5592. endif
  5593. # check if base/template specified
  5594. if($#longbaseid != 1) then
  5595. echo ""
  5596. echo "ERROR: Specify the <templateid> for this subject template "
  5597. echo " (created during the -base run):"
  5598. echo ""
  5599. echo " \' -long <tpNid> <templateid> \'"
  5600. echo ""
  5601. exit 1;
  5602. endif
  5603. # Error if longbaseid contains .long.
  5604. set haslong = `echo $longbaseid | grep "\.long\."`
  5605. if ( "$haslong" != "" ) then
  5606. echo ""
  5607. echo "ERROR: The <templateid> may not contain .long. (reserved for"
  5608. echo " automatic output of a longitudinal time point)."
  5609. echo " Specify the <templateid> for this subject template "
  5610. echo " (created during the -base run):"
  5611. echo ""
  5612. echo " \' -long <tpNid> <templateid> \'"
  5613. echo ""
  5614. exit 1;
  5615. endif
  5616. set longbasedir = $SUBJECTS_DIR/$longbaseid
  5617. if(! -e $longbasedir) then
  5618. echo "ERROR: cannot find base/template dir: $longbasedir"
  5619. echo ""
  5620. exit 1;
  5621. endif
  5622. if ( ! -e ${longbasedir}/${BaseSubjsListFname}) then
  5623. echo "ERROR: file ${longbasedir}/${BaseSubjsListFname} does not exist!"
  5624. echo ""
  5625. exit 1;
  5626. else
  5627. set found_tpNid = 0
  5628. set found_longbaseid = 0
  5629. foreach f (`cat ${longbasedir}/${BaseSubjsListFname}`)
  5630. if (${f} == ${tpNid}) set found_tpNid = 1
  5631. if (${f} == ${longbaseid}) set found_longbaseid = 1
  5632. end
  5633. if ( ! $found_tpNid ) then
  5634. echo "ERROR: $tpNid is not in ${longbasedir}/${BaseSubjsListFname}"
  5635. echo ""
  5636. exit 1
  5637. endif
  5638. # check that baseid is not the same as any of the timepoint subj IDs
  5639. if ( $found_longbaseid ) then
  5640. echo "ERROR: Template/base ID cannot be the same as a time point ID"
  5641. echo " (in ${longbasedir}/${BaseSubjsListFname})"
  5642. echo ""
  5643. echo " Find more info at:"
  5644. echo " http://surfer.nmr.mgh.harvard.edu/fswiki/LongitudinalProcessing"
  5645. echo ""
  5646. exit 1
  5647. endif
  5648. endif
  5649. else # ================= if cross run or base ==========================
  5650. # make sure $subjid does not contain .long.
  5651. set haslong = `echo $subjid | grep "\.long\."`
  5652. if ( "$haslong" != "" ) then
  5653. echo ""
  5654. echo "ERROR: Are you trying to run or re-run a longitudinal time point?"
  5655. echo " If so, please specify the following parameters:"
  5656. echo ""
  5657. echo " \' -long <tpNid> <templateid> \'"
  5658. echo ""
  5659. echo " where <tpNid> is the time point id (SAME as cross sectional"
  5660. echo " ID) and <templateid> is the ID created in the -base run."
  5661. echo " The directory <tpNid>.long.<templateid> will be created"
  5662. echo " automatically or used for output, if it already exists."
  5663. echo ""
  5664. exit 1;
  5665. endif
  5666. endif
  5667. # error if base subject is run as a regular subject:
  5668. if ( ! $DoCreateBaseSubj ) then
  5669. if ( -e $subjdir/$BaseSubjsListFname ) then
  5670. echo ""
  5671. echo "ERROR: It appears that this subject ID is an existing"
  5672. echo " base/template from longitudinal processing (-base)."
  5673. echo " Please make sure you pass all necessary flags. "
  5674. echo " For example, if you are trying to re-run a -base:"
  5675. echo ""
  5676. echo " \' -base <templateid> -tp <tpNid> ... \'"
  5677. echo ""
  5678. exit 1;
  5679. endif
  5680. endif
  5681. #----------------------------------------------------------------#
  5682. if($#InputList == 0) then
  5683. if(! $DoCreateBaseSubj) then
  5684. if($longitudinal) mkdir -p ${subjdir}
  5685. if(! -e $subjdir) then
  5686. echo "ERROR: cannot find $subjdir"
  5687. exit 1;
  5688. endif
  5689. if(! -w $subjdir) then
  5690. echo "ERROR: you do not have write permission to $subjdir"
  5691. exit 1;
  5692. endif
  5693. endif
  5694. else # An input was passed
  5695. if( -e $subjdir) then
  5696. echo "ERROR: You are trying to re-run an existing subject with (possibly)"
  5697. echo " new input data (-i). If this is truly new input data, you should delete"
  5698. echo " the subject folder and re-run, or specify a different subject name."
  5699. echo " If you are just continuing an analysis of an existing subject, then "
  5700. echo " omit all -i flags."
  5701. exit 1;
  5702. endif
  5703. mkdir -p $subjdir
  5704. endif
  5705. else
  5706. set subjdir = /tmp
  5707. endif
  5708. if(! $?FREESURFER_HOME ) then
  5709. echo "ERROR: environment variable FREESURFER_HOME not set."
  5710. exit 1;
  5711. endif
  5712. if(! -e $FREESURFER_HOME ) then
  5713. echo "ERROR: FREESURFER_HOME $FREESURFER_HOME does not exist."
  5714. exit 1;
  5715. endif
  5716. if(! -e ${GCADIR}/$GCA ) then
  5717. echo "ERROR: cannot find ${GCADIR}/$GCA" |& tee -a $LF
  5718. exit 1;
  5719. endif
  5720. if(! -e ${GCADIR}/$GCASkull ) then
  5721. echo "ERROR: cannot find ${GCADIR}/$GCASkull" \
  5722. |& tee -a $LF
  5723. exit 1;
  5724. endif
  5725. foreach hemi ($hemilist)
  5726. set avgtif = ${AvgCurvTifPath}/$hemi.${AvgCurvTif};
  5727. if(! -e $avgtif) then
  5728. echo "ERROR: cannot find $avgtif."
  5729. exit 1;
  5730. endif
  5731. set GCSHemi = ${GCSDIR}/$hemi.$GCS
  5732. if(! -e $GCSHemi) then
  5733. echo "ERROR: cannot find $GCSHemi."
  5734. exit 1;
  5735. endif
  5736. set CPAtlas = ${GCSDIR}/$hemi.$GCS
  5737. if(! -e $CPAtlas) then
  5738. echo "ERROR: cannot find $CPAtlas."
  5739. exit 1;
  5740. endif
  5741. end
  5742. if($XOptsUse == 1 && $XOptsClean == 1) then
  5743. echo "ERROR: cannot specify both -xopts-clean and -xopts-use"
  5744. exit(1);
  5745. endif
  5746. if($IsMPRAGE == 1 && $IsWashuMPRAGE == 1) then
  5747. echo "ERROR: cannot specify both -mprage and -washu_mprage"
  5748. exit(1);
  5749. endif
  5750. mkdir -p $subjdir/scripts
  5751. set XOptsPreExist = $subjdir/scripts/expert-options
  5752. if(-e $XOptsPreExist) then
  5753. # There is a pre-existing xopts file
  5754. if($#XOptsFile == 0) then
  5755. # XOpts not passed on cmd line
  5756. if($XOptsUse == 0 && $XOptsClean == 0) then
  5757. echo "ERROR: there is a pre-existing expert options file."
  5758. echo "You must explicitly specify whether to:"
  5759. echo " 1. Use the pre-existing file (-xopts-use)"
  5760. echo " 2. Delete the pre-existing file (-xopts-clean)"
  5761. exit(1);
  5762. endif
  5763. if($XOptsClean == 1) then
  5764. rm -f $XOptsPreExist
  5765. set XOptsFile = ();
  5766. endif
  5767. if($XOptsUse == 1) then
  5768. set XOptsFile = $XOptsPreExist;
  5769. endif
  5770. else
  5771. # XOpts was passed on cmd line, but pre-existing xopts file
  5772. if(! $XOptsOverwrite) then
  5773. echo "ERROR: there is a pre-existing expert options file and"
  5774. echo "you have specified an expert options file on the command-line."
  5775. echo "If you want to use the file specified on the command-line,"
  5776. echo "you must run with -xopts-overwrite, or you may edit the "
  5777. echo "existing file $XOptsFile (and not use the -expert option)."
  5778. exit(1);
  5779. endif
  5780. # If it gets here, then overwrite
  5781. rm -f $XOptsPreExist
  5782. cp $XOptsFile $XOptsPreExist
  5783. if($status) goto error_exit;
  5784. endif
  5785. else
  5786. # No pre-existing file
  5787. if($#XOptsFile != 0) then
  5788. # Expert options file specified on cmd line, make copy
  5789. cp $XOptsFile $XOptsPreExist
  5790. if($status) goto error_exit;
  5791. endif
  5792. endif
  5793. if($#NotifyFile != 0) then
  5794. rm -f $NotifyFile;
  5795. set tmpdir = `dirname $NotifyFile`;
  5796. mkdir -p $tmpdir;
  5797. pushd $tmpdir > /dev/null;
  5798. set tmpdir = `$PWD`;
  5799. set NotifyFile = $tmpdir/`basename $NotifyFile`;
  5800. popd > /dev/null;
  5801. endif
  5802. if($#WaitForFile != 0) then
  5803. set tmpdir = `dirname $WaitForFile`;
  5804. mkdir -p $tmpdir;
  5805. pushd $tmpdir > /dev/null;
  5806. set tmpdir = `$PWD`;
  5807. set WaitForFile = $tmpdir/`basename $WaitForFile`;
  5808. popd > /dev/null;
  5809. endif
  5810. if(! $DoCleanTal && ! $DoCleanCP && ! $DoCleanBM && ! $DoConvertInput && \
  5811. ! $DoCleanASeg && ! $DoCleanWM && ! $DoCleanSeed && ! $DoCleanCW256 && \
  5812. ! $DoCortParc && ! $DoCortParc2 && ! $DoGCAReg && ! $DoCARegInv && \
  5813. ! $DoMotionCor && ! $DoTalairach && ! $DoTalCheck && ! $DoCleanXopts && \
  5814. ! $DoNormalization && ! $#SurfRegToSubj &&\
  5815. ! $DoNormalization2 && ! $DoParcStats && ! $DoParcStats2 && \
  5816. ! $DoVersionsOnly && ! $DoDeface && ! $DoCleanPFH && \
  5817. ! $DoSkullStrip && ! $DoSegmentation && ! $DoNuIntensityCor &&\
  5818. ! $DoFill && ! $DoTessellate && ! $DoAParc2ASeg && ! $DoWMParc && \
  5819. ! $DoSmooth1 && ! $DoInflate1 && ! $DoQSphere && ! $DoRemoveNeck &&\
  5820. ! $DoFix && ! $DoSmooth2 && ! $DoInflate2 && ! $DoSphere &&\
  5821. ! $DoSkullLTA && ! $DoQdecCache && ! $DoVnoMatchCheck &&\
  5822. ! $DoSurfReg && ! $DoContraSurfReg && ! $DoAvgCurv && ! $DoSegStats &&\
  5823. ! $DoMorphRGB && ! $DoWhiteSurfs && ! $DoContraSurfRegWithinSubject &&\
  5824. ! $DoCortRibbonVolMask && ! $DoJacobianWhite && ! $DoJacobianDist0 && \
  5825. ! $DoCANormalize && ! $DoCAReg && ! $DoCALabel && \
  5826. ! $DoMaskBFS && ! $DoAParcASegStats && ! $DoLocalGyriIndex && \
  5827. ! $DoMakefile && ! $DoAsegStatsDiff && ! $DoAparcStatsDiff && \
  5828. ! $DoSurfVolume && ! $DoASegMerge && ! $DoCurvStats && ! $DoLabelV1 && \
  5829. ! $DoCreateBaseSubj && ! $DoBaLabels && ! $DoShowEdits && \
  5830. ! $DoLabelExvivoEC && ! $DoSurfSegEdit && ! $DoPialSurfs && \
  5831. ! $DoGEMS && ! $DoPctSurfCon && ! $DoT2pial && ! $DoFLAIRpial && \
  5832. ! $DoConvertT2Input && ! $DoConvertFlairInput && \
  5833. ! $DoCortParc3 && ! $DoParcStats3) then
  5834. echo "ERROR: nothing to do"
  5835. exit 1;
  5836. endif
  5837. if($WSMore && $WSLess) then
  5838. echo "ERROR: cannot specify both -wsmore and -wsless"
  5839. exit 1;
  5840. endif
  5841. if( ($WSMore || $WSLess) && $WSPctPreFlood ) then
  5842. echo "ERROR: cannot specify -wsmore or -wsless and -wsthresh"
  5843. exit 1;
  5844. endif
  5845. if ($DoAsegStatsDiff) then
  5846. if ( $#diffsubj != 1 ) then
  5847. echo "ERROR: -asegstatsdiff requires -diffsubj <subjid>"
  5848. exit 1;
  5849. endif
  5850. endif
  5851. if ($DoAparcStatsDiff) then
  5852. if ( $#diffsubj != 1 ) then
  5853. echo "ERROR: -aparcstatsdiff requires -diffsubj <subjid>"
  5854. exit 1;
  5855. endif
  5856. endif
  5857. if($#SurfRegToSubj) then
  5858. if(! -e $SUBJECTS_DIR/$SurfRegToSubj) then
  5859. echo "ERROR: cannot find $SurfRegToSubj"
  5860. exit 1;
  5861. endif
  5862. set AvgTif = $SUBJECTS_DIR/$SurfRegToSubj/$hemi.reg.template.tif
  5863. if(! -e $AvgTif) then
  5864. echo "ERROR: cannot find $AvgTif"
  5865. exit 1;
  5866. endif
  5867. endif
  5868. goto check_params_return;
  5869. ############--------------##################
  5870. ############--------------##################
  5871. usage_exit:
  5872. echo ""
  5873. echo "USAGE: $ProgName"
  5874. echo ""
  5875. echo " Required Arguments:";
  5876. echo " -subjid <subjid>"
  5877. echo " -<process directive>"
  5878. echo ""
  5879. echo " Fully-Automated Directive:"
  5880. echo " -all : performs all stages of cortical reconstruction"
  5881. echo " -autorecon-all : same as -all"
  5882. echo ""
  5883. echo " Manual-Intervention Workflow Directives:"
  5884. echo " -autorecon1 : process stages 1-5 (see below)"
  5885. echo " -autorecon2 : process stages 6-23"
  5886. echo " after autorecon2, check white surfaces:"
  5887. echo " a. if wm edit was required, then run -autorecon2-wm"
  5888. echo " b. if control points added, then run -autorecon2-cp"
  5889. echo " c. proceed to run -autorecon3"
  5890. echo " -autorecon2-cp : process stages 12-23 (uses -f w/ mri_normalize, -keep w/ mri_seg)"
  5891. echo " -autorecon2-wm : process stages 15-23"
  5892. echo " -autorecon2-inflate1 : 6-18"
  5893. echo " -autorecon2-perhemi : tess, sm1, inf1, q, fix, sm2, inf2, finalsurf, ribbon"
  5894. echo " -autorecon3 : process stages 24-34"
  5895. echo " if edits made to correct pial, then run -autorecon-pial"
  5896. echo " -hemi ?h : just do lh or rh (default is to do both)"
  5897. echo ""
  5898. echo " Autorecon Processing Stages (see -autorecon# flags above):"
  5899. echo " 1. Motion Correction and Conform"
  5900. echo " 2. NU (Non-Uniform intensity normalization)"
  5901. echo " 3. Talairach transform computation"
  5902. echo " 4. Intensity Normalization 1"
  5903. echo " 5. Skull Strip"
  5904. echo ""
  5905. echo " 6. EM Register (linear volumetric registration)"
  5906. echo " 7. CA Intensity Normalization"
  5907. echo " 8. CA Non-linear Volumetric Registration "
  5908. echo " 9. Remove neck"
  5909. echo " 10. EM Register, with skull"
  5910. echo " 11. CA Label (Aseg: Volumetric Labeling) and Statistics"
  5911. echo ""
  5912. echo " 12. Intensity Normalization 2 (start here for control points)"
  5913. echo " 13. White matter segmentation"
  5914. echo " 14. Edit WM With ASeg"
  5915. echo " 15. Fill (start here for wm edits)"
  5916. echo " 16. Tessellation (begins per-hemisphere operations)"
  5917. echo " 17. Smooth1"
  5918. echo " 18. Inflate1"
  5919. echo " 19. QSphere"
  5920. echo " 20. Automatic Topology Fixer"
  5921. echo " 21. White Surfs (start here for brain edits for pial surf)"
  5922. echo " 22. Smooth2"
  5923. echo " 23. Inflate2"
  5924. echo ""
  5925. echo " 24. Spherical Mapping"
  5926. echo " 25. Spherical Registration "
  5927. echo " 26. Spherical Registration, Contralater hemisphere"
  5928. echo " 27. Map average curvature to subject"
  5929. echo " 28. Cortical Parcellation (Labeling)"
  5930. echo " 29. Cortical Parcellation Statistics"
  5931. echo " 30. Pial Surfs"
  5932. echo " 31. WM/GM Contrast"
  5933. echo " 32. Cortical Ribbon Mask"
  5934. echo " 33. Cortical Parcellation mapped to ASeg"
  5935. echo " 34 Brodmann and exvio EC labels"
  5936. echo ""
  5937. echo " Step-wise Directives"
  5938. echo " See -help"
  5939. echo ""
  5940. echo " Expert Preferences"
  5941. echo " -pons-crs C R S : col, row, slice of seed point for pons, used in fill"
  5942. echo " -cc-crs C R S : col, row, slice of seed point for corpus callosum, used in fill"
  5943. echo " -lh-crs C R S : col, row, slice of seed point for left hemisphere, used in fill"
  5944. echo " -rh-crs C R S : col, row, slice of seed point for right hemisphere, used in fill"
  5945. echo " -nofill : do not use the automatic subcort seg to fill"
  5946. echo " -watershed cmd : control skull stripping/watershed program"
  5947. echo " -wsless : decrease watershed threshold (leaves less skull, but can strip more brain)"
  5948. echo " -wsmore : increase watershed threshold (leaves more skull, but can strip less brain)"
  5949. echo " -wsatlas : use atlas when skull stripping"
  5950. echo " -no-wsatlas : do not use atlas when skull stripping"
  5951. echo " -no-wsgcaatlas : do not use GCA atlas when skull stripping"
  5952. echo " -wsthresh pct : explicity set watershed threshold"
  5953. echo " -wsseed C R S : identify an index (C, R, S) point in the skull"
  5954. echo " -nuiterations N : set number of iterations for nu intensity "
  5955. echo " correction (default is $NuIterations)"
  5956. echo " -norm3diters niters : number of 3d iterations for mri_normalize"
  5957. echo " -normmaxgrad maxgrad : max grad (-g) for mri_normalize. Default is 1."
  5958. echo " -norm1-b N : in the _first_ usage of mri_normalize, use control "
  5959. echo " point with intensity N below target (default=10.0) "
  5960. echo " -norm2-b N : in the _second_ usage of mri_normalize, use control "
  5961. echo " point with intensity N below target (default=10.0) "
  5962. echo " -norm1-n N : in the _first_ usage of mri_normalize, do N number "
  5963. echo " of iterations"
  5964. echo " -norm2-n N : in the _second_ usage of mri_normalize, do N number "
  5965. echo " of iterations"
  5966. echo " -cm : conform volumes to the min voxel size "
  5967. echo " -no-fix-with-ga : do not use genetic algorithm when fixing topology"
  5968. echo " -fix-diag-only : topology fixer runs until ?h.defect_labels files"
  5969. echo " are created, then stops"
  5970. echo " -seg-wlo wlo : set wlo value for mri_segment and mris_make_surfaces"
  5971. echo " -seg-ghi ghi : set ghi value for mri_segment and mris_make_surfaces"
  5972. echo " -nothicken : pass '-thicken 0' to mri_segment"
  5973. echo " -no-ca-align-after : turn off -align-after with mri_ca_register"
  5974. echo " -no-ca-align : turn off -align with mri_ca_label"
  5975. echo " -deface : deface subject, written to orig_defaced.mgz"
  5976. echo ""
  5977. echo " -expert file : read-in expert options file"
  5978. echo " -xopts-use : use pre-existing expert options file"
  5979. echo " -xopts-clean : delete pre-existing expert options file"
  5980. echo " -xopts-overwrite : overwrite pre-existing expert options file"
  5981. echo ""
  5982. echo " -mprage : assume scan parameters are MGH MP-RAGE protocol"
  5983. echo " -washu_mprage : assume scan parameters are Wash.U. MP-RAGE protocol."
  5984. echo " both mprage flags affect mri_normalize and mri_segment,"
  5985. echo " and assumes a darker gm."
  5986. # echo " -schwartzya3t-atlas : for tal reg, use special young adult 3T atlas"
  5987. echo ""
  5988. echo " -use-gpu : use GPU versions of mri_em_register, mri_ca_register,"
  5989. echo " mris_inflate and mris_sphere"
  5990. echo ""
  5991. echo " Notification Files (Optional)"
  5992. echo " -waitfor file : wait for file to appear before beginning"
  5993. echo " -notify file : create this file after finishing"
  5994. echo ""
  5995. echo " Status and Log files (Optional)"
  5996. echo " -log file : default is scripts/recon-all.log"
  5997. echo " -status file : default is scripts/recon-all-status.log"
  5998. echo " -noappend : start new log and status files instead of appending"
  5999. echo " -no-isrunning : do not check whether this subject is currently being processed"
  6000. echo ""
  6001. echo " Other Arguments (Optional)"
  6002. echo " -sd subjectsdir : specify subjects dir (default env SUBJECTS_DIR)"
  6003. echo " -mail username : mail user when done"
  6004. echo " -umask umask : set unix file permission mask (default 002)"
  6005. echo " -grp groupid : check that current group is alpha groupid "
  6006. echo " -onlyversions : print version of each binary and exit"
  6007. echo " -debug : print out lots of info"
  6008. echo " -allowcoredump : set coredump limit to unlimited"
  6009. echo " -dontrun : do everything but execute each command"
  6010. echo " -version : print version of this script and exit"
  6011. echo " -help : voluminous bits of wisdom"
  6012. echo ""
  6013. if(! $PrintHelp) exit 1;
  6014. echo $VERSION
  6015. echo ""
  6016. cat $0 | awk 'BEGIN{prt=0}{if(prt) print $0;if($1 == "BEGINHELP") prt=1}'
  6017. exit 1;
  6018. #---- Everything below here is printed out as part of help -----#
  6019. BEGINHELP
  6020. Performs all, or any part of, the FreeSurfer cortical reconstruction
  6021. process. This help only gives some simple information. For more
  6022. detailed documentation, see https://surfer.nmr.mgh.harvard.edu
  6023. Basic usages:
  6024. 1. Subject dir does not exist:
  6025. recon-all -subject subjectname -i invol1 <-i invol2> -all
  6026. Creates analysis directory $SUBJECTS_DIR/subjectname, converts one or
  6027. more input volumes to MGZ format in subjectname/mri/orig, and runs
  6028. all processing steps. If subjectname exists, then an error is returned
  6029. when -i is used; but this can be overridden with -force (in which
  6030. case any pre-existing source volumes are deleted).
  6031. 2. Manual conversion into mgz:
  6032. mkdir -p $SUBJECTS_DIR/subjectname/mri/orig
  6033. mri_convert invol1 $SUBJECTS_DIR/subjectname/mri/orig/001.mgz
  6034. mri_convert invol2 $SUBJECTS_DIR/subjectname/mri/orig/002.mgz
  6035. recon-all -subject subjectname -all
  6036. If no input volumes are given, then it is assumed that the subject
  6037. directory has already been created and that the raw data already
  6038. exists in MGZ format in subjid/mri/orig as XXX.mgz, where XXX is a
  6039. 3-digit, zero-padded number.
  6040. SUBJECT IDENTIFICATION STRING
  6041. -s subjectname
  6042. -sid subjectname
  6043. -subjid subjectname
  6044. -subject subjectname
  6045. 'subjectname' is the FreeSurfer subject identification string which doubles
  6046. as the name of the reconstruction root directory for this subject. This
  6047. reconstruction should be referenced by this string for all FreeSurfer
  6048. commands and in the register.dat matrix (for functional interfacing).
  6049. SPECIFYING DIRECTIVES
  6050. Directives instruct recon-all which part(s) of the reconstruction
  6051. stream to run. While it is possible to do everything in one shot (using
  6052. the -all flag), there can be some benefits to customizing the
  6053. stream. These benefits include stopping to perform manual editing as
  6054. well as parallelization. Directives are either clustered or step-wise.
  6055. Clustered directives are sets of steps that can be performed by
  6056. specifying a single flag. A step-wise directive refers to a single
  6057. step. Directives accumulate. A step can be removed from a cluster by
  6058. adding -no<step> after the cluster flag. For example, specifying
  6059. -all followed by -notalairach will perform all the reconstruction
  6060. steps except talairaching. However, note that if -notalairach *preceeded*
  6061. -all, talairaching would still be performed.
  6062. CLUSTERED DIRECTIVES
  6063. -all
  6064. -autorecon-all
  6065. Perform all reconstruction steps.
  6066. -autorecon1
  6067. Motion correction through skull strip.
  6068. -autorecon2
  6069. Subcortical segmentation through make white surfaces.
  6070. -autorecon2-cp
  6071. Normalization2 through make final surfaces.
  6072. -autorecon2-wm
  6073. Fill through make white surfaces. Used after editing wm volume after running
  6074. -autorecon2.
  6075. -autorecon-pial
  6076. Makes final surfaces (white and pial). Used after editing brain.finalsurfs
  6077. volume after running -autorecon2. The brain.finalsurfs.mgz volume may be
  6078. edited to fix problems with the pial surface.
  6079. -autorecon3
  6080. Spherical morph, automatic cortical parcellation, pial surf and ribbon mask.
  6081. STEP-WISE DIRECTIVES
  6082. Step-wise directives allow the user to implement a single step in the
  6083. reconstruction process. See also STEP DESCRIPTION SUMMARIES below.
  6084. They also allow users to include/exclude a step from a clustered
  6085. DIRECTIVE. To include a step, use -step (eg, -skullstrip). To exclude
  6086. a step, use -nostep (eg -noskullstrip).
  6087. Run times are approximate for an AMD Opteron 64bit 2.5GHz processor:
  6088. -<no>motioncor < 5 min
  6089. -<no>nuintensitycor 3 min
  6090. -<no>talairach 4 min
  6091. -<no>normalization 3 min
  6092. -<no>skullstrip 1 min
  6093. -<no>gcareg 8 min
  6094. -<no>canorm 1 min
  6095. -<no>careg 10 hours
  6096. -<no>careginv 1 min
  6097. -<no>rmneck 3 min
  6098. -<no>skull-lta 9 min
  6099. -<no>calabel 30 min
  6100. -<no>normalization2 3 min
  6101. -<no>segmentation 4 min
  6102. -<no>fill 1 min
  6103. -<no>tessellate < 1 min per hemisphere
  6104. -<no>smooth1 < 1 min per hemisphere
  6105. -<no>inflate1 1 min per hemisphere
  6106. -<no>qsphere 16 min per hemisphere
  6107. -<no>fix 1-9 hours per hemisphere
  6108. -<no>euler < 1 min per hemisphere
  6109. -<no>smooth2 < 1 min per hemisphere
  6110. -<no>inflate2 2 min per hemisphere
  6111. -<no>white 1 hour per hemisphere
  6112. -<no>sphere 1-2 hours per hemisphere
  6113. -<no>surfreg 1 hour per hemisphere
  6114. -<no>jacobian_white < 1 min per hemisphere
  6115. -<no>contrasurfreg 1 hour per hemisphere
  6116. -<no>avgcurv < 1 min per hemisphere
  6117. -<no>cortparc 1 min per hemisphere
  6118. -<no>parcstats < 1 min per hemisphere
  6119. -<no>cortparc2 1 min per hemisphere
  6120. -<no>parcstats2 < 1 min per hemisphere
  6121. -<no>cortparc3 1 min per hemisphere
  6122. -<no>parcstats3 < 1 min per hemisphere
  6123. -<no>pial 1 hour per hemisphere
  6124. -<no>cortribbon 20 min
  6125. -<no>aparc2aseg 1 min
  6126. -<no>wmparc 20 min
  6127. -all 20-40 hours both hemipheres
  6128. EXPERT PREFERENCES
  6129. -pons-crs C R S
  6130. Specify a seed point for the pons during the fill operation. This is
  6131. used to cut the brain stem from brain. By default, this point will be
  6132. determined automatically. It should only be specified if there is a
  6133. cut failure. To determine what this point should be, find the center
  6134. of the pons in the T1 volume (in tkmedit) and record the column, row,
  6135. and slice. Creates a file called scripts/seed-ponscrs.man.dat
  6136. with the CRS.
  6137. -cc-crs C R S
  6138. Specify a seed point for the corpus callosum during the fill
  6139. operation. This is used to help separate the hemispheres. By default,
  6140. this point will be determined automatically. It should only be
  6141. specified if there is a cut failure. To determine what this point
  6142. should be, find the center of the CC in the T1 volume (in tkmedit) and
  6143. record the column, row, and slice. Creates a file called
  6144. scripts/seed-cccrs.man.dat with the CRS.
  6145. -lh-crs C R S
  6146. Specify a seed point for the left hemisphere during the fill
  6147. operation. This is used to help identify the left hemisphere. By
  6148. default, this point will be determined automatically. It should only
  6149. be specified if there is a cut failure. To determine what this point
  6150. should be, find a point in the white matter mass of the left
  6151. hemisphere in the T1 volume (in tkmedit) and record the column, row,
  6152. and slice. Creates a file called scripts/seed-cccrs.man.dat with the
  6153. CRS. Remember that tkmedit displays the volume in radiological
  6154. convention (ie, left is right).
  6155. -rh-crs C R S
  6156. Same as -lh-crs but for the right hemisphere. Creates a file called
  6157. scripts/seed-rhcrs.man.dat with the CRS.
  6158. -watershed cmd
  6159. This controls how the skull stripping will be performed. Legal values are
  6160. normal (the default), atlas, nowatershed, watershedonly, and watershedtemplate.
  6161. -wsmore/-wsless
  6162. Increase/decrease the preflooding height (threshold) when skull
  6163. stripping. -wsmore will expand the skull surface; -wsless will shrink
  6164. the skull surface. See also -wsthresh.
  6165. -wsthresh pctheight
  6166. Explicitly set the preflooding height when skull stripping.
  6167. -wsseed R C S
  6168. Supply a point in the volume that the user believes to be in the white
  6169. matter. By default, this point will be determined automatically. It
  6170. should only be specified if there is a strip failure. To determine
  6171. what this point should be, find a point in the white matter using
  6172. tkmedit and record the Volume Index values (NOT the XYZ coordinates).
  6173. -no-wsgcaatlas
  6174. Disable usage of the GCA atlas when running mri_watershed skull-stripping.
  6175. The default is to use the GCA atlas to locate anatomy aiding skull-strip.
  6176. -gca gcafile
  6177. Specify the name of the gaussian classifier array (GCA) file
  6178. to be used with GCA registration and automatic subcortical
  6179. segmentation. It must be found in the FREESURFER_HOME/average directory (or
  6180. use -gca-dir to specify an alternate path).
  6181. The Default is RB_all_YYYY-MM-DD.gca located in
  6182. FREESURFER_HOME/average. This has no effect unless the GCA registration
  6183. or subcortical segmentation stages are to be performed.
  6184. -gca-skull gcafile
  6185. Specify the name of the gaussian classifier array (GCA) file to be used with
  6186. registration with skull. It must be found in the FREESURFER_HOME/average
  6187. directory (or use -gca-dir to specify an alternate path).
  6188. The default is RB_all_withskull_YYYY-MM-DD.gca located in
  6189. FREESURFER_HOME/average.
  6190. -gcs gcsfile
  6191. Specify the name of the gaussian classifier surface atlas (GCS) file
  6192. to be used for the cortical parcellation stage. It must be found in the
  6193. FREESURFER_HOME/average directory (or use -gcs-dir to specify an alternate
  6194. path). The default is named
  6195. curvature.buckner40.filled.desikan_killiany.2007-06-20.gcs and is located in
  6196. FREESURFER_HOME/average.
  6197. -nuiterations
  6198. Number of iterations in the non-uniform intensity correction.
  6199. Default is 2.
  6200. -norm3diters niters
  6201. Use niters 3d normalization iterations (passes as -n to _both_ runs of
  6202. mri_normalize).
  6203. -normmaxgrad maxgrad
  6204. Passes "-g maxgrad" to _both_ runs of mri_normalize. Max grad default is 1.
  6205. -norm1-b N
  6206. In the _first_ usage of mri_normalize (during creation of T1.mgz), use
  6207. control point with intensity N below target (default=10.0)
  6208. -norm1-n N
  6209. In the _first_ usage of mri_normalize, do N number of iterations
  6210. -norm2-b N
  6211. In the _second_ usage of mri_normalize (during creation of brain.mgz), use
  6212. control point with intensity N below target (default=10.0)
  6213. -norm2-n N
  6214. In the _second_ usage of mri_normalize, do N number of iterations
  6215. -noaseg
  6216. Skips subcortical segmentation steps (same as -nosubcortseg), and does
  6217. not use aseg.mgz for inorm2, wm segmentation, or filling. Use this flag
  6218. for brains that do not support usage of Freesurfers subcortical
  6219. segmentation, such as baby brains, or non-human primates.
  6220. -noaseg-inorm2
  6221. Does not use aseg.mgz for the second mri_normalize step.
  6222. -bigventricles
  6223. If a subject has enlarged ventricles due to atrophy, include the -bigventricles
  6224. flag with the -autorecon2 stage in order to prevent surfaces extending into
  6225. the ventricle regions. The flag directly affects the binary mri_ca_register,
  6226. and mris_make_surfaces indirectly via aseg.mgz.
  6227. -norandomness
  6228. The random number generator used by certain binaries is seeded with the
  6229. same number, thus producing identical results from run to run.
  6230. -cw256
  6231. Include this flag after -autorecon1 if images have a FOV > 256. The
  6232. flag causes mri_convert to conform the image to dimensions of 256^3.
  6233. -notal-check
  6234. Skip the automatic failure detection of Talairach alignment.
  6235. -qcache
  6236. Produce the pre-cached files required by the Qdec utility, allowing rapid
  6237. analysis of group data. These files are created by running mris_preproc,
  6238. which creates smoothed surface data files sampled to the 'fsaverage'
  6239. common-space surface. By default, the surface data for thickness, curv, sulc,
  6240. area and jacobian_white are smoothed at 0, 5, 10, 15, 20, and 25 mm FWHM.
  6241. If just one set of surface data needs to be processed, then the option
  6242. -measure <surfmeas> can follow -qcache, where <surfmeas> is one of: thickness,
  6243. curv, sulc, area, jacobian_white or any surface measure. Multiple instances
  6244. of -measure <meas> is supported. The -measuredir option allows
  6245. specifying a directory other than the default of surf. Another option is
  6246. -fwhm <num> where <num> is a value in mm. Also, -target <name> allows
  6247. specifying a common-space target other than fsaverage (the default).
  6248. qcache is also a target for make, eg. recon-all -make qcache
  6249. See also: http://surfer.nmr.mgh.harvard.edu/fswiki/Qdec
  6250. -smooth-cortex-only
  6251. Only applies with -qcache. Only smooth data if it is part of the ?h.cortex.label.
  6252. This prevents values in the medial wall (which are meaningless) from being
  6253. smoothed into cortical areas. This is the default and you will have to turn
  6254. it off with -no-smooth-cortex-only.
  6255. -no-smooth-cortex-only
  6256. Allow medial wall values to smooth into cortex.
  6257. -make target
  6258. Runs recon-all through 'make', the standard utility used to create a file
  6259. only if its dependencies are out-of-date. This -make option makes use of the
  6260. file recon-all.makefile, where the dependency chain is specified.
  6261. A 'target' argument must be specified. The valid targets are:
  6262. all
  6263. autorecon1
  6264. autorecon2
  6265. autorecon2-volonly
  6266. autorecon2-perhemi
  6267. autorecon3
  6268. qcache
  6269. These targets correspond to their flag equivalents in recon-all. The
  6270. difference in behaviour is that files are created only if the file does not
  6271. exist or if an input file used to create it has a newer date than the file
  6272. in need of creation. It is also possible to supply the full pathname to a
  6273. particular file as a target.
  6274. The flag -dontrun can also be specified to show the commands that will run
  6275. without excuting them.
  6276. -lgi
  6277. -lGI
  6278. -localGI
  6279. Computes local measurements of pial-surface gyrification at thousands of
  6280. points over the cortical surface. See reference [13] for details.
  6281. -label_v1
  6282. Create a label of V1, based on Hinds et al., NeuroImage 39 (2008) 1585-1599.
  6283. -balabels
  6284. -ba-labels
  6285. -ba_labels
  6286. Creates Brodmann area labels of BA1, BA2, BA3a, BA3b, BA4a, BA4p, BA6, BA44,
  6287. BA45, V1, V2, and V5/MT by mapping labels from the 'fsaverage' subject.
  6288. The 'fsaverage' subject must exist within the SUBJECTS_DIR. Based on:
  6289. "Cortical Folding Patterns and Predicting Cytoarchitecture", Fischl et al.,
  6290. Cerebral Cortex 2007.
  6291. -use-gpu
  6292. Use the GPU versions of the binaries mri_em_register, mri_ca_register,
  6293. mris_inflate, and mris_sphere.
  6294. EXPERT OPTIONS FILE
  6295. While the expert preferences flags supported by recon-all cover most of
  6296. the instances where special flags need to be passed to a FreeSurfer binary,
  6297. to allow passing an arbitrary flag to a binary, recon-all supports the
  6298. reading of a user-created file containing special options to include in
  6299. the command string (in addition to, not in place of). The file should
  6300. contain as the first item the name of the command, and the items following
  6301. it on rest of the line will be passed as the extra options. For example,
  6302. if a file called expert.opts is created containing these lines:
  6303. mri_em_register -p .5
  6304. mris_topo_fixer -asc
  6305. then the option "-p .5" will be passed to mri_em_register, and "-asc"
  6306. will be passed to mris_topo_fixer. The name of the expert options file
  6307. is passed to recon-all with the -expert flag, eg.
  6308. recon-all -expert expert.opts
  6309. When an expert options is passed, it will be copied to scripts/expert-options.
  6310. Future calls to recon-all, the user MUST explicitly specify how to treat this file.
  6311. Options are (1) use the file (-xopts-use), or (2) delete it (-xopts-clean). If
  6312. this file exsts and the user specifies another expert options file, then
  6313. the user must also specify -xopts-overwrite.
  6314. The following FreeSurfer binaries will accept an expert option:
  6315. talairach_avi
  6316. mri_normalize
  6317. mri_watershed
  6318. mri_em_register
  6319. mri_ca_normalize
  6320. mri_ca_register
  6321. mri_remove_neck
  6322. mri_ca_label
  6323. mri_segstats
  6324. mri_mask
  6325. mri_segment
  6326. mri_edit_wm_with_aseg
  6327. mri_pretess
  6328. mri_fill
  6329. mri_tessellate
  6330. mris_smooth
  6331. mris_inflate
  6332. mris_sphere
  6333. mris_fix_topology
  6334. mris_topo_fixer
  6335. mris_remove_intersection
  6336. mris_make_surfaces
  6337. mris_surf2vol
  6338. mris_register
  6339. mris_jacobian
  6340. mrisp_paint
  6341. mris_ca_label
  6342. mris_anatomical_stats
  6343. mri_aparc2aseg
  6344. NOTIFICATION FILES
  6345. Notification files allow the user to cascade invocations to recon-all,
  6346. with one invocation waiting until another one terminates. This is done
  6347. by specifying a file that must exist before an invocation can precede
  6348. (-waitfor) and/or specifying a file that is created when an invocation
  6349. terminates (-notify). This type of interprocess communication can
  6350. allow users to parallelize the stream. If this is to be done, note
  6351. that each hemisphere can be run separately by specifying the -hemi
  6352. flag.
  6353. LOG AND STATUS FILES
  6354. By default, log and status files are created in subjid/scripts. The
  6355. log file contains all the output from all the programs that have been
  6356. run during the invocation to recon-all. The status file has a list of
  6357. all the programs that have been run and the time at which each
  6358. started. The log file is intended to be a record of what was done
  6359. whereas the status file allows the user to easily see where in the
  6360. stream a currently running process is. The log file should be sent
  6361. with all bug reports. By default, these files are called recon-all.log
  6362. and recon-all-status.log, but this can be changed with the -log and
  6363. -status options. By default, the log and status are appended to. New
  6364. log and status files can be forced with the -noappend flag.
  6365. OTHER ARGUMENTS
  6366. -sd subjectsdir
  6367. This allows the user to specify the root of the FreeSufer subjects
  6368. directory. If unspecified, the environment variable SUBJECTS_DIR
  6369. is used.
  6370. -mail username
  6371. Send email to username when the process terminates.
  6372. STEP DESCRIPTION SUMMARIES
  6373. Motion Correction (-<no>motioncor)
  6374. When there are multiple source volumes, this step will correct for
  6375. small motions between them and then average them together. The input
  6376. are the volumes found in file(s) mri/orig/XXX.mgz. The output will be
  6377. the volume mri/orig.mgz. If no runs are found, then it looks for
  6378. a volume in mri/orig (or mri/orig.mgz). If that volume is there, then
  6379. it is used in subsequent processes as if it was the motion corrected
  6380. volume. If no volume is found, then the process exits with errors.
  6381. The motion correction step uses a robust registration [14] procedure
  6382. to produce highly accurate registrations of the brain, ignoring outlier
  6383. regions, such as differen cropping planes, jaw, neck, eye movement etc.
  6384. NU Intensity Correction (-<no>nuintensitycor)
  6385. Non-parametric Non-uniform intensity Normalization (N3), corrects for
  6386. intensity non-uniformity in MR data, making relatively few assumptions
  6387. about the data. This runs the MINC tool 'nu_correct'. By default, four
  6388. iterations of nu_correct are run. The flag -nuiterations specification
  6389. of some other number of iterations.
  6390. Talairach (-<no>talairach)
  6391. This computes the affine transform from the orig volume to the MNI305
  6392. atlas using Avi Snyders 4dfp suite of image registration tools,
  6393. through a FreeSurfer script called talairach_avi. Several of the downstream
  6394. programs use talairach coordinates as seed points. You can/should check
  6395. how good the talairach registration is using
  6396. "tkregister2 --s subjid --fstal-avi". You must have an "fsaverage" subject in
  6397. your SUBJECTS_DIR. tkregister2 allows you to compare the orig volume
  6398. against the talairach volume resampled into the orig space. If you modify
  6399. the registration, it will change the talairach.xfm file. Your edits will
  6400. be *not* be overwritten unless you run recon-all specifying -clean-tal.
  6401. Run "tkregister2 --help" for more information.
  6402. Creates the files mri/transform/talairach.auto.xfm and talairach.xfm.
  6403. The flag -tal-check will check the registration against known-good transforms.
  6404. Adding the flag -use-mritotal after -talairach will use the MINC program
  6405. mritotal (see Collins, et al., 1994) to perform the transform.
  6406. Normalization (-<no>normalization)
  6407. Performs intensity normalization of the orig volume and places the
  6408. result in mri/T1.mgz. Attempts to correct for fluctuations in
  6409. intensity that would otherwise make intensity-based segmentation much
  6410. more difficult. Intensities for all voxels are scaled so that the mean
  6411. intensity of the white matter is 110. If there are problems with the
  6412. normalization, users can add control points. See also Normalization2.
  6413. Skull Strip (-<no>skullstrip)
  6414. Removes the skull from mri/T1.mgz and stores the result in
  6415. mri/brainmask.auto.mgz and mri/brainmask.mgz.
  6416. Runs the mri_watershed program. If the strip fails, users can specify
  6417. seed points (-wsseed) or change the threshold (-wsthresh, -wsmore, -wsless).
  6418. The -autorecon1 stage ends here.
  6419. Automatic Subcortical Segmentation (-<no>subcortseg)
  6420. This is done in six stages. (1) GCA linear registration
  6421. (-gcareg). This is an initial registration to a template. (2)
  6422. Canonical Normalization (-canorm), (3) Canonical Registration
  6423. (-careg). (4) Neck removal (-rmneck), (5) Registration, w/skull
  6424. (-skull-lta), and (6) Subcortical labeling (-calabel).
  6425. The stages are listed next.
  6426. EM (GCA) Registration (-<no>gcareg)
  6427. Computes transform to align the mri/nu.mgz volume to the default GCA atlas
  6428. found in FREESURFER_HOME/average (see -gca flag for more info).
  6429. Creates the file mri/transforms/talairach.lta.
  6430. The -autorecon2 stage starts here.
  6431. CA Normalize (-<no>canorm)
  6432. Further normalization, based on GCA model.
  6433. Creates mri/norm.mgz.
  6434. CA Register (-<no>careg)
  6435. Computes a nonlinear transform to align with GCA atlas.
  6436. Creates the file mri/transform/talairach.m3z.
  6437. CA Register Inverse (-<no>careginv)
  6438. Computes the inverse of the nonlinear transform to align with GCA
  6439. atlas. Creates the files mri/transform/talairach.m3z.{x,y,z}.mgz.
  6440. Remove neck (-<no>rmneck)
  6441. The neck region is removed from the NU-corrected volume mri/nu.mgz.
  6442. Makes use of transform computed from prior CA Register stage.
  6443. Creates the file mri/nu_noneck.mgz.
  6444. EM Registration, with Skull (-<no>skull-lta)
  6445. Computes transform to align volume mri/nu_noneck.mgz with GCA volume
  6446. possessing the skull.
  6447. Creates the file mri/transforms/talairach_with_skull_2.lta.
  6448. CA Label (-<no>calabel)
  6449. Labels subcortical structures, based in GCA model.
  6450. Creates the files mri/aseg.auto.mgz and mri/aseg.mgz.
  6451. ASeg Stats (-<no>segstats)
  6452. Computes statistics on the segmented subcortical structures found
  6453. in mri/aseg.mgz. Writes output to file stats/aseg.stats.
  6454. Normalization2 (-<no>normalization)
  6455. Performs a second (major) intensity correction using only the brain
  6456. volume as the input (so that it has to be done after the skull strip).
  6457. Intensity normalization works better when the skull has been removed.
  6458. Creates a new brain.mgz volume. The -autorecon2-cp stage begins here.
  6459. If -noaseg flag is used, then aseg.mgz is not used by mri_normalize.
  6460. WM Segmentation (-<no>segmentation)
  6461. Attempts to separate white matter from everything else. The input is
  6462. mri/brain.mgz, and the output is mri/wm.mgz. Uses intensity,
  6463. neighborhood, and smoothness constraints. This is the volume that is
  6464. edited when manually fixing defects. Calls mri_segment,
  6465. mri_edit_wm_with_aseg, and mri_pretess. To keep previous edits, run
  6466. with -keep. If -noaseg is used, them mri_edit_wm_aseg is skipped.
  6467. Cut/Fill (-<no>fill)
  6468. This creates the subcortical mass from which the orig surface is
  6469. created. The mid brain is cut from the cerebrum, and the hemispheres
  6470. are cut from each other. The left hemisphere is binarized to 255.
  6471. The right hemisphere is binarized to 127. The input is mri/wm.mgz
  6472. and the output is mri/filled.mgz. Calls mri_fill. If the cut fails,
  6473. then seed points can be supplied (see -cc-crs, -pons-crs, -lh-crs,
  6474. -rh-crs). The actual points used for the cutting planes in the
  6475. corpus callosum and pons can be found in scripts/ponscc.cut.log.
  6476. The stage -autorecon2-wm begins here. This is the last stage of
  6477. volumetric processing. If -noaseg is used, then aseg.mgz is not used
  6478. by mri_fill.
  6479. Tessellation (-<no>tessellate)
  6480. This is the step where the orig surface (ie, surf/?h.orig.nofix) is
  6481. created. The surface is created by covering the filled hemisphere with
  6482. triangles. Runs mri_tessellate. The places where the points of the
  6483. triangles meet are called vertices. Creates the file surf/?h.orig.nofix
  6484. Note: the topology fixer will create the surface ?h.orig.
  6485. Orig Surface Smoothing (-<no>smooth1, -<no>smooth2)
  6486. After tesselation, the orig surface is very jagged because each
  6487. triangle is on the edge of a voxel face and so are at right angles to
  6488. each other. The vertex positions are adjusted slightly here to reduce
  6489. the angle. This is only necessary for the inflation processes.
  6490. Creates surf/?h.smoothwm(.nofix). Calls mris_smooth. Smooth1 is the step
  6491. just after tessellation, and smooth2 is the step just after topology
  6492. fixing.
  6493. Inflation (-<no>inflate1, -<no>inflate2)
  6494. Inflation of the surf/?h.smoothwm(.nofix) surface to create
  6495. surf/?h.inflated. The inflation attempts to minimize metric distortion
  6496. so that distances and areas are perserved (ie, the surface is not
  6497. stretched). In this sense, it is like inflating a paper bag and not a
  6498. balloon. Inflate1 is the step just after tessellation, and inflate2
  6499. is the step just after topology fixing. Calls mris_inflate. Creates
  6500. ?h.inflated, ?h.sulc, ?h.curv, and ?h.area.
  6501. QSphere (-<no>qsphere)
  6502. This is the initial step of automatic topology fixing. It is a
  6503. quasi-homeomorphic spherical transformation of the inflated surface designed
  6504. to localize topological defects for the subsequent automatic topology fixer.
  6505. Calls mris_sphere. Creates surf/?h.qsphere.nofix.
  6506. Automatic Topology Fixer (-<no>fix)
  6507. Finds topological defects (ie, holes in a filled hemisphere) using
  6508. surf/?h.qsphere.nofix, and changes the orig surface (surf/?h.orig.nofix)
  6509. to remove the defects. Changes the number of vertices. All the defects
  6510. will be removed, but the user should check the orig surface in the volume
  6511. to make sure that it looks appropriate. Calls mris_topo_fixer.
  6512. Creates surf/?h.orig (by iteratively fixing surf/?h.orig.nofix).
  6513. White Surface (-<no>white)
  6514. Creates the ?h.white surfacees as well as the curvature file (?h.curv).
  6515. The white surface is created by "nudging" the orig surface so that it
  6516. closely follows the white-gray intensity gradient as found in the T1 volume.
  6517. Calls mris_make_surfaces. See also "Pial Surface" and "Final Surfaces".
  6518. Spherical Inflation (-<no>sphere)
  6519. Inflates the orig surface into a sphere while minimizing metric
  6520. distortion. This step is necessary in order to register the surface
  6521. to the spherical atlas. (also known as the spherical morph). Calls
  6522. mris_sphere. Creates surf/?h.sphere. The -autorecon3 stage begins here.
  6523. Ipsilateral Surface Registation (Spherical Morph) (-<no>surfreg)
  6524. Registers the orig surface to the spherical atlas through
  6525. surf/?h.sphere. The surfaces are first coarsely registered by aligning
  6526. the large scale folding patterns found in ?h.sulc and then fine tuned
  6527. using the small-scale patterns as in ?h.curv.
  6528. Calls mris_register. Creates surf/?h.sphere.reg.
  6529. Jacobian (-<no>jacobian_white)
  6530. Computes how much the white surface was distorted in order to register
  6531. to the spherical atlas during the -surfreg step. Creates ?h.jacobian_white
  6532. (a curv formatted file). This step follows the surface registration step.
  6533. Surface Registation, maximal distortion, with Jacobian (-<no>jacobian_dist0)
  6534. Run spherical registration with no metric distortion penalty. This will
  6535. cause surface geometry to align regardless of the amount of distortion
  6536. induced (ie, distance contraints are turned off). The distortion will then
  6537. be quantified by the Jacobian of the transform. Creates ?h.jacobian_dist0 (a
  6538. curv formatted file) and ?h.sphere.dist0.jacobian.reg (a surface file). This
  6539. step is not run automatically because it can add about an hour per hemi.
  6540. Note: the file ?h.jacobian_white (see prior help text) is the Jacobian of
  6541. the white surface to spherical atlas alignment from -surfreg.
  6542. Contralateral Surface Registation (Spherical Morph) (-<no>contrasurfreg)
  6543. Same as ipsilateral but registers to the contralateral atlas.
  6544. Creates lh.rh.sphere.reg and rh.lh.sphere.reg.
  6545. Average Curvature (-<no>avgcurv)
  6546. Resamples the average curvature from the atlas to that of the subject.
  6547. Allows the user to display activity on the surface of an individual
  6548. with the folding pattern (ie, anatomy) of a group. Calls mrisp_paint.
  6549. Creates surf/?h.avg_curv.
  6550. Cortical Parcellation (-<no>cortparc, -<no>cortparc2, -<no>cortparc3 )
  6551. Assigns a neuroanatomical label to each location on the cortical surface.
  6552. Incorporates both geometric information derived from the cortical model
  6553. (sulcus and curvature), and neuroanatomical convention.
  6554. Calls mris_ca_label. -cortparc creates label/?h.aparc.annot,
  6555. -cortparc2 creates /label/?h.aparc.a2009s.annot, and
  6556. -cortparc3 creates /label/?h.aparc.DKTatlas40.annot.
  6557. Pial Surface (-<no>pial)
  6558. Creates the ?h.pial surfaces as well as the thickness file (?h.thickness).
  6559. The pial surface is created by expanding the white surface so that it closely
  6560. follows the gray-CSF intensity gradient as found in the T1 volume. The
  6561. cortical parcellation is also used to refine the surface in certain areas.
  6562. Calls mris_make_surfaces. See also "Final Surfaces".
  6563. Final Surfaces (-<no>finalsurfs)
  6564. !!! DEPRECATED !!! This flag is intended to emulate the old-style single-run
  6565. mris_make_surfaces, where the white and pial surfaces are created at the same
  6566. time without aid from the cortical parcellation data.
  6567. WM/GM Contrast (-<no>pctsurfcon)
  6568. Computes the vertex-by-vertex percent contrast between white and gray matter.
  6569. The computation is:
  6570. 100*(W-G)
  6571. pct = ---------
  6572. 0.5*(W+G)
  6573. The white matter is sampled 1mm below the white surface. The gray matter is
  6574. sampled 30% the thickness into the cortex. The volume that is sampled is
  6575. rawavg.mgz. The output is stored in the surf dir of the given subject as
  6576. ?h.w-g.pct.mgh. Non-cortical regions (medial wall) are zeroed.
  6577. A stats file named ?h.w-g.pct.stats is also computed.
  6578. Surface Volume (-surfvolume)
  6579. Creates the ?h.volume file by first creating the ?h.mid.area file by
  6580. adding ?h.area(.white) to ?h.area.pial, then dividing by two. Then
  6581. ?h.volume is created by multiplying ?.mid.area with ?h.thickness.
  6582. This step is also run at the end of the -pial step.
  6583. Parcellation Statistics (-<no>parcstats, -<no>parcstats2, -<no>parcstats3)
  6584. Runs mris_anatomical_stats to create a summary table of cortical
  6585. parcellation statistics for each structure, including 1. structure
  6586. name 2. number of vertices 3. total wm surface area (mm^2) 4. total gray
  6587. matter volume (mm^3) 5. average cortical thickness (mm) 6. standard
  6588. error of cortical thickness (mm) 7. integrated rectified mean wm
  6589. curvature 8. integrated rectified Gaussian wm curvature 9. folding index
  6590. 10. intrinsic curvature index.
  6591. For -parcstats, the file is saved in stats/?h.aparc.stats.
  6592. For -parcstats2, the file is saved in stats/?h.aparc.${DESTRIEUX_NAME}.stats.
  6593. For -parcstats3, the file is saved in stats/?h.aparc.${DKTATLAS40_NAME}.stats.
  6594. Cortical Ribbon Mask (-<no>cortribbon)
  6595. Creates binary volume masks of the cortical ribbon, ie, each voxel is
  6596. either a 1 or 0 depending upon whether it falls in the ribbon or not.
  6597. Saved as ?h.ribbon.mgz. Uses mgz regardless of whether the -mgz
  6598. option is used.
  6599. Curvature Statistics (-<no>curvstats)
  6600. Runs mris_curvature_stats to create a summary file (stats/?h.curv.stats)
  6601. of cortical curvature statistics.
  6602. LONGITUDINAL PROCESSING
  6603. The longitudinal processing scheme aims to incorporate the subject-wise
  6604. correlation of longitudinal data into the processing stream in order to
  6605. increase sensitivity and repeatability, see [14-16]. Care is taken to
  6606. avoid introduction of asymmetry-induced bias.
  6607. Here is a summary of the longitudinal workflow, where tpN refers to the
  6608. name of one timepoint of subject data, and longbase refers to the name
  6609. given to the base subject of a collection of timepoints:
  6610. 1) cross-sectionally process tpN subjects (the default workflow):
  6611. recon-all -s tp1 -i path_to_tp1_dicom -all
  6612. recon-all -s tp2 -i path_to_tp2_dicom -all
  6613. 2) create and process the unbiased base (subject template):
  6614. recon-all -base longbase -tp tp1 -tp tp2 -all
  6615. 3) longitudinally process tpN subjects:
  6616. recon-all -long tp1 longbase -all
  6617. recon-all -long tp2 longbase -all
  6618. 4) do comparisons on results from 3), e.g. calculate differences
  6619. between tp2.long.longbase - tp1.long.longbase
  6620. Note that the longitudinal processing stream always produces output subject
  6621. data containing .long. in the name (to help distinguish from the default
  6622. stream).
  6623. Notice that the -all flag is included in the -base and -long calls above.
  6624. A work directive flag is required.
  6625. Other flags:
  6626. -uselongbasectrlvol
  6627. With -long: Switch on use of control-points from the base in the long
  6628. runs for intensity normalization (T1.mgz).
  6629. -uselongbasewmedits
  6630. With -long: Optionally transfer WM edits from base/template.
  6631. Default: map WM edits from corresponding cross run.
  6632. -no-orig-pial
  6633. If the orig pial surface data is not available, then specify this flag so that
  6634. mris_make_surfaces does not attempt to use it.
  6635. -noasegfusion
  6636. Do not create 'fused' aseg from the longbase timepoints, which would normally
  6637. be used to initialize the ca_labeling. Instead, initialize using the longbase
  6638. aseg.mgz.
  6639. -addtp
  6640. If a new timepoint needs to be added to a longitudinal run where a base subject
  6641. has already been created (from prior timepoints), then the -addtp command
  6642. can be added to the -long command in order to 'fix-up' the longitudinal
  6643. stream to accept the new timepoint. Note that the base subject is *not*
  6644. recomputed using the new timepoint. This potentially introduces a bias, and it
  6645. is recommended to NOT add a time point this way! Instead recreate the base
  6646. from all time points and run all longitudinals again.
  6647. See the LongitudinalProcessing wiki page.
  6648. Example:
  6649. recon-all -long <tpNsubjid> <longbasesubjid> -addtp -all
  6650. In this example, 'tnNsubjid' is the subject name (assumed processed in the
  6651. cross-sectional stream) to add as a new timepoint and upon which to run
  6652. the longitudinal stream (creating <tpNsubjid>.long.<longbasesubjid>).
  6653. MANUAL CHECKING AND EDITING OF SURFACES
  6654. To manually edit segmenation, run the following command (make sure
  6655. that your SUBJECTS_DIR environment variable is properly set).
  6656. tkmedit subjid wm.mgz -aux T1.mgz
  6657. The surfaces can be loaded through the menu item
  6658. File->LoadMainSurface. To enable editing, set Tools->EditVoxels. It
  6659. may also be convenient to bring up the reconstruction toolbar with
  6660. View->ToolBars->Reconstruction. Alt-C toggles between the main (wm)
  6661. and auxiliary (T1) volumes. Middle clicking will set a voxel value to
  6662. 255; left clicking will set a voxel value to 0. Only edit the wm
  6663. volume. When finished, File->SaveMainVolume.
  6664. To view the inflated surface simultaneosly with the volume, run the
  6665. following command from a different shell:
  6666. tksurfer subjid lh inflated
  6667. To goto a point on the surface inside the volume, click on the point
  6668. and hit SavePoint (icon looks like a floppy disk), then, in tkmedit,
  6669. hit GotoSavedPoint (icon looks like an open file).
  6670. Be sure to see the tutorials found at:
  6671. https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial
  6672. TOUCH FILES
  6673. This script creates a directory called "touch". Each time a stage is
  6674. run a "touch file" is created (eg, skull_strip.touch). This will be
  6675. used in the future to automatically determine which stages need to be
  6676. run or re-run. The modification time of the touch file is important.
  6677. The content is irrelevent, though it often contains a command-line.
  6678. FLATTENING
  6679. Flattening is not actually done in this script. This part just documents
  6680. how one would go about performing the flattening. First, load the subject
  6681. surface into tksurfer:
  6682. tksurfer subjid lh inflated
  6683. Load the curvature through the File->Curvature->Load menu (load
  6684. lh.curv). This should show a green/red curvature pattern. Red = sulci.
  6685. Right click before making a cut; this will clear previous points. This
  6686. is needed because it will string together all the previous places you
  6687. have clicked to make the cut. To make a line cut, left click on a line
  6688. of points. Make the points fairly close together; if they are too far
  6689. appart, the cut fails. After making your line of points, execute the
  6690. cut by clicking on the Cut icon (scissors with an open triangle for a
  6691. line cut or scissors with a closed triangle for a closed cut). To make
  6692. a plane cut, left click on three points to define the plane, then left
  6693. click on the side to keep. Then hit the CutPlane icon.
  6694. Fill the patch. Left click in the part of the surface that you want to
  6695. form your patch. Then hit the Fill Uncut Area button (icon = filled
  6696. triangle). This will fill the patch with white. The non-patch area
  6697. will be unaccessible through the interface. Save the patch through
  6698. File->Patch->SaveAs. For whole cortex, save it to something like
  6699. lh.cort.patch.3d. For occipital patches, save it to lh.occip.patch.3d.
  6700. Cd into the subject surf directory and run
  6701. mris_flatten -w N -distances Size Radius lh.patch.3d lh.patch.flat
  6702. where N instructs mris_flatten to write out an intermediate surface
  6703. every N interations. This is only useful for making movies; otherwise
  6704. set N=0. Size is maximum number of neighbors; Radius radius (mm) in
  6705. which to search for neighbors. In general, the more neighbors that are
  6706. taken into account, the less the metric distortion but the more
  6707. computationally intensive. Typical values are Size=12 for large
  6708. patches, and Size=20 for small patches. Radius is typically 7.
  6709. Note: flattening may take 12-24 hours to complete. The patch can be
  6710. viewed at any time by loading the subjects inflated surface, then
  6711. loading the patch through File->Patch->LoadPatch...
  6712. GETTING HELP
  6713. Send email to freesurfer@nmr.mgh.harvard.edu. Also see
  6714. https://surfer.nmr.mgh.harvard.edu. In particular, there is both a
  6715. reconstruction guide and tutorial as well as manuals for tkmedit and
  6716. tksurfer.
  6717. REFERENCES
  6718. [1] Collins, DL, Neelin, P., Peters, TM, and Evans, AC. (1994)
  6719. Automatic 3D Inter-Subject Registration of MR Volumetric Data in
  6720. Standardized Talairach Space, Journal of Computer Assisted Tomography,
  6721. 18(2) p192-205, 1994 PMID: 8126267; UI: 94172121
  6722. [2] Cortical Surface-Based Analysis I: Segmentation and Surface
  6723. Reconstruction Dale, A.M., Fischl, Bruce, Sereno, M.I.,
  6724. (1999). Cortical Surface-Based Analysis I: Segmentation and Surface
  6725. Reconstruction. NeuroImage 9(2):179-194
  6726. [3] Fischl, B.R., Sereno, M.I.,Dale, A. M. (1999) Cortical
  6727. Surface-Based Analysis II: Inflation, Flattening, and Surface-Based
  6728. Coordinate System. NeuroImage, 9, 195-207.
  6729. [4] Fischl, Bruce, Sereno, M.I., Tootell, R.B.H., and Dale, A.M.,
  6730. (1999). High-resolution inter-subject averaging and a coordinate
  6731. system for the cortical surface. Human Brain Mapping, 8(4): 272-284
  6732. [5] Fischl, Bruce, and Dale, A.M., (2000). Measuring the Thickness of
  6733. the Human Cerebral Cortex from Magnetic Resonance Images. Proceedings
  6734. of the National Academy of Sciences, 97:11044-11049.
  6735. [6] Fischl, Bruce, Liu, Arthur, and Dale, A.M., (2001). Automated
  6736. Manifold Surgery: Constructing Geometrically Accurate and
  6737. Topologically Correct Models of the Human Cerebral Cortex. IEEE
  6738. Transactions on Medical Imaging, 20(1):70-80
  6739. [7] Non-Uniform Intensity Correction.
  6740. http://www.nitrc.org/projects/nu_correct/
  6741. [8] Fischl B, Salat DH, Busa E, Albert M, Dieterich M, Haselgrove C,
  6742. van der Kouwe A, Killiany R, Kennedy D, Klaveness S, Montillo A,
  6743. Makris N, Rosen B, Dale AM. Whole brain segmentation: automated
  6744. labeling of neuroanatomical structures in the human
  6745. brain. Neuron. 2002 Jan 31;33(3):341-55.
  6746. [9] Bruce Fischl, Andre van der Kouwe, Christophe Destrieux, Eric
  6747. Halgren, Florent Segonne, David H. Salat, Evelina Busa, Larry
  6748. J. Seidman, Jill Goldstein, David Kennedy, Verne Caviness, Nikos
  6749. Makris, Bruce Rosen, and Anders M. Dale. Automatically Parcellating
  6750. the Human Cerebral Cortex. Cerebral Cortex January 2004; 14:11-22.
  6751. [10] Fischl B, Salat DH, van der Kouwe AJW, Makris N, Ségonne F, Dale
  6752. AM. Sequence-Independent Segmentation of Magnetic Resonance Images.
  6753. NeuroImage 23 Suppl 1, S69-84.
  6754. [11] Segonne F, Dale, AM, Busa E, Glessner M, Salvolini U, Hahn HK,
  6755. Fischl B, A Hybrid Approach to the Skull-Stripping Problem in MRI.
  6756. NeuroImage, 22, pp. 1160-1075, 2004
  6757. [12] Han et al., Reliability of MRI-derived measurements of human
  6758. cerebral cortical thickness: The effects of field strength, scanner
  6759. upgrade and manufacturer, (2006) NeuroImage, 32(1):180-194.
  6760. [13] Schaer et al., A Surface-based Approach to Quantify Local Cortical
  6761. Gyrification (2007) IEEE Transactions on Medical Imaging.
  6762. [14] Martin Reuter, H Diana Rosas, Bruce Fischl.
  6763. Highly Accurate Inverse Consistent Registration: A Robust Approach.
  6764. NeuroImage 53(4), 1181-1196, 2010. http://dx.doi.org/10.1016/j.neuroimage.2010.07.020
  6765. [15] Martin Reuter, Bruce Fischl.
  6766. Avoiding Asymmetry-Induced Bias in Longitudinal Image Processing.
  6767. NeuroImage 51(1), 19-21, 2011. http://dx.doi.org/10.1016/j.neuroimage.2011.02.076
  6768. [16] Martin Reuter, Nicholas J Schmansky, H Diana Rosas, Bruce Fischl.
  6769. Within-Subject Template Estimation for Unbiased Longitudinal Image Analysis.
  6770. NeuroImage 61(4), 1402-1418, 2012. http://dx.doi.org/10.1016/j.neuroimage.2012.02.084