recon-all.local-copy 320 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270
  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: zkaufman $
  10. # $Date: 2017/01/18 14:11:24 $
  11. # $Revision: 1.580.2.16 $
  12. #
  13. # Copyright © 2011-2016 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.580.2.16 2017/01/18 14:11:24 zkaufman 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. if($?SET_FS_CMD_TIMING) set DoTime = 1;
  47. set fs_time = "";
  48. set ErrorFile = /dev/null
  49. set cmd = ();
  50. set tcsh61706 = (`tcsh --version | grep "6\.17\.06"`)
  51. if ("$tcsh61706" != "") then
  52. echo ""
  53. echo "WARNING: tcsh v6.17.06 has an exit code bug! Please update tcsh!"
  54. echo ""
  55. # workaround to force expected behavior:
  56. set anyerror
  57. endif
  58. set Force = 0;
  59. set DoCleanCSDF = 0;
  60. set DoCleanCW256 = 0;
  61. set DoCleanTal = 0;
  62. set DoCleanLta = 0;
  63. set DoCleanCP = 0;
  64. set DoCleanTWM = 0;
  65. set DoCleanSeed = 0;
  66. set DoCleanPFH = 0;
  67. set DoCleanBM = 0;
  68. set DoCleanBFSE = 0;
  69. set DoCleanASeg = 0;
  70. set DoCleanWM = 0;
  71. set DoCleanXopts = 0;
  72. set DoCleanT2 = 0;
  73. set DoCleanFLAIR = 0;
  74. set DoSuperClean = 0;
  75. set DoShowEdits = 0;
  76. set InputList = ();
  77. # parameter defaults (most can be overriden with flags)
  78. set XOptsFile = ();
  79. set XOptsClean = 0; # Delete a pre-existing xopts file
  80. set XOptsUse = 1; # Use a pre-existing xopts file (default '1': always use)
  81. set XOptsOverwrite = 0; # Overwrite a pre-existing xopts file
  82. set TermScriptList = ();
  83. set ControlPointsFile = ();
  84. set TWMControlPointsFile = ();
  85. set PonsSeedCRS = (); # SeedCRS center of pons for mri_fill #
  86. set CCSeedCRS = (); # SeedCRS center of corpus callosum for mri_fill #
  87. set RHSeedCRS = (); # SeedCRS point in the right hemi wm for mri_fill #
  88. set LHSeedCRS = (); # SeedCRS point in the left hemi wm for mri_fill #
  89. set UseMincMritotal = 0; # if 1, then use the BIC-MNI mritotal tal reg tools
  90. set DoTalairachUseNu = 0; # if 1, use nu.mgz as input to talairach stage
  91. set UseYa3tTalAtlas = 0; # if 1, use 3T18yoSchwartz young-adult 3T atlas
  92. # for tal_avi (recommended as 3T default by Avi S.)
  93. set CustomTalAtlas = ""; # -custom-tal-atlas <name of atlas in average dir>
  94. set NoEMReg = 0; # Do not run mri_em_register. Instead convert tal.xfm to lta
  95. set DoNuMakeUchar = 1; # if 1, then run mri_nu_correct.mni using talairach.xfm
  96. # to run mri_make_uchar to correct histogram problem
  97. # Neither of these are used right now
  98. set UseMaskNuCorrect = 0; # if 1, nu_correct runs with -mask brainmask.mgz
  99. set DilateMaskNuCorrect = (); # grow nu_correct mask by this amount
  100. set WaterShed = 1; # 0=no WS, 1= WS normal, 2 = WS only, 3 = WS+1st
  101. set WSLess = 0; # Shrinks skull surface
  102. set WSMore = 0; # Expands skull surface
  103. set WSPctPreFlood = (); # Pre-flooding height
  104. set WSSeedPoint = (); # C R S
  105. set WSAtlas = 0; # 0=don't use atlas, 1=use atlas (for skull strip)
  106. set WSGcaAtlas = 1; # 1=use GCA atlas and registration to do skull strip
  107. set WSUseTalXfm = 0; # 1=use talairach.xfm instead of talairach_with_skull
  108. # to do atlas alignment during mri_watershed
  109. set WSCopy = 0; # Simply copy input to output ignoring other opts,
  110. # for when brain is already stripped
  111. set DoGcut = 0; # 1=run mri_gcut after mri_watershed
  112. set NuIterations = 2; # Number of iterations for nu intensity correction
  113. set ConformMin = 0; # 1=conformed to min dimension
  114. set ConformKeepDC = 0; # Keep volume direction cosines when conforming
  115. set HiRes = 0; # 1=hires option (conformed to min dimension)
  116. set Norm3dIters = (); # passed as -n to *both* mri_normalize runs
  117. set NormMaxGrad = 1; # passed as -g to *both* mri_normalize runs
  118. set Norm1_b = (); # passed as -b to the *first* mri_normalize only
  119. set Norm1_n = (); # passed as -n to the *first* mri_normalize only
  120. set Norm2_b = (); # passed as -b to the *second* mri_normalize only
  121. set Norm2_n = (); # passed as -n to the *second* mri_normalize only
  122. set WMSeg_wlo = (); # from -seg-ghi and -seg-wlo, passed to mri_segment
  123. set WMSeg_ghi = (); # and mris_make_surfaces
  124. set FixWithGA = 1; # for topology fixer
  125. set FixDiagOnly = 0; # for topology fixer
  126. set RmNeckRadius = 25; # used by mri_remove_neck
  127. set UseCAAlign = (-align); # flag added to mri_ca_label
  128. set UseCAAlignAfter = (-align-after); # flag added to mri_ca_register
  129. set UseAseg = 1 # when set to 0 (using -noaseg),then aseg.presurf.mgz not used
  130. # nor is ?h.cortex.label (which originates through the aseg)
  131. set NoAsegInorm2 = 0 # when set to 1 (using -noaseg-inorm2), then aseg.presurf
  132. # is not used during the 2nd mri_normalize step
  133. set UseNoNeg = 0 # if 1, add '-remove_negative 1' to mris_sphere,mris_register
  134. set NoThicken = 0 # if 1, add '-thicken 0' to mri_segment
  135. set UnCompress = 0 # if 1, add '-uncompress' to mri_ca_reg
  136. set BigVentricles = 0 # if 1, add '-bigventricles' to mri_ca_reg.
  137. # else, add '-nobigventricles'
  138. set DoSecondPassRenorm = 0 # if 1, add -secondpassrenorm to mri_ca_register
  139. set UseOldTopoFix = 1 # if 1, use mris_fix_topology instead of mris_topo_fixer
  140. set UseNewTopoFix = 0 # if 1, use mris_topo_fixer instead of mris_fix_topology
  141. set NoRandomness = 1 # if 1, seed critical binaries with identical seeds, to
  142. # ensure consistency in surface creation. otherwise, the
  143. # default is to seed with current time and date,
  144. # resulting in slightly different surfaces each run.
  145. # affects: mris_smooth, mris_sphere, mris_topology_fixer,
  146. # mris_topo_fixer, mris_ca_label,
  147. # mri_robust_template (1st-base-call-only)
  148. set RngSeed = 1234 # seed for random number generator, used only when
  149. # -norandomness flag is used, and can be overriden by
  150. # the flag -rng-seed <seed>
  151. set DoMultiStrip = 0 # if 1, then multiple instances of mri_watershed and
  152. # mri_em_register are run in order to determine the best
  153. # skull-strip
  154. set IsMPRAGE = 1 # if 1, then -mprage added to mri_normalize/segment, turn off with -no-mprage
  155. set IsWashuMPRAGE = 0 # if 1, then -washu_mprage added to mri_normalize/segment
  156. set DoConformWidth256 = 0 # if 1, then conform to 256^3 during
  157. # the mri_convert -conform step
  158. set NoNormMGZ = 0; # set to 1 when -nosubcortseg or -noaseg flag is used,
  159. # which causes norm.mgz not to used during inorm2 step
  160. set NoWMSA = 0; # if 1, then -nowmsa flag is added to mri_ca_label
  161. set TH3Flag = 1; # turns on new vertex-wise volume calc for mris_anat_stats and ?h.volume
  162. set DoQdecCache = 0; # if 1, then create smoothed fsaverage surface files
  163. set measurelist = ( thickness area area.pial volume curv sulc \
  164. white.K white.H jacobian_white w-g.pct.mgh )
  165. # ^ these are the files smoothed by DoQdecCache (-qcache)
  166. set UserMeasureList = 0; # if 1, then 'measurelist' gets -measure args
  167. set measuredir = (); # for specifying an alternate path to measure files
  168. set fwhmlist = ( 0 5 10 15 20 25 ) # see DoQdecCache
  169. set target = fsaverage # see DoQdecCache
  170. set SmoothCortexOnly = 1; # For -qcache. smooths only within ?h.cortex.label
  171. set DoMakefile = 0; # if 1, run make -f recon-all.makefile $(MakefileTarget)
  172. set MakefileTarget = () # argument to recon-all -make
  173. set DoLabelV1 = 0; # if 1, create V1 label from O.Hinds V1 prediction atlas
  174. set DoRobustMotionCor = 1; # if 1, then use mri_robust_template for motion cor
  175. set mc_robust_template_avg_arg = 1; # when using mri_robust_template for motion
  176. # correction, construct template from: 0 Mean, 1 Median
  177. set UseCuda = 0; # if 1 (-use-cuda), then use GPU versions of tools:
  178. # mri_em_register_cuda, mri_ca_register_cuda,
  179. # mris_inflate_cuda, mris_sphere_cuda
  180. set GetCuda = 0; # if 1 (-get-cuda) then print cuda info and exit
  181. set PialNoAparc = 0; # if 1 (-pial-noaparc), then add -noaparc flag to
  182. # mris_make_surfaces to bypass usage of parcellation
  183. set UseCPsWithCaNorm = 0 # -canorm-usecps enable control points with ca_norm
  184. set DoT2pial = 0; # if 1, mris_make_surfaces refines pial using T2
  185. set T2max = ();
  186. set DoFLAIRpial = 0; # if 1, mris_make_surfaces refines pial using FLAIR
  187. # set multi-threaded stuff to single-threaded/cpu for cluster politeness.
  188. # various binaries (em_reg, ca_reg, mris_sphere) have OpenMP enabled code.
  189. # -openmp <num_threads> allows specifying more threads.
  190. # to support -make, where recon-all is re-entrant, look for FS_OMP_NUM_THREADS
  191. if ($?FS_OMP_NUM_THREADS) then
  192. setenv OMP_NUM_THREADS $FS_OMP_NUM_THREADS # var declared in -openmp
  193. else
  194. setenv OMP_NUM_THREADS 1 # default is one thread, -openmp will override
  195. endif
  196. set OMP_NUM_SET = 0 # set to 1 if -openmp <num> is used
  197. # hippocampal subfields processing uses ITK threading
  198. setenv ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS 1 # -itkthreads <num_threads>
  199. set DoParallel = 0; # if 1, then run with -openmp 4 and -itkthreads 4,
  200. # and run rh/lh stages in parallel
  201. # Longitudinal processing:
  202. set longitudinal = 0; # if 1, will run the longitudinal scheme
  203. set longbaseid = ();
  204. set tpNid = ();
  205. set longbasetotpN_regfile = (); # reg file to align longbase to current subj
  206. set UseConcatLtaTal = 0; # if 1, use mri_concatenate_lta during tal creation
  207. set UseLongbaseCtrlVol = 0; # if 1, use ctrl volume of longbase in norm step
  208. set UseLongbaseWMedits = 0; # if 1, xfer wm edits from base (default is cross)
  209. set UseAsegFusion = 1; # if 0, dont create 'fused' asegs from timepoints
  210. set DoCreateBaseSubj = 0; # if 1, create the 'base' subject used in longitud
  211. set BaseSubjInvol = (orig.mgz); # -base-invol allows using some other file
  212. set BaseSubjsList = (); # subject set grabbed from -base-tp args
  213. set BaseSubjsListFname = (base-tps); # file containing BaseSubjsList
  214. set robust_template_avg_arg = 1; # construct template from: 0 Mean, 1 Median
  215. set DoNuIntensityCor3T = 0; # if 1, use Zheng, Chee, Zagorodnov params for 3T
  216. set DoAddTp = 0; # if 1, then 'fake'-add this timepoint to long subj set
  217. set DoAffineBase = 0; # if 1, allow affine when creating base (fix calibration)
  218. set UseCubic = 0; # if 1, use cubic spline when mri_convert does conform step
  219. set UseFixMtl = 0; # if 1, add -fix_mtl flag to make_surfaces
  220. # Hippocampal subfields:
  221. set DoHippoSF_T1 = 0; # if 1, run hippo subfield seg, exvivo atlas (only T1)
  222. set DoHippoSF_T1T2 = 0;# if 1, run hippo subfield seg, exvivo atlas (T1 and T2)
  223. set DoHippoSF_T2 = 0; # if 1, run hippo subfield seg, exvivo atlas (only T2)
  224. set T2volHippoSF = ();
  225. # Brainstem substructures
  226. set DoBSsubst = 0;
  227. # For defacing, as found in:
  228. # $FREESURFER_HOME/average/
  229. set brain_template = talairach_mixed_with_skull.gca
  230. set face_template = face.gca
  231. # For subcortical segmentation
  232. set GCA = RB_all_2016-05-10.vc700.gca
  233. set GCASkull = RB_all_withskull_2016-05-10.vc700.gca
  234. set GCADIR = "${FREESURFER_HOME}/average"
  235. set GCAOutputName = ();
  236. set GCARegIterations = ();
  237. set GCARegTol = ();
  238. # For cortical registration, as found in $AvgCurvTifPath/$hemi.$AvgCurvTif
  239. set AvgCurvTifPath = "${FREESURFER_HOME}/average"
  240. #set AvgCurvTif = average.curvature.filled.buckner40.tif
  241. #set AvgCurvTif = curvature.buckner40.2016-03-20.tif
  242. set AvgCurvTif = folding.atlas.acfb40.noaparc.i12.2016-08-02.tif
  243. # Desikan-Killiany cortical parcellation atlas (-cortparc), as found in:
  244. # $FREESURFER_HOME/average/$hemi.$GCS
  245. # The 2009-03-04 atlas contains the insula label.
  246. # The 2010-03-25 atlas has a different color for temporalpole (the old
  247. # color was gray, which looked like the default tksurfer surface color).
  248. set OLD_OLD_GCS = curvature.buckner40.filled.desikan_killiany.2007-06-20.gcs
  249. set OLD_GCS = curvature.buckner40.filled.desikan_killiany.2009-03-04.gcs
  250. set NEW_OLD_GCS = curvature.buckner40.filled.desikan_killiany.2010-03-25.gcs
  251. # The GCSs must have been created with the matching folding atlas
  252. set GCS = DKaparc.atlas.acfb40.noaparc.i12.2016-08-02.gcs
  253. set GCSDIR = "${FREESURFER_HOME}/average"
  254. # Christophe Destrieux cortical parcellation atlas (-cortparc2):
  255. set OLD_OLD_DESTRIEUX_GCS = atlas2002_simple.gcs
  256. set OLD_OLD_DESTRIEUX_NAME = a2002s
  257. set OLD_DESTRIEUX_GCS = atlas2005_simple.gcs
  258. set OLD_DESTRIEUX_NAME = a2005s
  259. set NEW_OLD_DESTRIEUX_GCS = destrieux.simple.2009-07-29.gcs
  260. set DESTRIEUX_GCS = CDaparc.atlas.acfb40.noaparc.i12.2016-08-02.gcs
  261. set DESTRIEUX_NAME = a2009s
  262. # Mindboggle cortical parcellation atlas (-cortparc3):
  263. set DKTATLAS40_GCS = DKTatlas40.gcs
  264. set DKTATLAS40_NAME = DKTatlas40
  265. set DKTATLAS_GCS = DKTaparc.atlas.acfb40.noaparc.i12.2016-08-02.gcs
  266. set DKTATLAS_NAME = DKTatlas
  267. # Initialization method for BBR
  268. set BBRInit = coreg; # others are spm, header, rr, best
  269. # Set this to 0 to do everything but run the command.
  270. # This is good for debugging.
  271. set RunIt = 1;
  272. set PatchDir = ();
  273. # print versions and exit
  274. set DoVersionsOnly = 0;
  275. #----- Volume -----------#
  276. set DoConvertInput = 0;
  277. set DoConvertT2Input = 0;
  278. set DoConvertFlairInput = 0;
  279. set DoCreateBaseInput = 0;
  280. set DoMotionCor = 0;
  281. set DoDeface = 0;
  282. set DoNuIntensityCor = 0;
  283. set DoTalairach = 0;
  284. set DoTalCheck = 0;
  285. set DoNormalization = 0;
  286. set DoNormalization2 = 0;
  287. set DoMaskBFS = 0;
  288. set UseControlPoints = 0;
  289. set UseTWMControlPoints = 0;
  290. set DoSkullStrip = 0;
  291. set DoSegmentation = 0;
  292. set DoGCAReg = 0;
  293. set DoCARegInv = 0;
  294. set DoCANormalize = 0;
  295. set DoCAReg = 0;
  296. set DoRemoveNeck = 0;
  297. set DoSkullLTA = 0;
  298. set DoCALabel = 0;
  299. set DoASegMerge = 0;
  300. set DoFill = 0;
  301. #----- Surface -----------#
  302. set DoTessellate = 0;
  303. set SvInitOrigSurf = 0;
  304. set DoSmooth1 = 0;
  305. set DoInflate1 = 0;
  306. set DoQSphere = 0;
  307. set DoFix = 0;
  308. set DoSmooth2 = 0;
  309. set DoInflate2 = 0;
  310. set DoCurvHK = 0;
  311. set DoCurvStats = 0;
  312. set DoSphere = 0;
  313. set DoSurfReg = 0;
  314. set SurfRegToSubj = ();
  315. set DoJacobianWhite = 0;
  316. set DoJacobianDist0 = 0;
  317. set DoContraSurfReg = 0;
  318. set DoContraSurfRegWithinSubject = 0;
  319. set DoAvgCurv = 0;
  320. set DoMorphRGB = 0;
  321. set DoWhiteSurfs = 0;
  322. set DoCortParc = 0;
  323. set DoCortParc2 = 0;
  324. set DoCortParc3 = 0;
  325. set DoPialSurfs = 0;
  326. set DoPctSurfCon = 0;
  327. set DoSurfVolume = 0;
  328. set DoParcStats = 0;
  329. set DoParcStats2 = 0;
  330. set DoParcStats3 = 0;
  331. set DoLocalGyriIndex = 0;
  332. set DoBaLabels = 0;
  333. set DoLabelExvivoEC = 0;
  334. # ----------- Surface and Volume -----------#
  335. set DoCortRibbonVolMask = 0;
  336. set DoRelabelHypos = 0;
  337. set DoAParc2ASeg = 0;
  338. set DoAPas2ASeg = 0;
  339. set DoSegStats = 0;
  340. set DoWMParc = 0;
  341. set DoAParcASegStats = 0;
  342. set DoVnoMatchCheck = 0;
  343. set DoIsRunning = 1;
  344. set IsRunningFile = ();
  345. set DoneFile = ();
  346. setenv LANG C # Required by MNI tool
  347. # -------------------------------------------------- #
  348. set argv0 = ($argv); # make a copy
  349. set PWD = pwd;
  350. # better yet, make sure the real pwd is used:
  351. if ( -e /bin/pwd ) set PWD = /bin/pwd
  352. if($#argv == 0) goto usage_exit;
  353. set n = `echo $argv | egrep -e -help | wc -l`
  354. if($n != 0) then
  355. set PrintHelp = 1;
  356. goto usage_exit;
  357. endif
  358. set n = `echo $argv | egrep -e -version | wc -l`
  359. if($n != 0) then
  360. cat $FREESURFER_HOME/build-stamp.txt
  361. exit 0;
  362. endif
  363. source $FREESURFER_HOME/sources.csh
  364. goto parse_args;
  365. parse_args_return:
  366. goto check_params;
  367. check_params_return:
  368. set StartTime = `date`;
  369. set tSecStart = `date '+%s'`;
  370. # This allows the user to require that the build stamp be
  371. # consistent from one recon-all invocation to the next.
  372. # Good for frozen versions.
  373. if($?REQUIRE_FS_MATCH == 0) setenv REQUIRE_FS_MATCH 0
  374. #echo "REQUIRE_FS_MATCH $REQUIRE_FS_MATCH"
  375. set bstampfile0 = $FREESURFER_HOME/build-stamp.txt
  376. mkdir -p $SUBJECTS_DIR/$subjid/scripts
  377. set bstampfile = $SUBJECTS_DIR/$subjid/scripts/build-stamp.txt
  378. if(-e $bstampfile0) then
  379. if(! -e $bstampfile) cp $bstampfile0 $bstampfile
  380. set bstamp0 = `cat $bstampfile0`
  381. set bstamp = `cat $bstampfile`
  382. if("$bstamp0" != "$bstamp") then
  383. if($REQUIRE_FS_MATCH) then
  384. echo "ERROR: FreeSurfer build stamps do not match"
  385. echo "Subject Stamp: $bstamp"
  386. echo "Current Stamp: $bstamp0"
  387. exit 1;
  388. else
  389. echo "INFO: FreeSurfer build stamps do not match"
  390. endif
  391. endif
  392. echo "Subject Stamp: $bstamp"
  393. echo "Current Stamp: $bstamp0"
  394. endif
  395. rm -f $SUBJECTS_DIR/$subjid/scripts/patchdir.txt
  396. if($?PatchDir) then
  397. echo "$PatchDir" > $SUBJECTS_DIR/$subjid/scripts/patchdir.txt
  398. endif
  399. cp $bstampfile0 $SUBJECTS_DIR/$subjid/scripts/lastcall.build-stamp.txt
  400. if ($DoMakefile) then
  401. setenv RECONALL_MAKE_SUBJECT $subjid
  402. set make_flags=( $MakefileTarget )
  403. if ( ! $RunIt) set make_flags=( -n $make_flags )
  404. echo "Subject '$subjid': make $make_flags"
  405. make -f $FREESURFER_HOME/bin/recon-all.makefile ${make_flags}
  406. set makestatus=($status)
  407. unsetenv RECONALL_MAKE_SUBJECT
  408. exit ($makestatus)
  409. endif
  410. if ($DoTime) then
  411. fs_time ls >& /dev/null
  412. if ( ! $status) set fs_time=(fs_time)
  413. endif
  414. echo "INFO: SUBJECTS_DIR is $SUBJECTS_DIR"
  415. # Get "True" FS HOME
  416. pushd $FREESURFER_HOME > /dev/null
  417. set freesurfer_home_true = `pwd`;
  418. popd > /dev/null
  419. echo "Actual FREESURFER_HOME $freesurfer_home_true"
  420. set DateString = "`date '+%y%m%d%H%M'`"
  421. # -superclean deletes everything except contents of mri/orig
  422. if($DoSuperClean) then
  423. echo "super-cleaning..."
  424. set cmd = (rm -Rfv \
  425. $subjdir/label \
  426. $subjdir/scripts \
  427. $subjdir/stats \
  428. $subjdir/surf \
  429. $subjdir/tmp \
  430. $subjdir/touch \
  431. $subjdir/trash \
  432. $subjdir/mri/transforms)
  433. echo "$cmd"
  434. if($RunIt) $cmd
  435. set cmd = (rm -v $subjdir/mri/* $subjdir/mri/.xdebug*)
  436. echo "$cmd"
  437. if($RunIt) $cmd
  438. endif
  439. cd $subjdir # This variable is set in check_params
  440. mkdir -p mri scripts surf tmp label touch stats touch trash
  441. mkdir -p mri/transforms mri/transforms/bak mri/orig
  442. set touchdir = $subjdir/touch
  443. # Create cmd and env files from scratch
  444. if(! $DoVersionsOnly) then
  445. set CF = ($subjdir/scripts/$CF_DEFAULT_NAME)
  446. # rm -f $CF, let it accumulate commands
  447. echo "\n\n#---------------------------------" >> $CF
  448. echo "# New invocation of recon-all `date` " >> $CF
  449. # Create a separate file for the env
  450. set ENVF = $subjdir/scripts/recon-all.env
  451. if(-e $ENVF) mv -f $ENVF $ENVF.bak
  452. date >> $ENVF
  453. echo "FREESURFER_HOME $FREESURFER_HOME" >> $ENVF
  454. echo "Actual FREESURFER_HOME $freesurfer_home_true" >> $ENVF
  455. pwd >> $ENVF
  456. echo "setenv SUBJECTS_DIR $SUBJECTS_DIR" >> $ENVF
  457. echo $inputargs >> $ENVF
  458. uname -a >> $ENVF
  459. echo "" >> $ENVF
  460. limit >> $ENVF
  461. echo "" >> $ENVF
  462. printenv >> $ENVF
  463. endif
  464. if($DoVersionsOnly) then
  465. if (-e /dev/stdout) then
  466. set LF = /dev/stdout
  467. set SF = /dev/stdout
  468. else
  469. set LF = /dev/null
  470. set SF = /dev/null
  471. endif
  472. endif
  473. # ------------ Create the log file --------------- #
  474. if($#LF == 0) then
  475. set LF = ($subjdir/scripts/$LF_DEFAULT_NAME)
  476. if(-e $LF) then
  477. ls -l $LF
  478. if(! $AppendLog) then
  479. mv -f $LF $LF.old
  480. else
  481. # if running using -make, then dont bother with repeated info dumps
  482. if ($?RECONALL_MAKE_SUBJECT) goto skip_new_invo
  483. echo "\n\n" >> $LF
  484. echo "New invocation of recon-all " >> $LF
  485. echo "\n\n" >> $LF
  486. endif
  487. endif
  488. else
  489. if(-e $LF) then
  490. if ($?RECONALL_MAKE_SUBJECT) goto skip_new_invo
  491. echo "\n\n" >> $LF
  492. echo "New invocation of recon-all " >> $LF
  493. echo "\n\n" >> $LF
  494. endif
  495. endif
  496. skip_new_invo:
  497. date >> $LF
  498. $PWD >> $LF
  499. echo $0 >> $LF
  500. echo $inputargs >> $LF
  501. # if running using -make, then dont bother with repeated info dumps
  502. if ($?RECONALL_MAKE_SUBJECT) goto skip_all_info
  503. echo "subjid $subjid" >> $LF
  504. echo "setenv SUBJECTS_DIR $SUBJECTS_DIR" >> $LF
  505. echo "FREESURFER_HOME $FREESURFER_HOME" >> $LF
  506. echo "Actual FREESURFER_HOME $freesurfer_home_true" >> $LF
  507. if (-e $FREESURFER_HOME/build-stamp.txt) then
  508. echo "build-stamp.txt: `cat $FREESURFER_HOME/build-stamp.txt`" >> $LF
  509. endif
  510. uname -a | tee -a $LF
  511. limit >> $LF
  512. if (-e /usr/bin/free) then
  513. echo "" >> $LF
  514. /usr/bin/free >> $LF
  515. echo "" >> $LF
  516. endif
  517. if ("`uname -s`" == "Darwin") then
  518. echo "" >> $LF
  519. /usr/bin/top -l 1 | grep PhysMem >> $LF
  520. echo "" >> $LF
  521. endif
  522. if($?PBS_JOBID) then
  523. # If the job has been submitted to launchpad, get jobid
  524. echo "pbsjob $PBS_JOBID" >> $LF
  525. endif
  526. # check for existence of bc (binary calculator)
  527. # some minimal installs of centos do not have it
  528. set cmd = (which bc)
  529. $cmd >& /dev/null
  530. if($status) then
  531. echo "ERROR: OS is missing bc (binary calculator) utility" |& tee -a $LF
  532. exit 1;
  533. endif
  534. ## gather all versions here
  535. echo "########################################" >> $LF
  536. echo "program versions used" >> $LF
  537. echo $VERSION >> $LF
  538. mri_motion_correct.fsl -version >> $LF
  539. if (-e $FREESURFER_HOME/bin/flirt.fsl) flirt.fsl -version >> $LF
  540. talairach_avi --version >> $LF
  541. tkregister2_cmdl --all-info >> $LF
  542. nu_correct -version >> $LF
  543. mri_make_uchar -all-info >> $LF
  544. mri_normalize -all-info >> $LF
  545. mri_watershed -all-info >> $LF
  546. mri_gcut -all-info >> $LF
  547. mri_segment -all-info >> $LF
  548. mri_label2label -all-info >> $LF
  549. mri_em_register -all-info >> $LF
  550. mri_ca_normalize -all-info >> $LF
  551. mri_ca_register -all-info >> $LF
  552. mri_ca_label -all-info >> $LF
  553. mri_pretess -all-info >> $LF
  554. mri_fill -all-info >> $LF
  555. mri_tessellate -all-info >> $LF
  556. mri_concatenate_lta -all-info >> $LF
  557. mri_normalize_tp2 -all-info >> $LF
  558. mris_smooth -all-info >> $LF
  559. mris_inflate -all-info >> $LF
  560. mris_curvature -all-info >> $LF
  561. mris_sphere -all-info >> $LF
  562. mris_fix_topology -all-info >> $LF
  563. mris_topo_fixer -all-info >> $LF
  564. mris_ca_label -all-info >> $LF
  565. mris_euler_number -all-info >> $LF
  566. mris_make_surfaces -all-info >> $LF
  567. mris_register -all-info >> $LF
  568. mris_volmask --all-info >> $LF
  569. mris_anatomical_stats -all-info >> $LF
  570. mrisp_paint -all-info >> $LF
  571. mris_curvature_stats -all-info >> $LF
  572. if(-e .xdebug_mris_curvature_stats) rm -f .xdebug_mris_curvature_stats
  573. mris_calc -all-info >> $LF
  574. if(-e .xdebug_mris_calc) rm -f .xdebug_mris_calc
  575. mri_robust_register -all-info >> $LF
  576. mri_robust_template -all-info >> $LF
  577. mri_and -all-info >> $LF
  578. mri_or -all-info >> $LF
  579. mri_fuse_segmentations -all-info >> $LF
  580. mri_segstats -all-info >> $LF
  581. mri_relabel_hypointensities -all-info >> $LF
  582. echo "#######################################" >> $LF
  583. echo "GCADIR $GCADIR" >> $LF
  584. echo "GCA $GCA" >> $LF
  585. echo "GCASkull $GCASkull" >> $LF
  586. echo "AvgCurvTif $AvgCurvTif" >> $LF
  587. echo "GCSDIR $GCSDIR" >> $LF
  588. echo "GCS $GCS" >> $LF
  589. echo "#######################################" >> $LF
  590. skip_all_info:
  591. if($DoVersionsOnly) exit 0;
  592. # Delete the error file. This is created when error_exit is run.
  593. set ErrorFile = $subjdir/scripts/recon-all.error
  594. rm -f $ErrorFile
  595. # Delete the done file. This is created when recon-all exits normally
  596. if($#DoneFile == 0) then
  597. set DoneFile = $subjdir/scripts/recon-all.done
  598. rm -f $DoneFile
  599. endif
  600. # ------------ Create the IsRunning File --------- #
  601. if($DoIsRunning) then
  602. set IsRunningLH = $subjdir/scripts/IsRunning.lh
  603. set IsRunningRH = $subjdir/scripts/IsRunning.rh
  604. set IsRunningLHRH = $subjdir/scripts/IsRunning.lh+rh
  605. set bailfile = ();
  606. if($#hemilist == 1) then
  607. set hemi = $hemilist;
  608. set IsRunningFile = $subjdir/scripts/IsRunning.$hemi
  609. if(-e $IsRunningLHRH) set bailfile = $IsRunningLHRH
  610. else
  611. set IsRunningFile = $subjdir/scripts/IsRunning.lh+rh
  612. if(-e $IsRunningLH) set bailfile = $IsRunningLH
  613. if(-e $IsRunningRH) set bailfile = $IsRunningRH
  614. endif
  615. if(-e $IsRunningFile) set bailfile = $IsRunningFile
  616. if($#bailfile) then
  617. echo ""
  618. echo "ERROR: it appears that recon-all is already running"
  619. echo "for $subjid based on the presence of $bailfile. It could"
  620. echo "also be that recon-all was running at one point but"
  621. echo "died in an unexpected way. If it is the case that there"
  622. echo "is a process running, you can kill it and start over or"
  623. echo "just let it run. If the process has died, you should type:"
  624. echo ""
  625. echo "rm $bailfile"
  626. echo ""
  627. echo "and re-run. Or you can add -no-isrunning to the recon-all"
  628. echo "command-line. The contents of this file are:"
  629. echo "----------------------------------------------------------"
  630. cat $bailfile
  631. echo "----------------------------------------------------------"
  632. exit 1;
  633. endif
  634. echo "------------------------------" > $IsRunningFile
  635. echo "SUBJECT $subjid" >> $IsRunningFile
  636. echo "HEMI $hemilist" >> $IsRunningFile
  637. echo "DATE `date`" >> $IsRunningFile
  638. echo "USER $user" >> $IsRunningFile
  639. echo "HOST `hostname`" >> $IsRunningFile
  640. echo "PROCESSID $$ " >> $IsRunningFile
  641. echo "PROCESSOR `uname -m`" >> $IsRunningFile
  642. echo "OS `uname -s`" >> $IsRunningFile
  643. uname -a >> $IsRunningFile
  644. echo $VERSION >> $IsRunningFile
  645. if($?PBS_JOBID) then
  646. echo "pbsjob $PBS_JOBID" >> $IsRunningFile
  647. endif
  648. endif
  649. # ------- Check FREESURFER_HOME consistency --------------#
  650. set CSDF = $subjdir/scripts/csurfdir
  651. if($DoCleanCSDF) rm -vf $CSDF
  652. if(-e $CSDF) then
  653. set tmp = `cat $CSDF`;
  654. if($tmp != $FREESURFER_HOME) then
  655. echo "INFO: current FREESURFER_HOME does not match that of previous processing." \
  656. | tee -a $LF
  657. echo " Current: $FREESURFER_HOME" | tee -a $LF
  658. echo " Previous: $tmp" | tee -a $LF
  659. sleep 1;
  660. endif
  661. endif
  662. # --------------- Create the status file ---------------- #
  663. if($#SF == 0) then
  664. set SF = ($subjdir/scripts/$SF_DEFAULT_NAME)
  665. if(-e $SF) then
  666. if(! $AppendStatus) then
  667. mv -f $SF $SF.old
  668. else
  669. echo "\n\n" >> $SF
  670. echo "New invocation of recon-all " >> $SF
  671. echo "\n\n" >> $SF
  672. endif
  673. endif
  674. else
  675. if(-e $SF) then
  676. echo "\n\n" >> $SF
  677. echo "New invocation of recon-all " >> $SF
  678. echo "\n\n" >> $SF
  679. endif
  680. endif
  681. echo "status file for recon-all" >> $SF
  682. date >> $SF
  683. # Put a copy of myself (this script) in the scripts dir
  684. if ("`uname -s`" == "Linux") then
  685. set FullProgName = `readlink -f $0`;
  686. cp -v $FullProgName $subjdir/scripts/recon-all.local-copy
  687. endif
  688. # Wait for a file to appear #
  689. if($#WaitForFile != 0) then
  690. echo "Waiting for $WaitForFile" |& tee -a $SF |& tee -a $LF
  691. echo " WaitSleep $WaitSleep" |& tee -a $SF |& tee -a $LF
  692. echo " nWaitsMax $nWaitsMax" |& tee -a $SF |& tee -a $LF
  693. @ nWaits = 1;
  694. while(! -e $WaitForFile && $nWaits < $nWaitsMax)
  695. sleep $WaitSleep;
  696. @ nWaits = $nWaits + 1;
  697. end
  698. if(! -e $WaitForFile ) then
  699. echo "ERROR: timed out waiting for $WaitForFile"
  700. goto error_exit;
  701. endif
  702. echo "Finished Waiting `date`" |& tee -a $SF |& tee -a $LF
  703. endif
  704. if( ! $RunIt) then
  705. echo "INFO: -dontrun flag is in effect, so subsequent commands" |& tee -a $LF
  706. echo "may not have accurate arguments!" |& tee -a $LF
  707. endif
  708. #------------ --------------#
  709. ##----------- -clean --------------#
  710. #------------ --------------#
  711. if($DoCleanSeed) then
  712. set cmd = ("mv -f $subjdir/scripts/seed-*.crs.man.dat $subjdir/trash");
  713. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  714. if($RunIt) $cmd |& tee -a $LF
  715. endif
  716. if($DoCleanCW256) then
  717. set cmd = (mv -f $subjdir/tmp/cw256 $subjdir/trash)
  718. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  719. if($RunIt) $cmd |& tee -a $LF
  720. endif
  721. if($DoCleanTal) then
  722. set cmd = (mv -f $subjdir/mri/transforms/talairach.xfm $subjdir/trash)
  723. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  724. if($RunIt) $cmd |& tee -a $LF
  725. set cmd = (mv -f $subjdir/mri/orig_nu.mgz $subjdir/trash)
  726. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  727. if($RunIt) $cmd |& tee -a $LF
  728. endif
  729. if($DoCleanLta) then
  730. set cmd = ("mv -f $subjdir/mri/transforms/*.lta $subjdir/trash")
  731. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  732. if($RunIt) $cmd |& tee -a $LF
  733. endif
  734. if($DoCleanPFH) then
  735. set cmd = (mv -f $subjdir/mri/optimal_preflood_height $subjdir/trash)
  736. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  737. if($RunIt) $cmd |& tee -a $LF
  738. set cmd = (mv -f $subjdir/mri/optimal_skullstrip_invol $subjdir/trash)
  739. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  740. if($RunIt) $cmd |& tee -a $LF
  741. endif
  742. if($DoCleanBM) then
  743. set cmd = (mv -f $subjdir/mri/brainmask.mgz $subjdir/trash)
  744. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  745. if($RunIt) $cmd |& tee -a $LF
  746. endif
  747. if($DoCleanASeg) then
  748. set cmd = (mv -f $subjdir/mri/aseg.mgz $subjdir/trash)
  749. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  750. if($RunIt) $cmd |& tee -a $LF
  751. set cmd = (mv -f $subjdir/mri/aseg.presurf.mgz $subjdir/trash)
  752. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  753. if($RunIt) $cmd |& tee -a $LF
  754. set cmd = (mv -f $subjdir/mri/aseg.manedit.mgz $subjdir/trash)
  755. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  756. if($RunIt) $cmd |& tee -a $LF
  757. endif
  758. if($DoCleanWM) then
  759. set cmd = (mv -f $subjdir/mri/wm.mgz $subjdir/trash)
  760. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  761. if($RunIt) $cmd |& tee -a $LF
  762. set cmd = (mv -f $subjdir/mri/wm.seg.mgz $subjdir/trash)
  763. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  764. if($RunIt) $cmd |& tee -a $LF
  765. endif
  766. if($DoCleanCP) then
  767. set cmd = (mv -f $subjdir/tmp/control.dat $subjdir/trash)
  768. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  769. if($RunIt) $cmd |& tee -a $LF
  770. endif
  771. if($DoCleanTWM) then
  772. set cmd = (mv -f $subjdir/tmp/twm.dat $subjdir/trash)
  773. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  774. if($RunIt) $cmd |& tee -a $LF
  775. endif
  776. if($DoCleanBFSE) then
  777. set cmd = (mv -f $subjdir/mri/brain.finalsurfs.manedit.mgz $subjdir/trash)
  778. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  779. if($RunIt) $cmd |& tee -a $LF
  780. endif
  781. if($DoCleanXopts) then
  782. set cmd = (mv -f $subjdir/scripts/expert-options $subjdir/trash)
  783. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  784. if($RunIt) $cmd |& tee -a $LF
  785. endif
  786. if($DoCleanT2) then
  787. set mdir = $subjdir/mri
  788. set flist = ($mdir/T2.mgz $mdir/transforms/T2raw.lta $mdir/transforms/T2raw.auto.lta)
  789. foreach f ($flist)
  790. if(-e $f) then
  791. set cmd = (mv -f $f $subjdir/trash)
  792. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  793. if($RunIt) $cmd |& tee -a $LF
  794. endif
  795. end
  796. endif
  797. if($DoCleanFLAIR) then
  798. set mdir = $subjdir/mri
  799. set flist = ($mdir/FLAIR.mgz $mdir/transforms/FLAIRraw.lta $mdir/transforms/FLAIRraw.auto.lta)
  800. foreach f ($flist)
  801. if(-e $f) then
  802. set cmd = (mv -f $f $subjdir/trash)
  803. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  804. if($RunIt) $cmd |& tee -a $LF
  805. endif
  806. end
  807. endif
  808. #------------ Handle Seed Points for Fill/Cut, and Watershed ---------------#
  809. set seedfile = $subjdir/scripts/seed-pons.crs.man.dat
  810. if($#PonsSeedCRS) then
  811. echo "# Manually specified seed CRS for Pons" > $seedfile
  812. echo $PonsSeedCRS >> $seedfile
  813. endif
  814. if(-e $seedfile) set PonsSeedCRS = `cat $seedfile | grep -v \#`
  815. set seedfile = $subjdir/scripts/seed-cc.crs.man.dat
  816. if($#CCSeedCRS) then
  817. echo "# Manually specified seed CRS for CC" > $seedfile
  818. echo $CCSeedCRS >> $seedfile
  819. endif
  820. if(-e $seedfile) set CCSeedCRS = `cat $seedfile | grep -v \#`
  821. set seedfile = $subjdir/scripts/seed-lh.crs.man.dat
  822. if($#LHSeedCRS) then
  823. echo "# Manually specified seed CRS for LH" > $seedfile
  824. echo $LHSeedCRS >> $seedfile
  825. endif
  826. if(-e $seedfile) set LHSeedCRS = `cat $seedfile | grep -v \#`
  827. set seedfile = $subjdir/scripts/seed-rh.crs.man.dat
  828. if($#RHSeedCRS) then
  829. echo "# Manually specified seed CRS for RH" > $seedfile
  830. echo $RHSeedCRS >> $seedfile
  831. endif
  832. if(-e $seedfile) set RHSeedCRS = `cat $seedfile | grep -v \#`
  833. set seedfile = $subjdir/scripts/seed-ws.crs.man.dat
  834. if($#WSSeedPoint) then
  835. echo "# Manually specified seed CRS for watershed" > $seedfile
  836. echo $WSSeedPoint >> $seedfile
  837. endif
  838. if(-e $seedfile) set WSSeedPoint = `cat $seedfile | grep -v \#`
  839. #------------ Control Points for Intensity Normalization -----------#
  840. set ControlPointsFile = $subjdir/tmp/control.dat
  841. if(-e $ControlPointsFile) then
  842. set UseControlPoints = 1;
  843. endif
  844. #------------ Control Points for Registration -----------#
  845. set DefaultTWMControlPointsFile = $subjdir/tmp/twm.dat
  846. if( $UseTWMControlPoints ) then
  847. #copy twmfile to $subjdir/tmp/twm.dat:
  848. set cmd = (mkdir -p ${subjdir}/tmp)
  849. echo "\n $cmd"|& tee -a $LF |& tee -a $CF
  850. if($RunIt) $cmd |& tee -a $LF
  851. set cmd = (cp -vf ${TWMControlPointsFile} $DefaultTWMControlPointsFile)
  852. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  853. if($RunIt) $cmd |& tee -a $LF
  854. if($status) goto error_exit;
  855. set TWMControlPointsFile = $DefaultTWMControlPointsFile
  856. else
  857. if (-e $DefaultTWMControlPointsFile) then
  858. set UseControlPoints = 1;
  859. set TWMControlPointsFile = $DefaultTWMControlPointsFile
  860. endif
  861. endif
  862. #---- ----#
  863. #---- Conform Width to 256 ----#
  864. ##--- -cw256 ----#
  865. if( $DoConformWidth256) then
  866. echo "-cw256 option is now persistent (remove with -clean-cw256)" \
  867. |& tee -a $LF
  868. touch $subjdir/tmp/cw256
  869. endif
  870. #----------- -----------#
  871. ##---------- -show-edits -----------#
  872. #----------- -----------#
  873. # discover which edits a user has made, list them, and if volume edits were
  874. # made, create a file which shows them (using mri_compile_edits)
  875. if($DoShowEdits) then
  876. @ edit_count = 0;
  877. echo "-----------------------------------------------" |& tee -a $LF
  878. echo "Subject $subjid has the following edits..." |& tee -a $LF
  879. # control points
  880. if(-e $ControlPointsFile) then
  881. @ edit_count = $edit_count + 1;
  882. set num_cps = (`grep numpoints $ControlPointsFile | awk '{print $2}'`)
  883. echo "$num_cps control points declared in file $ControlPointsFile" |& tee -a $LF
  884. endif
  885. # seeds
  886. set seedfile = $subjdir/scripts/seed-pons.crs.man.dat
  887. if(-e $seedfile) then
  888. @ edit_count = $edit_count + 1;
  889. echo "Manually specified seed CRS for Pons in file $seedfile" |& tee -a $LF
  890. endif
  891. set seedfile = $subjdir/scripts/seed-cc.crs.man.dat
  892. if($#CCSeedCRS) then
  893. @ edit_count = $edit_count + 1;
  894. echo "Manually specified seed CRS for CC in file $seedfile" |& tee -a $LF
  895. endif
  896. set seedfile = $subjdir/scripts/seed-lh.crs.man.dat
  897. if($#LHSeedCRS) then
  898. @ edit_count = $edit_count + 1;
  899. echo "Manually specified seed CRS for LH in file $seedfile" |& tee -a $LF
  900. endif
  901. set seedfile = $subjdir/scripts/seed-rh.crs.man.dat
  902. if($#RHSeedCRS) then
  903. @ edit_count = $edit_count + 1;
  904. echo "Manually specified seed CRS for RH in file $seedfile" |& tee -a $LF
  905. endif
  906. set seedfile = $subjdir/scripts/seed-ws.crs.man.dat
  907. if($#WSSeedPoint) then
  908. @ edit_count = $edit_count + 1;
  909. echo "Manually specified seed CRS for watershed in file $seedfile" \
  910. |& tee -a $LF
  911. endif
  912. # expert opts
  913. if($#XOptsFile != 0) then
  914. if (-e $XOptsFile) then
  915. @ edit_count = $edit_count + 1;
  916. echo "Expert options declared in file $XOptsFile" |& tee -a $LF
  917. endif
  918. endif
  919. # talairach.xfm
  920. set xfm = $subjdir/mri/transforms/talairach.xfm
  921. set xfma = $subjdir/mri/transforms/talairach.auto.xfm
  922. if(-e $xfm && -e $xfma) then
  923. diff $xfm $xfma >& /dev/null
  924. if($status) then
  925. @ edit_count = $edit_count + 1;
  926. echo "The talairach.xfm file appears to have been edited" |& tee -a $LF
  927. endif
  928. endif
  929. # cw256
  930. if(-e $subjdir/tmp/cw256) then
  931. @ edit_count = $edit_count + 1;
  932. echo "Conform-width (reduce FOV) to 256 is enabled" |& tee -a $LF
  933. endif
  934. # volume edits, as determined by mri_compile_edits:
  935. # brainmask.mgz, aseg.presurf.mgz, brain.finalsurfs.mgz, wm.mgz, brain.mgz
  936. set compile_edits=($subjdir/tmp/compile_edits)
  937. set cmd = (mri_compile_edits ${subjid} $subjdir/mri/edits.mgz)
  938. if($RunIt) then
  939. if ( -e $compile_edits) rm -f $compile_edits
  940. $cmd |& tee -a $LF |& tee -a $compile_edits
  941. set vol_edits=(`grep mri_compile_edits_found $compile_edits | awk '{print $1}'`)
  942. if($#vol_edits != 0) then
  943. @ edit_count = $edit_count + $vol_edits;
  944. endif
  945. endif
  946. # summarize
  947. echo "$edit_count edits were found for subject $subjid" |& tee -a $LF
  948. endif
  949. #----------- -----------#
  950. #----------- Longitudinal -----------#
  951. ##---------- -long and -tp ----------#
  952. #----------- -----------#
  953. if($longitudinal) then
  954. # if adding a new timepoint was requested by -addtp flag
  955. if($DoAddTp) then
  956. echo "Adding $tpNid as timepoint to base $longbaseid" |& tee -a $LF
  957. set cmd=(mri_add_new_tp $longbaseid $tpNid)
  958. if($RunIt) $cmd |& tee -a $LF
  959. if($status) goto error_exit;
  960. endif
  961. # init regfile variable with map cross_tp to base:
  962. # used later in many places
  963. set tpNtobase_regfile = ${longbasedir}/mri/transforms/${tpNid}_to_${longbaseid}.lta
  964. # map control.dat file from the cross-sectional data for this subj
  965. if ( -e ${SUBJECTS_DIR}/${tpNid}/tmp/control.dat && ! $UseLongbaseCtrlVol ) then
  966. # only if it does not already exist:
  967. if ( ! -e ${subjdir}/tmp/control.dat ) then
  968. set cmd = (mkdir -p ${subjdir}/tmp)
  969. echo "\n $cmd"|& tee -a $LF |& tee -a $CF
  970. if($RunIt) $cmd |& tee -a $LF
  971. set cmd = (mri_map_cpdat -in ${SUBJECTS_DIR}/${tpNid}/tmp/control.dat)
  972. set cmd = ($cmd -out ${subjdir}/tmp/control.dat)
  973. set cmd = ($cmd -lta $tpNtobase_regfile)
  974. echo " $cmd \n"|& tee -a $LF |& tee -a $CF
  975. if($RunIt) $cmd |& tee -a $LF
  976. if($status) goto error_exit;
  977. set UseControlPoints = 1;
  978. endif
  979. endif
  980. endif
  981. #----------- -----------#
  982. #----------- Convert T1 Input -----------#
  983. ##---------- -i <file> -----------#
  984. #----------- -----------#
  985. if($#InputList != 0) then
  986. @ nth = 1;
  987. foreach InputVol ($InputList)
  988. set nthid = `printf %03d.mgz $nth`
  989. set cmd = (mri_convert $InputVol $subjdir/mri/orig/$nthid)
  990. $PWD |& tee -a $LF
  991. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  992. if($RunIt) then
  993. $fs_time $cmd |& tee -a $LF
  994. if($status) goto error_exit;
  995. endif
  996. # sanity-check: make sure each input has the same dimensions
  997. if ($nth == 1) then
  998. # assume first input has 'correct' dimensions
  999. set firstInput = $subjdir/mri/orig/$nthid
  1000. set rows = `mri_info --nrows $firstInput |& tail -n 1`
  1001. set cols = `mri_info --ncols $firstInput |& tail -n 1`
  1002. set slices = `mri_info --nslices $firstInput |& tail -n 1`
  1003. else
  1004. # check subsequent against the first input
  1005. set nextInput = $subjdir/mri/orig/$nthid
  1006. set nrows = `mri_info --nrows $nextInput |& tail -n 1`
  1007. set ncols = `mri_info --ncols $nextInput |& tail -n 1`
  1008. set nslices = `mri_info --nslices $nextInput |& tail -n 1`
  1009. if (($nrows != $rows) || ($ncols != $cols) || ($nslices != $slices)) then
  1010. echo "ERROR: inputs have mismatched dimensions!" |& tee -a $LF
  1011. echo "$firstInput is" |& tee -a $LF
  1012. echo "$rows x $cols x $slices while" |& tee -a $LF
  1013. echo "$InputVol is" |& tee -a $LF
  1014. echo "$nrows x $ncols x $nslices" |& tee -a $LF
  1015. goto error_exit;
  1016. endif
  1017. endif
  1018. @ nth = $nth + 1;
  1019. end # loop over input list
  1020. endif
  1021. #----------- -----------#
  1022. #----------- Input T2 or FLAIR images -----------#
  1023. ##---------- -T2 <file> -FLAIR <file> -----------#
  1024. #----------- -----------#
  1025. if ($DoConvertT2Input || $DoConvertFlairInput) then
  1026. echo "#--------------------------------------------" \
  1027. |& tee -a $LF |& tee -a $CF
  1028. echo "#@# T2/FLAIR Input `date`" \
  1029. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1030. if ($DoConvertT2Input) then
  1031. set cmd = (mri_convert \
  1032. --no_scale 1 \
  1033. $InputT2Vol \
  1034. $subjdir/mri/orig/T2raw.mgz)
  1035. $PWD |& tee -a $LF
  1036. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1037. if($RunIt) then
  1038. $fs_time $cmd |& tee -a $LF
  1039. if($status) goto error_exit;
  1040. endif
  1041. endif
  1042. if ($DoConvertFlairInput) then
  1043. set cmd = (mri_convert \
  1044. --no_scale 1 \
  1045. $InputFlairVol \
  1046. $subjdir/mri/orig/FLAIRraw.mgz)
  1047. $PWD |& tee -a $LF
  1048. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1049. if($RunIt) then
  1050. $fs_time $cmd |& tee -a $LF
  1051. if($status) goto error_exit;
  1052. endif
  1053. endif
  1054. endif
  1055. #------------- ------------#
  1056. #------------- Longitudinal 'base' subject input file creation ------------#
  1057. ##------------ -base ------------#
  1058. #------------- ------------#
  1059. if ($DoCreateBaseInput && $DoCreateBaseSubj) then
  1060. echo "#--------------------------------------------" \
  1061. |& tee -a $LF |& tee -a $CF
  1062. echo "#@# Longitudinal Base Subject Creation `date`" \
  1063. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1064. if ($#BaseSubjsList == 0) then
  1065. echo "ERROR: must specify subjects for base subject using -base-tp" \
  1066. |& tee -a $LF
  1067. goto error_exit;
  1068. endif
  1069. cd $subjdir > /dev/null
  1070. $PWD |& tee -a $LF
  1071. if($RunIt) rm -f ${BaseSubjsListFname};
  1072. set subjInVols=();
  1073. set normInVols=();
  1074. set ltaXforms=();
  1075. set lta1forms=();
  1076. set ltaAforms=();
  1077. set headInVols=();
  1078. set geodiff=0;
  1079. foreach s ($BaseSubjsList)
  1080. if($RunIt) echo "${s}" >> ${BaseSubjsListFname};
  1081. set normInVols = ($normInVols ${SUBJECTS_DIR}/${s}/mri/norm.mgz)
  1082. set headInVols = ($headInVols ${SUBJECTS_DIR}/${s}/mri/T1.mgz)
  1083. set subjInVols = ($subjInVols ${SUBJECTS_DIR}/${s}/mri/${BaseSubjInvol})
  1084. set ltaname = ${s}_to_${subjid}.lta
  1085. set ltaXforms = ($ltaXforms ${subjdir}/mri/transforms/${ltaname})
  1086. set lta1forms = ($lta1forms ${subjdir}/mri/transforms/${s}_to_${subjid}_norm.lta)
  1087. set ltaAforms = ($ltaAforms ${subjdir}/mri/transforms/${s}_to_${subjid}_affine.lta)
  1088. # check if geometry differs across time
  1089. if ( "$s" != "$BaseSubjsList[1]" ) then
  1090. set cmd = ( mri_diff --notallow-pix --notallow-geo \
  1091. ${SUBJECTS_DIR}/$s/mri/rawavg.mgz \
  1092. ${SUBJECTS_DIR}/$BaseSubjsList[1]/mri/rawavg.mgz )
  1093. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1094. if($RunIt) then
  1095. $fs_time $cmd |& tee -a $LF
  1096. if($status) set geodiff = 1;
  1097. endif
  1098. endif
  1099. end
  1100. if ( "$geodiff" == "1" ) then
  1101. echo "\n*******************************************************************************" |& tee -a $LF
  1102. echo "WARNING: Image parameters differ across time, maybe due to aquisition changes?" |& tee -a $LF
  1103. echo " Consistent changes in, e.g., resolution can potentially bias a " |& tee -a $LF
  1104. echo " longitudinal study! You can check image parameters by running mri_info" |& tee -a $LF
  1105. echo " on each input image. Will continue in 10 seconds ..." |& tee -a $LF
  1106. echo "*******************************************************************************\n" |& tee -a $LF
  1107. sleep 10
  1108. endif
  1109. if ($#BaseSubjsList == 1) then
  1110. # if only a single time point, create fake 'base' by making the image upright
  1111. # this assures that also subjects with a single time point get processes as the other
  1112. # subjects in the longitudinal stream
  1113. # 1. make the norm upright (base space)
  1114. set cmd = ( make_upright $normInVols[1] \
  1115. ${subjdir}/mri/norm_template.mgz $ltaXforms[1] )
  1116. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1117. if($RunIt) then
  1118. $fs_time $cmd |& tee -a $LF
  1119. if($status) goto error_exit;
  1120. endif
  1121. # 2. create the upright orig volume
  1122. set cmd = ( mri_convert -rt cubic \
  1123. -at $ltaXforms[1] $subjInVols[1] ${subjdir}/mri/orig.mgz )
  1124. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1125. if($RunIt) then
  1126. $fs_time $cmd |& tee -a $LF
  1127. if($status) goto error_exit;
  1128. endif
  1129. else #more than 1 time point:
  1130. # create the 'mean/median' norm volume:
  1131. set cmd = (mri_robust_template --mov ${normInVols})
  1132. if ($DoAffineBase) then
  1133. # this is only initial rigid reg
  1134. set cmd = ($cmd --lta ${lta1forms})
  1135. set cmd = ($cmd --template ${subjdir}/mri/norm1_template.mgz)
  1136. else
  1137. # this is final rigid reg
  1138. set cmd = ($cmd --lta ${ltaXforms})
  1139. set cmd = ($cmd --template ${subjdir}/mri/norm_template.mgz)
  1140. endif
  1141. set cmd = ($cmd --average ${robust_template_avg_arg})
  1142. set cmd = ($cmd --sat 4.685 )
  1143. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1144. if($RunIt) then
  1145. $fs_time $cmd |& tee -a $LF
  1146. if($status) goto error_exit;
  1147. endif
  1148. if ($DoAffineBase) then
  1149. # use registration on norm.mgz to initialize affine reg on full head imgs:
  1150. set cmd = (mri_robust_template --mov ${headInVols})
  1151. set cmd = ($cmd --lta ${ltaAforms})
  1152. set cmd = ($cmd --average ${robust_template_avg_arg})
  1153. set cmd = ($cmd --template ${subjdir}/mri/head_template.mgz)
  1154. set cmd = ($cmd --sat 4.685 )
  1155. set cmd = ($cmd --ixforms ${lta1forms})
  1156. set cmd = ($cmd --affine)
  1157. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1158. if($RunIt) then
  1159. $fs_time $cmd |& tee -a $LF
  1160. if($status) goto error_exit;
  1161. endif
  1162. # use affine reg to init rigid reg on norm.mgz (fine tuning)
  1163. # not sure if it is really necessary
  1164. set cmd = (mri_robust_template --mov ${normInVols})
  1165. set cmd = ($cmd --lta ${ltaXforms})
  1166. set cmd = ($cmd --average ${robust_template_avg_arg})
  1167. set cmd = ($cmd --template ${subjdir}/mri/norm_template.mgz)
  1168. set cmd = ($cmd --sat 4.685 )
  1169. set cmd = ($cmd --ixforms ${ltaAforms})
  1170. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1171. if($RunIt) then
  1172. $fs_time $cmd |& tee -a $LF
  1173. if($status) goto error_exit;
  1174. endif
  1175. endif
  1176. # create the 'mean/median' input (orig) volume:
  1177. set cmd = (mri_robust_template --mov ${subjInVols})
  1178. set cmd = ($cmd --average ${robust_template_avg_arg})
  1179. set cmd = ($cmd --ixforms ${ltaXforms})
  1180. set cmd = ($cmd --noit)
  1181. set cmd = ($cmd --template ${subjdir}/mri/orig.mgz)
  1182. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1183. if($RunIt) then
  1184. $fs_time $cmd |& tee -a $LF
  1185. if($status) goto error_exit;
  1186. endif
  1187. endif # more than one time point
  1188. # now create the inverse transforms
  1189. cd $subjdir/mri/transforms > /dev/null
  1190. $PWD |& tee -a $LF
  1191. foreach s ($BaseSubjsList)
  1192. set cmd = (mri_concatenate_lta -invert1)
  1193. set cmd = ($cmd ${s}_to_${subjid}.lta)
  1194. set cmd = ($cmd identity.nofile)
  1195. set cmd = ($cmd ${subjid}_to_${s}.lta)
  1196. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1197. if($RunIt) then
  1198. $fs_time $cmd |& tee -a $LF
  1199. if($status) goto error_exit;
  1200. endif
  1201. end
  1202. touch $touchdir/base.touch
  1203. endif
  1204. #----------- -------------#
  1205. ##---------- AUTORECON 1 -------------#
  1206. #----------- -------------#
  1207. #----------- -----------#
  1208. #----------- Motion Correct and Average -----------#
  1209. ##---------- -motioncor -----------#
  1210. #----------- -----------#
  1211. if($DoMotionCor) then
  1212. echo "#--------------------------------------------" \
  1213. |& tee -a $LF |& tee -a $CF
  1214. echo "#@# MotionCor `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1215. if ($longitudinal) then
  1216. # longitudinal processing to create orig.mgz:
  1217. # in order to create orig.mgz in LONG we need at least 001.mgz in CROSS:
  1218. if ( ! -e ${SUBJECTS_DIR}/${tpNid}/mri/orig/001.mgz ) then
  1219. echo "ERROR: no CROSS run data found in ${SUBJECTS_DIR}/${tpNid}/mri/orig/. Make sure to" \
  1220. |& tee -a $LF
  1221. echo "have a volume called 001.mgz there." |& tee -a $LF
  1222. echo "If you have a second run of data call it 002.mgz, etc." \
  1223. |& tee -a $LF
  1224. echo "See also: http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Conversion" \
  1225. |& tee -a $LF
  1226. goto error_exit;
  1227. endif
  1228. # use orig/00?.mgz from cross:
  1229. set CrossList = `ls ${SUBJECTS_DIR}/${tpNid}/mri/orig/[0-9][0-9][0-9].mgz`;
  1230. set origvol = $subjdir/mri/orig.mgz
  1231. set rawvol = $subjdir/mri/rawavg.mgz
  1232. if($#CrossList == 1) then
  1233. # if only single input, directly resample to base space
  1234. set cmd = (mri_convert -at $tpNtobase_regfile -odt uchar)
  1235. set cmd = ($cmd -rt cubic)
  1236. set cmd = ($cmd ${SUBJECTS_DIR}/${tpNid}/mri/orig/001.mgz)
  1237. set cmd = ($cmd ${origvol})
  1238. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1239. if($RunIt) $fs_time $cmd |& tee -a $LF
  1240. if($status) goto error_exit;
  1241. # also create rawavg (usually float) image
  1242. set cmd = (mri_convert -at $tpNtobase_regfile )
  1243. set cmd = ($cmd -rt cubic)
  1244. set cmd = ($cmd ${SUBJECTS_DIR}/${tpNid}/mri/orig/001.mgz)
  1245. set cmd = ($cmd ${rawvol})
  1246. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1247. if($RunIt) $fs_time $cmd |& tee -a $LF
  1248. if($status) goto error_exit;
  1249. goto motioncor_post_process
  1250. endif
  1251. # if ltas and iscales exist in cross, copy them over
  1252. set CrossLtas = `ls ${SUBJECTS_DIR}/${tpNid}/mri/orig/[0-9][0-9][0-9].lta`;
  1253. set CrossIscales = `ls ${SUBJECTS_DIR}/${tpNid}/mri/orig/[0-9][0-9][0-9]-iscale.txt`;
  1254. if ( $#CrossLtas > 0 ) then
  1255. # check if one lta for each mgz:
  1256. # here we could better check if really each 00?.mgz has its own 00?.lta in future
  1257. if ( $#CrossList != $#CrossLtas ) then
  1258. echo "ERROR: Orig 00?.mgz runs and number of 00?.lta files must agree in" \
  1259. |& tee -a $LF
  1260. echo "${SUBJECTS_DIR}/${tpNid}/mri/orig/" \
  1261. |& tee -a $LF
  1262. goto error_exit;
  1263. endif
  1264. #copy ltas:
  1265. cd $subjdir/mri/
  1266. set cmd = (cp -vf ${CrossLtas})
  1267. set cmd = ($cmd orig/)
  1268. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1269. if($RunIt) $fs_time $cmd |& tee -a $LF
  1270. if($status) goto error_exit;
  1271. #copy iscales if available:
  1272. if ($#CrossIscales > 0) then
  1273. # here we could better check if really each 00?.mgz has its own iscale file in future
  1274. if ( $#CrossList != $#CrossIscales ) then
  1275. echo "ERROR: Orig 00?.mgz runs and number of 00?-iscale.txt files must agree in" \
  1276. |& tee -a $LF
  1277. echo "${SUBJECTS_DIR}/${tpNid}/mri/orig/" \
  1278. |& tee -a $LF
  1279. goto error_exit;
  1280. endif
  1281. cd $subjdir/mri/
  1282. set cmd = (cp -vf ${CrossIscales})
  1283. set cmd = ($cmd orig/)
  1284. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1285. if($RunIt) $fs_time $cmd |& tee -a $LF
  1286. if($status) goto error_exit;
  1287. endif
  1288. else
  1289. # else the ltas don't exist (maybe because 5.0 or fsl was used,
  1290. # they are created by 5.1+ in cross sectional stream)
  1291. # if more than one input, re-receate the ltas:
  1292. if($#CrossList > 1) then
  1293. # set output names for ltas and iscales in long dir
  1294. set LongLtas = ""
  1295. set LongIscales = ""
  1296. foreach nthid ($CrossList)
  1297. set nthname=`basename $nthid .mgz`
  1298. set nthdir=$subjdir/mri/orig
  1299. set nthlta=${nthdir}/${nthname}.lta
  1300. set LongLtas=($LongLtas $nthlta)
  1301. set LongIscales=($LongIscales $nthdir/${nthname}-iscale.txt)
  1302. end
  1303. # perform motion correction again to obtain the ltas (but in long dir, don't touch cross):
  1304. set rawavg = $subjdir/mri/rawavg.mgz
  1305. # the output rawavg in long will be ignored and not used for anything
  1306. # except maybe debugging, we only need the ltas and iscales!
  1307. set cmd = (mri_robust_template)
  1308. set cmd = ($cmd --mov ${CrossList})
  1309. set cmd = ($cmd --average 1)
  1310. set cmd = ($cmd --template ${rawavg})
  1311. set cmd = ($cmd --satit)
  1312. set cmd = ($cmd --inittp 1)
  1313. set cmd = ($cmd --fixtp)
  1314. set cmd = ($cmd --noit)
  1315. set cmd = ($cmd --iscale)
  1316. set cmd = ($cmd --iscaleout $LongIscales)
  1317. set cmd = ($cmd --subsample 200)
  1318. set cmd = ($cmd --lta $LongLtas)
  1319. echo "#-----------------------------------------------"
  1320. $PWD |& tee -a $LF
  1321. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1322. if($RunIt) then
  1323. $fs_time $cmd |& tee -a $LF
  1324. if($status) goto error_exit;
  1325. endif
  1326. # better get rid of rawavg to avoid confusion
  1327. # as it is not in the base/long space, but in 001.mgz space
  1328. set cmd = (rm -f $rawavg )
  1329. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1330. if($RunIt) then
  1331. $fs_time $cmd |& tee -a $LF
  1332. if($status) goto error_exit;
  1333. endif
  1334. else
  1335. # we should never get here, this case hase been dealt with above
  1336. echo Only single run - should not get here
  1337. goto error_exit;
  1338. endif
  1339. endif
  1340. # now we have the ltas in long (current tp : subjdir)
  1341. set LongLtas = `ls $subjdir/mri/orig/[0-9][0-9][0-9].lta`;
  1342. set LongIscales = `ls $subjdir/mri/orig/[0-9][0-9][0-9]-iscale.txt`;
  1343. # concat ltas (e.g. 002 -> 001 -> base/orig.mgz)
  1344. set ConcatLtas = ""
  1345. foreach nthlta ($LongLtas)
  1346. set nthname=`basename $nthlta .lta`
  1347. set nthdir=$subjdir/mri/orig
  1348. set concatlta=${nthdir}/${nthname}-long.lta
  1349. set ConcatLtas=($ConcatLtas $nthdir/${nthname}-long.lta)
  1350. set cmd = (mri_concatenate_lta $nthlta $tpNtobase_regfile $concatlta)
  1351. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1352. if($RunIt) $fs_time $cmd |& tee -a $LF
  1353. if($status) goto error_exit;
  1354. end
  1355. # use mri_robust_template just to create the average in base orig space:
  1356. set cmd = (mri_robust_template)
  1357. set cmd = ($cmd --mov ${CrossList})
  1358. set cmd = ($cmd --average 1)
  1359. set cmd = ($cmd --ixforms ${ConcatLtas})
  1360. if ($#LongIscales > 0) then
  1361. set cmd = ($cmd --iscalein ${LongIscales})
  1362. endif
  1363. set cmd = ($cmd --noit)
  1364. set cmd = ($cmd --template ${rawvol})
  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. # make sure orig is uchar:
  1371. set cmd = (mri_convert -odt uchar ${rawvol} ${origvol})
  1372. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1373. if($RunIt) then
  1374. $fs_time $cmd |& tee -a $LF
  1375. if($status) goto error_exit;
  1376. endif
  1377. goto motioncor_post_process
  1378. endif #longitudinal
  1379. # base processing (we do not need to do anything,
  1380. # as orig should be there, rawavg is not there, due to difficulties of
  1381. # averaging different image geometries across time)
  1382. if ($DoCreateBaseSubj) then
  1383. set origvol = $subjdir/mri/orig.mgz
  1384. goto motioncor_post_process
  1385. endif
  1386. # default processing:
  1387. set cmd = ();
  1388. # Get list of input run directories #
  1389. set RunList = ();
  1390. ls $subjdir/mri/orig/[0-9][0-9][0-9].mgz >& /dev/null
  1391. if(! $status) then
  1392. set RunList = `ls $subjdir/mri/orig/[0-9][0-9][0-9].mgz`;
  1393. else
  1394. # No runs found
  1395. ls $subjdir/mri//[0-9][0-9][0-9].mgz >& /dev/null
  1396. if(! $status) then
  1397. set RunList = `ls $subjdir/mri//[0-9][0-9][0-9].mgz`;
  1398. endif
  1399. endif
  1400. if($#RunList == 0 && $RunIt) then
  1401. echo "ERROR: no run data found in $subjdir/mri. Make sure to" \
  1402. |& tee -a $LF
  1403. echo "have a volume called 001.mgz in $subjdir/mri/orig." |& tee -a $LF
  1404. echo "If you have a second run of data call it 002.mgz, etc." \
  1405. |& tee -a $LF
  1406. echo "See also: http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Conversion" \
  1407. |& tee -a $LF
  1408. goto error_exit;
  1409. else
  1410. if ($RunIt) then
  1411. echo "Found $#RunList runs" |& tee -a $LF
  1412. foreach run ($RunList)
  1413. echo $run |& tee -a $LF
  1414. end
  1415. endif
  1416. endif
  1417. # sanity-check: check if the input contains multiple frames, which would
  1418. # be the case if a multi-echo frame mprage was accidently used as input.
  1419. # without this check, andre is unhappy
  1420. foreach RunVol ($RunList)
  1421. echo "Checking for (invalid) multi-frame inputs..." |& tee -a $LF
  1422. set nframes = `mri_info --nframes $RunVol |& tail -n 1`
  1423. if ($nframes != 1) then
  1424. echo "ERROR: input(s) cannot have multiple frames!" |& tee -a $LF
  1425. echo "$RunVol has $nframes frames" |& tee -a $LF
  1426. if ($nframes == 4) then
  1427. echo "If this is a multi-frame MEMPRAGE image," |& tee -a $LF
  1428. echo "use mri_concat --rms to combine echo frames." |& tee -a $LF
  1429. endif
  1430. goto error_exit;
  1431. endif
  1432. end
  1433. set origvol = $subjdir/mri/orig.mgz
  1434. set rawavg = $subjdir/mri/rawavg.mgz
  1435. # Only one run, copy to rawavg
  1436. if($#RunList == 1) then
  1437. echo "WARNING: only one run found. This is OK, but motion"|& tee -a $LF
  1438. echo "correction cannot be performed on one run, so I'll"|& tee -a $LF
  1439. echo "copy the run to rawavg and continue."|& tee -a $LF
  1440. sleep 2s;
  1441. set cmd = (cp $RunList $rawavg)
  1442. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1443. if($RunIt) then
  1444. sleep 1; # Sleep here to assure that they have diff time stamps
  1445. $cmd |& tee -a $LF
  1446. if($status) goto error_exit;
  1447. endif
  1448. endif
  1449. # Actually perform the motion correction -- creates rawavg
  1450. if($#RunList > 1) then
  1451. # set names for ltas
  1452. set RunLtas = ""
  1453. set RunIscales = ""
  1454. foreach nthid ($RunList)
  1455. set nthname=`basename $nthid .mgz`
  1456. set nthdir=`dirname $nthid`
  1457. set nthlta=${nthdir}/${nthname}.lta
  1458. set RunLtas=($RunLtas $nthlta)
  1459. set RunIscales=($RunIscales ${nthdir}/${nthname}-iscale.txt)
  1460. end
  1461. if($DoRobustMotionCor) then
  1462. set cmd = (mri_robust_template)
  1463. set cmd = ($cmd --mov ${RunList})
  1464. set cmd = ($cmd --average 1)
  1465. set cmd = ($cmd --template ${rawavg})
  1466. set cmd = ($cmd --satit)
  1467. set cmd = ($cmd --inittp 1)
  1468. set cmd = ($cmd --fixtp)
  1469. set cmd = ($cmd --noit)
  1470. set cmd = ($cmd --iscale)
  1471. set cmd = ($cmd --iscaleout $RunIscales)
  1472. set cmd = ($cmd --subsample 200)
  1473. set cmd = ($cmd --lta $RunLtas)
  1474. else
  1475. # use FSL's flirt to do motion correction (averaging of runs)
  1476. set cmd = (mri_motion_correct.fsl -o $rawavg -wild $RunList)
  1477. endif
  1478. echo "#-----------------------------------------------"
  1479. $PWD |& tee -a $LF
  1480. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1481. if($RunIt) then
  1482. $fs_time $cmd |& tee -a $LF
  1483. if($status) goto error_exit;
  1484. echo $cmd > $touchdir/motion_correct.touch
  1485. endif
  1486. endif
  1487. # At this point, rawavg.mgz exists. Use it to create orig.mgz,
  1488. # conform to COR FOV but keep mgz format.
  1489. set cmd = (mri_convert $rawavg $origvol)
  1490. if($UseCubic) set cmd = ($cmd -rt cubic)
  1491. if($ConformKeepDC) set cmd = ($cmd --conform-dc)
  1492. if($ConformMin) then
  1493. set cmd = ($cmd --conform_min)
  1494. else
  1495. set cmd = ($cmd --conform)
  1496. if($DoConformWidth256 || -e $subjdir/tmp/cw256) then
  1497. # force conform width to 256
  1498. set cmd = ($cmd --cw256)
  1499. # see note just below on when -cw256 is necessary (ie, when FOV > 256)
  1500. endif
  1501. endif
  1502. $PWD |& tee -a $LF
  1503. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1504. if($RunIt) then
  1505. $fs_time $cmd |& tee -a $LF
  1506. if($status) goto error_exit;
  1507. echo $cmd > $touchdir/conform.touch
  1508. endif
  1509. # this is the goto target for longitudinal processing (from above):
  1510. motioncor_post_process:
  1511. # check if FOV > 256 and error exit if so
  1512. set FOV=`mri_info ${origvol} | grep fov: | awk '{print $2}'`
  1513. set FOV_gt_256=`echo "${FOV} > 256" | bc`
  1514. if ($FOV_gt_256) then
  1515. echo "\n****************************************" |& tee -a $LF
  1516. echo "ERROR! FOV=${FOV} > 256" |& tee -a $LF
  1517. echo "Include the flag -cw256 with recon-all!" |& tee -a $LF
  1518. echo "Inspect orig.mgz to ensure the head is fully visible." |& tee -a $LF
  1519. echo "****************************************\n" |& tee -a $LF
  1520. goto error_exit;
  1521. endif
  1522. # Add xfm to orig, even though it does not exist yet. This is a
  1523. # compromise to keep from having to change the time stamp of
  1524. # the orig volume after talairaching.
  1525. set cmd = (mri_add_xform_to_header -c \
  1526. $subjdir/mri/transforms/talairach.xfm \
  1527. $origvol $origvol)
  1528. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1529. if($RunIt) then
  1530. $fs_time $cmd |& tee -a $LF
  1531. if($status) goto error_exit;
  1532. endif
  1533. endif # Motion Correction
  1534. #----------- -----------#
  1535. ##---------- -deface -----------#
  1536. #----------- -----------#
  1537. if($DoDeface) then
  1538. echo "#--------------------------------------------" \
  1539. |& tee -a $LF |& tee -a $CF
  1540. echo "#@# Deface `date`" \
  1541. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1542. cd $subjdir/mri > /dev/null
  1543. set cmd = (mri_deface orig.mgz \
  1544. $FREESURFER_HOME/average/$brain_template \
  1545. $FREESURFER_HOME/average/$face_template \
  1546. orig_defaced.mgz)
  1547. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1548. if($RunIt) $fs_time $cmd |& tee -a $LF
  1549. if($status) goto error_exit;
  1550. touch $touchdir/deface.touch
  1551. endif
  1552. #----------- -----------#
  1553. ##---------- -talairach -----------#
  1554. #----------- -----------#
  1555. if($DoTalairach) then
  1556. talairach:
  1557. echo "#--------------------------------------------" \
  1558. |& tee -a $LF |& tee -a $CF
  1559. echo "#@# Talairach `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1560. cd $subjdir/mri > /dev/null
  1561. $PWD |& tee -a $LF
  1562. set xfma = transforms/talairach.auto.xfm
  1563. set xfm = transforms/talairach.xfm
  1564. if ($longitudinal) then
  1565. # longitudinal processing:
  1566. if( -e $longbasedir/mri/$xfm) then
  1567. set tal_xfm = $xfm
  1568. else
  1569. set tal_xfm = $xfma
  1570. endif
  1571. # copy from the base (as we are now in same space)
  1572. # if edits were made to base, they will be also in long
  1573. set cmd = (cp $longbasedir/mri/$tal_xfm $subjdir/mri/$xfma)
  1574. else
  1575. # default processing:
  1576. # first run bias correction...
  1577. if ($DoTalairachUseNu) then
  1578. # note that this only works if nu exists
  1579. # this is used as an alternative if tal is giving bad results
  1580. set tal_input = nu.mgz
  1581. else
  1582. # default: run one pass of nu_correct, as its been found that scans
  1583. # with strong bias fields can cause talairach_avi to fail. note that
  1584. # this orig_nu.mgz uses the full head, whereas nu.mgz is created using
  1585. # the brainmask, and talairach.xfm used to find the white matter ball.
  1586. set tal_input = orig_nu.mgz
  1587. set cmd = (mri_nu_correct.mni --no-rescale --i orig.mgz --o $tal_input)
  1588. # -3T flag support:
  1589. if ($DoNuIntensityCor3T) then
  1590. # 3T params from Zheng, Chee, Zagorodnov 2009 NeuroImage paper
  1591. # "Improvement of brain segmentation accuracy by optimizing
  1592. # non-uniformity correction using N3"
  1593. # namely specifying iterations, proto-iters and distance:
  1594. set cmd = ($cmd --n 1 --proto-iters 1000 --distance 50)
  1595. else
  1596. # 1.5T default:
  1597. # DNG: changed distance from 200 to 50 to match 5.3
  1598. set cmd = ($cmd --n 1 --proto-iters 1000 --distance 50)
  1599. endif
  1600. # allow expert-options override
  1601. set xopts = `fsr-getxopts mri_nu_correct.mni $XOptsFile`;
  1602. set cmd = ($cmd $xopts)
  1603. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1604. if($RunIt) $fs_time $cmd |& tee -a $LF
  1605. if($status) goto error_exit;
  1606. endif
  1607. # now run the talairach registration...
  1608. if ($UseMincMritotal) then
  1609. # use the MINC mritotal utility
  1610. set xopts = `fsr-getxopts talairach $XOptsFile`;
  1611. set cmd = (talairach --i $tal_input --xfm $xfma $xopts)
  1612. else
  1613. # Avi Snyder's registration tools
  1614. set xopts = `fsr-getxopts talairach_avi $XOptsFile`;
  1615. set cmd = (talairach_avi --i $tal_input --xfm $xfma)
  1616. if($?CustomTalAtlas && "$CustomTalAtlas" != "") then
  1617. # use user-specified atlas found in average dir
  1618. set cmd = ($cmd --atlas "$CustomTalAtlas")
  1619. else
  1620. if($UseYa3tTalAtlas) then
  1621. # special atlas composed of young adults scanned at 3T
  1622. set cmd = ($cmd --atlas 3T18yoSchwartzReactN32_as_orig)
  1623. endif
  1624. endif
  1625. set cmd = ($cmd $xopts)
  1626. endif
  1627. endif
  1628. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1629. if ( ! $UseMincMritotal) then
  1630. echo "talairach_avi log file is transforms/talairach_avi.log..." \
  1631. |& tee -a $LF |& tee -a $CF
  1632. endif
  1633. if($RunIt) $fs_time $cmd |& tee -a $LF
  1634. if($status) goto error_exit;
  1635. if( -e $xfm && ! $DoCleanTal) then
  1636. echo "\nINFO: $xfm already exists!" \
  1637. |& tee -a $LF |& tee -a $CF
  1638. echo "The new $xfma will not be copied to $xfm" \
  1639. |& tee -a $LF |& tee -a $CF
  1640. echo "This is done to retain any edits made to $xfm" \
  1641. |& tee -a $LF |& tee -a $CF
  1642. echo "Add the -clean-tal flag to recon-all to overwrite $xfm\n" \
  1643. |& tee -a $LF |& tee -a $CF
  1644. endif
  1645. if($DoCleanTal || ! -e $xfm) then
  1646. if(-e $xfm) cp $xfm transforms/bak/talairach.xfm.$DateString
  1647. set cmd = (cp $xfma $xfm)
  1648. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1649. if($RunIt) then
  1650. sleep 2; # Sleep here to assure that they have diff time stamps
  1651. $cmd |& tee -a $LF
  1652. if($status) goto error_exit;
  1653. endif
  1654. endif
  1655. echo $cmd > $touchdir/talairach.touch
  1656. endif
  1657. # perform the failure detection scheme
  1658. if($DoTalCheck) then
  1659. echo "#--------------------------------------------" \
  1660. |& tee -a $LF |& tee -a $CF
  1661. echo "#@# Talairach Failure Detection `date`" \
  1662. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1663. cd $subjdir/mri > /dev/null
  1664. # first run Laurence's AFD tool:
  1665. set xopts = `fsr-getxopts talairach_afd $XOptsFile`;
  1666. set xfm = transforms/talairach.xfm
  1667. set cmd = (talairach_afd -T 0.005 -xfm $xfm $xopts)
  1668. set afdTestFailed = 0;
  1669. $PWD |& tee -a $LF
  1670. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1671. if($RunIt) then
  1672. $fs_time $cmd |& tee -a $LF
  1673. if($status) then
  1674. set handleTalErrors = 1;
  1675. goto handle_tal_error;
  1676. endif
  1677. endif
  1678. # now run Avi's QA check on the results found in talairach_avi.log
  1679. # see document RLB700_preprocessing_statistics.pdf for details
  1680. set avilog = ($subjdir/mri/transforms/talairach_avi.log)
  1681. if ( ! $UseMincMritotal && -e $avilog) then
  1682. set cmd = (awk -f $FREESURFER_HOME/bin/extract_talairach_avi_QA.awk)
  1683. set cmd = ($cmd $avilog)
  1684. set qalog = ($subjdir/mri/transforms/talairach_avi_QA.log)
  1685. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1686. set cmd2 = (tal_QC_AZS $avilog)
  1687. set qalog2 = ($subjdir/mri/transforms/talairach_avi_QA2.log)
  1688. echo "\n $cmd2 \n"|& tee -a $LF |& tee -a $CF
  1689. if($RunIt) then
  1690. rm -f $qalog $qalog2
  1691. $fs_time $cmd >& $qalog
  1692. if($status) then
  1693. echo "ERROR: ${cmd} failed! See logfile ${qalog}" |& tee -a $LF
  1694. goto error_exit;
  1695. endif
  1696. # tal_QC_AZS disabled:
  1697. # failing in weird ways. getting caught in infinite 'test' loops.
  1698. if (0) then
  1699. $fs_time $cmd2 >& $qalog2
  1700. set tal_QC_AZS_status = $status
  1701. if($tal_QC_AZS_status) then
  1702. echo "INFO: ${cmd2} failed! See logfile ${qalog2}" |& tee -a $LF
  1703. echo " skipping tal_QC_AZS test" |& tee -a $LF
  1704. #NJS: skip instead of exit because tal_QC_AZS doesnt work on centos5.4
  1705. #goto error_exit;
  1706. endif
  1707. endif
  1708. # first set of QA data:
  1709. set talAviQA=`grep "TalAviQA" ${qalog} | awk '{print $2}'`
  1710. echo "TalAviQA: ${talAviQA}" |& tee -a $LF
  1711. set mean=(0.9781) # buckner40 mean TalAviQA
  1712. set std=(0.0044) # buckner40 std TalAviQA
  1713. set zscore=`echo "scale=0;(${talAviQA} - ${mean}) / ${std}" | bc`
  1714. echo "z-score: ${zscore}" |& tee -a $LF
  1715. set zscoreThreshold=(-9) # conservative value, but catches M.Harms subjs.
  1716. # tal_QC_AZS disabled:
  1717. if (0) then
  1718. # second set:
  1719. if ( ! $tal_QC_AZS_status ) then
  1720. set talAviQA2=`grep "atlas_transform_error" ${qalog2} | awk '{print $6}'`
  1721. echo "TalAviQA2: ${talAviQA2}" |& tee -a $LF
  1722. set atlaserrhi=`echo "${talAviQA2} > 24" | bc`
  1723. set atlaserrlo=`echo "${talAviQA2} < -60" | bc`
  1724. else
  1725. set talAviQA2=0
  1726. set atlaserrhi=0
  1727. set atlaserrlo=0
  1728. endif
  1729. else
  1730. set talAviQA2=0
  1731. set atlaserrhi=0
  1732. set atlaserrlo=0
  1733. endif
  1734. # check scores:
  1735. set handleTalErrors = 0;
  1736. if (($zscore < $zscoreThreshold) || $atlaserrhi || $atlaserrlo) then
  1737. echo "WARNING: Talairach QA check failed!" |& tee -a $LF
  1738. echo "z-score of ${zscore} is <= threshold of ${zscoreThreshold}\n" \
  1739. |& tee -a $LF
  1740. # tal_QC_AZS disabled:
  1741. if (0) then
  1742. echo "or the atlas xform error of $talAviQA2 is < -60 | > 24" \
  1743. |& tee -a $LF
  1744. endif
  1745. set handleTalErrors = 1;
  1746. endif
  1747. handle_tal_error:
  1748. if ($handleTalErrors) then
  1749. echo "\nManual Talairach alignment may be necessary, or" |& tee -a $LF
  1750. echo "include the -notal-check flag to skip this test," |& tee -a $LF
  1751. echo "making sure the -notal-check flag follows -all" |& tee -a $LF
  1752. echo "or -autorecon1 in the command string." |& tee -a $LF
  1753. echo "See:\n" |& tee -a $LF
  1754. echo "http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Talairach" \
  1755. |& tee -a $LF
  1756. echo "" |& tee -a $LF
  1757. # IF Talairach alignment was run
  1758. # AND it was using the default (711-2C) atlas
  1759. # AND a check failed,
  1760. # THEN first retry avi method using newer 3T Schwartz atlas
  1761. # THEN (if that fails) try Talairach alignment using MINC mritotal tool
  1762. # ELSE error exit
  1763. if($DoTalairach && ! $UseMincMritotal && ! $longitudinal && \
  1764. ! $UseYa3tTalAtlas ) then
  1765. echo "INFO: Retrying Talairach align using 3T-based atlas...\n" \
  1766. |& tee -a $LF
  1767. set UseYa3tTalAtlas = 1; # try 3T-based atlas
  1768. set UseMincMritotal = 0;
  1769. set DoCleanTal = 1;
  1770. goto talairach;
  1771. else if($DoTalairach && ! $UseMincMritotal && ! $longitudinal) then
  1772. echo "INFO: Trying MINC mritotal to perform Talairach align...\n" \
  1773. |& tee -a $LF
  1774. set UseMincMritotal = 1;
  1775. set DoCleanTal = 1;
  1776. goto talairach;
  1777. else
  1778. echo "\nERROR: Talairach failed!\n" |& tee -a $LF
  1779. goto error_exit;
  1780. endif
  1781. endif
  1782. endif
  1783. endif
  1784. endif
  1785. #----------- -----------#
  1786. #----------- Nu Intensity Correction -----------#
  1787. ##---------- -nuintensitycor -----------#
  1788. #----------- -----------#
  1789. if($DoNuIntensityCor) then
  1790. echo "#--------------------------------------------" \
  1791. |& tee -a $LF |& tee -a $CF
  1792. echo "#@# Nu Intensity Correction `date`" \
  1793. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1794. cd $subjdir/mri > /dev/null
  1795. set xopts = `fsr-getxopts mri_nu_correct.mni $XOptsFile`;
  1796. set cmd = (mri_nu_correct.mni --i orig.mgz --o nu.mgz)
  1797. # to fix a problem with mri_nu_correct.mni messing with the histogramming
  1798. # in some odd subjects (due to voxels outside the brain, which has the
  1799. # effect of altering white matter intensity interpretation downstream),
  1800. # the inclusion of talairach.xfm with mri_nu_correct.mni causes
  1801. # mri_make_uchar to run, which uses the Tal xform to find a ball of voxels
  1802. # that are mostly brain. The top of the intensity histogram in this ball
  1803. # will then be white matter, which allows us to center it at the desired
  1804. # value, approximately (110).
  1805. if ($DoNuMakeUchar) then
  1806. if ( ! -e transforms/talairach.xfm && $RunIt) then
  1807. echo "WARNING: transforms/talairach.xfm does not exist!" \
  1808. |& tee -a $LF
  1809. echo "It will not be used by mri_nu_correct.mni." \
  1810. |& tee -a $LF
  1811. else
  1812. set cmd = ($cmd --uchar transforms/talairach.xfm)
  1813. endif
  1814. endif
  1815. # --cm for hi-res support:
  1816. if ($ConformMin) set cmd = ($cmd --cm)
  1817. # -3T flag support:
  1818. if ($DoNuIntensityCor3T) then
  1819. # 3T params from Zheng, Chee, Zagorodnov 2009 NeuroImage paper
  1820. # "Improvement of brain segmentation accuracy by optimizing
  1821. # non-uniformity correction using N3"
  1822. # namely specifying iterations, proto-iters and distance:
  1823. set NuIterations = 1;
  1824. set cmd = ($cmd --proto-iters 1000 --distance 50)
  1825. endif
  1826. # add user-specified option (from an 'experts file')
  1827. set cmd = ($cmd --n $NuIterations $xopts)
  1828. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1829. if($RunIt) $fs_time $cmd |& tee -a $LF
  1830. if($status) goto error_exit;
  1831. # Add xfm to nu
  1832. set cmd = (mri_add_xform_to_header -c \
  1833. $subjdir/mri/transforms/talairach.xfm \
  1834. nu.mgz nu.mgz)
  1835. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1836. if($RunIt) then
  1837. $fs_time $cmd |& tee -a $LF
  1838. if($status) goto error_exit;
  1839. endif
  1840. if($?CREATE_NU_DIFF_FILES) then
  1841. # for debug, create difference volumes between orig and nu files
  1842. set cmd1 = (mri_diff orig.mgz orig_nu.mgz --diff diff-orig-orig_nu.mgz)
  1843. set cmd2 = (mri_diff orig.mgz nu.mgz --diff diff-orig-nu.mgz)
  1844. set cmd3 = (mri_diff orig_nu.mgz nu.mgz --diff diff-orig_nu-nu.mgz)
  1845. echo "\n $cmd1 \n" |& tee -a $LF |& tee -a $CF
  1846. echo "\n $cmd2 \n" |& tee -a $LF |& tee -a $CF
  1847. echo "\n $cmd3 \n" |& tee -a $LF |& tee -a $CF
  1848. if($RunIt) then
  1849. $fs_time $cmd1 |& tee -a $LF
  1850. $fs_time $cmd2 |& tee -a $LF
  1851. $fs_time $cmd3 |& tee -a $LF
  1852. endif
  1853. endif
  1854. # done:
  1855. date > $touchdir/nu.touch
  1856. endif
  1857. #----------- -----------#
  1858. #----------- Intensity Normalization1 -----------#
  1859. ##---------- -normalization -----------#
  1860. #----------- -----------#
  1861. if($DoNormalization) then
  1862. echo "#--------------------------------------------" \
  1863. |& tee -a $LF |& tee -a $CF
  1864. echo "#@# Intensity Normalization `date`" \
  1865. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1866. cd $subjdir/mri > /dev/null
  1867. $PWD |& tee -a $LF
  1868. set xopts = `fsr-getxopts mri_normalize $XOptsFile`;
  1869. if ( $longitudinal && $UseLongbaseCtrlVol) then
  1870. # longitudinal processing stream AND using ctrl_vol.mgz from base:
  1871. if( ! -e $longbasedir/mri/ctrl_vol.mgz || \
  1872. ! -e $longbasedir/mri/bias_vol.mgz ) then
  1873. echo "Recompute intensity norm to create $longbaseid ctrl_vol.mgz" \
  1874. |& tee -a $LF
  1875. set cmd = (mri_normalize)
  1876. if($#Norm3dIters) set cmd = ($cmd -n $Norm3dIters)
  1877. if($#Norm1_b) set cmd = ($cmd -b $Norm1_b)
  1878. if($#Norm1_n) set cmd = ($cmd -n $Norm1_n)
  1879. if($IsMPRAGE) set cmd = ($cmd -mprage)
  1880. if($IsWashuMPRAGE) set cmd = ($cmd -washu_mprage)
  1881. set cmd = ($cmd \
  1882. -mask $longbasedir/mri/brain.mgz \
  1883. -W $longbasedir/mri/ctrl_vol.mgz $longbasedir/mri/bias_vol.mgz \
  1884. $longbasedir/mri/nu.mgz \
  1885. $longbasedir/mri/T1_tmp.mgz)
  1886. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1887. if($RunIt) $fs_time $cmd |& tee -a $LF
  1888. if($status) goto error_exit;
  1889. if( ! -e $longbasedir/mri/ctrl_vol.mgz ) then
  1890. echo "ERROR: unable to generate cntl-point volume for longbase" \
  1891. |& tee -a $LF
  1892. goto error_exit;
  1893. endif
  1894. rm -f $longbasedir/mri/T1_tmp.mgz
  1895. endif
  1896. # use ctrl_vol.mgz from base for normalization:
  1897. set cmd = (mri_normalize \
  1898. -w $subjdir/mri/ctrl_vol.mgz $subjdir/mri/bias_vol.mgz \
  1899. -l $longbasedir/mri/ctrl_vol.mgz $longbasedir/mri/bias_vol.mgz \
  1900. $subjdir/mri/nu.mgz \
  1901. $subjdir/mri/T1.mgz)
  1902. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1903. if($RunIt) $fs_time $cmd |& tee -a $LF
  1904. if($status) goto error_exit;
  1905. else
  1906. if ( $longitudinal ) then
  1907. # the longitudinal stream skips the talairach step, so orig_nu does not
  1908. # get created, so create it now...
  1909. set cmd = (mri_nu_correct.mni --no-rescale --i orig.mgz --o orig_nu.mgz)
  1910. # -3T flag support:
  1911. if ($DoNuIntensityCor3T) then
  1912. # 3T params from Zheng, Chee, Zagorodnov 2009 NeuroImage paper
  1913. # "Improvement of brain segmentation accuracy by optimizing
  1914. # non-uniformity correction using N3"
  1915. # namely specifying iterations, proto-iters and distance:
  1916. set cmd = ($cmd --n 1 --proto-iters 1000 --distance 50)
  1917. else
  1918. # 1.5T default:
  1919. set cmd = ($cmd --n 1 --proto-iters 1000 --distance 200)
  1920. endif
  1921. # allow expert-options override
  1922. set xopts = `fsr-getxopts mri_nu_correct.mni $XOptsFile`;
  1923. set cmd = ($cmd $xopts)
  1924. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1925. if($RunIt) $fs_time $cmd >& orig_nu.log
  1926. if($status) goto error_exit;
  1927. endif
  1928. # for cross, base (and long if not useLongBaseCtrlVol) processing streams:
  1929. set cmd = (mri_normalize -g $NormMaxGrad);
  1930. if($UseControlPoints) set cmd = ($cmd -f $ControlPointsFile)
  1931. if($#Norm3dIters) set cmd = ($cmd -n $Norm3dIters)
  1932. if($#Norm1_b) set cmd = ($cmd -b $Norm1_b)
  1933. if($#Norm1_n) set cmd = ($cmd -n $Norm1_n)
  1934. if($IsMPRAGE) set cmd = ($cmd -mprage)
  1935. if($IsWashuMPRAGE) set cmd = ($cmd -washu_mprage)
  1936. if($ConformMin) set cmd = ($cmd -noconform)
  1937. # in base create the ctrl_vol.mgz for init longs later:
  1938. if($DoCreateBaseSubj) set cmd = ($cmd -W ctrl_vol.mgz bias_vol.mgz)
  1939. set cmd = ($cmd $xopts nu.mgz T1.mgz)
  1940. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1941. if($RunIt) $fs_time $cmd |& tee -a $LF
  1942. if($status) goto error_exit;
  1943. endif
  1944. echo $cmd > $touchdir/inorm1.touch
  1945. endif
  1946. #----------- -----------#
  1947. #----------- Skull Stripping -----------#
  1948. ##---------- -skullstrip -----------#
  1949. #----------- -----------#
  1950. if($DoSkullStrip) then
  1951. skullstrip:
  1952. echo "#--------------------------------------------" \
  1953. |& tee -a $LF |& tee -a $CF
  1954. echo "#@# Skull Stripping `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  1955. cd $subjdir/mri > /dev/null
  1956. $PWD |& tee -a $LF
  1957. if ($longitudinal) then
  1958. # longitudinal processing stream (copy from base):
  1959. set BM = brainmask.mgz
  1960. set BMA = brainmask.auto.mgz
  1961. set bmbase = brainmask_${longbaseid}.mgz
  1962. set cmd = (cp -vf ${longbasedir}/mri/${BM} ./${bmbase})
  1963. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1964. if($RunIt) $fs_time $cmd |& tee -a $LF
  1965. if($status) goto error_exit;
  1966. # first apply mask and keep deletion edits (1)
  1967. set cmd = (mri_mask -keep_mask_deletion_edits)
  1968. set cmd = ($cmd T1.mgz ${bmbase} ${BMA})
  1969. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  1970. if($RunIt) $fs_time $cmd |& tee -a $LF
  1971. if($status) goto error_exit;
  1972. # then transfer the 255 edits (still keep deletions)
  1973. set cmd = (mri_mask -transfer 255)
  1974. set cmd = ($cmd -keep_mask_deletion_edits)
  1975. set cmd = ($cmd $BMA ${bmbase} $BMA)
  1976. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  1977. if($RunIt) $fs_time $cmd |& tee -a $LF
  1978. if($status) goto error_exit;
  1979. goto skipped_skullstrip;
  1980. endif
  1981. # base subject stream:
  1982. if($DoCreateBaseSubj) then
  1983. set BMA = brainmask.auto.mgz
  1984. set BM = brainmask.mgz #used later
  1985. # create lists with all cross brainmasks and all ltas:
  1986. set bmInVols=""
  1987. set ltaXforms=""
  1988. foreach s ($BaseSubjsList)
  1989. set bmInVols = ($bmInVols ${SUBJECTS_DIR}/${s}/mri/brainmask.mgz)
  1990. set ltaname = ${s}_to_${subjid}.lta
  1991. set ltaXforms = ($ltaXforms ${subjdir}/mri/transforms/${ltaname})
  1992. end
  1993. if ($#bmInVols == 1) then
  1994. # only a single time point in base
  1995. set cmd = (mri_convert \
  1996. -at $ltaXforms[1] \
  1997. -rt nearest \
  1998. $bmInVols[1] brainmask_template.mgz )
  1999. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2000. if($RunIt) then
  2001. $fs_time $cmd |& tee -a $LF
  2002. if($status) goto error_exit;
  2003. endif
  2004. else
  2005. # map all brainmask with nearest neighbor and average 0=mean=logicalOR:
  2006. set cmd = (mri_robust_template --mov ${bmInVols})
  2007. set cmd = ($cmd --average 0)
  2008. set cmd = ($cmd --ixforms ${ltaXforms})
  2009. set cmd = ($cmd --noit)
  2010. set cmd = ($cmd --finalnearest)
  2011. set cmd = ($cmd --template brainmask_template.mgz)
  2012. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2013. if($RunIt) then
  2014. $fs_time $cmd |& tee -a $LF
  2015. if($status) goto error_exit;
  2016. endif
  2017. endif # more than 1 tp
  2018. # create brainmask.auto by applying brainmask_template to T1
  2019. # first apply mask and keep deletion edits (1)
  2020. set cmd = (mri_mask -keep_mask_deletion_edits)
  2021. set cmd = ($cmd T1.mgz brainmask_template.mgz $BMA)
  2022. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2023. if($RunIt) $fs_time $cmd |& tee -a $LF
  2024. if($status) goto error_exit;
  2025. # then copy over the 255 (edits) and still keep deletions (1)
  2026. set cmd = (mri_mask -transfer 255)
  2027. set cmd = ($cmd -keep_mask_deletion_edits)
  2028. set cmd = ($cmd $BMA brainmask_template.mgz $BMA)
  2029. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2030. if($RunIt) $fs_time $cmd |& tee -a $LF
  2031. if($status) goto error_exit;
  2032. goto skipped_skullstrip;
  2033. endif
  2034. # default stream...
  2035. set xopts = `fsr-getxopts mri_watershed $XOptsFile`;
  2036. set opts = ();
  2037. if($WaterShed == 0) set opts = ($opts -n);
  2038. if($WaterShed == 2) set opts = ($opts -wat);
  2039. if($WaterShed == 3) set opts = ($opts -wat+temp);
  2040. if($WaterShed == 4) set opts = ($opts -atlas);
  2041. if($WSLess) set opts = ($opts -less);
  2042. if($WSMore) set opts = ($opts -more);
  2043. if($WSAtlas) set opts = ($opts -atlas);
  2044. if($WSCopy) set opts = ($opts -copy);
  2045. if($#WSSeedPoint != 0) set opts = ($opts -s $WSSeedPoint);
  2046. if($#WSPctPreFlood != 0) then
  2047. set opts = ($opts -h $WSPctPreFlood);
  2048. set DoMultiStrip = 0
  2049. else if( -e optimal_preflood_height) then
  2050. set WSPctPreFlood = `cat optimal_preflood_height`
  2051. set opts = ($opts -h $WSPctPreFlood);
  2052. set DoMultiStrip = 0
  2053. echo "Using optimal preflood height of $WSPctPreFlood" |& tee -a $LF
  2054. endif
  2055. set cmd = (mri_watershed)
  2056. set cmd = ($cmd -rusage $touchdir/rusage.mri_watershed.dat)
  2057. set BM = brainmask.mgz
  2058. if ($WSGcaAtlas || $DoMultiStrip) then
  2059. if ( ! $WSUseTalXfm) then # dont bother if using talairach.xfm
  2060. # if using the GCA atlas to help with the skull-strip, then run the
  2061. # GCA registration (mri_em_register) to align to an atlas with a skull,
  2062. # unless that file already exists
  2063. if ( ! -e transforms/talairach_with_skull.lta || $DoCleanLta ) then
  2064. if($NoEMReg == 0) then
  2065. set xopts2 = `fsr-getxopts mri_em_register $XOptsFile`;
  2066. set cmd2 = (mri_em_register)
  2067. if($UseCuda) set cmd2 = (mri_em_register_cuda)
  2068. set cmd2 = ($cmd2 -rusage $touchdir/rusage.mri_em_register.skull.dat)
  2069. set cmd2 = ($cmd2 -skull)
  2070. set cmd2 = ($cmd2 $xopts2 nu.mgz ${GCADIR}/$GCASkull)
  2071. set cmd2 = ($cmd2 transforms/talairach_with_skull.lta)
  2072. else
  2073. # Convert talairach.xfm to LTA format
  2074. set mni305 = $FREESURFER_HOME/average/mni305.cor.mgz
  2075. set xfm = transforms/talairach.xfm
  2076. set lta = transforms/talairach_with_skull.lta
  2077. set cmd2 = (lta_convert --src orig.mgz --trg $mni305 \
  2078. --inxfm $xfm --outlta $lta --subject fsaverage --ltavox2vox)
  2079. endif
  2080. echo "\n $cmd2 \n"|& tee -a $LF |& tee -a $CF
  2081. if($RunIt) $fs_time $cmd2 |& tee -a $LF
  2082. if($status) goto error_exit;
  2083. echo $cmd2 > $touchdir/skull.lta.touch
  2084. endif
  2085. endif
  2086. if ($WSGcaAtlas) then
  2087. # if just using -brain_atlas flag, then include necessary options
  2088. if ($WSUseTalXfm) then
  2089. set opts = (-brain_atlas ${GCADIR}/$GCASkull \
  2090. transforms/talairach.xfm $opts)
  2091. else
  2092. set opts = (-brain_atlas ${GCADIR}/$GCASkull \
  2093. transforms/talairach_with_skull.lta $opts)
  2094. endif
  2095. endif
  2096. endif
  2097. if($DoMultiStrip) then
  2098. # when DoMultiStrip is enabled, multiple instances of mri_watershed are
  2099. # run each using the following preflood height parameters
  2100. if ( $?WATERSHED_PREFLOOD_HEIGHTS ) then
  2101. # externally specified in the environment
  2102. set PREFLOOD_HEIGHTS = ( $WATERSHED_PREFLOOD_HEIGHTS )
  2103. else
  2104. # defaults:
  2105. set PREFLOOD_HEIGHTS = ( 5 10 20 30 )
  2106. endif
  2107. set SS_VOLUMES = ( orig orig_nu T1 )
  2108. if ( $?GOTO_LL_CALC ) goto ll_calc
  2109. # create command files, one job for each volume type and preflood height...
  2110. set CMDFS = ()
  2111. foreach vol ( $SS_VOLUMES )
  2112. foreach pfh ( $PREFLOOD_HEIGHTS )
  2113. set cmd = (mri_watershed)
  2114. set cmd = ($cmd -rusage $touchdir/rusage.mri_watershed.dat)
  2115. set BMA_OLD = brainmask.auto.mgz
  2116. set BMA = brainmask_${vol}_PFH${pfh}.auto.mgz
  2117. if(-e $BMA_OLD && -e $BM && ! $DoCleanBM) then
  2118. set cmd = ($cmd -keep $BMA_OLD $BM $BMA)
  2119. endif
  2120. set cmd = ($cmd $opts -h ${pfh} $xopts ${vol}.mgz $BMA)
  2121. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2122. set CMDF = mri_watershed_${vol}_PFH${pfh}.cmd
  2123. echo "$cmd" > $CMDF
  2124. set CMDFS = ( $CMDFS $CMDF )
  2125. end
  2126. end
  2127. # and launch parallel jobs and wait for completion.
  2128. # the reconbatchjobs script will append each job output to $LF
  2129. if($RunIt) then
  2130. reconbatchjobs $LF $CMDFS
  2131. if($status) then
  2132. # don't exit, since some may encounter 'preflood height' failures
  2133. echo "WARNING: Some multi-skullstrip operations may have failed!" \
  2134. |& tee -a $LF |& tee -a $CF
  2135. echo " Continuing multi-skullstrip with the others..." \
  2136. |& tee -a $LF |& tee -a $CF
  2137. endif
  2138. endif
  2139. # brainmask volumes actually need to be T1 volumes, because while
  2140. # mri_watershed may run best in some cases using orig.mgz as input,
  2141. # we really want the brainmask to be from T1.mgz (post normalization)
  2142. set CMDFS = ()
  2143. foreach pfh ( $PREFLOOD_HEIGHTS )
  2144. set BMA_ORIG = brainmask_orig_PFH${pfh}.auto.mgz
  2145. if ( -e $BMA_ORIG ) then
  2146. set cmd = (mri_mask T1.mgz $BMA_ORIG $BMA_ORIG)
  2147. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2148. set CMDF = mri_mask_PFH${pfh}.cmd
  2149. echo "$cmd" > $CMDF
  2150. set CMDFS = ( $CMDFS $CMDF )
  2151. endif
  2152. end
  2153. # and launch parallel jobs and wait for completion.
  2154. # the reconbatchjobs script will append each job output to $LF
  2155. if($RunIt) then
  2156. if($#CMDFS != 0) then
  2157. reconbatchjobs $LF $CMDFS
  2158. if($status) goto error_exit;
  2159. endif
  2160. endif
  2161. echo $cmd > $touchdir/skull_strip.touch
  2162. # calculate a measure of skull-strip performance (mri_log_likelihood):
  2163. ll_calc:
  2164. set max_ll = -9999999999;
  2165. set best_pfh = 0;
  2166. set best_vol = ();
  2167. set xopts = `fsr-getxopts mri_log_likelihood $XOptsFile`;
  2168. foreach vol ( $SS_VOLUMES )
  2169. foreach pfh ( $PREFLOOD_HEIGHTS )
  2170. set BMA = brainmask_${vol}_PFH${pfh}.auto.mgz
  2171. if ( ! -e $BMA) continue;
  2172. set LTA = transforms/talairach_with_skull.lta
  2173. set cmd = (mri_log_likelihood -orig T1.mgz $BMA)
  2174. set cmd = ($cmd $xopts ${GCADIR}/$GCA $LTA)
  2175. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2176. if($RunIt) then
  2177. $cmd |& tee -a $LF |& tee -a ll_tmp
  2178. # extract the last line of output, containing the result
  2179. set ll = `tail -n 1 ll_tmp`
  2180. rm -f ll_tmp
  2181. endif
  2182. if($status) goto error_exit;
  2183. # and make the best result the brainmask.auto.mgz
  2184. if($RunIt) then
  2185. echo "$BMA log_likelihood= $ll" |& tee -a $LF
  2186. if ("$ll" == "nan") continue
  2187. if ($ll > $max_ll) then
  2188. set max_ll = $ll;
  2189. set best_pfh = $pfh;
  2190. set best_vol = $vol;
  2191. rm -f brainmask.auto.mgz
  2192. cp $BMA brainmask.auto.mgz
  2193. if($status) goto error_exit;
  2194. endif
  2195. endif
  2196. end
  2197. end
  2198. if($RunIt) then
  2199. if ($best_pfh == 0) then
  2200. echo "ERROR: failure in calculating best preflood height param." \
  2201. |& tee -a $LF
  2202. goto error_exit;
  2203. endif
  2204. echo ""
  2205. echo "Optimal input vol: $best_vol, pre-flood height= $best_pfh, results in log_likelihood= $max_ll" \
  2206. |& tee -a $LF
  2207. #rm -f *_PFH*.auto.*
  2208. #rm -f *_PFH*.*
  2209. # save this result, so that it is used next time, negating the need
  2210. # to run mulitstrip (parallel jobs) again
  2211. echo "$best_vol" > optimal_skullstrip_invol
  2212. echo "$best_pfh" > optimal_preflood_height
  2213. endif
  2214. echo $cmd > $touchdir/log_likelihood.touch
  2215. # make sure this is set properly:
  2216. set BMA = brainmask.auto.mgz
  2217. else
  2218. # single-job skull-strip (default)
  2219. set BMA = brainmask.auto.mgz
  2220. if(-e $BMA && -e $BM && ! $DoCleanBM) set cmd = ($cmd -keep $BMA $BM $BM)
  2221. set INVOL = T1
  2222. if( -e optimal_skullstrip_invol) set INVOL = `cat optimal_skullstrip_invol`
  2223. if("$INVOL" == "T1") set opts = ( -T1 $opts )
  2224. set cmd = ($cmd $opts $xopts $INVOL.mgz $BMA)
  2225. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2226. if($RunIt) $fs_time $cmd |& tee -a $LF
  2227. if($status) goto error_exit;
  2228. if("$INVOL" == "orig") then
  2229. # while mri_watershed may run best in some cases using orig.mgz as input,
  2230. # we really want the brainmask to be from T1.mgz (post normalization)
  2231. set cmd = (mri_mask T1.mgz $BMA $BMA)
  2232. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2233. if($RunIt) $fs_time $cmd |& tee -a $LF
  2234. if($status) goto error_exit;
  2235. endif
  2236. echo $cmd > $touchdir/skull_strip.touch
  2237. endif
  2238. # Gcut:
  2239. # Nanyang Technological University's skull-stripper, which is intended to
  2240. # work best running after watershed. it further removes dura. see:
  2241. # 'Skull Stripping Using Graph Cuts', Neuroimage, 2009
  2242. # brainmask.gcuts.mgz is a debug file showing voxels that were cut.
  2243. if($DoGcut) then
  2244. set BMA = brainmask.auto.mgz
  2245. set BGC = brainmask.gcuts.mgz
  2246. set cmd = (rm -f $BGC)
  2247. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2248. if($RunIt) $cmd |& tee -a $LF
  2249. set xopts = `fsr-getxopts mri_gcut $XOptsFile`;
  2250. set cmd = (mri_gcut $xopts -110 -mult $BMA T1.mgz $BMA $BGC)
  2251. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2252. echo "" |& tee -a $LF
  2253. echo "INFO: Care must be taken to thoroughly inspect your data" \
  2254. |& tee -a $LF
  2255. echo " when using mri_gcut. In particular, inspect the edges of" \
  2256. |& tee -a $LF
  2257. echo " gm and cerebellum for over-aggressive cutting." |& tee -a $LF
  2258. echo " Add -segmentation brainmask.gcuts.mgz to the tkmedit" |& tee -a $LF
  2259. echo " command string to view the voxels which gcut has removed." |& tee -a $LF
  2260. echo "" |& tee -a $LF
  2261. if($RunIt) $fs_time $cmd |& tee -a $LF
  2262. if($status) goto error_exit;
  2263. # binarize the gcuts file, setting vals to label 999 which appears as red
  2264. # when loaded as a segmentation
  2265. if ( -e $BGC) then
  2266. set cmd = (mri_binarize --i $BGC --o $BGC --binval 999 --min 1)
  2267. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2268. if($RunIt) $fs_time $cmd |& tee -a $LF
  2269. if($status) goto error_exit;
  2270. endif
  2271. endif
  2272. skipped_skullstrip:
  2273. if( -e $BM && ! $DoCleanBM) then
  2274. echo "\nINFO: brainmask.mgz already exists!" \
  2275. |& tee -a $LF |& tee -a $CF
  2276. echo "The new brainmask.auto.mgz will not be copied to brainmask.mgz." \
  2277. |& tee -a $LF |& tee -a $CF
  2278. echo "This is done to retain any edits made to brainmask.mgz." \
  2279. |& tee -a $LF |& tee -a $CF
  2280. echo "Add the -clean-bm flag to recon-all to overwrite brainmask.mgz.\n" \
  2281. |& tee -a $LF |& tee -a $CF
  2282. endif
  2283. if(! -e $BM || $DoCleanBM) then
  2284. set cmd = (cp $BMA $BM)
  2285. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2286. if($RunIt) then
  2287. sleep 1; # Sleep here to assure that they have diff time stamps
  2288. $cmd |& tee -a $LF
  2289. if($status) goto error_exit;
  2290. endif
  2291. endif
  2292. endif
  2293. #----------- -------------#
  2294. ##---------- AUTORECON 2 -------------#
  2295. #----------- -------------#
  2296. #-------------- ---------------#
  2297. #-------------- GCA Registration ---------------#
  2298. ##------------- -gcareg ---------------#
  2299. #-------------- ---------------#
  2300. if($DoGCAReg) then
  2301. echo "#-------------------------------------"|& tee -a $LF |& tee -a $CF
  2302. echo "#@# EM Registration `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2303. cd $subjdir/mri > /dev/null
  2304. $PWD |& tee -a $LF
  2305. set xopts = `fsr-getxopts mri_em_register $XOptsFile`;
  2306. if($longitudinal) then
  2307. # longitudinal processing:
  2308. set cmd = (cp -vf $longbasedir/mri/transforms/talairach.lta \
  2309. transforms/talairach.lta )
  2310. else
  2311. if($NoEMReg == 0) then
  2312. set cmd = (mri_em_register)
  2313. if($UseCuda) set cmd = (mri_em_register_cuda)
  2314. set cmd = ($cmd -rusage $touchdir/rusage.mri_em_register.dat)
  2315. if($DoCreateBaseSubj) then
  2316. # base subj processing (norm_template instead of nu, and no mask needed):
  2317. set cmd = ($cmd -mask brainmask.mgz $xopts \
  2318. norm_template.mgz ${GCADIR}/$GCA \
  2319. transforms/talairach.lta)
  2320. else
  2321. # default processing:
  2322. set lta = transforms/talairach.lta
  2323. if($#GCAOutputName) set lta = transforms/talairach.$GCAOutputName.lta
  2324. set cmd = ($cmd -uns 3 -mask brainmask.mgz $xopts \
  2325. nu.mgz ${GCADIR}/$GCA $lta)
  2326. endif
  2327. else
  2328. set mni305 = $FREESURFER_HOME/average/mni305.cor.mgz
  2329. set xfm = transforms/talairach.xfm
  2330. set lta = transforms/talairach.lta
  2331. if($#GCAOutputName) set lta = transforms/talairach.$GCAOutputName.lta
  2332. set cmd = (lta_convert --src orig.mgz --trg $mni305 \
  2333. --inxfm $xfm --outlta $lta --subject fsaverage --ltavox2vox)
  2334. endif
  2335. endif
  2336. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2337. if($RunIt) $fs_time $cmd |& tee -a $LF
  2338. if($status) goto error_exit;
  2339. echo $cmd > $touchdir/em_register.touch
  2340. endif
  2341. #------------ --------------#
  2342. #----------- Canonical Intensity Normalization -----#
  2343. ##----------- -canorm --------------#
  2344. #------------ --------------#
  2345. if($DoCANormalize) then
  2346. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2347. echo "#@# CA Normalize `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2348. cd $subjdir/mri > /dev/null
  2349. $PWD |& tee -a $LF
  2350. set lta = transforms/talairach.lta
  2351. set norm = norm.mgz
  2352. set ctrl_pts = ctrl_pts.mgz
  2353. if($#GCAOutputName) then
  2354. set lta = transforms/talairach.$GCAOutputName.lta
  2355. set norm = norm.$GCAOutputName.mgz
  2356. set ctrl_pts = ctrl_pts.$GCAOutputName.mgz
  2357. endif
  2358. if ($longitudinal) then
  2359. # longitudinal processing:
  2360. # cp aseg from base to current TP:
  2361. set cmd = (cp -vf ${longbasedir}/mri/aseg.mgz aseg_${longbaseid}.mgz)
  2362. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2363. if ($RunIt) $fs_time $cmd |& tee -a $LF
  2364. if ($status) goto error_exit;
  2365. endif
  2366. set xopts = `fsr-getxopts mri_ca_normalize $XOptsFile`;
  2367. set cmd = (mri_ca_normalize)
  2368. if($UseCPsWithCaNorm) set cmd = ($cmd -f $ControlPointsFile)
  2369. if ($longitudinal) then
  2370. # longitudinal processing:
  2371. # use the aseg_base (just created) as initialization of the current TP:
  2372. set cmd = ($cmd -long aseg_${longbaseid}.mgz)
  2373. else
  2374. # default stream
  2375. set cmd = ($cmd -c $ctrl_pts)
  2376. endif
  2377. set cmd = ($cmd -mask brainmask.mgz $xopts)
  2378. if($DoCreateBaseSubj) then
  2379. # base subject stream
  2380. # (use norm vol created during -base-init, no mask needed)
  2381. set cmd = ($cmd norm_template.mgz)
  2382. else
  2383. # default stream
  2384. set cmd = ($cmd nu.mgz)
  2385. endif
  2386. set cmd = ($cmd ${GCADIR}/$GCA $lta $norm)
  2387. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2388. if($RunIt) $fs_time $cmd |& tee -a $LF
  2389. if($status) goto error_exit;
  2390. echo $cmd > $touchdir/ca_normalize.touch
  2391. endif # DoCANormalize
  2392. #------------ --------------#
  2393. #------------ Canonical Registration --------------#
  2394. ##----------- -careg --------------#
  2395. #------------ --------------#
  2396. if($DoCAReg) then
  2397. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2398. echo "#@# CA Reg `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2399. cd $subjdir/mri > /dev/null
  2400. $PWD |& tee -a $LF
  2401. set xopts = `fsr-getxopts mri_ca_register $XOptsFile`;
  2402. set cmd = (mri_ca_register)
  2403. if($UseCuda) set cmd = (mri_ca_register_cuda)
  2404. set cmd = ($cmd -rusage $touchdir/rusage.mri_ca_register.dat)
  2405. if($#GCARegIterations) set cmd = ($cmd -n $GCARegIterations)
  2406. if($#GCARegTol) set cmd = ($cmd -tol $GCARegTol)
  2407. set lta = transforms/talairach.lta
  2408. set m3z = transforms/talairach.m3z
  2409. set norm = norm.mgz
  2410. if($#GCAOutputName) then
  2411. set lta = transforms/talairach.$GCAOutputName.lta
  2412. set m3z = transforms/talairach.$GCAOutputName.m3z
  2413. set norm = norm.$GCAOutputName.mgz
  2414. endif
  2415. if($UnCompress) set cmd = ($cmd -uncompress)
  2416. if($BigVentricles) set cmd = ($cmd -bigventricles -smoothness 0.5)
  2417. if( ! $BigVentricles) set cmd = ($cmd -nobigventricles)
  2418. if($DoSecondPassRenorm) set cmd = ($cmd -secondpassrenorm)
  2419. if( ! $longitudinal) set cmd = ($cmd -T $lta)
  2420. if($UseTWMControlPoints) set cmd = ($cmd -twm $TWMControlPointsFile)
  2421. if ( $longitudinal ) then
  2422. # here is tpN's longitudinal command
  2423. # init with warp (m3z) from base
  2424. # no need to concatenate, as we are in same space now
  2425. set cmd = ($cmd -levels 2 -A 1 \
  2426. -l $longbasedir/mri/transforms/talairach.m3z \
  2427. identity.nofile)
  2428. endif
  2429. set cmd = ($cmd $UseCAAlignAfter)
  2430. set cmd = ($cmd -mask brainmask.mgz)
  2431. set cmd = ($cmd $xopts $norm ${GCADIR}/$GCA $m3z)
  2432. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2433. if($RunIt) $fs_time $cmd |& tee -a $LF
  2434. set st = $status
  2435. if($st) then
  2436. echo "ERROR: mri_ca_register with non-zero status $st" |& tee -a $LF
  2437. echo "but continuing despite the error" |& tee -a $LF
  2438. #goto error_exit;
  2439. endif
  2440. echo $cmd > $touchdir/ca_register.touch
  2441. endif
  2442. #------------ --------------#
  2443. #------------ Inverse of Canonical Registration --------------#
  2444. ##----------- -careginv --------------#
  2445. #------------ --------------#
  2446. if($DoCARegInv) then
  2447. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2448. echo "#@# CA Reg Inv `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2449. cd $subjdir/mri > /dev/null
  2450. $PWD |& tee -a $LF
  2451. # set xopts = `fsr-getxopts mri_ca_register $XOptsFile`; # careful here
  2452. set cmd = (mri_ca_register)
  2453. #NJS: cuda version doesnt work will -invert-and-save:
  2454. #if($UseCuda) set cmd = (mri_ca_register_cuda)
  2455. set cmd = ($cmd -invert-and-save transforms/talairach.m3z)
  2456. set cmd = ($cmd -rusage $touchdir/rusage.mri_ca_register.inv.dat)
  2457. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2458. if($RunIt) $fs_time $cmd |& tee -a $LF
  2459. if($status) then
  2460. echo "ERROR: mri_ca_register with non-zero status $status" |& tee -a $LF
  2461. goto error_exit;
  2462. endif
  2463. echo $cmd > $touchdir/ca_register_inv.touch
  2464. endif
  2465. #------------ --------------#
  2466. #------------ Removes neck and part of the face --------------#
  2467. ##----------- -rmneck, needed if doing SkullLTA --------------#
  2468. #------------ --------------#
  2469. if($DoRemoveNeck) then
  2470. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2471. echo "#@# Remove Neck `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2472. cd $subjdir/mri > /dev/null
  2473. set xopts = `fsr-getxopts mri_remove_neck $XOptsFile`;
  2474. set xform = (transforms/talairach.m3z)
  2475. if ( ! -e $xform) then
  2476. echo "INFO: $xform not found, using talairach.lta instead" \
  2477. |& tee -a $LF |& tee -a $CF
  2478. set xform = (transforms/talairach.lta)
  2479. endif
  2480. set cmd = (mri_remove_neck -radius $RmNeckRadius $xopts \
  2481. nu.mgz $xform \
  2482. ${GCADIR}/$GCA nu_noneck.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. echo $cmd > $touchdir/mri_remove_neck.touch
  2487. endif
  2488. #------------ --------------#
  2489. #------------ Recompute lta with skull but no neck --------------#
  2490. ##----------- -skull-lta --------------#
  2491. #------------ --------------#
  2492. if($DoSkullLTA) then
  2493. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2494. echo "#@# SkullLTA `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2495. cd $subjdir/mri > /dev/null
  2496. set xopts = `fsr-getxopts mri_em_register $XOptsFile`;
  2497. set cmd = (mri_em_register)
  2498. if ($UseCuda) set cmd = (mri_em_register_cuda)
  2499. set cmd = ($cmd -skull -t transforms/talairach.lta \
  2500. $xopts nu_noneck.mgz ${GCADIR}/$GCASkull \
  2501. transforms/talairach_with_skull_2.lta)
  2502. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2503. if($RunIt) $fs_time $cmd |& tee -a $LF
  2504. if($status) goto error_exit;
  2505. echo $cmd > $touchdir/skull_2.lta.touch
  2506. endif
  2507. #-------------- --------------#
  2508. #-------------- SubCort Segmentation --------------#
  2509. ##------------- -calabel --------------#
  2510. #-------------- --------------#
  2511. if($DoCALabel) then
  2512. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2513. echo "#@# SubCort Seg `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2514. cd $subjdir/mri > /dev/null
  2515. set DoASegMerge = 1; # Force
  2516. if($DoCleanASeg) then
  2517. set cmd = (rm -f aseg.presurf.mgz aseg.manedit.mgz)
  2518. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2519. if($RunIt) $cmd |& tee -a $LF
  2520. if($status) goto error_exit;
  2521. endif
  2522. # ----------- Prior to changing aseg.auto.mgz ------------#
  2523. if( -e aseg.presurf.mgz && -e aseg.auto.mgz ) then
  2524. # aseg.presurf.mgz and aseg.auto.mgz DO exist (at least 2nd pass)
  2525. if( ! -e aseg.manedit.mgz) then
  2526. # aseg.manedit.mgz does NOT exist
  2527. # Check for diffs between aseg.auto and aseg.presurf
  2528. # Note: if there are no diffs, then aseg.manedit.mgz is not created
  2529. set cmd = (mri_seg_diff --seg1 aseg.auto.mgz \
  2530. --seg2 aseg.presurf.mgz --diff aseg.manedit.mgz)
  2531. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2532. if( ! $RunIt) then
  2533. echo "INFO: mri_seg_diff was not actually executed," |& tee -a $LF
  2534. echo "so subsequent commands (shown with -dontrun)" |& tee -a $LF
  2535. echo "may not have accurate arguments!" |& tee -a $LF
  2536. endif
  2537. if($RunIt) $cmd |& tee -a $LF
  2538. if($status) goto error_exit;
  2539. else
  2540. # aseg.manedit.mgz DOES exist
  2541. # This has to be handled in two stages in case manedit itself has
  2542. # been edited.
  2543. # 1. Check for diffs between aseg.auto and aseg.presurf (new & old edits)
  2544. set cmd = (mri_seg_diff --seg1 aseg.auto.mgz \
  2545. --seg2 aseg.presurf.mgz --diff aseg.manedit.tmp.mgz)
  2546. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2547. if( ! $RunIt) then
  2548. echo "INFO: mri_seg_diff was not actually executed," |& tee -a $LF
  2549. echo "so subsequent commands (shown with -dontrun)" |& tee -a $LF
  2550. echo "may not have accurate arguments!" |& tee -a $LF
  2551. endif
  2552. if($RunIt) $cmd |& tee -a $LF
  2553. if($status) goto error_exit;
  2554. # 2. Merge new and old edits with manedit. If manedit has not
  2555. # been edited, then there will be no change.
  2556. if(-e aseg.manedit.tmp.mgz) then
  2557. set cmd = (mri_seg_diff --seg aseg.manedit.mgz \
  2558. --diff-in aseg.manedit.tmp.mgz --merged aseg.manedit.mgz)
  2559. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2560. if($RunIt) $cmd |& tee -a $LF
  2561. if($status) goto error_exit;
  2562. rm aseg.manedit.tmp.mgz
  2563. endif
  2564. endif
  2565. endif
  2566. # ------------ longitudinal (pre)processing ----------------#
  2567. # fuse segmentations of subjects composing the 'longbase' subject
  2568. if ($longitudinal && $UseAsegFusion) then
  2569. cd $subjdir/mri > /dev/null
  2570. $PWD |& tee -a $LF
  2571. set BaseSubjsList = (`cat ${longbasedir}/${BaseSubjsListFname}`)
  2572. # first create lta's of basesubjs to longsubj
  2573. set asegprecount = 0
  2574. foreach s (${BaseSubjsList})
  2575. # copy the transform (tpi cross to base) to local transform dir
  2576. # where mri_fuse_segmentations is looking for it:
  2577. set cmd = (cp -vf \
  2578. ${longbasedir}/mri/transforms/${s}_to_${longbaseid}.lta \
  2579. ${subjdir}/mri/transforms/${s}_to_${subjid}.lta)
  2580. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2581. if($RunIt) then
  2582. $fs_time $cmd |& tee -a $LF
  2583. if($status) goto error_exit;
  2584. endif
  2585. # check if all cross dirs have aseg.presurf
  2586. if ( -e ${SUBJECTS_DIR}/${s}/mri/aseg.presurf.mgz ) then
  2587. @ asegprecount++
  2588. endif
  2589. end
  2590. # if we are missing aseg.presurf, assume that cross is 5.3 or older
  2591. # and use aseg.mgz for fusion
  2592. set crossaseg = aseg.presurf.mgz
  2593. if ( $#BaseSubjsList > $asegprecount ) then
  2594. set crossaseg = aseg.mgz
  2595. endif
  2596. # now create the fused aseg
  2597. set cmd = (mri_fuse_segmentations)
  2598. set cmd = ($cmd -a $crossaseg -c aseg.auto_noCCseg.mgz -n norm.mgz)
  2599. set cmd = ($cmd ${subjid} ${BaseSubjsList} aseg.fused.mgz)
  2600. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2601. if($RunIt) then
  2602. $fs_time $cmd |& tee -a $LF
  2603. if($status) goto error_exit;
  2604. endif
  2605. endif
  2606. #------------------- mri_ca_label ------------------------#
  2607. # Run mri_ca_label to create aseg.auto_noCCseg.mgz
  2608. set xopts = `fsr-getxopts mri_ca_label $XOptsFile`;
  2609. set rusage = $touchdir/rusage.mri_ca_label.dat
  2610. set cmd = (mri_ca_label -relabel_unlikely 9 .3 -prior 0.5)
  2611. set cmd = ($cmd $UseCAAlign)
  2612. if($NoWMSA) set cmd = ($cmd -nowmsa)
  2613. set asegbasename=(aseg.auto_noCCseg)
  2614. if($longitudinal && $UseAsegFusion) then
  2615. # longitudinal processing: use 'fused' aseg just created
  2616. set cmd=($cmd -r $subjdir/mri/aseg.fused.mgz)
  2617. set cmd=($cmd -ri $longbasedir/mri/${asegbasename}.label_intensities.txt)
  2618. endif
  2619. set cmd = ($cmd $xopts norm.mgz)
  2620. set cmd = ($cmd transforms/talairach.m3z)
  2621. set cmd = ($cmd ${GCADIR}/$GCA)
  2622. set cmd = ($cmd ${asegbasename}.mgz)
  2623. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2624. if($RunIt) $fs_time $cmd |& tee -a $LF
  2625. if($status) goto error_exit;
  2626. #--- Corpus Callosum Segmentation ---#
  2627. # Run mri_cc to create aseg.auto.mgz
  2628. set xopts = `fsr-getxopts mri_cc $XOptsFile`;
  2629. set cmd = (mri_cc -aseg aseg.auto_noCCseg.mgz -o aseg.auto.mgz \
  2630. -lta ${subjdir}/mri/transforms/cc_up.lta $xopts $subjid);
  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/ca_label.touch
  2635. endif
  2636. # --------- Incorporate Manual ASeg Changes ----------------------
  2637. # Allow it to be done outside of CALabel. Note that DoASegMerge
  2638. # will be 1 if CALabel is run. This just allows the user to
  2639. # merge with Man Edits even if CALabel was not run, which will
  2640. # only have an effect if the user has actually changed aseg.manedit
  2641. if($DoASegMerge) then
  2642. echo "#--------------------------------------"|& tee -a $LF |& tee -a $CF
  2643. echo "#@# Merge ASeg `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2644. cd $subjdir/mri > /dev/null
  2645. if(-e aseg.manedit.mgz ) then
  2646. set cmd = (mri_seg_diff --seg aseg.auto.mgz \
  2647. --diff-in aseg.manedit.mgz --merged aseg.presurf.mgz)
  2648. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2649. if( ! $RunIt) then
  2650. echo "INFO: mri_seg_diff was not actually executed," |& tee -a $LF
  2651. echo "so subsequent commands (shown with -dontrun)" |& tee -a $LF
  2652. echo "may not have accurate arguments!" |& tee -a $LF
  2653. endif
  2654. if($RunIt) $cmd |& tee -a $LF
  2655. if($status) goto error_exit;
  2656. else
  2657. set cmd = (cp aseg.auto.mgz aseg.presurf.mgz)
  2658. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2659. if($RunIt) $cmd |& tee -a $LF
  2660. if($status) goto error_exit;
  2661. endif
  2662. echo $cmd > $touchdir/asegmerge.touch
  2663. endif
  2664. #----------- -----------------#
  2665. #----------- Intensity Normalization2 -----------------#
  2666. ##---------- -normalization2 -----------------#
  2667. #----------- -----------------#
  2668. if($DoNormalization2) then
  2669. echo "#--------------------------------------------" \
  2670. |& tee -a $LF |& tee -a $CF
  2671. echo "#@# Intensity Normalization2 `date`" \
  2672. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2673. cd $subjdir/mri > /dev/null
  2674. set xopts = `fsr-getxopts mri_normalize $XOptsFile`;
  2675. set cmd = (mri_normalize);
  2676. if($UseControlPoints) set cmd = ($cmd -f $ControlPointsFile)
  2677. if($#Norm3dIters) set cmd = ($cmd -n $Norm3dIters)
  2678. if($#Norm2_b) set cmd = ($cmd -b $Norm2_b)
  2679. if($#Norm2_n) set cmd = ($cmd -n $Norm2_n)
  2680. if($IsMPRAGE) set cmd = ($cmd -mprage)
  2681. if($IsWashuMPRAGE) set cmd = ($cmd -washu_mprage)
  2682. if($ConformMin) set cmd = ($cmd -noconform)
  2683. if($UseAseg && ! $NoAsegInorm2) set cmd = ($cmd -aseg aseg.presurf.mgz)
  2684. if($NoNormMGZ) then
  2685. # norm.mgz doesnt exist with -noaseg or -nosubcortseg, so use brainmask.mgz
  2686. set cmd = ($cmd $xopts brainmask.mgz brain.mgz)
  2687. else
  2688. set cmd = ($cmd -mask brainmask.mgz $xopts norm.mgz brain.mgz)
  2689. endif
  2690. $PWD |& tee -a $LF
  2691. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2692. if($RunIt) $fs_time $cmd |& tee -a $LF
  2693. if($status) goto error_exit;
  2694. echo $cmd > $touchdir/inorm2.touch
  2695. endif
  2696. #-------------- ---------------#
  2697. #-------------- Create BrainFinalSurfs ---------------#
  2698. ##------------- -maskbfs ---------------#
  2699. #-------------- ---------------#
  2700. if($DoMaskBFS) then
  2701. echo "#--------------------------------------------" \
  2702. |& tee -a $LF |& tee -a $CF
  2703. echo "#@# Mask BFS `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2704. cd $subjdir/mri > /dev/null
  2705. set xopts = `fsr-getxopts mri_mask $XOptsFile`;
  2706. # Set threshold to WM_MIN_VAL=5
  2707. set cmd = (mri_mask -T 5 $xopts brain.mgz brainmask.mgz brain.finalsurfs.mgz)
  2708. $PWD |& tee -a $LF
  2709. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2710. if($RunIt) $fs_time $cmd |& tee -a $LF
  2711. if($status) goto error_exit;
  2712. # if they exist, transfer finalsurfs edits (voxels=255 and voxels=1)
  2713. if( -e brain.finalsurfs.manedit.mgz ) then
  2714. set cmd = (mri_mask -transfer 255)
  2715. set cmd = ($cmd -keep_mask_deletion_edits)
  2716. set cmd = ($cmd brain.finalsurfs.mgz brain.finalsurfs.manedit.mgz \
  2717. brain.finalsurfs.mgz)
  2718. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2719. if($RunIt) $fs_time $cmd |& tee -a $LF
  2720. if($status) goto error_exit;
  2721. else
  2722. if ( $longitudinal && -e ${SUBJECTS_DIR}/${tpNid}/mri/brain.finalsurfs.manedit.mgz ) then
  2723. # transfer edits from cross
  2724. set cmd = (mri_mask -transfer 255)
  2725. set cmd = ($cmd -keep_mask_deletion_edits)
  2726. set cmd = ($cmd -xform $tpNtobase_regfile)
  2727. set cmd = ($cmd brain.finalsurfs.mgz)
  2728. set cmd = ($cmd ${SUBJECTS_DIR}/${tpNid}/mri/brain.finalsurfs.manedit.mgz)
  2729. set cmd = ($cmd brain.finalsurfs.mgz)
  2730. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2731. if($RunIt) $fs_time $cmd |& tee -a $LF
  2732. if($status) goto error_exit;
  2733. endif
  2734. endif
  2735. endif
  2736. #---------------- -------------------#
  2737. #---------------- WM Segmentation -------------------#
  2738. ##--------------- -segmentation -------------------#
  2739. #---------------- -------------------#
  2740. if($DoSegmentation) then
  2741. echo "#--------------------------------------------" \
  2742. |& tee -a $LF |& tee -a $CF
  2743. echo "#@# WM Segmentation `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2744. cd $subjdir/mri > /dev/null
  2745. set AllowLongWMtransfers = "1"
  2746. if(! $DoCleanWM && -e wm.mgz) then
  2747. # test if edits were made
  2748. # count 255 edits:
  2749. set cmd = (mri_binarize --i wm.mgz --min 255 --max 255 \
  2750. --o wm255.mgz --count wm255.txt)
  2751. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2752. if($RunIt) $cmd |& tee -a $LF
  2753. if($status) goto error_exit;
  2754. # count 1 edits:
  2755. set cmd = (mri_binarize --i wm.mgz --min 1 --max 1 \
  2756. --o wm1.mgz --count wm1.txt)
  2757. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2758. if($RunIt) $cmd |& tee -a $LF
  2759. if($status) goto error_exit;
  2760. # remove unnecessary mgz's
  2761. set cmd = (rm wm1.mgz wm255.mgz)
  2762. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2763. if($RunIt) $cmd |& tee -a $LF
  2764. if($status) goto error_exit;
  2765. # get number of edits:
  2766. set wm255=""
  2767. if ( -e wm255.txt ) then
  2768. set wm255 = `cat wm255.txt | awk ' { print $1 } '`
  2769. endif
  2770. set wm1=""
  2771. if ( -e wm1.txt ) then
  2772. set wm1 = `cat wm1.txt | awk ' { print $1 } '`
  2773. endif
  2774. # if edits exist:
  2775. if ( "$wm1" != "0" || "$wm255" != "0" ) then
  2776. echo "Found wm edits: $wm1 deletes, $wm255 fills" |& tee -a $LF
  2777. set cmd = (cp wm.mgz wm.seg.mgz)
  2778. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2779. if($RunIt) $cmd |& tee -a $LF
  2780. if($status) goto error_exit;
  2781. # wm.mgz was available (probably edited):
  2782. # don't allow transfers in long below
  2783. set AllowLongWMtransfers = "0"
  2784. endif
  2785. endif
  2786. # ----------- Segment -------------------------
  2787. set xopts = `fsr-getxopts mri_segment $XOptsFile`;
  2788. set cmd = (mri_segment);
  2789. if ($NoThicken) set cmd = ($cmd -thicken 0)
  2790. # note: check for wm.mgz happens so that -dontrun output is correct
  2791. if(! $DoCleanWM && -e wm.mgz && -e wm.seg.mgz) set cmd = ($cmd -keep)
  2792. if($IsMPRAGE) set cmd = ($cmd -mprage)
  2793. if($IsWashuMPRAGE) set cmd = ($cmd -washu_mprage)
  2794. set cmd = ($cmd $WMSeg_wlo $WMSeg_ghi $xopts brain.mgz wm.seg.mgz)
  2795. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2796. if($RunIt) $fs_time $cmd |& tee -a $LF
  2797. if($status) goto error_exit;
  2798. # ----------- Edit with ASeg -------------------------
  2799. if($UseAseg) then
  2800. set xopts = `fsr-getxopts mri_edit_wm_with_aseg $XOptsFile`;
  2801. set cmd = (mri_edit_wm_with_aseg)
  2802. if(! $DoCleanWM) set cmd = ($cmd -keep-in)
  2803. set cmd = ($cmd $xopts wm.seg.mgz brain.mgz \
  2804. aseg.presurf.mgz wm.asegedit.mgz)
  2805. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2806. if($RunIt) $fs_time $cmd |& tee -a $LF
  2807. if($status) goto error_exit;
  2808. endif
  2809. # ----------- PreTess -------------------------
  2810. set xopts = `fsr-getxopts mri_pretess $XOptsFile`;
  2811. set wmlabelstring = "wm"
  2812. if($UseAseg) then
  2813. set WM_vol = wm.asegedit.mgz
  2814. else
  2815. set WM_vol = wm.seg.mgz
  2816. endif
  2817. if($NoNormMGZ) then
  2818. set norm_vol = brain.mgz
  2819. else
  2820. set norm_vol = norm.mgz
  2821. endif
  2822. set cmd = (mri_pretess )
  2823. if(! $DoCleanWM && -e wm.mgz) set cmd = ($cmd -keep)
  2824. set cmd = ($cmd $xopts $WM_vol $wmlabelstring $norm_vol wm.mgz)
  2825. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2826. if($RunIt) $fs_time $cmd |& tee -a $LF
  2827. if($status) goto error_exit;
  2828. if($longitudinal && $AllowLongWMtransfers) then
  2829. if ($UseLongbaseWMedits) then
  2830. # transfer wm edits (voxels=255) from longbase wm.mgz to long tpN wm.mgz
  2831. # and -keep_mask_deletion_edits transfers voxel-deletion (voxels=1) edits
  2832. set cmd = (mri_mask -transfer 255)
  2833. set cmd = ($cmd -keep_mask_deletion_edits)
  2834. set cmd = ($cmd wm.mgz $longbasedir/mri/wm.mgz wm.mgz)
  2835. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2836. if($RunIt) $fs_time $cmd |& tee -a $LF
  2837. if($status) goto error_exit;
  2838. else #default in -long:
  2839. # transfer wm matter edits (voxels=255) from cross wm.mgz to long tpN wm.mgz
  2840. # and -keep_mask_deletion_edits transfers voxel-deletion (voxels=1) edits
  2841. set cmd = (mri_mask -transfer 255)
  2842. set cmd = ($cmd -keep_mask_deletion_edits)
  2843. set cmd = ($cmd -xform $tpNtobase_regfile)
  2844. set cmd = ($cmd wm.mgz ${SUBJECTS_DIR}/${tpNid}/mri/wm.mgz wm.mgz)
  2845. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2846. if($RunIt) $fs_time $cmd |& tee -a $LF
  2847. if($status) goto error_exit;
  2848. endif
  2849. endif
  2850. echo $cmd > $touchdir/wmsegment.touch
  2851. endif
  2852. #---------------- -------------------#
  2853. ##--------------- -fill -------------------#
  2854. #---------------- -------------------#
  2855. if($DoFill) then
  2856. echo "#--------------------------------------------" \
  2857. |& tee -a $LF |& tee -a $CF
  2858. echo "#@# Fill `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2859. cd $subjdir/mri > /dev/null
  2860. set xopts = `fsr-getxopts mri_fill $XOptsFile`;
  2861. set seedopts = ();
  2862. if($#PonsSeedCRS) set seedopts = ($seedopts -Pv $PonsSeedCRS);
  2863. if($#CCSeedCRS) set seedopts = ($seedopts -Cv $CCSeedCRS);
  2864. if($#LHSeedCRS) set seedopts = ($seedopts -lhv $LHSeedCRS);
  2865. if($#RHSeedCRS) set seedopts = ($seedopts -rhv $RHSeedCRS);
  2866. set cmd = (mri_fill -a ../scripts/ponscc.cut.log $seedopts)
  2867. if(-e transforms/talairach.lta) then
  2868. set cmd = ($cmd -xform transforms/talairach.lta)
  2869. endif
  2870. if($UseAseg) set cmd = ($cmd -segmentation aseg.auto_noCCseg.mgz);
  2871. if(! $UseOldTopoFix && ! $NoNormMGZ) set cmd = ($cmd -topofix norm.mgz);
  2872. set cmd = ($cmd $xopts wm.mgz filled.mgz)
  2873. $PWD |& tee -a $LF
  2874. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  2875. if($RunIt) $fs_time $cmd |& tee -a $LF
  2876. if($status) goto error_exit;
  2877. echo $cmd > $touchdir/fill.touch
  2878. endif
  2879. #########################################################
  2880. # Per-Hemisphere #
  2881. #########################################################
  2882. #
  2883. # Notes on -parallel ($DoParallel) implementation:
  2884. # - clear the var CMDFS that stores command-files to run in parallel
  2885. # - start for loop on each hemi
  2886. # - print start-up log message, and build the 'cmd' var as usual
  2887. # - if DoParallel:
  2888. # write 'cmd' to a file and put that filename in CMDFS
  2889. # don't run the command just yet
  2890. # - else if not DoParallel (the traditional usage)
  2891. # run the command
  2892. # check error status
  2893. # - end for loop
  2894. # - if DoParallel:
  2895. # run 'reconbatchjobs', which does the following grunt work:
  2896. # - calls 'exec' on each command in the command file
  2897. # - directs stdout/stderr to a temporary log file
  2898. # - waits for each command to complete
  2899. # - appends each temp log into recon-all.log
  2900. # - check command return status and error-exit if error
  2901. # check error status of reconbatchjobs
  2902. #
  2903. #---------------- -------------------#
  2904. ##--------------- -tessellate -------------------#
  2905. #---------------- -------------------#
  2906. if($DoTessellate && ( ! $longitudinal )) then
  2907. # no need to run hemis in parallel, as this already runs in seconds
  2908. foreach hemi ($hemilist)
  2909. echo "#--------------------------------------------" \
  2910. |& tee -a $LF |& tee -a $CF
  2911. echo "#@# Tessellate $hemi `date`" \
  2912. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2913. cd $subjdir/scripts > /dev/null
  2914. $PWD |& tee -a $LF
  2915. if($hemi == "lh") then
  2916. set hemivalue = 255;
  2917. else
  2918. set hemivalue = 127;
  2919. endif
  2920. # necessary second pretess, per f.segonne
  2921. set xopts = `fsr-getxopts mri_pretess $XOptsFile`;
  2922. if($NoNormMGZ) then
  2923. set norm_vol = brain.mgz
  2924. else
  2925. set norm_vol = norm.mgz
  2926. endif
  2927. set cmd = (mri_pretess $xopts ../mri/filled.mgz $hemivalue \
  2928. ../mri/$norm_vol ../mri/filled-pretess$hemivalue.mgz)
  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. set xopts = `fsr-getxopts mri_tessellate $XOptsFile`;
  2933. set cmd = (mri_tessellate $xopts ../mri/filled-pretess$hemivalue.mgz \
  2934. $hemivalue ../surf/$hemi.orig.nofix)
  2935. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2936. if($RunIt) $fs_time $cmd |& tee -a $LF
  2937. if($status) goto error_exit;
  2938. set cmd = (rm -f ../mri/filled-pretess$hemivalue.mgz)
  2939. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2940. if($RunIt) $cmd |& tee -a $LF
  2941. # remove possible extra components, per f.segonne
  2942. set xopts = `fsr-getxopts mris_extract_main_component $XOptsFile`;
  2943. set cmd = (mris_extract_main_component $xopts ../surf/$hemi.orig.nofix \
  2944. ../surf/$hemi.orig.nofix)
  2945. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2946. if($RunIt) $fs_time $cmd |& tee -a $LF
  2947. if($status) goto error_exit;
  2948. echo $cmd > $touchdir/$hemi.tessellate.touch
  2949. end # Loop over hemilist
  2950. endif
  2951. #---------------- -------------------#
  2952. ##--------------- -smooth1 -------------------#
  2953. #---------------- -------------------#
  2954. if($DoSmooth1 && ( ! $longitudinal )) then
  2955. set CMDFS = () # see earlier notes on -parallel implementation
  2956. foreach hemi ($hemilist)
  2957. echo "#--------------------------------------------" \
  2958. |& tee -a $LF |& tee -a $CF
  2959. echo "#@# Smooth1 $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2960. cd $subjdir/scripts > /dev/null
  2961. $PWD |& tee -a $LF
  2962. set xopts = `fsr-getxopts mris_smooth $XOptsFile`;
  2963. # -nw prevents it from writing curv and area
  2964. set cmd = (mris_smooth -nw)
  2965. if ($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  2966. set cmd = ($cmd $xopts \
  2967. ../surf/$hemi.orig.nofix ../surf/$hemi.smoothwm.nofix)
  2968. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  2969. if($DoParallel) then
  2970. set CMDF = mris_smooth_${hemi}.cmd
  2971. echo "$cmd" > $CMDF
  2972. set CMDFS = ( $CMDFS $CMDF )
  2973. else
  2974. if($RunIt) $fs_time $cmd |& tee -a $LF
  2975. if($status) goto error_exit;
  2976. endif
  2977. echo $cmd > $touchdir/$hemi.smoothwm1.touch
  2978. end # Loop over hemilist
  2979. if($RunIt && $DoParallel) then
  2980. reconbatchjobs $LF $CMDFS |& tee -a $LF
  2981. if($status) goto error_exit;
  2982. endif
  2983. endif
  2984. #---------------- -------------------#
  2985. ##--------------- -inflate1 -------------------#
  2986. #---------------- -------------------#
  2987. if($DoInflate1 && ( ! $longitudinal )) then
  2988. set CMDFS = () # see earlier notes on -parallel implementation
  2989. foreach hemi ($hemilist)
  2990. echo "#--------------------------------------------" \
  2991. |& tee -a $LF |& tee -a $CF
  2992. echo "#@# Inflation1 $hemi `date`" \
  2993. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  2994. cd $subjdir/scripts > /dev/null
  2995. $PWD |& tee -a $LF
  2996. set xopts = `fsr-getxopts mris_inflate $XOptsFile`;
  2997. set cmd = (mris_inflate)
  2998. if($UseCuda) set cmd = (mris_inflate_cuda)
  2999. set cmd = ($cmd -no-save-sulc $xopts \
  3000. ../surf/$hemi.smoothwm.nofix ../surf/$hemi.inflated.nofix)
  3001. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3002. if($DoParallel) then
  3003. set CMDF = mris_inflate_${hemi}.cmd
  3004. echo "$cmd" > $CMDF
  3005. set CMDFS = ( $CMDFS $CMDF )
  3006. else
  3007. if($RunIt) $fs_time $cmd |& tee -a $LF
  3008. if($status) goto error_exit;
  3009. endif
  3010. echo $cmd > $touchdir/$hemi.inflate1.touch
  3011. end # Loop over hemilist
  3012. if($RunIt && $DoParallel) then
  3013. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3014. if($status) goto error_exit;
  3015. endif
  3016. endif
  3017. #---------------- -------------------#
  3018. ##--------------- -qsphere -------------------#
  3019. #---------------- -------------------#
  3020. if($DoQSphere && ( ! $longitudinal )) then
  3021. set CMDFS = () # see earlier notes on -parallel implementation
  3022. foreach hemi ($hemilist)
  3023. echo "#--------------------------------------------" \
  3024. |& tee -a $LF |& tee -a $CF
  3025. echo "#@# QSphere $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3026. cd $subjdir/scripts > /dev/null
  3027. $PWD |& tee -a $LF
  3028. set xopts = `fsr-getxopts mris_sphere $XOptsFile`;
  3029. set cmd = (mris_sphere -q)
  3030. if($UseCuda) set cmd = (mris_sphere_cuda -q)
  3031. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  3032. set cmd = ($cmd $xopts)
  3033. set cmd = ($cmd ../surf/$hemi.inflated.nofix ../surf/$hemi.qsphere.nofix)
  3034. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3035. if($DoParallel) then
  3036. set CMDF = mris_sphere_${hemi}.cmd
  3037. echo "$cmd" > $CMDF
  3038. set CMDFS = ( $CMDFS $CMDF )
  3039. else
  3040. if($RunIt) $fs_time $cmd |& tee -a $LF
  3041. if($status) goto error_exit;
  3042. endif
  3043. echo $cmd > $touchdir/$hemi.qsphere.touch
  3044. end # Loop over hemilist
  3045. if($RunIt && $DoParallel) then
  3046. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3047. if($status) goto error_exit;
  3048. endif
  3049. endif
  3050. #---------------- -------------------#
  3051. #---------------- Fix Topology -------------------#
  3052. ##--------------- -fix -------------------#
  3053. #---------------- -------------------#
  3054. if($DoFix && ( ! $longitudinal )) then
  3055. foreach hemi ($hemilist)
  3056. echo "#--------------------------------------------" \
  3057. |& tee -a $LF |& tee -a $CF
  3058. echo "#@# Fix Topology Copy $hemi `date`" \
  3059. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3060. cd $subjdir/scripts > /dev/null
  3061. $PWD |& tee -a $LF
  3062. # Must copy unfixed to fixed
  3063. set cmd = (cp ../surf/$hemi.orig.nofix ../surf/$hemi.orig)
  3064. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3065. if($RunIt) $cmd |& tee -a $LF
  3066. if($status) goto error_exit;
  3067. set cmd = (cp ../surf/$hemi.inflated.nofix ../surf/$hemi.inflated)
  3068. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3069. if($RunIt) $cmd |& tee -a $LF
  3070. if($status) goto error_exit;
  3071. end # hemi first loop
  3072. set NewTopoFixHemiList = (); # to handle Old/NewTopoFix use cases
  3073. # Now can run fixer
  3074. if($UseOldTopoFix) then
  3075. set CMDFS = () # see earlier notes on -parallel implementation
  3076. foreach hemi ($hemilist)
  3077. echo "#@# Fix Topology $hemi `date`" \
  3078. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3079. set xopts = `fsr-getxopts mris_fix_topology $XOptsFile`;
  3080. set cmd = (mris_fix_topology)
  3081. set cmd = ($cmd -rusage $touchdir/rusage.mris_fix_topology.$hemi.dat)
  3082. set cmd = ($cmd -mgz -sphere qsphere.nofix)
  3083. if($FixWithGA) set cmd = ($cmd -ga)
  3084. if($FixDiagOnly) set cmd = ($cmd -diagonly)
  3085. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  3086. set cmd = ($cmd $xopts $subjid $hemi)
  3087. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3088. if($DoParallel) then
  3089. set CMDF = mris_fix_topology_${hemi}.cmd
  3090. echo "$cmd" > $CMDF
  3091. set CMDFS = ( $CMDFS $CMDF )
  3092. else
  3093. if($RunIt) $fs_time $cmd |& tee -a $LF
  3094. if($status) goto error_exit;
  3095. endif
  3096. end # hemi loop
  3097. if($RunIt && $DoParallel) then # if -parallel flag is used
  3098. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3099. if($status) goto error_exit;
  3100. endif
  3101. foreach hemi ($hemilist)
  3102. # check if total defect index != 0, meaning, euler # != 2 (surface bad)
  3103. set cmd = (mris_euler_number ../surf/$hemi.orig)
  3104. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3105. if($RunIt) then
  3106. $cmd >& mris_euler_number.${hemi}.log
  3107. if($status) goto error_exit;
  3108. set defect_idx=`grep "total defect index" mris_euler_number.${hemi}.log | awk '{print $5}'`
  3109. if("$defect_idx" != "0") then
  3110. echo "mris_fix_topology failed on ${hemi}! (euler number != 2)" |& tee -a $LF
  3111. echo "Trying new mris_topo_fixer on ${hemi}..." |& tee -a $LF
  3112. set UseNewTopoFix = 1
  3113. set NewTopoFixHemiList = ($NewTopoFixHemiList $hemi)
  3114. set UseOldTopoFix = 0
  3115. # cannot use the failed ?h.orig surface, must revert to ?.orig.nofix
  3116. set cmd = (cp ../surf/$hemi.orig.nofix ../surf/$hemi.orig)
  3117. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3118. if($RunIt) $cmd |& tee -a $LF
  3119. if($status) goto error_exit;
  3120. endif
  3121. cat mris_euler_number.${hemi}.log |& tee -a $LF
  3122. rm -f mris_euler_number.${hemi}.log
  3123. endif
  3124. end # hemi loop
  3125. endif # UseOldTopoFix
  3126. # the 'new' topology fixer is run if either the 'old' one failed,
  3127. # or if usage is flagged on the recon-all command-string (-use-new_fixer)
  3128. if($UseNewTopoFix) then
  3129. if($#NewTopoFixHemiList == 0) then
  3130. set NewTopoFixHemiList = ($hemilist) # use command-line default
  3131. # else use the bad hemi(s) found in prior euler-number check
  3132. endif
  3133. set CMDFS = () # see earlier notes on -parallel implementation
  3134. foreach hemi ($NewTopoFixHemiList)
  3135. set cmd = (cp ../surf/$hemi.qsphere.nofix ../surf/$hemi.qsphere)
  3136. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3137. if($RunIt) $cmd |& tee -a $LF
  3138. if($status) goto error_exit;
  3139. set cmd = (cp ../surf/$hemi.smoothwm.nofix ../surf/$hemi.smoothwm)
  3140. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3141. if($RunIt) $cmd |& tee -a $LF
  3142. if($status) goto error_exit;
  3143. set xopts = `fsr-getxopts mris_topo_fixer $XOptsFile`;
  3144. set cmd = (mris_topo_fixer -mgz -warnings)
  3145. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  3146. set cmd = ($cmd $xopts $subjid $hemi)
  3147. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3148. if($DoParallel) then
  3149. set CMDF = mris_topo_fixer_${hemi}.cmd
  3150. echo "$cmd" > $CMDF
  3151. set CMDFS = ( $CMDFS $CMDF )
  3152. else
  3153. if($RunIt) $fs_time $cmd |& tee -a $LF
  3154. if($status) goto error_exit;
  3155. endif
  3156. end # hemi loop
  3157. if($RunIt && $DoParallel) then # if -parallel flag is used
  3158. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3159. if($status) goto error_exit;
  3160. endif
  3161. endif # UseNewTopoFix
  3162. # run surface intersection checker/fixer
  3163. foreach hemi ($hemilist)
  3164. set xopts = `fsr-getxopts mris_remove_intersection $XOptsFile`;
  3165. set cmd = (mris_remove_intersection)
  3166. set cmd = ($cmd $xopts ../surf/$hemi.orig ../surf/$hemi.orig)
  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. # Remove hemi.inflated, real one created after mris_make_surfaces
  3172. set cmd = (rm ../surf/$hemi.inflated)
  3173. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3174. if($RunIt) $cmd
  3175. if($UseNewTopoFix && -e ../surf/$hemi.orig_corrected ) then
  3176. # Copy *h.orig_corrected to *h.orig. orig_corrected is created
  3177. # by mris_topo_fixer, which runs only when mris_fix_topology fails,
  3178. # which could happen for one hemi and not the other, so check
  3179. # if it exists prior to the copy in addition to checking the
  3180. # UseNewTopoFix flag.
  3181. set cmd = (cp ../surf/$hemi.orig_corrected ../surf/$hemi.orig )
  3182. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3183. if($RunIt) $cmd
  3184. if($status) goto error_exit;
  3185. endif
  3186. echo $cmd > $touchdir/$hemi.topofix.touch
  3187. end # Loop over hemilist
  3188. endif
  3189. # Smooth2 and Inflate2 stages run after make white surfs
  3190. #---------------- -------------------#
  3191. #---------------- Make White Surfaces -------------------#
  3192. ##--------------- -white -------------------#
  3193. #---------------- -------------------#
  3194. if($DoWhiteSurfs) then
  3195. set CMDFS = () # see earlier notes on -parallel implementation
  3196. foreach hemi ($hemilist)
  3197. echo "#--------------------------------------------" \
  3198. |& tee -a $LF |& tee -a $CF
  3199. echo "#@# Make White Surf $hemi `date`" \
  3200. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3201. cd $subjdir/scripts > /dev/null
  3202. $PWD |& tee -a $LF
  3203. if( $longitudinal ) then
  3204. set cmd = (cp -vf $longbasedir/surf/${hemi}.white \
  3205. $subjdir/surf/${hemi}.orig)
  3206. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3207. if($RunIt) $fs_time $cmd |& tee -a $LF
  3208. if($status) goto error_exit;
  3209. set cmd = (cp -vf $longbasedir/surf/${hemi}.white \
  3210. $subjdir/surf/${hemi}.orig_white)
  3211. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3212. if($RunIt) $fs_time $cmd |& tee -a $LF
  3213. if($status) goto error_exit;
  3214. # also copy pial just in case (needed if $DoPialSurf == 0 below)
  3215. set cmd = (cp -vf $longbasedir/surf/${hemi}.pial \
  3216. $subjdir/surf/${hemi}.orig_pial)
  3217. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3218. if($RunIt) $fs_time $cmd |& tee -a $LF
  3219. if($status) goto error_exit;
  3220. endif
  3221. # Note mris_make_surfaces uses filled.mgz implicitly
  3222. set xopts = `fsr-getxopts mris_make_surfaces $XOptsFile`;
  3223. if($longitudinal) then
  3224. # longitudinal processing:
  3225. set cmd = (mris_make_surfaces \
  3226. -orig_white orig_white \
  3227. -orig orig_white \
  3228. -long \
  3229. -max 3.5)
  3230. else
  3231. # default stream:
  3232. set cmd = (mris_make_surfaces)
  3233. endif
  3234. if ($UseAseg) then
  3235. set cmd = ($cmd -aseg ../mri/aseg.presurf)
  3236. else
  3237. set cmd = ($cmd -noaseg)
  3238. endif
  3239. # Save output as white.preaparc. The true white surface will be
  3240. # generated in the next call to mris_make_surfaces and will use
  3241. # the aparc. Several outputs below rely on white.preaparc but
  3242. # maybe should be using the white. We have decided to keep it this
  3243. # way for now because it matches the 5.3 stream.
  3244. set cmd = ($cmd -white white.preaparc -noaparc)
  3245. if($DoPialSurfs) then
  3246. # if creating pial downstream, then only do white surface now
  3247. set cmd = ($cmd -whiteonly)
  3248. else
  3249. # else old-style single-run -finalsurfs is emulated
  3250. if($longitudinal) set cmd = ($cmd -orig_pial orig_pial)
  3251. endif
  3252. set cmd = ($cmd -mgz -T1 brain.finalsurfs)
  3253. set cmd = ($cmd $WMSeg_wlo $WMSeg_ghi $xopts $subjid $hemi)
  3254. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3255. if($DoParallel) then
  3256. set CMDF = mris_make_surfaces_${hemi}.cmd
  3257. echo "$cmd" > $CMDF
  3258. set CMDFS = ( $CMDFS $CMDF )
  3259. else
  3260. if($RunIt) $fs_time $cmd |& tee -a $LF
  3261. if($status) goto error_exit;
  3262. endif
  3263. echo $cmd > $touchdir/$hemi.white_surface.touch
  3264. if( ! $DoPialSurfs) echo $cmd > $touchdir/$hemi.final_surfaces.touch
  3265. end # Loop over hemilist
  3266. if($RunIt && $DoParallel) then # if -parallel flag is used
  3267. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3268. if($status) goto error_exit;
  3269. endif
  3270. endif
  3271. #---------------- -------------------#
  3272. ##--------------- -smooth2 -------------------#
  3273. #---------------- -------------------#
  3274. if($DoSmooth2) then
  3275. set CMDFS = () # see earlier notes on -parallel implementation
  3276. foreach hemi ($hemilist)
  3277. echo "#--------------------------------------------" \
  3278. |& tee -a $LF |& tee -a $CF
  3279. echo "#@# Smooth2 $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3280. cd $subjdir/scripts > /dev/null
  3281. $PWD |& tee -a $LF
  3282. set xopts = `fsr-getxopts mris_smooth $XOptsFile`;
  3283. # Use -nw to keep from writing out curv and area
  3284. # Default number of iterations is 10, but use 3 here
  3285. set cmd = (mris_smooth -n 3 -nw)
  3286. if ($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  3287. set cmd = ($cmd $xopts)
  3288. set cmd = ($cmd ../surf/$hemi.white.preaparc ../surf/$hemi.smoothwm)
  3289. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3290. if($DoParallel) then
  3291. set CMDF = mris_smooth_${hemi}.cmd
  3292. echo "$cmd" > $CMDF
  3293. set CMDFS = ( $CMDFS $CMDF )
  3294. else
  3295. if($RunIt) $fs_time $cmd |& tee -a $LF
  3296. if($status) goto error_exit;
  3297. endif
  3298. echo $cmd > $touchdir/$hemi.smoothwm2.touch
  3299. end # Loop over hemilist
  3300. if($RunIt && $DoParallel) then
  3301. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3302. if($status) goto error_exit;
  3303. endif
  3304. endif
  3305. #---------------- -------------------#
  3306. ##--------------- -inflate2 -------------------#
  3307. #---------------- -------------------#
  3308. if($DoInflate2) then
  3309. set CMDFS = () # see earlier notes on -parallel implementation
  3310. foreach hemi ($hemilist)
  3311. echo "#--------------------------------------------" \
  3312. |& tee -a $LF |& tee -a $CF
  3313. echo "#@# Inflation2 $hemi `date`" \
  3314. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3315. cd $subjdir/scripts > /dev/null
  3316. $PWD |& tee -a $LF
  3317. set xopts = `fsr-getxopts mris_inflate $XOptsFile`;
  3318. set cmd = (mris_inflate)
  3319. if($UseCuda) set cmd = (mris_inflate_cuda)
  3320. set cmd = ($cmd -rusage $touchdir/rusage.mris_inflate.$hemi.dat)
  3321. set cmd = ($cmd $xopts ../surf/$hemi.smoothwm \
  3322. ../surf/$hemi.inflated)
  3323. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3324. if($DoParallel) then
  3325. set CMDF = mris_inflate_${hemi}.cmd
  3326. echo "$cmd" > $CMDF
  3327. set CMDFS = ( $CMDFS $CMDF )
  3328. else
  3329. if($RunIt) $fs_time $cmd |& tee -a $LF
  3330. if($status) goto error_exit;
  3331. endif
  3332. echo $cmd > $touchdir/$hemi.inflate2.touch
  3333. end # Loop over hemilist
  3334. if($RunIt && $DoParallel) then
  3335. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3336. if($status) goto error_exit;
  3337. endif
  3338. endif
  3339. #---------- -----------#
  3340. #---------- Curvature .H and .K -----------#
  3341. ##--------- -curvHK -----------#
  3342. #---------- -----------#
  3343. if($DoCurvHK) then
  3344. set CMDFS = () # see earlier notes on -parallel implementation
  3345. foreach hemi ($hemilist)
  3346. echo "#--------------------------------------------" \
  3347. |& tee -a $LF |& tee -a $CF
  3348. echo "#@# Curv .H and .K $hemi `date`" \
  3349. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3350. cd $subjdir/surf > /dev/null
  3351. $PWD |& tee -a $LF
  3352. # create curvature files ?h.white.H and ?h.white.K
  3353. set xopts = `fsr-getxopts mris_curatvure $XOptsFile`;
  3354. set cmd = (mris_curvature -w $xopts $hemi.white.preaparc)
  3355. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3356. if($DoParallel) then
  3357. set CMDF = mris_curvature_white_${hemi}.cmd
  3358. echo "$cmd" > $CMDF
  3359. set CMDFS = ( $CMDFS $CMDF )
  3360. else
  3361. if($RunIt) $fs_time $cmd |& tee -a $LF
  3362. if($status) goto error_exit;
  3363. endif
  3364. # This is a bit of a hack to account for the change in the name of the input white
  3365. # surface. There needs to be a file called ?h.white.{H,K} but mris_curvature creates
  3366. # ?h.white.preaparc.{H,K}. This just creates a symlink
  3367. foreach suffix (H K)
  3368. set cmd1 = (rm -f $hemi.white.$suffix)
  3369. set cmd2 = (ln -s $hemi.white.preaparc.$suffix $hemi.white.$suffix)
  3370. echo $cmd1 | tee -a $LF
  3371. echo $cmd2 | tee -a $LF
  3372. if($DoParallel) then
  3373. set CMDF = rm_curvature_white_${hemi}.$suffix.cmd
  3374. echo "$cmd1" > $CMDF
  3375. set CMDFS = ( $CMDFS $CMDF )
  3376. set CMDF = ln_curvature_white_${hemi}.$suffix.cmd
  3377. echo "$cmd2" > $CMDF
  3378. set CMDFS = ( $CMDFS $CMDF )
  3379. else
  3380. if($RunIt) then
  3381. $cmd1 | tee -a $LF
  3382. if($status) goto error_exit
  3383. $cmd2 | tee -a $LF
  3384. if($status) goto error_exit
  3385. endif
  3386. endif
  3387. end
  3388. echo $cmd > $touchdir/$hemi.white.H.K.touch
  3389. # create curvature files ?h.inflated.H and ?h.inflated.K
  3390. set xopts = `fsr-getxopts mris_curatvure $XOptsFile`;
  3391. set cmd = (mris_curvature -thresh .999 -n -a 5 -w -distances 10 10)
  3392. set cmd = ($cmd $xopts $hemi.inflated)
  3393. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3394. if($DoParallel) then
  3395. set CMDF = mris_curvature_inflated_${hemi}.cmd
  3396. echo "$cmd" > $CMDF
  3397. set CMDFS = ( $CMDFS $CMDF )
  3398. else
  3399. if($RunIt) $fs_time $cmd |& tee -a $LF
  3400. if($status) goto error_exit;
  3401. endif
  3402. echo $cmd > $touchdir/$hemi.inflate.H.K.touch
  3403. end # Loop over hemilist
  3404. if($RunIt && $DoParallel) then
  3405. set cmd = (reconbatchjobs $LF $CMDFS)
  3406. echo "cd `pwd`" | tee -a $LF
  3407. echo $cmd | tee -a $LF
  3408. $cmd |& tee -a $LF
  3409. if($status) goto error_exit;
  3410. endif
  3411. foreach hemi ($hemilist)
  3412. if($RunIt && ! -e ${hemi}.white.H) then
  3413. pwd | tee -a $LF
  3414. echo "Cannot find ${hemi}.white.H" | tee -a $LF
  3415. goto error_exit;
  3416. endif
  3417. if($RunIt && ! -e ${hemi}.inflated.H) then
  3418. pwd | tee -a $LF
  3419. echo "Cannot find ${hemi}.inflated.H" | tee -a $LF
  3420. goto error_exit;
  3421. endif
  3422. end
  3423. endif
  3424. #---------- -----------#
  3425. #---------- Curvature Anatomical Stats -----------#
  3426. ##--------- -curvstats -----------#
  3427. #---------- -----------#
  3428. if($DoCurvStats) then
  3429. foreach hemi ($hemilist)
  3430. echo "\n#-----------------------------------------" \
  3431. |& tee -a $LF |& tee -a $CF
  3432. echo "#@# Curvature Stats $hemi `date`" \
  3433. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3434. cd $subjdir/surf > /dev/null
  3435. $PWD |& tee -a $LF
  3436. set stats = ../stats/$hemi.curv.stats
  3437. set xopts = `fsr-getxopts mris_curvature_stats $XOptsFile`;
  3438. set cmd = (mris_curvature_stats -m --writeCurvatureFiles -G \
  3439. -o $stats -F smoothwm \
  3440. $xopts $subjid $hemi curv sulc);
  3441. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3442. if($RunIt) $fs_time $cmd |& tee -a $LF
  3443. if($status) goto error_exit;
  3444. if(-e .xdebug_mris_curvature_stats) rm -f .xdebug_mris_curvature_stats
  3445. echo $cmd > $touchdir/$hemi.curvstats.touch
  3446. end # Loop over hemilist
  3447. endif
  3448. #----------- -------------#
  3449. ##---------- AUTORECON 3 -------------#
  3450. #----------- -------------#
  3451. #---------------- ----------------#
  3452. ##--------------- -sphere ----------------#
  3453. #---------------- ----------------#
  3454. if($DoSphere) then
  3455. set CMDFS = () # see earlier notes on -parallel implementation
  3456. foreach hemi ($hemilist)
  3457. echo "#--------------------------------------------" \
  3458. |& tee -a $LF |& tee -a $CF
  3459. echo "#@# Sphere $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3460. cd $subjdir/scripts > /dev/null
  3461. $PWD |& tee -a $LF
  3462. if($longitudinal) then
  3463. # longitudinal processing:
  3464. set cmd = (cp $longbasedir/surf/$hemi.sphere $subjdir/surf/$hemi.sphere)
  3465. else
  3466. # default stream:
  3467. set xopts = `fsr-getxopts mris_sphere $XOptsFile`;
  3468. set cmd = (mris_sphere)
  3469. if($UseCuda) set cmd = (mris_sphere_cuda)
  3470. set cmd = ($cmd -rusage $touchdir/rusage.mris_sphere.$hemi.dat)
  3471. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  3472. if($UseNoNeg) set cmd = ($cmd -remove_negative 1)
  3473. set cmd = ($cmd $xopts)
  3474. set cmd = ($cmd ../surf/$hemi.inflated ../surf/$hemi.sphere)
  3475. endif
  3476. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3477. if($DoParallel) then
  3478. set CMDF = mris_sphere_${hemi}.cmd
  3479. echo "$cmd" > $CMDF
  3480. set CMDFS = ( $CMDFS $CMDF )
  3481. else
  3482. if($RunIt) $fs_time $cmd |& tee -a $LF
  3483. if($status) goto error_exit;
  3484. endif
  3485. echo $cmd > $touchdir/$hemi.sphmorph.touch
  3486. end # Loop over hemilist
  3487. if($RunIt && $DoParallel) then
  3488. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3489. if($status) goto error_exit;
  3490. endif
  3491. endif
  3492. #---------------- -------------------#
  3493. #---------------- Surface Registration -------------------#
  3494. ##--------------- -surfreg -------------------#
  3495. #---------------- -------------------#
  3496. if($DoSurfReg) then
  3497. set CMDFS = () # see earlier notes on -parallel implementation
  3498. foreach hemi ($hemilist)
  3499. echo "#--------------------------------------------" \
  3500. |& tee -a $LF |& tee -a $CF
  3501. echo "#@# Surf Reg $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3502. cd $subjdir/scripts > /dev/null
  3503. $PWD |& tee -a $LF
  3504. set AvgTif = ${AvgCurvTifPath}/$hemi.${AvgCurvTif}
  3505. set xopts = `fsr-getxopts mris_register $XOptsFile`;
  3506. set cmd = (mris_register -curv)
  3507. set cmd = ($cmd -rusage $touchdir/rusage.mris_register.$hemi.dat)
  3508. if($UseNoNeg) set cmd = ($cmd -remove_negative 1)
  3509. set cmd = ($cmd $xopts)
  3510. if($longitudinal) then
  3511. # longitudinal processing:
  3512. set cmd = ($cmd -nosulc -norot \
  3513. $longbasedir/surf/$hemi.sphere.reg \
  3514. $AvgTif \
  3515. ../surf/$hemi.sphere.reg)
  3516. else
  3517. # default stream:
  3518. set cmd = ($cmd ../surf/$hemi.sphere $AvgTif ../surf/$hemi.sphere.reg)
  3519. endif
  3520. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3521. if($DoParallel) then
  3522. set CMDF = mris_register_${hemi}.cmd
  3523. echo "$cmd" > $CMDF
  3524. set CMDFS = ( $CMDFS $CMDF )
  3525. else
  3526. if($RunIt) $fs_time $cmd |& tee -a $LF
  3527. if($status) goto error_exit;
  3528. endif
  3529. echo $cmd > $touchdir/$hemi.sphreg.touch
  3530. end # Loop over hemilist
  3531. if($RunIt && $DoParallel) then
  3532. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3533. if($status) goto error_exit;
  3534. endif
  3535. endif
  3536. #-------- ---------#
  3537. #-------- Contra Surface Registration ---------#
  3538. ##------- -contrasurfreg ---------#
  3539. ##------- -contrasurfreg-subj ---------#
  3540. #-------- ---------#
  3541. # Registers ipsi and contra
  3542. if($DoContraSurfReg) then
  3543. set CMDFS = () # see earlier notes on -parallel implementation
  3544. foreach hemi ($hemilist)
  3545. if($hemi == lh) then
  3546. set nothemi = rh;
  3547. else
  3548. set nothemi = lh;
  3549. endif
  3550. echo "#--------------------------------------------" \
  3551. |& tee -a $LF |& tee -a $CF
  3552. echo "#@# Contra Surf Reg $hemi `date`" \
  3553. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3554. cd $subjdir/scripts > /dev/null
  3555. $PWD |& tee -a $LF
  3556. set AvgTif = ${AvgCurvTifPath}/$nothemi.${AvgCurvTif}
  3557. set xopts = `fsr-getxopts mris_register $XOptsFile`;
  3558. set cmd = (mris_register -curv -reverse ../surf/$hemi.sphere)
  3559. if($UseNoNeg) set cmd = ($cmd -remove_negative 1)
  3560. set cmd = ($cmd $xopts)
  3561. set cmd = ($cmd $AvgTif ../surf/$hemi.$nothemi.sphere.reg)
  3562. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3563. if($DoParallel) then
  3564. set CMDF = mris_register_${hemi}.cmd
  3565. echo "$cmd" > $CMDF
  3566. set CMDFS = ( $CMDFS $CMDF )
  3567. else
  3568. if($RunIt) $fs_time $cmd |& tee -a $LF
  3569. if($status) goto error_exit;
  3570. endif
  3571. echo $cmd > $touchdir/$hemi.sphreg.contra.touch
  3572. end # Loop over hemilist
  3573. if($RunIt && $DoParallel) then
  3574. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3575. if($status) goto error_exit;
  3576. endif
  3577. endif
  3578. # Register ipsi to contra directly (instead of thru sphere)
  3579. # Creates lh.rh.sphere (note that there is no .reg)
  3580. if($DoContraSurfRegWithinSubject) then
  3581. set CMDFS = () # see earlier notes on -parallel implementation
  3582. foreach hemi ($hemilist)
  3583. cd $subjdir/surf
  3584. $PWD |& tee -a $LF
  3585. if($hemi == lh) then
  3586. set nothemi = rh;
  3587. else
  3588. set nothemi = lh;
  3589. endif
  3590. if(! -e $nothemi.inflated.H) then
  3591. echo "ERROR: cannot find $nothemi.inflated.H, try running -inflate2" \
  3592. |& tee -a $LF
  3593. goto error_exit;
  3594. endif
  3595. echo "#--------------------------------------------" \
  3596. |& tee -a $LF |& tee -a $CF
  3597. echo "#@# Contra Surf Reg Within Subject $hemi `date`" \
  3598. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3599. set cmd = (mris_register -dist 0.3 -reverse -1 \
  3600. ./$hemi.sphere ./$nothemi.sphere ./$hemi.$nothemi.sphere)
  3601. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3602. if($DoParallel) then
  3603. set CMDF = mris_register_${hemi}.cmd
  3604. echo "$cmd" > $CMDF
  3605. set CMDFS = ( $CMDFS $CMDF )
  3606. else
  3607. if($RunIt) $fs_time $cmd |& tee -a $LF
  3608. if($status) goto error_exit;
  3609. endif
  3610. echo $cmd > $touchdir/$hemi.sphere.contra.touch
  3611. end # hemi
  3612. if($RunIt && $DoParallel) then
  3613. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3614. if($status) goto error_exit;
  3615. endif
  3616. endif
  3617. #---------- ----------------#
  3618. #---------- Surface Registration to Average Subject ----------------#
  3619. ##--------- -surfreg-to-subject ----------------#
  3620. #---------- ----------------#
  3621. if($#SurfRegToSubj) then
  3622. set CMDFS = () # see earlier notes on -parallel implementation
  3623. foreach hemi ($hemilist)
  3624. echo "#--------------------------------------------" \
  3625. |& tee -a $LF |& tee -a $CF
  3626. echo "#@# Surf RegTo $SurfRegToSubj $hemi `date`" \
  3627. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3628. cd $subjdir/scripts > /dev/null
  3629. $PWD |& tee -a $LF
  3630. set AvgTif = $SUBJECTS_DIR/$SurfRegToSubj/$hemi.reg.template.tif
  3631. set outreg = ../surf/$hemi.sphere.$SurfRegToSubj.reg
  3632. set cmd = (mris_register -curv)
  3633. if($UseNoNeg) set cmd = ($cmd -remove_negative 1)
  3634. set cmd = ($cmd ../surf/$hemi.sphere $AvgTif $outreg);
  3635. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3636. if($DoParallel) then
  3637. set CMDF = mris_register_${hemi}.cmd
  3638. echo "$cmd" > $CMDF
  3639. set CMDFS = ( $CMDFS $CMDF )
  3640. else
  3641. if($RunIt) $fs_time $cmd |& tee -a $LF
  3642. if($status) goto error_exit;
  3643. endif
  3644. echo $cmd > $touchdir/$hemi.sphreg.$SurfRegToSubj.touch
  3645. end # Loop over hemilist
  3646. if($RunIt && $DoParallel) then
  3647. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3648. if($status) goto error_exit;
  3649. endif
  3650. endif
  3651. #---------------- -------------------#
  3652. ##--------------- -jacobian_white -------------------#
  3653. #---------------- -------------------#
  3654. if($DoJacobianWhite) then
  3655. set CMDFS = () # see earlier notes on -parallel implementation
  3656. foreach hemi ($hemilist)
  3657. echo "#--------------------------------------------" \
  3658. |& tee -a $LF |& tee -a $CF
  3659. echo "#@# Jacobian white $hemi `date`" \
  3660. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3661. cd $subjdir/scripts > /dev/null
  3662. $PWD |& tee -a $LF
  3663. # produce the jacobian, from the white surface to the sphere
  3664. set cmd = (mris_jacobian \
  3665. ../surf/$hemi.white.preaparc \
  3666. ../surf/$hemi.sphere.reg \
  3667. ../surf/$hemi.jacobian_white)
  3668. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3669. if($DoParallel) then
  3670. set CMDF = mris_jacobian_${hemi}.cmd
  3671. echo "$cmd" > $CMDF
  3672. set CMDFS = ( $CMDFS $CMDF )
  3673. else
  3674. if($RunIt) $fs_time $cmd |& tee -a $LF
  3675. if($status) goto error_exit;
  3676. endif
  3677. echo $cmd > $touchdir/$hemi.jacobian_white.touch
  3678. end # Loop over hemilist
  3679. if($RunIt && $DoParallel) then
  3680. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3681. if($status) goto error_exit;
  3682. endif
  3683. endif
  3684. #--- ---#
  3685. #--- Surface Registration, allow maximal distortion, produce Jacobian ---#
  3686. ##-- -jacobian_dist0 ---#
  3687. #--- ---#
  3688. if($DoJacobianDist0) then
  3689. set CMDFS = () # see earlier notes on -parallel implementation
  3690. foreach hemi ($hemilist)
  3691. echo "#--------------------------------------------" \
  3692. |& tee -a $LF |& tee -a $CF
  3693. echo "#@# Jacobian dist0 $hemi `date`" \
  3694. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3695. cd $subjdir/scripts > /dev/null
  3696. $PWD |& tee -a $LF
  3697. set AvgTif = ${AvgCurvTifPath}/$hemi.${AvgCurvTif}
  3698. set xopts = `fsr-getxopts mris_register $XOptsFile`;
  3699. set cmd = (mris_register -curv -norot -jacobian \
  3700. ../surf/$hemi.jacobian_dist0 -dist 0)
  3701. set cmd = ($cmd $xopts)
  3702. set cmd = ($cmd ../surf/$hemi.sphere.reg $AvgTif \
  3703. ../surf/$hemi.sphere.dist0.jacobian.reg)
  3704. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3705. if($DoParallel) then
  3706. set CMDF = mris_register_${hemi}.cmd
  3707. echo "$cmd" > $CMDF
  3708. set CMDFS = ( $CMDFS $CMDF )
  3709. else
  3710. if($RunIt) $fs_time $cmd |& tee -a $LF
  3711. if($status) goto error_exit;
  3712. endif
  3713. echo $cmd > $touchdir/$hemi.jacobian_dist0.touch
  3714. end # Loop over hemilist
  3715. if($RunIt && $DoParallel) then
  3716. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3717. if($status) goto error_exit;
  3718. endif
  3719. endif
  3720. #--------------- ---------------#
  3721. #--------------- Average Curv for Display ---------------#
  3722. ##-------------- -avgcurv ---------------#
  3723. #--------------- ---------------#
  3724. if($DoAvgCurv) then
  3725. set CMDFS = () # see earlier notes on -parallel implementation
  3726. foreach hemi ($hemilist)
  3727. echo "#--------------------------------------------" \
  3728. |& tee -a $LF |& tee -a $CF
  3729. echo "#@# AvgCurv $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3730. cd $subjdir/scripts > /dev/null
  3731. $PWD |& tee -a $LF
  3732. set AvgTif = ${AvgCurvTifPath}/$hemi.${AvgCurvTif}
  3733. set xopts = `fsr-getxopts mrisp_paint $XOptsFile`;
  3734. # -a 5 means to smooth 5 iterations
  3735. set cmd = (mrisp_paint -a 5 $xopts "$AvgTif#6" \
  3736. ../surf/$hemi.sphere.reg ../surf/$hemi.avg_curv)
  3737. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3738. if($DoParallel) then
  3739. set CMDF = mrisp_paint_${hemi}.cmd
  3740. echo "$cmd" > $CMDF
  3741. set CMDFS = ( $CMDFS $CMDF )
  3742. else
  3743. if($RunIt) $fs_time $cmd |& tee -a $LF
  3744. if($status) goto error_exit;
  3745. endif
  3746. echo $cmd > $touchdir/$hemi.avgcurv.touch
  3747. end # Loop over hemilist
  3748. if($RunIt && $DoParallel) then
  3749. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3750. if($status) goto error_exit;
  3751. endif
  3752. endif
  3753. #---------------- -----------------#
  3754. #---------------- Cortical Parcellation -----------------#
  3755. ##--------------- -cortparc -----------------#
  3756. #---------------- -----------------#
  3757. if($DoCortParc) then
  3758. set CMDFS = () # see earlier notes on -parallel implementation
  3759. foreach hemi ($hemilist)
  3760. echo "#-----------------------------------------" \
  3761. |& tee -a $LF |& tee -a $CF
  3762. echo "#@# Cortical Parc $hemi `date`" \
  3763. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3764. cd $subjdir/scripts > /dev/null
  3765. $PWD |& tee -a $LF
  3766. set xopts = `fsr-getxopts mris_ca_label $XOptsFile`;
  3767. set CPAtlas = ${GCSDIR}/$hemi.$GCS
  3768. set annot = ../label/$hemi.aparc.annot
  3769. set cmd = (mris_ca_label)
  3770. if($UseAseg) set cmd = ($cmd -l ../label/$hemi.cortex.label)
  3771. if($UseAseg) set cmd = ($cmd -aseg ../mri/aseg.presurf.mgz)
  3772. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  3773. set cmd = ($cmd $xopts)
  3774. if($longitudinal) then
  3775. # longitudinal:
  3776. set cmd = ($cmd -long -R $longbasedir/label/${hemi}.aparc.annot)
  3777. endif
  3778. set cmd = ($cmd $subjid $hemi ../surf/$hemi.sphere.reg $CPAtlas $annot)
  3779. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  3780. if($DoParallel) then
  3781. set CMDF = mris_ca_label_${hemi}.cmd
  3782. echo "$cmd" > $CMDF
  3783. set CMDFS = ( $CMDFS $CMDF )
  3784. else
  3785. if($RunIt) $fs_time $cmd |& tee -a $LF
  3786. if($status) goto error_exit;
  3787. endif
  3788. echo $cmd > $touchdir/$hemi.aparc.touch
  3789. end # Loop over hemilist
  3790. if($RunIt && $DoParallel) then
  3791. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3792. if($status) goto error_exit;
  3793. endif
  3794. endif
  3795. #---------------- -------------------#
  3796. #---------------- Make Pial Surfaces -------------------#
  3797. ##--------------- -pial -------------------#
  3798. #---------------- -------------------#
  3799. if($DoPialSurfs) then
  3800. set CMDFS = () # see earlier notes on -parallel implementation
  3801. foreach hemi ($hemilist)
  3802. echo "#--------------------------------------------" \
  3803. |& tee -a $LF |& tee -a $CF
  3804. echo "#@# Make Pial Surf $hemi `date`" \
  3805. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3806. cd $subjdir/scripts > /dev/null
  3807. $PWD |& tee -a $LF
  3808. if( $longitudinal && ! -e $subjdir/surf/${hemi}.orig_pial ) then
  3809. # should rarely get here as this is copied above in Make White Surfaces
  3810. set cmd = (cp -vf $longbasedir/surf/${hemi}.pial\
  3811. $subjdir/surf/${hemi}.orig_pial)
  3812. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3813. if($RunIt) $fs_time $cmd |& tee -a $LF
  3814. if($status) goto error_exit;
  3815. endif
  3816. # Note mris_make_surfaces uses filled.mgz implicitly
  3817. set xopts = `fsr-getxopts mris_make_surfaces $XOptsFile`;
  3818. if($longitudinal) then
  3819. # longitudinal processing:
  3820. set cmd = (mris_make_surfaces \
  3821. -orig orig_white \
  3822. -orig_white orig_white \
  3823. -orig_pial orig_pial \
  3824. -long -max 3.5)
  3825. else
  3826. # default stream:
  3827. # NJS: -orig_pial white added 16Feb2015 per BF
  3828. set cmd = (mris_make_surfaces \
  3829. -orig_white white.preaparc \
  3830. -orig_pial white.preaparc)
  3831. if ($UseFixMtl) then
  3832. # NJS: now external flag option, 3Jun2015
  3833. set cmd = ($cmd -fix_mtl)
  3834. endif
  3835. endif
  3836. if ($UseAseg) then
  3837. set cmd = ($cmd -aseg ../mri/aseg.presurf)
  3838. else
  3839. set cmd = ($cmd -noaseg)
  3840. endif
  3841. if ($PialNoAparc) set cmd = ($cmd -noaparc)
  3842. # -nowhite : do not refit white surface (nothing wrt white gets overwritten)
  3843. # set cmd = ($cmd -nowhite);
  3844. # Don't use -nowrite or -white NOWRITE because we want to regenerate the
  3845. # white using the aparc (ie, not -noaparc) and write out that surface
  3846. # as the white since that is the one that is used for thickness computations
  3847. set cmd = ($cmd -mgz -T1 brain.finalsurfs)
  3848. set cmd = ($cmd $WMSeg_wlo $WMSeg_ghi $xopts $subjid $hemi);
  3849. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3850. if($DoParallel) then
  3851. set CMDF = mris_make_surfaces_${hemi}.cmd
  3852. echo "$cmd" > $CMDF
  3853. set CMDFS = ( $CMDFS $CMDF )
  3854. else
  3855. if($RunIt) $fs_time $cmd |& tee -a $LF
  3856. if($status) goto error_exit;
  3857. endif
  3858. echo $cmd > $touchdir/$hemi.pial_surface.touch
  3859. echo $cmd > $touchdir/$hemi.final_surfaces.touch
  3860. end # Loop hemilist
  3861. if($RunIt && $DoParallel) then
  3862. reconbatchjobs $LF $CMDFS |& tee -a $LF
  3863. if($status) goto error_exit;
  3864. endif
  3865. endif
  3866. #---------------- ----------------#
  3867. #---------------- Refine Pial Surfaces Using T2/FLAIR ----------------#
  3868. ##--------------- -T2pial and -FLAIRpial ----------------#
  3869. #---------------- ----------------#
  3870. # note: the registration portion requires existence of both surfaces
  3871. if($DoT2pial || $DoFLAIRpial) then
  3872. echo "#--------------------------------------------" \
  3873. |& tee -a $LF |& tee -a $CF
  3874. echo "#@# Refine Pial Surfs w/ T2/FLAIR `date`" \
  3875. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  3876. cd $subjdir/scripts > /dev/null
  3877. # should be one or the other. 'check_params' section checks for this.
  3878. if($DoT2pial) set t2flair=(T2)
  3879. if($DoFLAIRpial) set t2flair=(FLAIR)
  3880. set mdir=$SUBJECTS_DIR/${subjid}/mri
  3881. set sdir=$SUBJECTS_DIR/${subjid}/surf
  3882. set tdir=$SUBJECTS_DIR/${subjid}/touch
  3883. if (! -e $mdir/${t2flair}.mgz) then
  3884. set t2flairraw = $mdir/orig/${t2flair}raw.mgz
  3885. # Longitudinal processing
  3886. if ($longitudinal) then
  3887. # use T2/FLAIR raw from cross if missing in long
  3888. if (! -e $t2flairraw) then
  3889. set t2flairraw = ${SUBJECTS_DIR}/${tpNid}/mri/orig/${t2flair}raw.mgz
  3890. endif
  3891. if (! -e $t2flairraw) then
  3892. echo "ERROR: mri/orig/${t2flair}raw.mgz missing in long and cross." \
  3893. |& tee -a $LF
  3894. goto error_exit;
  3895. endif
  3896. # concatenate lta if created in cross (T2cross->T1cross->longspace)
  3897. # this avoids registering again if already done in cross
  3898. if ( -e ${SUBJECTS_DIR}/${tpNid}/mri/transforms/${t2flair}raw.lta ) then
  3899. set cmd = (mri_concatenate_lta )
  3900. set cmd = ($cmd ${SUBJECTS_DIR}/${tpNid}/mri/transforms/${t2flair}raw.lta )
  3901. set cmd = ($cmd $tpNtobase_regfile $mdir/transforms/${t2flair}raw.lta)
  3902. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  3903. if($RunIt) $fs_time $cmd |& tee -a $LF
  3904. if($status) goto error_exit;
  3905. else
  3906. # if t2flairraw.lta does not exist in cross, register T2raw to longspace
  3907. set xopts = `fsr-getxopts bbregister $XOptsFile`;
  3908. set bbcmd = (bbregister \
  3909. --s $subjid \
  3910. --mov $t2flairraw \
  3911. --lta $mdir/transforms/${t2flair}raw.lta \
  3912. --init-$BBRInit \
  3913. --T2 $xopts)
  3914. echo "\n $bbcmd \n"|& tee -a $LF |& tee -a $CF
  3915. if($RunIt) $fs_time $bbcmd |& tee -a $LF
  3916. if($status) goto error_exit;
  3917. endif
  3918. else #regular processing, register T2flairraw to T1 and create lta
  3919. set LTAAuto = $mdir/transforms/${t2flair}raw.auto.lta
  3920. set LTAMan = $mdir/transforms/${t2flair}raw.lta
  3921. set DontCopy = 0
  3922. if(-e $LTAAuto && -e $LTAMan) then
  3923. set DontCopy = `diff $LTAAuto $LTAMan | grep -v \# | grep -v filename | wc -l`
  3924. endif
  3925. # first create a T2/FLAIR that is registered to the T1s
  3926. set xopts = `fsr-getxopts bbregister $XOptsFile`;
  3927. set bbcmd = (bbregister \
  3928. --s $subjid \
  3929. --mov $t2flairraw \
  3930. --lta $LTAAuto \
  3931. --init-$BBRInit \
  3932. --T2 $xopts)
  3933. echo "\n $bbcmd \n"|& tee -a $LF |& tee -a $CF
  3934. if($RunIt) $fs_time $bbcmd |& tee -a $LF
  3935. if($status) goto error_exit;
  3936. if($DontCopy == 0) then
  3937. set cmd = (cp $LTAAuto $LTAMan)
  3938. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3939. if($RunIt) $fs_time $cmd |& tee -a $LF
  3940. if($status) goto error_exit;
  3941. endif
  3942. endif
  3943. # both regular and long processing:
  3944. # actually map the input (and make conform as the T1 target)
  3945. # this creates the ${t2flair}.prenorm.mgz
  3946. set mapcmd = (mri_convert \
  3947. -odt float \
  3948. -at $mdir/transforms/${t2flair}raw.lta)
  3949. if($UseCubic) set mapcmd = ($mapcmd -rt cubic -ns 1)
  3950. set mapcmd = ($mapcmd -rl $mdir/orig.mgz )
  3951. set mapcmd = ($mapcmd $t2flairraw )
  3952. set mapcmd = ($mapcmd $mdir/${t2flair}.prenorm.mgz )
  3953. echo "\n $mapcmd \n"|& tee -a $LF |& tee -a $CF
  3954. if($RunIt) $fs_time $mapcmd |& tee -a $LF
  3955. if($status) goto error_exit;
  3956. # then give the T2/FLAIR a little normalizing
  3957. # note: pre-normalized file remains for debug, with .prenorm in name
  3958. # this creates ${t2flair}.norm.mgz
  3959. set normcmd = (mri_normalize \
  3960. -sigma 0.5 -nonmax_suppress 0 -min_dist 1 \
  3961. -aseg $mdir/aseg.presurf.mgz \
  3962. -surface $sdir/rh.white identity.nofile \
  3963. -surface $sdir/lh.white identity.nofile \
  3964. $mdir/${t2flair}.prenorm.mgz \
  3965. $mdir/${t2flair}.norm.mgz)
  3966. echo "\n $normcmd \n"|& tee -a $LF |& tee -a $CF
  3967. if($RunIt) $fs_time $normcmd |& tee -a $LF
  3968. if($status) goto error_exit;
  3969. # then mask the T2/FLAIR
  3970. # note: post-normalized file remains for debug, with .norm in name
  3971. # this creates ${t2flair}.mgz
  3972. set maskcmd = (mri_mask \
  3973. $mdir/${t2flair}.norm.mgz \
  3974. $mdir/brainmask.mgz \
  3975. $mdir/${t2flair}.mgz)
  3976. echo "\n $maskcmd \n"|& tee -a $LF |& tee -a $CF
  3977. if($RunIt) $fs_time $maskcmd |& tee -a $LF
  3978. if($status) goto error_exit;
  3979. endif
  3980. set CMDFS = () # see earlier notes on -parallel implementation
  3981. foreach hemi ($hemilist)
  3982. $PWD |& tee -a $LF
  3983. set xopts = `fsr-getxopts mris_make_surfaces $XOptsFile`;
  3984. set nv1=(`mris_info $sdir/${hemi}.pial |& grep nvertices`)
  3985. set nv2=(`mris_info $sdir/${hemi}.wo${t2flair}.pial |& grep nvertices`)
  3986. set touch1=($tdir/${hemi}.pial_refine.touch)
  3987. set touch2=($tdir/${hemi}.pial_surface.touch)
  3988. if ( (! -e $sdir/${hemi}.wo${t2flair}.pial) || \
  3989. ("$nv1" != "$nv2") || \
  3990. (`UpdateNeeded $touch1 $touch2`) ) then
  3991. set cmd = (cp -v $sdir/${hemi}.pial $sdir/${hemi}.wo${t2flair}.pial)
  3992. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  3993. if($RunIt) $fs_time $cmd |& tee -a $LF
  3994. if($status) goto error_exit;
  3995. endif
  3996. set cmd = (mris_make_surfaces \
  3997. -orig_white white \
  3998. -orig_pial wo${t2flair}.pial)
  3999. if ($UseAseg) then
  4000. set cmd = ($cmd -aseg ../mri/aseg.presurf)
  4001. else
  4002. set cmd = ($cmd -noaseg)
  4003. endif
  4004. if ($PialNoAparc) set cmd = ($cmd -noaparc)
  4005. # -nowhite : do not refit white surface (nothing wrt white gets overwritten)
  4006. set cmd = ($cmd -nowhite)
  4007. set cmd = ($cmd -mgz -T1 brain.finalsurfs)
  4008. # if using a T2 or FLAIR to remove dura that might be confused with pial...
  4009. if($DoT2pial) then
  4010. set cmd = ($cmd -T2 ../mri/T2 -nsigma_above 2 -nsigma_below 5)
  4011. if($#T2max) set cmd = ($cmd -T2_max $T2max);
  4012. endif
  4013. if ($DoFLAIRpial) set cmd = ($cmd -FLAIR ../mri/FLAIR \
  4014. -nsigma_above 3 -nsigma_below 3)
  4015. set cmd = ($cmd $WMSeg_wlo $WMSeg_ghi $xopts $subjid $hemi);
  4016. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4017. if($DoParallel) then
  4018. set CMDF = mris_make_surfaces_${hemi}.cmd
  4019. echo "$cmd" > $CMDF
  4020. set CMDFS = ( $CMDFS $CMDF )
  4021. else
  4022. if($RunIt) $fs_time $cmd |& tee -a $LF
  4023. if($status) goto error_exit;
  4024. endif
  4025. echo $cmd > $touchdir/$hemi.pial_refine.touch
  4026. end # for each hemi
  4027. if($RunIt && $DoParallel) then
  4028. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4029. if($status) goto error_exit;
  4030. endif
  4031. # redo ?h.volume files
  4032. if(-e $subjdir/surf/rh.volume || -e $subjdir/surf/lh.volume) then
  4033. foreach hemi ($hemilist)
  4034. echo "#--------------------------------------------" |& tee -a $LF |& tee -a $CF
  4035. echo "#@# Surf Volume $hemi `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4036. cd $subjdir/surf > /dev/null
  4037. $PWD |& tee -a $LF
  4038. set cmd = (vertexvol --s $subjid --$hemi -$TH3Opt)
  4039. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4040. if($RunIt) $fs_time $cmd |& tee -a $LF
  4041. if($status) goto error_exit;
  4042. echo $cmd > $touchdir/$hemi.surfvolume.touch
  4043. end # Loop over hemilist
  4044. endif
  4045. endif # if correct pial w/ T2/FLAIR
  4046. # stats and GWcontrast must run here, after T2 pial refinement
  4047. #---------------- -------------------#
  4048. ##--------------- -surfvolume -------------------#
  4049. #---------------- -------------------#
  4050. if($DoPialSurfs || $DoT2pial || $DoFLAIRpial || $DoSurfVolume) then
  4051. foreach hemi ($hemilist)
  4052. echo "#--------------------------------------------" \
  4053. |& tee -a $LF |& tee -a $CF
  4054. echo "#@# Surf Volume $hemi `date`" \
  4055. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4056. cd $subjdir/surf > /dev/null
  4057. $PWD |& tee -a $LF
  4058. set cmd = (vertexvol --s $subjid --$hemi -$TH3Opt)
  4059. if($RunIt) $fs_time $cmd |& tee -a $LF
  4060. if($status) goto error_exit;
  4061. echo $cmd > $touchdir/$hemi.surfvolume.touch
  4062. end # Loop over hemilist
  4063. endif
  4064. #---------------- ------------------#
  4065. #---------------- Cortical Ribbon ------------------#
  4066. ##--------------- -cortribbon ------------------#
  4067. #---------------- ------------------#
  4068. if($DoCortRibbonVolMask) then
  4069. echo "#--------------------------------------------" \
  4070. |& tee -a $LF |& tee -a $CF
  4071. echo "#@# Cortical ribbon mask `date`" \
  4072. |& tee -a $SF|& tee -a $LF|& tee -a $CF
  4073. cd $subjdir/mri > /dev/null
  4074. set xopts = `fsr-getxopts mris_volmask $XOptsFile`;
  4075. set cmd = (mris_volmask \
  4076. --aseg_name aseg.presurf \
  4077. --label_left_white 2 --label_left_ribbon 3 \
  4078. --label_right_white 41 --label_right_ribbon 42 \
  4079. --save_ribbon $subjid)
  4080. $PWD |& tee -a $LF
  4081. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4082. if($RunIt) $fs_time $cmd |& tee -a $LF
  4083. if($status) goto error_exit;
  4084. echo $cmd > $touchdir/cortical_ribbon.touch
  4085. endif
  4086. #---------- -----------#
  4087. #---------- Surface Anatomical Stats -----------#
  4088. ##--------- -parcstats -----------#
  4089. #---------- -----------#
  4090. if($DoParcStats) then
  4091. set CMDFS = () # see earlier notes on -parallel implementation
  4092. foreach hemi ($hemilist)
  4093. echo "#-----------------------------------------" \
  4094. |& tee -a $LF |& tee -a $CF
  4095. echo "#@# Parcellation Stats $hemi `date`" \
  4096. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4097. cd $subjdir/scripts > /dev/null
  4098. $PWD |& tee -a $LF
  4099. set annot = ../label/$hemi.aparc.annot
  4100. set ctab = ../label/aparc.annot.ctab
  4101. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  4102. foreach surfname (white pial)
  4103. if($surfname == white) set stats = ../stats/$hemi.aparc.stats
  4104. if($surfname == pial) set stats = ../stats/$hemi.aparc.pial.stats
  4105. set cmd = (mris_anatomical_stats $TH3Opt -mgz)
  4106. if($UseAseg) set cmd = ($cmd -cortex ../label/$hemi.cortex.label)
  4107. set cmd = ($cmd -f $stats -b -a $annot -c $ctab $xopts \
  4108. $subjid $hemi $surfname);
  4109. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4110. if($DoParallel) then
  4111. set CMDF = mris_anatomical_stats_${hemi}_${surfname}.cmd
  4112. echo "$cmd" > $CMDF
  4113. set CMDFS = ( $CMDFS $CMDF )
  4114. else
  4115. if($RunIt) $fs_time $cmd |& tee -a $LF
  4116. if($status) goto error_exit;
  4117. endif
  4118. end
  4119. echo $cmd > $touchdir/$hemi.aparcstats.touch
  4120. end # Loop over hemilist
  4121. if($RunIt && $DoParallel) then
  4122. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4123. if($status) goto error_exit;
  4124. endif
  4125. endif
  4126. #---------------- -----------------#
  4127. #---------------- Cortical Parcellation 2 -----------------#
  4128. ##--------------- -cortparc2 -----------------#
  4129. #---------------- -----------------#
  4130. if($DoCortParc2) then
  4131. set CMDFS = () # see earlier notes on -parallel implementation
  4132. foreach hemi ($hemilist)
  4133. echo "#-----------------------------------------"\
  4134. |& tee -a $LF |& tee -a $CF
  4135. echo "#@# Cortical Parc 2 $hemi `date`" \
  4136. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4137. cd $subjdir/scripts > /dev/null
  4138. $PWD |& tee -a $LF
  4139. set xopts = `fsr-getxopts mris_ca_label $XOptsFile`;
  4140. set CPAtlas = ${GCSDIR}/${hemi}.${DESTRIEUX_GCS}
  4141. set annot = ../label/$hemi.aparc.${DESTRIEUX_NAME}.annot
  4142. set cmd = (mris_ca_label)
  4143. if($UseAseg) set cmd = ($cmd -l ../label/$hemi.cortex.label)
  4144. if($UseAseg) set cmd = ($cmd -aseg ../mri/aseg.presurf.mgz)
  4145. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  4146. set cmd = ($cmd $xopts)
  4147. if($longitudinal) then
  4148. # longitudinal:
  4149. set cmd = ($cmd -long -R \
  4150. $longbasedir/label/${hemi}.aparc.${DESTRIEUX_NAME}.annot)
  4151. endif
  4152. set cmd = ($cmd $subjid $hemi ../surf/$hemi.sphere.reg $CPAtlas $annot)
  4153. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  4154. if($DoParallel) then
  4155. set CMDF = mris_ca_label_${hemi}.cmd
  4156. echo "$cmd" > $CMDF
  4157. set CMDFS = ( $CMDFS $CMDF )
  4158. else
  4159. if($RunIt) $fs_time $cmd |& tee -a $LF
  4160. if($status) goto error_exit;
  4161. endif
  4162. echo $cmd > $touchdir/$hemi.aparc2.touch
  4163. end # Loop over hemilist
  4164. if($RunIt && $DoParallel) then
  4165. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4166. if($status) goto error_exit;
  4167. endif
  4168. endif
  4169. #---------- ------------#
  4170. #---------- Surface Anatomical Stats 2 ------------#
  4171. ##--------- -parcstats2 -----------#
  4172. #---------- ------------#
  4173. if($DoParcStats2) then
  4174. set CMDFS = () # see earlier notes on -parallel implementation
  4175. foreach hemi ($hemilist)
  4176. echo "#-----------------------------------------" \
  4177. |& tee -a $LF |& tee -a $CF
  4178. echo "#@# Parcellation Stats 2 $hemi `date`" \
  4179. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4180. cd $subjdir/scripts > /dev/null
  4181. $PWD |& tee -a $LF
  4182. set annot = ../label/$hemi.aparc.${DESTRIEUX_NAME}.annot
  4183. set stats = ../stats/$hemi.aparc.${DESTRIEUX_NAME}.stats
  4184. set ctab = ../label/aparc.annot.${DESTRIEUX_NAME}.ctab
  4185. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  4186. set cmd = (mris_anatomical_stats $TH3Opt -mgz)
  4187. if($UseAseg) set cmd = ($cmd -cortex ../label/$hemi.cortex.label)
  4188. set cmd = ($cmd -f $stats -b -a $annot -c $ctab $xopts $subjid $hemi white);
  4189. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4190. if($DoParallel) then
  4191. set CMDF = mris_anatomical_stats_${hemi}.cmd
  4192. echo "$cmd" > $CMDF
  4193. set CMDFS = ( $CMDFS $CMDF )
  4194. else
  4195. if($RunIt) $fs_time $cmd |& tee -a $LF
  4196. if($status) goto error_exit;
  4197. endif
  4198. echo $cmd > $touchdir/$hemi.aparcstats2.touch
  4199. end # Loop over hemilist
  4200. if($RunIt && $DoParallel) then
  4201. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4202. if($status) goto error_exit;
  4203. endif
  4204. endif
  4205. #---------------- -----------------#
  4206. #---------------- Cortical Parcellation 3 -----------------#
  4207. ##--------------- -cortparc3 -----------------#
  4208. #---------------- -----------------#
  4209. if($DoCortParc3) then
  4210. set CMDFS = () # see earlier notes on -parallel implementation
  4211. foreach hemi ($hemilist)
  4212. echo "#-----------------------------------------"\
  4213. |& tee -a $LF |& tee -a $CF
  4214. echo "#@# Cortical Parc 3 $hemi `date`" \
  4215. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4216. cd $subjdir/scripts > /dev/null
  4217. $PWD |& tee -a $LF
  4218. set xopts = `fsr-getxopts mris_ca_label $XOptsFile`;
  4219. set CPAtlas = ${GCSDIR}/${hemi}.${DKTATLAS_GCS}
  4220. set annot = ../label/$hemi.aparc.${DKTATLAS_NAME}.annot
  4221. set cmd = (mris_ca_label)
  4222. if($UseAseg) set cmd = ($cmd -l ../label/$hemi.cortex.label)
  4223. if($UseAseg) set cmd = ($cmd -aseg ../mri/aseg.presurf.mgz)
  4224. if($NoRandomness) set cmd = ($cmd -seed $RngSeed)
  4225. set cmd = ($cmd $xopts)
  4226. if($longitudinal) then
  4227. # longitudinal:
  4228. set cmd = ($cmd -long -R \
  4229. $longbasedir/label/${hemi}.aparc.${DKTATLAS_NAME}.annot)
  4230. endif
  4231. set cmd = ($cmd $subjid $hemi ../surf/$hemi.sphere.reg $CPAtlas $annot)
  4232. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  4233. if($DoParallel) then
  4234. set CMDF = mris_ca_label_${hemi}.cmd
  4235. echo "$cmd" > $CMDF
  4236. set CMDFS = ( $CMDFS $CMDF )
  4237. else
  4238. if($RunIt) $fs_time $cmd |& tee -a $LF
  4239. if($status) goto error_exit;
  4240. endif
  4241. echo $cmd > $touchdir/$hemi.aparc2.touch
  4242. end # Loop over hemilist
  4243. if($RunIt && $DoParallel) then
  4244. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4245. if($status) goto error_exit;
  4246. endif
  4247. endif
  4248. #---------- -----------#
  4249. #---------- Surface Anatomical Stats 3 -----------#
  4250. ##--------- -parcstats3 -----------#
  4251. #---------- -----------#
  4252. if($DoParcStats3) then
  4253. set CMDFS = () # see earlier notes on -parallel implementation
  4254. foreach hemi ($hemilist)
  4255. echo "#-----------------------------------------" \
  4256. |& tee -a $LF |& tee -a $CF
  4257. echo "#@# Parcellation Stats 3 $hemi `date`" \
  4258. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4259. cd $subjdir/scripts > /dev/null
  4260. $PWD |& tee -a $LF
  4261. set annot = ../label/$hemi.aparc.${DKTATLAS_NAME}.annot
  4262. set stats = ../stats/$hemi.aparc.${DKTATLAS_NAME}.stats
  4263. set ctab = ../label/aparc.annot.${DKTATLAS_NAME}.ctab
  4264. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  4265. set cmd = (mris_anatomical_stats $TH3Opt -mgz)
  4266. if($UseAseg) set cmd = ($cmd -cortex ../label/$hemi.cortex.label)
  4267. set cmd = ($cmd -f $stats -b -a $annot -c $ctab $xopts $subjid $hemi white);
  4268. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4269. if($DoParallel) then
  4270. set CMDF = mris_anatomical_stats_${hemi}.cmd
  4271. echo "$cmd" > $CMDF
  4272. set CMDFS = ( $CMDFS $CMDF )
  4273. else
  4274. if($RunIt) $fs_time $cmd |& tee -a $LF
  4275. if($status) goto error_exit;
  4276. endif
  4277. echo $cmd > $touchdir/$hemi.aparcstats3.touch
  4278. end # Loop over hemilist
  4279. if($RunIt && $DoParallel) then
  4280. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4281. if($status) goto error_exit;
  4282. endif
  4283. endif
  4284. #---------- ----------#
  4285. #---------- WM/GM Contrast ----------#
  4286. ##--------- -pctsurfcon ----------#
  4287. #---------- ----------#
  4288. # for longitutinal stream, skip in base (as rawavg does not exist)
  4289. if($DoPctSurfCon && ( ! $DoCreateBaseSubj )) then
  4290. set CMDFS = () # see earlier notes on -parallel implementation
  4291. foreach hemi ($hemilist)
  4292. echo "#-----------------------------------------" \
  4293. |& tee -a $LF |& tee -a $CF
  4294. echo "#@# WM/GM Contrast $hemi `date`" \
  4295. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4296. cd $subjdir/scripts > /dev/null
  4297. $PWD |& tee -a $LF
  4298. set xopts = `fsr-getxopts pctsurfcon $XOptsFile`;
  4299. set cmd = (pctsurfcon --s $subjid)
  4300. if($hemi == lh) set cmd = ($cmd --lh-only)
  4301. if($hemi == rh) set cmd = ($cmd --rh-only)
  4302. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4303. if($DoParallel) then
  4304. set CMDF = pctsurfcon_${hemi}.cmd
  4305. echo "$cmd" > $CMDF
  4306. set CMDFS = ( $CMDFS $CMDF )
  4307. else
  4308. if($RunIt) $fs_time $cmd |& tee -a $LF
  4309. if($status) goto error_exit;
  4310. endif
  4311. echo $cmd > $touchdir/$hemi.pctsurfcon.touch
  4312. end # Loop over hemilist
  4313. if($RunIt && $DoParallel) then
  4314. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4315. if($status) goto error_exit;
  4316. endif
  4317. endif
  4318. #----------------- ------------------#
  4319. #----------------- Relabel Hypointensities ------------------#
  4320. ##---------------- -hyporelabel ------------------#
  4321. #----------------- ------------------ #
  4322. if($DoRelabelHypos) then
  4323. echo "#-----------------------------------------" \
  4324. |& tee -a $LF |& tee -a $CF
  4325. echo "#@# Relabel Hypointensities `date`" \
  4326. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4327. cd $subjdir/mri > /dev/null
  4328. $PWD |& tee -a $LF
  4329. set cmd = (mri_relabel_hypointensities \
  4330. aseg.presurf.mgz ../surf aseg.presurf.hypos.mgz)
  4331. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4332. if($RunIt) $fs_time $cmd |& tee -a $LF
  4333. if($status) goto error_exit;
  4334. echo $cmd > $touchdir/relabelhypos.touch
  4335. endif
  4336. #----------------- -----------------#
  4337. ##---------------- -aparc2aseg -----------------#
  4338. #----------------- -----------------#
  4339. if($DoAParc2ASeg) then
  4340. set CMDFS = () # see earlier notes on -parallel implementation
  4341. foreach parc (aparc ${DESTRIEUX_NAME} ${DKTATLAS_NAME})
  4342. echo "#-----------------------------------------" \
  4343. |& tee -a $LF |& tee -a $CF
  4344. echo "#@# AParc-to-ASeg ${parc} `date`" \
  4345. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4346. cd $subjdir > /dev/null
  4347. $PWD |& tee -a $LF
  4348. set xopts = `fsr-getxopts mri_aparc2aseg $XOptsFile`;
  4349. if(! $longitudinal) then
  4350. set asegintensities = mri/aseg.auto_noCCseg.label_intensities.txt
  4351. else
  4352. set asegintensities = $longbasedir/mri/aseg.auto_noCCseg.label_intensities.txt
  4353. endif
  4354. set cmd = (mri_aparc2aseg --s $subjid --volmask --aseg aseg.presurf.hypos \
  4355. --relabel mri/norm.mgz mri/transforms/talairach.m3z \
  4356. ${GCADIR}/$GCA $asegintensities)
  4357. if(${parc} != "aparc") then
  4358. # do Christophe and Mindboggle atlases (if exist)
  4359. if( -e ${subjdir}/label/lh.aparc.${parc}.annot && \
  4360. -e ${subjdir}/label/rh.aparc.${parc}.annot ) then
  4361. # Note: the --a2009s is needed to get the index offset correct
  4362. if($parc == ${DESTRIEUX_NAME}) set cmd = ($cmd --a2009s)
  4363. if($parc == ${DKTATLAS_NAME}) set cmd = ($cmd --annot aparc.DKTatlas --o mri/aparc.DKTatlas+aseg.mgz)
  4364. echo $cmd > $touchdir/aparc.$parc"2aseg".touch
  4365. else
  4366. echo "INFO: skipping ${parc} aparc2aseg" |& tee -a $LF |& tee -a $CF
  4367. continue;
  4368. endif
  4369. endif
  4370. set cmd = ($cmd $xopts)
  4371. echo "\n $cmd \n" |& tee -a $LF |& tee -a $CF
  4372. if($DoParallel) then
  4373. set CMDF = mri_aparc2aseg_${parc}.cmd
  4374. echo "$cmd" > $CMDF
  4375. set CMDFS = ( $CMDFS $CMDF )
  4376. else
  4377. if($RunIt) $fs_time $cmd |& tee -a $LF
  4378. if($status) goto error_exit;
  4379. endif
  4380. end # Loop over parc list
  4381. if($RunIt && $DoParallel) then
  4382. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4383. if($status) goto error_exit;
  4384. endif
  4385. endif
  4386. #----------------- ------------------ #
  4387. #----------------- Final Aseg ------------------ #
  4388. ##---------------- -apas2aseg ------------------ #
  4389. #----------------- ------------------ #
  4390. if($DoAPas2ASeg) then
  4391. echo "#-----------------------------------------" \
  4392. |& tee -a $LF |& tee -a $CF
  4393. echo "#@# APas-to-ASeg `date`" \
  4394. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4395. cd $subjdir/mri > /dev/null
  4396. $PWD |& tee -a $LF
  4397. set cmd = (apas2aseg --i aparc+aseg.mgz --o aseg.mgz)
  4398. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4399. if($RunIt) $fs_time $cmd |& tee -a $LF
  4400. if($status) goto error_exit;
  4401. echo $cmd > $touchdir/apas2aseg.touch
  4402. endif
  4403. #-------------- --------------#
  4404. ##------------- -segstats --------------#
  4405. #-------------- --------------#
  4406. if($DoSegStats) then
  4407. # Stats on the automatic segmentation
  4408. echo "#--------------------------------------------" \
  4409. |& tee -a $LF |& tee -a $CF
  4410. echo "#@# ASeg Stats `date`" \
  4411. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4412. cd $subjdir > /dev/null
  4413. $PWD |& tee -a $LF
  4414. set xopts = `fsr-getxopts mri_segstats $XOptsFile`;
  4415. set cmd = (mri_segstats --seg mri/aseg.mgz --sum stats/aseg.stats)
  4416. set cmd = ($cmd --pv mri/norm.mgz --empty)
  4417. set cmd = ($cmd --brainmask mri/brainmask.mgz --brain-vol-from-seg)
  4418. set cmd = ($cmd --excludeid 0 --excl-ctxgmwm)
  4419. if ( -e mri/ribbon.mgz ) then
  4420. set cmd = ($cmd --supratent)
  4421. else
  4422. echo "\nINFO: mri_segstats will not calculate Supratentorial" |& tee -a $LF
  4423. echo " due to missing ribbon.mgz file" |& tee -a $LF
  4424. endif
  4425. set cmd = ($cmd --subcortgray)
  4426. set cmd = ($cmd --in mri/norm.mgz --in-intensity-name norm)
  4427. set cmd = ($cmd --in-intensity-units MR)
  4428. if ( -e mri/transforms/talairach.xfm ) then
  4429. set cmd = ($cmd --etiv);
  4430. else
  4431. echo "\nINFO: mri_segstats will not calculate eTIV" |& tee -a $LF
  4432. echo " due to missing talairach.xfm file" |& tee -a $LF
  4433. endif
  4434. if ( ( -e surf/lh.white ) && ( -e surf/rh.white ) ) then
  4435. set cmd = ($cmd --surf-wm-vol)
  4436. if ( ( -e surf/lh.pial ) && ( -e surf/rh.pial ) ) then
  4437. set cmd = ($cmd --surf-ctx-vol --totalgray)
  4438. else
  4439. echo "\nINFO: ?h.pial surfaces not available to mri_segstats.\n"\
  4440. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4441. endif
  4442. else
  4443. echo "\nINFO: ?h.white surfaces not available to mri_segstats.\n"\
  4444. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4445. endif
  4446. if( ( -e surf/lh.orig.nofix ) && ( -e surf/rh.orig.nofix ) ) then
  4447. set cmd = ($cmd --euler)
  4448. endif
  4449. set cmd = ($cmd --ctab $FREESURFER_HOME/ASegStatsLUT.txt)
  4450. set cmd = ($cmd --subject $subjid $xopts);
  4451. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4452. if($RunIt) $fs_time $cmd |& tee -a $LF
  4453. if($status) goto error_exit;
  4454. echo $cmd > $touchdir/segstats.touch
  4455. endif
  4456. #----------------- ------------------#
  4457. ##---------------- -wmparc ------------------#
  4458. #----------------- ------------------#
  4459. if($DoWMParc) then
  4460. echo "#-----------------------------------------" \
  4461. |& tee -a $LF |& tee -a $CF
  4462. echo "#@# WMParc `date`" \
  4463. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4464. cd $subjdir > /dev/null
  4465. $PWD |& tee -a $LF
  4466. set xopts = `fsr-getxopts mri_aparc2aseg $XOptsFile`;
  4467. set cmd = (mri_aparc2aseg --s $subjid --labelwm --hypo-as-wm --rip-unknown \
  4468. --volmask --o mri/wmparc.mgz --ctxseg aparc+aseg.mgz $xopts )
  4469. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4470. if($RunIt) $fs_time $cmd |& tee -a $LF
  4471. if($status) goto error_exit;
  4472. echo $cmd > $touchdir/wmaparc.touch
  4473. # Do wm segstats while we're here
  4474. set cmd = (mri_segstats)
  4475. set cmd = ($cmd --seg mri/wmparc.mgz --sum stats/wmparc.stats \
  4476. --pv mri/norm.mgz --excludeid 0 \
  4477. --brainmask mri/brainmask.mgz --in mri/norm.mgz --in-intensity-name norm \
  4478. --in-intensity-units MR --subject $subjid --surf-wm-vol \
  4479. --ctab $FREESURFER_HOME/WMParcStatsLUT.txt )
  4480. if ( -e mri/transforms/talairach.xfm ) then
  4481. set cmd = ($cmd --etiv);
  4482. else
  4483. echo "INFO: mri_segstats will not calculate eTIV" |& tee -a $LF
  4484. echo " due to missing talairach.xfm file" |& tee -a $LF
  4485. endif
  4486. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4487. if($RunIt) $fs_time $cmd |& tee -a $LF
  4488. if($status) goto error_exit;
  4489. echo $cmd > $touchdir/wmaparc.stats.touch
  4490. endif
  4491. #-------------- -----------------#
  4492. ##------------- -aparc+aseg-stats -----------------#
  4493. #-------------- -----------------#
  4494. # This is not something you want to do in general. The volumes
  4495. # of cortical structures should be obtained from the aparc.stats,
  4496. # but getting the intensity means and stddevs can be useful.
  4497. if($DoAParcASegStats) then
  4498. echo "#--------------------------------------------" \
  4499. |& tee -a $LF |& tee -a $CF
  4500. echo "#@# AParcASeg Stats `date`" |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4501. cd $subjdir > /dev/null
  4502. set xopts = `fsr-getxopts mri_segstats $XOptsFile`;
  4503. set cmd = (mri_segstats)
  4504. set cmd = ($cmd --seg mri/aparc+aseg.mgz --sum stats/aparc+aseg.stats)
  4505. set cmd = ($cmd --pv mri/norm.mgz )
  4506. set cmd = ($cmd --excludeid 0 --ctab-default --empty)
  4507. set cmd = ($cmd --brain-vol-from-seg --brainmask mri/brainmask.mgz)
  4508. set cmd = ($cmd --in mri/norm.mgz --in-intensity-name norm)
  4509. set cmd = ($cmd --in-intensity-units MR)
  4510. set cmd = ($cmd --subject $subjid);
  4511. if ( -e mri/transforms/talairach.xfm ) then
  4512. set cmd = ($cmd --etiv);
  4513. else
  4514. echo "INFO: mri_segstats will not calculate eTIV" |& tee -a $LF
  4515. echo " due to missing talairach.xfm file" |& tee -a $LF
  4516. endif
  4517. set cmd = ($cmd $xopts);
  4518. $PWD |& tee -a $LF
  4519. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4520. if($RunIt) $fs_time $cmd |& tee -a $LF
  4521. if($status) goto error_exit;
  4522. echo $cmd > $touchdir/aparc+aseg.stats.touch
  4523. endif
  4524. #-------- --------#
  4525. #-------- Brodmann Area Labels --------#
  4526. ##------- -balabels --------#
  4527. #-------- --------#
  4528. # Create Brodmann area labels by mapping from fsaverage,
  4529. # then create the ?h.BA_exvivo.annot file from these labels,
  4530. # then generate a ?h.BA_exvivo.stats file from that annot.
  4531. if ($DoBaLabels) then
  4532. cd $subjdir/label
  4533. $PWD |& tee -a $LF
  4534. # if fsaverage is not in subjects dir, put it there
  4535. set HaveFsAverage=1;
  4536. if ( ! -e $SUBJECTS_DIR/fsaverage) then
  4537. echo "INFO: fsaverage subject does not exist in SUBJECTS_DIR" \
  4538. |& tee -a $LF |& tee -a $CF
  4539. set HaveFsAverage=0;
  4540. else
  4541. # check if the latest-greatest fsaverage is here (which would not be
  4542. # the case if running on subjects processed by an older version)
  4543. if ( ! -e $SUBJECTS_DIR/fsaverage/label/lh.entorhinal_exvivo.thresh.label) then
  4544. echo "INFO: fsaverage subject does not have uptodate *rhinal labels!" \
  4545. |& tee -a $LF |& tee -a $CF
  4546. set HaveFsAverage=0;
  4547. set cmd=(rm -Rf fsaverage)
  4548. echo "\n cd $SUBJECTS_DIR; $cmd; cd - \n"|& tee -a $LF |& tee -a $CF
  4549. cd $SUBJECTS_DIR
  4550. if($RunIt && -e fsaverage) $fs_time $cmd |& tee -a $LF
  4551. cd -
  4552. endif
  4553. endif
  4554. if ( ! $HaveFsAverage ) then
  4555. echo "INFO: Creating symlink to fsaverage subject..." \
  4556. |& tee -a $LF |& tee -a $CF
  4557. set cmd=(ln -s $FREESURFER_HOME/subjects/fsaverage)
  4558. echo "\n cd $SUBJECTS_DIR; $cmd; cd - \n"|& tee -a $LF |& tee -a $CF
  4559. cd $SUBJECTS_DIR
  4560. if($RunIt && ! -e fsaverage) $cmd |& tee -a $LF
  4561. cd -
  4562. endif
  4563. foreach hemi ($hemilist)
  4564. echo "#--------------------------------------------" \
  4565. |& tee -a $LF |& tee -a $CF
  4566. echo "#@# BA_exvivo Labels $hemi `date`" \
  4567. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4568. # need to split parallel processing into sets so as not to exceed 4GB
  4569. set EV_LABELS_1 = (BA1_exvivo \
  4570. BA2_exvivo \
  4571. BA3a_exvivo \
  4572. BA3b_exvivo \
  4573. BA4a_exvivo)
  4574. set EV_LABELS_2 = (BA4p_exvivo \
  4575. BA6_exvivo \
  4576. BA44_exvivo \
  4577. BA45_exvivo)
  4578. set EV_LABELS_3 = (V1_exvivo \
  4579. V2_exvivo \
  4580. MT_exvivo \
  4581. entorhinal_exvivo \
  4582. perirhinal_exvivo)
  4583. set ALL_EV_LABELS = ("$EV_LABELS_1" "$EV_LABELS_2" "$EV_LABELS_3")
  4584. set EV_IDXS = (1 2 3)
  4585. # generate labels
  4586. # run in three sets, so as not to consume more than 4GB in parallel mode
  4587. foreach labelset ($EV_IDXS)
  4588. set CMDFS = () # see earlier notes on -parallel implementation
  4589. foreach balabel ( $ALL_EV_LABELS[$labelset] )
  4590. set cmd=(mri_label2label \
  4591. --srcsubject fsaverage \
  4592. --srclabel $SUBJECTS_DIR/fsaverage/label/${hemi}.${balabel}.label \
  4593. --trgsubject $subjid \
  4594. --trglabel ./${hemi}.${balabel}.label \
  4595. --hemi ${hemi} \
  4596. --regmethod surface)
  4597. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4598. if($DoParallel) then
  4599. set CMDF = mri_label2label_${balabel}_${hemi}.cmd
  4600. echo "$cmd" > $CMDF
  4601. set CMDFS = ( $CMDFS $CMDF )
  4602. else
  4603. if($RunIt) $fs_time $cmd |& tee -a $LF
  4604. if($status) goto error_exit;
  4605. endif
  4606. end # balabel
  4607. if($RunIt && $DoParallel) then
  4608. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4609. if($status) goto error_exit;
  4610. endif
  4611. end # labelset
  4612. # generate .thresh labels
  4613. # run in three sets, so as not to consume more than 4GB in parallel mode
  4614. foreach labelset ($EV_IDXS)
  4615. set CMDFS = () # see earlier notes on -parallel implementation
  4616. foreach balabel ( $ALL_EV_LABELS[$labelset] )
  4617. set cmd=(mri_label2label \
  4618. --srcsubject fsaverage \
  4619. --srclabel $SUBJECTS_DIR/fsaverage/label/${hemi}.${balabel}.thresh.label \
  4620. --trgsubject $subjid \
  4621. --trglabel ./${hemi}.${balabel}.thresh.label \
  4622. --hemi ${hemi} \
  4623. --regmethod surface)
  4624. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4625. if($DoParallel) then
  4626. set CMDF = mri_label2label_${balabel}_${hemi}.cmd
  4627. echo "$cmd" > $CMDF
  4628. set CMDFS = ( $CMDFS $CMDF )
  4629. else
  4630. if($RunIt) $fs_time $cmd |& tee -a $LF
  4631. if($status) goto error_exit;
  4632. endif
  4633. end # balabel
  4634. if($RunIt && $DoParallel) then
  4635. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4636. if($status) goto error_exit;
  4637. endif
  4638. end # labelsets
  4639. # create .annot
  4640. set cmd=(mris_label2annot \
  4641. --s $subjid \
  4642. --hemi $hemi \
  4643. --ctab $FREESURFER_HOME/average/colortable_BA.txt \
  4644. --l $hemi.BA1_exvivo.label \
  4645. --l $hemi.BA2_exvivo.label \
  4646. --l $hemi.BA3a_exvivo.label \
  4647. --l $hemi.BA3b_exvivo.label \
  4648. --l $hemi.BA4a_exvivo.label \
  4649. --l $hemi.BA4p_exvivo.label \
  4650. --l $hemi.BA6_exvivo.label \
  4651. --l $hemi.BA44_exvivo.label \
  4652. --l $hemi.BA45_exvivo.label \
  4653. --l $hemi.V1_exvivo.label \
  4654. --l $hemi.V2_exvivo.label \
  4655. --l $hemi.MT_exvivo.label \
  4656. --l $hemi.entorhinal_exvivo.label \
  4657. --l $hemi.perirhinal_exvivo.label \
  4658. --a BA_exvivo \
  4659. --maxstatwinner \
  4660. --noverbose )
  4661. if($RunIt) if ( -e ./$hemi.BA_exvivo.annot) rm -fv ./$hemi.BA_exvivo.annot
  4662. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4663. if($RunIt) $fs_time $cmd |& tee -a $LF
  4664. if($status) goto error_exit;
  4665. # create .thresh.annot
  4666. set cmd=(mris_label2annot \
  4667. --s $subjid \
  4668. --hemi $hemi \
  4669. --ctab $FREESURFER_HOME/average/colortable_BA.txt \
  4670. --l $hemi.BA1_exvivo.thresh.label \
  4671. --l $hemi.BA2_exvivo.thresh.label \
  4672. --l $hemi.BA3a_exvivo.thresh.label \
  4673. --l $hemi.BA3b_exvivo.thresh.label \
  4674. --l $hemi.BA4a_exvivo.thresh.label \
  4675. --l $hemi.BA4p_exvivo.thresh.label \
  4676. --l $hemi.BA6_exvivo.thresh.label \
  4677. --l $hemi.BA44_exvivo.thresh.label \
  4678. --l $hemi.BA45_exvivo.thresh.label \
  4679. --l $hemi.V1_exvivo.thresh.label \
  4680. --l $hemi.V2_exvivo.thresh.label \
  4681. --l $hemi.MT_exvivo.thresh.label \
  4682. --l $hemi.entorhinal_exvivo.thresh.label \
  4683. --l $hemi.perirhinal_exvivo.thresh.label \
  4684. --a BA_exvivo.thresh \
  4685. --maxstatwinner \
  4686. --noverbose )
  4687. if($RunIt) if ( -e ./$hemi.BA_exvivo.thresh.annot) rm -fv ./$hemi.BA_exvivo.thresh.annot
  4688. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4689. if($RunIt) $fs_time $cmd |& tee -a $LF
  4690. if($status) goto error_exit;
  4691. # generate stats
  4692. set annot = ./$hemi.BA_exvivo.annot
  4693. set stats = ../stats/$hemi.BA_exvivo.stats
  4694. set ctab = ./BA_exvivo.ctab
  4695. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  4696. set cmd = (mris_anatomical_stats $TH3Opt -mgz -f $stats \
  4697. -b -a $annot -c $ctab $xopts $subjid $hemi white);
  4698. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4699. if($RunIt) $fs_time $cmd |& tee -a $LF
  4700. if($status) goto error_exit;
  4701. # generate .thresh stats
  4702. set annot = ./$hemi.BA_exvivo.thresh.annot
  4703. set stats = ../stats/$hemi.BA_exvivo.thresh.stats
  4704. set ctab = ./BA_exvivo.thresh.ctab
  4705. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  4706. set cmd = (mris_anatomical_stats $TH3Opt -mgz -f $stats \
  4707. -b -a $annot -c $ctab $xopts $subjid $hemi white);
  4708. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4709. if($RunIt) $fs_time $cmd |& tee -a $LF
  4710. if($status) goto error_exit;
  4711. end # hemi
  4712. endif # DoBaLabels
  4713. #---------- ------------#
  4714. ##--------- -label-V1 ------------#
  4715. #---------- ------------#
  4716. if($DoLabelV1) then
  4717. set CMDFS = () # see earlier notes on -parallel implementation
  4718. foreach hemi ($hemilist)
  4719. echo "#-----------------------------------------" \
  4720. |& tee -a $LF |& tee -a $CF
  4721. echo "#@# Label V1 $hemi `date`" \
  4722. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4723. if ( ! -e $SUBJECTS_DIR/V1_average) then
  4724. echo "ERROR: V1_average subject does not exist in SUBJECTS_DIR!"
  4725. goto error_exit;
  4726. endif
  4727. cd $subjdir/label > /dev/null
  4728. $PWD |& tee -a $LF
  4729. set cmd=(predict_v1.sh)
  4730. if( ! $RunIt) set cmd=($cmd -p)
  4731. set cmd = ($cmd -h $hemi $subjid);
  4732. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4733. if($DoParallel) then
  4734. set CMDF = predicit_v1_${hemi}.cmd
  4735. echo "$cmd" > $CMDF
  4736. set CMDFS = ( $CMDFS $CMDF )
  4737. else
  4738. if($RunIt) $fs_time $cmd |& tee -a $LF
  4739. if($status) goto error_exit;
  4740. endif
  4741. echo $cmd > $touchdir/$hemi.label_v1.touch
  4742. end # Loop over hemilist
  4743. if($RunIt && $DoParallel) then
  4744. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4745. if($status) goto error_exit;
  4746. endif
  4747. endif
  4748. #-------- --------#
  4749. #-------- Entorhinal Cortex Labels --------#
  4750. ##------- -label-exvivo-ec-avg --------#
  4751. #-------- --------#
  4752. # create entorhinal cortex labels by mapping from exvivo subjects,
  4753. # then generate ?h.EC_exvivo_average.stats files
  4754. if ($DoLabelExvivoEC) then
  4755. cd $subjdir/label
  4756. $PWD |& tee -a $LF
  4757. foreach hemi ($hemilist)
  4758. echo "#--------------------------------------------" \
  4759. |& tee -a $LF |& tee -a $CF
  4760. echo "#@# Ex-vivo Entorhinal Cortex Label $hemi `date`" \
  4761. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4762. if ( ! -e $SUBJECTS_DIR/${hemi}.EC_average) then
  4763. echo "INFO: ${hemi}.EC_average subject does not exist in SUBJECTS_DIR" \
  4764. |& tee -a $LF |& tee -a $CF
  4765. echo "INFO: Creating symlink to ${hemi}.EC_average subject..." \
  4766. |& tee -a $LF |& tee -a $CF
  4767. set cmd=(ln -s $FREESURFER_HOME/subjects/${hemi}.EC_average)
  4768. echo "\n cd $SUBJECTS_DIR; $cmd; cd - \n"|& tee -a $LF |& tee -a $CF
  4769. cd $SUBJECTS_DIR
  4770. if($RunIt && ! -e ${hemi}.EC_average) $cmd |& tee -a $LF
  4771. cd -
  4772. endif
  4773. # generate label
  4774. set cmd = (mris_spherical_average \
  4775. -erode 1 \
  4776. -orig white \
  4777. -t 0.4 \
  4778. -o ${subjid} \
  4779. label ${hemi}.entorhinal \
  4780. $hemi sphere.reg \
  4781. ${hemi}.EC_average \
  4782. ${hemi}.EC_exvivo_average.label)
  4783. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4784. if($RunIt) $fs_time $cmd |& tee -a $LF
  4785. if($status) goto error_exit;
  4786. # generate stats
  4787. set label = ./$hemi.EC_exvivo_average.label
  4788. set stats = ../stats/$hemi.EC_exvivo_average.stats
  4789. set xopts = `fsr-getxopts mris_anatomical_stats $XOptsFile`;
  4790. set cmd = (mris_anatomical_stats $TH3Opt -mgz -f $stats \
  4791. -b -l $label $xopts $subjid $hemi white);
  4792. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4793. if($RunIt) $fs_time $cmd |& tee -a $LF
  4794. if($status) goto error_exit;
  4795. end # hemi
  4796. endif # DoLabelExvivoEC
  4797. #-------------- -----------------#
  4798. #-------------- Hippocampal Subfields -----------------#
  4799. ##----------- -hippocampal-subfields-T1 -------------#
  4800. ##----------- -hippocampal-subfields-T1T2 -----------#
  4801. ##----------- -hippocampal-subfields-T2 -------------#
  4802. #-------------- -----------------#
  4803. #-------------- Brainstem Substructures ---------------#
  4804. ##----------- -brainstem-structures -----------------#
  4805. #-------------- -----------------#
  4806. # For substructure segmentation of hippocampus or brainstem: check if Matlab runtime is there
  4807. if ($DoHippoSF_T1 || $DoHippoSF_T1T2 || $DoHippoSF_T2 || $DoBSsubst) then
  4808. if ( ! -e ${FREESURFER_HOME}/MCRv80/bin/glnxa64/libdctprocess.so \
  4809. && ! -e ${FREESURFER_HOME}/MCRv80/bin/maci64/libdctprocess.jnilib ) then
  4810. echo " "
  4811. echo "ERROR: cannot find Matlab 2012b runtime in location:"
  4812. echo " "
  4813. echo "${FREESURFER_HOME}/MCRv80"
  4814. echo " "
  4815. echo "It is looking for either: "
  4816. echo " bin/glnxa64/libdctprocess.so (Linux 64b) or"
  4817. echo " bin/maci64/libdctprocess.jnilib (Mac 64b)"
  4818. echo " "
  4819. echo "You will need to download the Matlab Compiler Runtime (MCR) for Matlab 2012b."
  4820. echo "To do so, please run the following commands (you might need root permissions):"
  4821. echo " "
  4822. echo "LINUX:"
  4823. echo " "
  4824. echo "cd ${FREESURFER_HOME}"
  4825. echo "curl "\""http://surfer.nmr.mgh.harvard.edu/fswiki/MatlabRuntime?action=AttachFile&do=get&target=runtime2012bLinux.tar.gz"\"" -o "\""runtime2012b.tar.gz"\"""
  4826. echo "tar xvf runtime2012b.tar.gz"
  4827. echo " "
  4828. echo "MAC:"
  4829. echo " "
  4830. echo "cd ${FREESURFER_HOME}"
  4831. echo "curl "\""http://surfer.nmr.mgh.harvard.edu/fswiki/MatlabRuntime?action=AttachFile&do=get&target=runtime2012bMAC.tar.gz"\"" -o "\""runtime2012b.tar.gz"\"""
  4832. echo "tar xvf runtime2012b.tar.gz"
  4833. echo " "
  4834. echo " "
  4835. echo "For further details, please visit:"
  4836. echo " "
  4837. echo "https://surfer.nmr.mgh.harvard.edu/fswiki/MatlabRuntime"
  4838. echo " "
  4839. goto error_exit;
  4840. endif
  4841. endif
  4842. # brainstem structures: make sure required files from from default freesurfer processing are in there
  4843. if ($DoBSsubst) then
  4844. if (! -e ${subjdir}/mri/aseg.mgz || \
  4845. ! -e ${subjdir}/mri/norm.mgz ) then
  4846. echo "ERROR: cannot find norm.mgz or aseg.mgz for the subject."
  4847. echo "ERROR: Maybe, run recon-all again or disable segmentation of brainstem substructures."
  4848. goto error_exit;
  4849. endif #checking of aseg.mgz and norm.mgz
  4850. endif
  4851. # hippocampal subfields: make sure required files from default freesurfer processing are in there, and convert hemilist
  4852. if ($DoHippoSF_T1 || $DoHippoSF_T1T2 || $DoHippoSF_T2) then
  4853. if (! -e ${subjdir}/mri/wmparc.mgz || \
  4854. ! -e ${subjdir}/mri/norm.mgz || \
  4855. ! -e ${subjdir}/mri/transforms/talairach.xfm ) then
  4856. echo "ERROR: cannot find wmparc.mgz or aseg.mgz or talairach.xfm for the subject."
  4857. echo "ERROR: Maybe, run recon-all again or disable hippocampal subfields processing."
  4858. goto error_exit;
  4859. endif #checking of wmparc.mgz, norm.mgz and talairach.xfm
  4860. # these tools assume 'left' and 'right' instead of our usual 'lh' and 'rh'
  4861. if($#hemilist == 1) then
  4862. if ("$hemilist" == "lh") set hippohemilist=(left)
  4863. if ("$hemilist" == "rh") set hippohemilist=(right)
  4864. else
  4865. set hippohemilist=(left right)
  4866. endif
  4867. endif
  4868. #-------------- -----------------#
  4869. ##----------- -brainstem-structures -----------------#
  4870. #-------------- -----------------#
  4871. if($DoBSsubst) then
  4872. set BSSLOG = ($subjdir/scripts/brainstem-structures.log)
  4873. rm -f $BSSLOG
  4874. echo "#--------------------------------------------" \
  4875. |& tee -a $LF |& tee -a $CF |& tee -a $BSSLOG
  4876. echo "#@# Segmentation of brainstem substructures `date`" \
  4877. |& tee -a $SF |& tee -a $LF |& tee -a $CF |& tee -a $BSSLOG
  4878. # segmentation of brainstem structures
  4879. set cmd = ( ${FREESURFER_HOME}/bin/segmentBS.sh \
  4880. ${FREESURFER_HOME}/MCRv80 \
  4881. $FREESURFER_HOME \
  4882. $subjid \
  4883. $SUBJECTS_DIR )
  4884. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4885. echo "See log file: $BSSLOG"|& tee -a $LF |& tee -a $CF
  4886. if($RunIt) $fs_time $cmd |& tee -a $BSSLOG
  4887. if($status) goto error_exit;
  4888. echo $cmd > $touchdir/brainstem-structures.touch
  4889. endif
  4890. #-------------- -----------------#
  4891. ##----------- -hippocampal-subfields-T1 -------------#
  4892. #-------------- -----------------#
  4893. if($DoHippoSF_T1) then
  4894. set HSFLOG = ($subjdir/scripts/hippocampal-subfields-T1.log)
  4895. rm -f $HSFLOG
  4896. # do hippocampal processing using just T1 data
  4897. foreach hemi ($hippohemilist)
  4898. echo "#--------------------------------------------" \
  4899. |& tee -a $LF |& tee -a $CF |& tee -a $HSFLOG
  4900. echo "#@# Hippocampal Subfields processing (T1 only) $hemi `date`" \
  4901. |& tee -a $SF |& tee -a $LF |& tee -a $CF |& tee -a $HSFLOG
  4902. set cmd = ( ${FREESURFER_HOME}/bin/segmentSF_T1.sh \
  4903. ${FREESURFER_HOME}/MCRv80 \
  4904. $FREESURFER_HOME \
  4905. $subjid \
  4906. $SUBJECTS_DIR \
  4907. $hemi )
  4908. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4909. echo "See log file: $HSFLOG"|& tee -a $LF |& tee -a $CF
  4910. if($RunIt) $fs_time $cmd |& tee -a $HSFLOG
  4911. if($status) goto error_exit;
  4912. end
  4913. echo $cmd > $touchdir/hippo-subfields-T1.touch
  4914. endif
  4915. #-------------- -----------------#
  4916. ##------------- -hippocampal-subfields-T1T2 -----------#
  4917. #-------------- -----------------#
  4918. if($DoHippoSF_T1T2) then
  4919. set HSFLOG = ($subjdir/scripts/hippocampal-subfields-T1T2.log)
  4920. rm -f $HSFLOG
  4921. # do hippocampal processing
  4922. foreach hemi ($hippohemilist)
  4923. echo "#--------------------------------------------" \
  4924. |& tee -a $LF |& tee -a $CF |& tee -a $HSFLOG
  4925. echo "#@# Hippocampal Subfields processing (T1 + T2 volume) $hemi `date`" \
  4926. |& tee -a $SF |& tee -a $LF |& tee -a $CF |& tee -a $HSFLOG
  4927. set cmd = ( ${FREESURFER_HOME}/bin/segmentSF_T1T2.sh \
  4928. ${FREESURFER_HOME}/MCRv80 \
  4929. $FREESURFER_HOME \
  4930. $subjid \
  4931. $SUBJECTS_DIR \
  4932. $T2volHippoSF \
  4933. $hemi \
  4934. $UserSuffix )
  4935. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4936. echo "See log file: $HSFLOG"|& tee -a $LF |& tee -a $CF
  4937. if($RunIt) $fs_time $cmd |& tee -a $HSFLOG
  4938. if($status) goto error_exit;
  4939. end
  4940. echo $cmd > $touchdir/hippo-subfields-T1T2.touch
  4941. endif
  4942. #-------------- -----------------#
  4943. ##------------- -hippocampal-subfields-T2 -------------#
  4944. #-------------- -----------------#
  4945. if($DoHippoSF_T2) then
  4946. set HSFLOG = ($subjdir/scripts/hippocampal-subfields-T2.log)
  4947. rm -f $HSFLOG
  4948. # do hippocampal processing
  4949. foreach hemi ($hippohemilist)
  4950. echo "#--------------------------------------------" \
  4951. |& tee -a $LF |& tee -a $CF |& tee -a $HSFLOG
  4952. echo "#@# Hippocampal Subfields processing (T2 only) $hemi `date`" \
  4953. |& tee -a $SF |& tee -a $LF |& tee -a $CF |& tee -a $HSFLOG
  4954. set cmd = ( ${FREESURFER_HOME}/bin/segmentSF_T2.sh \
  4955. ${FREESURFER_HOME}/MCRv80 \
  4956. $FREESURFER_HOME \
  4957. $subjid \
  4958. $SUBJECTS_DIR \
  4959. $T2volHippoSF \
  4960. $hemi \
  4961. $UserSuffix )
  4962. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4963. echo "See log file: $HSFLOG"|& tee -a $LF |& tee -a $CF
  4964. if($RunIt) $fs_time $cmd |& tee -a $HSFLOG
  4965. if($status) goto error_exit;
  4966. end
  4967. echo $cmd > $touchdir/hippo-subfields-T2.touch
  4968. endif
  4969. #-------- --------#
  4970. #-------- Local Gyrification Index --------#
  4971. ##------- -lgi --------#
  4972. #-------- --------#
  4973. if ($DoLocalGyriIndex) then
  4974. cd $subjdir/surf
  4975. $PWD |& tee -a $LF
  4976. set CMDFS = () # see earlier notes on -parallel implementation
  4977. foreach hemi ($hemilist)
  4978. echo "#--------------------------------------------" \
  4979. |& tee -a $LF |& tee -a $CF
  4980. echo "#@# Local Gyrification Index $hemi `date`" \
  4981. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  4982. set cmd=(mris_compute_lgi --i ${hemi}.pial)
  4983. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  4984. if($DoParallel) then
  4985. set CMDF = mris_compute_lgi_${hemi}.cmd
  4986. echo "$cmd" > $CMDF
  4987. set CMDFS = ( $CMDFS $CMDF )
  4988. else
  4989. if($RunIt) $fs_time $cmd |& tee -a $LF
  4990. if($status) goto error_exit;
  4991. endif
  4992. end # hemi
  4993. if($RunIt && $DoParallel) then
  4994. reconbatchjobs $LF $CMDFS |& tee -a $LF
  4995. if($status) goto error_exit;
  4996. endif
  4997. endif # DoLocalGyriIndex
  4998. #----------------- ------------------#
  4999. ##---------------- -qcache ------------------#
  5000. #----------------- ------------------#
  5001. # Create the smoothed surfaces to fsaverage target needed by Qdec.
  5002. if ($DoQdecCache) then
  5003. # check for the target subject 'fsaverage' (if using as default target)
  5004. # and create symlink from distribution dir if not found in subjects dir
  5005. if (("${target}" == "fsaverage") && ( ! -e $SUBJECTS_DIR/fsaverage)) then
  5006. echo "INFO: fsaverage subject does not exist in SUBJECTS_DIR" \
  5007. |& tee -a $LF |& tee -a $CF
  5008. echo "INFO: Creating symlink to fsaverage subject..." \
  5009. |& tee -a $LF |& tee -a $CF
  5010. set cmd=(ln -s $FREESURFER_HOME/subjects/fsaverage)
  5011. echo "\n cd $SUBJECTS_DIR; $cmd; cd - \n"|& tee -a $LF |& tee -a $CF
  5012. cd $SUBJECTS_DIR
  5013. if($RunIt && ! -e fsaverage) $cmd |& tee -a $LF
  5014. cd -
  5015. endif
  5016. set CMDFS = () # see earlier notes on -parallel implementation
  5017. foreach hemi ($hemilist)
  5018. foreach measure ($measurelist)
  5019. echo "#--------------------------------------------" \
  5020. |& tee -a $LF |& tee -a $CF
  5021. echo "#@# Qdec Cache preproc $hemi $measure $target `date`" \
  5022. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  5023. if ("${measuredir}" != "") then
  5024. cd ${measuredir}
  5025. else
  5026. cd $subjdir/surf
  5027. endif
  5028. $PWD |& tee -a $LF
  5029. set MeasFile=(${hemi}.${measure})
  5030. # strip .mgz from filename (does nothing if not .mgz extension):
  5031. set MeasFile=`basename ${MeasFile} .mgz`
  5032. set MeasFile=(${MeasFile}.${target})
  5033. set cmd=(mris_preproc \
  5034. --s ${subjid} \
  5035. --hemi ${hemi} \
  5036. --meas ${measure} \
  5037. --target ${target} \
  5038. --out ${MeasFile}.mgh)
  5039. if ("${measuredir}" != "") set cmd = ($cmd --surfdir ${measuredir})
  5040. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  5041. if($DoParallel) then
  5042. set CMDF = mris_preproc_${hemi}_${measure}_${target}.cmd
  5043. echo "$cmd" > $CMDF
  5044. set CMDFS = ( $CMDFS $CMDF )
  5045. else
  5046. if($RunIt) $fs_time $cmd |& tee -a $LF
  5047. if($status) goto error_exit;
  5048. endif
  5049. end # measure
  5050. end # hemi
  5051. if($RunIt && $DoParallel) then
  5052. reconbatchjobs $LF $CMDFS |& tee -a $LF
  5053. if($status) goto error_exit;
  5054. endif
  5055. # now surf2surf
  5056. set CMDFS = () # see earlier notes on -parallel implementation
  5057. foreach hemi ($hemilist)
  5058. foreach measure ($measurelist)
  5059. set MeasFile=(${hemi}.${measure})
  5060. # strip .mgz from filename (does nothing if not .mgz extension):
  5061. set MeasFile=`basename ${MeasFile} .mgz`
  5062. set MeasFile=(${MeasFile}.${target})
  5063. foreach fwhm ($fwhmlist)
  5064. echo "#--------------------------------------------" \
  5065. |& tee -a $LF |& tee -a $CF
  5066. echo "#@# Qdec Cache surf2surf $hemi $measure fwhm$fwhm $target `date`" \
  5067. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  5068. set OutFile=(${hemi}.${measure})
  5069. # strip .mgz from filename (does nothing if not .mgz extension):
  5070. set OutFile=`basename ${OutFile} .mgz`
  5071. set OutFile=(${OutFile}.fwhm${fwhm}.${target})
  5072. set cmd=(mri_surf2surf --prune\
  5073. --s ${target} \
  5074. --hemi ${hemi} \
  5075. --fwhm ${fwhm} \
  5076. --sval ${MeasFile}.mgh \
  5077. --tval ${OutFile}.mgh)
  5078. if($SmoothCortexOnly) set cmd = ($cmd --cortex)
  5079. if(! $SmoothCortexOnly) set cmd = ($cmd --no-cortex)
  5080. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  5081. if($DoParallel) then
  5082. set CMDF = mris_surf2surf_${hemi}_${measure}_${fwhm}_${target}.cmd
  5083. echo "$cmd" > $CMDF
  5084. set CMDFS = ( $CMDFS $CMDF )
  5085. else
  5086. if($RunIt) $fs_time $cmd |& tee -a $LF
  5087. if($status) goto error_exit;
  5088. endif
  5089. echo $cmd > $touchdir/${hemi}.${measure}.${fwhm}.qcache.touch
  5090. end # fwhm
  5091. end # measure
  5092. end # hemi
  5093. if($RunIt && $DoParallel) then
  5094. reconbatchjobs $LF $CMDFS |& tee -a $LF
  5095. if($status) goto error_exit;
  5096. endif
  5097. # file move
  5098. foreach hemi ($hemilist)
  5099. foreach measure ($measurelist)
  5100. foreach fwhm ($fwhmlist)
  5101. set OutFile=(${hemi}.${measure})
  5102. # strip .mgz from filename (does nothing if not .mgz extension):
  5103. set OutFile=`basename ${OutFile} .mgz`
  5104. set OutFile=(${OutFile}.fwhm${fwhm}.${target})
  5105. if($RunIt) then
  5106. if ("${measuredir}" != "") then
  5107. set cmd = (mv -f -v ${OutFile}.mgh $subjdir/surf)
  5108. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  5109. $cmd |& tee -a $LF
  5110. endif
  5111. endif
  5112. echo $cmd > $touchdir/$hemi.$measure.$fwhm.qcache.touch
  5113. end # fwhm
  5114. end # measure
  5115. end # hemi
  5116. if($RunIt) rm -Rf tmp.mris_preproc.* # cleanup
  5117. endif # DoQdecCache
  5118. #---------- --------------#
  5119. #---------- Surface Vertices Number Match Check --------------#
  5120. ##--------- -vno-check --------------#
  5121. #---------- --------------#
  5122. if($DoVnoMatchCheck) then
  5123. set CMDFS = () # see earlier notes on -parallel implementation
  5124. foreach hemi ($hemilist)
  5125. echo "#-----------------------------------------" \
  5126. |& tee -a $LF |& tee -a $CF
  5127. echo "#@# Vno Match Check $hemi `date`" \
  5128. |& tee -a $SF |& tee -a $LF |& tee -a $CF
  5129. cd $subjdir/scripts > /dev/null
  5130. $PWD |& tee -a $LF
  5131. set cmd = (vno_match_check $subjid $hemi);
  5132. echo "\n $cmd \n"|& tee -a $LF |& tee -a $CF
  5133. if($DoParallel) then
  5134. set CMDF = vno_match_check_${hemi}.cmd
  5135. echo "$cmd" > $CMDF
  5136. set CMDFS = ( $CMDFS $CMDF )
  5137. else
  5138. if($RunIt) $fs_time $cmd |& tee -a $LF
  5139. if($status) goto error_exit;
  5140. endif
  5141. echo $cmd > $touchdir/$hemi.vnomatchcheck.touch
  5142. end # Loop over hemilist
  5143. if($RunIt && $DoParallel) then
  5144. reconbatchjobs $LF $CMDFS |& tee -a $LF
  5145. if($status) goto error_exit;
  5146. endif
  5147. endif
  5148. if($#TermScriptList) then
  5149. echo "Running termination scripts ---------------" | tee -a $LF
  5150. cd $SUBJECTS_DIR
  5151. foreach TermScript ($TermScriptList)
  5152. echo "Termination script $TermScript --------------" | tee -a $LF
  5153. date | tee -a $LF
  5154. echo "cd `pwd`" | tee -a $LF
  5155. set cmd = ($TermScript $subjid)
  5156. echo $cmd |& tee -a $LF
  5157. if($RunIt) $fs_time $cmd |& tee -a $LF
  5158. if($status) goto error_exit;
  5159. end
  5160. echo "---------------------------------" |& tee -a $LF
  5161. echo "Done with termination scripts " |& tee -a $LF
  5162. endif
  5163. #-------------- ----------------#
  5164. ##------------- END OF RECON-ALL ----------------#
  5165. #-------------- ----------------#
  5166. if($?SET_FS_CMD_TIMING) then
  5167. # copy information about this process for profiling
  5168. cp /proc/$$/status $SUBJECTS_DIR/${subjid}/scripts/proc.status
  5169. # copy information about the cpu for profiling
  5170. cp /proc/cpuinfo $SUBJECTS_DIR/${subjid}/scripts/cpuinfo
  5171. chmod ug+w $SUBJECTS_DIR/${subjid}/scripts/proc.status $SUBJECTS_DIR/${subjid}/scripts/cpuinfo
  5172. endif
  5173. echo "" |& tee -a $LF
  5174. set EndTime = `date`;
  5175. set tSecEnd = `date '+%s'`;
  5176. @ tSecRun = $tSecEnd - $tSecStart;
  5177. set tRunHours = `echo $tSecRun/3600|bc -l`
  5178. set tRunHours = `printf %6.3f $tRunHours`
  5179. echo "Started at $StartTime " |& tee -a $LF
  5180. echo "Ended at $EndTime" |& tee -a $LF
  5181. echo "#@#%# recon-all-run-time-hours $tRunHours" |& tee -a $LF
  5182. if($#NotifyFile != 0) then
  5183. echo "INFO: touching notification file $NotifyFile" |& tee -a $LF
  5184. touch $NotifyFile
  5185. endif
  5186. if($DoIsRunning && $#IsRunningFile) rm -f $IsRunningFile
  5187. # Create the Done File
  5188. if($#DoneFile) then
  5189. echo "------------------------------" > $DoneFile
  5190. echo "SUBJECT $subjid" >> $DoneFile
  5191. echo "START_TIME $StartTime" >> $DoneFile
  5192. echo "END_TIME $EndTime" >> $DoneFile
  5193. echo "RUNTIME_HOURS $tRunHours" >> $DoneFile
  5194. echo "USER $user" >> $DoneFile
  5195. echo "HOST `hostname`" >> $DoneFile
  5196. echo "PROCESSOR `uname -m`" >> $DoneFile
  5197. echo "OS `uname -s`" >> $DoneFile
  5198. echo "UNAME `uname -a`" >> $DoneFile
  5199. echo "VERSION $VERSION" >> $DoneFile
  5200. echo "CMDPATH $0" >> $DoneFile
  5201. echo "CMDARGS $argv0" >> $DoneFile
  5202. endif
  5203. echo "recon-all -s $subjid finished without error at `date`" \
  5204. |& tee -a $LF |& tee -a $SF
  5205. if($#mailuser != 0) then
  5206. echo "recon-all -s $subjid finished without error at `date`" | \
  5207. mail -s "$subjid DONE `date`" $mailuser
  5208. endif
  5209. echo "done"
  5210. # add to usage tracking file, if configured and writable
  5211. # a sysadmin would need to have users set the environment var
  5212. # RECONALL_USAGE_FILE to a world-writable file. example:
  5213. # setenv RECONALL_USAGE_FILE /space/freesurfer/recon-all_run_log
  5214. if($?RECONALL_USAGE_FILE) then
  5215. if(-e $RECONALL_USAGE_FILE) then
  5216. if(-w $RECONALL_USAGE_FILE) then
  5217. if ($RunIt) then
  5218. echo "`date` `cat $FREESURFER_HOME/build-stamp.txt`" \
  5219. >> $RECONALL_USAGE_FILE
  5220. endif
  5221. endif
  5222. endif
  5223. endif
  5224. exit 0
  5225. #-------------- ----------------#
  5226. ##------------- EXIT RECON-ALL ----------------#
  5227. #-------------- ----------------#
  5228. #-------------------------------------------------#
  5229. error_exit:
  5230. #-------------------------------------------------#
  5231. uname -a | tee -a $LF | tee -a $SF
  5232. echo "" |& tee -a $LF |& tee -a $SF
  5233. echo "recon-all -s $subjid exited with ERRORS at `date`" \
  5234. |& tee -a $LF |& tee -a $SF
  5235. echo "" |& tee -a $LF |& tee -a $SF
  5236. echo "For more details, see the log file $LF"
  5237. echo "To report a problem, see http://surfer.nmr.mgh.harvard.edu/fswiki/BugReporting"|& tee -a $LF
  5238. echo ""
  5239. # Handle IsRunningFile
  5240. if($DoIsRunning && $#IsRunningFile) rm -f $IsRunningFile
  5241. # Mail the user
  5242. if($#mailuser != 0) then
  5243. echo "recon-all -s $subjid finished with errors at `date`" | \
  5244. mail -s "$subjid ERROR `date`" $mailuser
  5245. endif
  5246. # Create an error file with date, cmd, etc of error
  5247. if ( $?ErrorFile ) then
  5248. echo "------------------------------" > $ErrorFile
  5249. echo "SUBJECT $subjid" >> $ErrorFile
  5250. echo "DATE `date`" >> $ErrorFile
  5251. echo "USER $user" >> $ErrorFile
  5252. echo "HOST `hostname`" >> $ErrorFile
  5253. echo "PROCESSOR `uname -m`" >> $ErrorFile
  5254. echo "OS `uname -s`" >> $ErrorFile
  5255. uname -a >> $ErrorFile
  5256. echo $VERSION >> $ErrorFile
  5257. echo $0 >> $ErrorFile
  5258. echo "PWD `pwd`" >> $ErrorFile
  5259. echo "CMD $cmd" >> $ErrorFile
  5260. endif
  5261. if($#DoneFile) then
  5262. echo "1" > $DoneFile
  5263. endif
  5264. # Finally exit
  5265. exit 1;
  5266. endif
  5267. #-------------------------------------------------#
  5268. parse_args:
  5269. #-------------------------------------------------#
  5270. set cmdline = ($argv);
  5271. while( $#argv != 0 )
  5272. set flag = $argv[1]; shift;
  5273. switch($flag)
  5274. case "-subject":
  5275. case "-subjid":
  5276. case "-sid":
  5277. case "-s":
  5278. if ( $#argv < 1) goto arg1err;
  5279. set subjid = $argv[1]; shift;
  5280. set subjid = `basename $subjid`; # removes trailing /
  5281. breaksw
  5282. case "-sb":
  5283. # Hidden option: same as -s but no basename;
  5284. # needed when passing a subdir of a subject
  5285. # as a subject as with xhemi
  5286. if( $#argv < 1) goto arg1err;
  5287. set subjid = $argv[1]; shift;
  5288. breaksw
  5289. case "-sd":
  5290. if ( $#argv < 1) goto arg1err;
  5291. setenv SUBJECTS_DIR $argv[1]; shift;
  5292. breaksw
  5293. case "-i"
  5294. if( $#argv < 1) goto arg1err;
  5295. set InputVol = "$argv[1]"; shift;
  5296. if(! -e "$InputVol") then
  5297. echo "ERROR: cannot find $InputVol"
  5298. goto error_exit;
  5299. endif
  5300. if (-d "$InputVol") then
  5301. echo "ERROR: You cannot give recon-all a folder as input. It must be an image file."
  5302. echo "If you have multiple files, you need multiple -i flags."
  5303. goto error_exit;
  5304. endif
  5305. if(! -r "$InputVol") then
  5306. echo "ERROR: $InputVol exists but is not readable"
  5307. goto error_exit;
  5308. endif
  5309. set InVolDir = `dirname "$InputVol"`;
  5310. set InVolBase = `basename "$InputVol"`;
  5311. pushd $InVolDir > /dev/null
  5312. set InVolDir = `pwd`;
  5313. popd > /dev/null
  5314. set InputVol = "$InVolDir/$InVolBase";
  5315. set InputList = ($InputList "$InputVol");
  5316. set DoConvertInput = 1;
  5317. breaksw
  5318. case "-T2"
  5319. case "-t2"
  5320. if( $#argv < 1) goto arg1err;
  5321. set InputT2Vol = "$argv[1]"; shift;
  5322. if(! -e "$InputT2Vol") then
  5323. echo "ERROR: cannot find $InputT2Vol"
  5324. goto error_exit;
  5325. endif
  5326. if(! -r "$InputT2Vol") then
  5327. echo "ERROR: $InputT2Vol exists but is not readable"
  5328. goto error_exit;
  5329. endif
  5330. set T2InVolDir = `dirname "$InputT2Vol"`;
  5331. set T2InVolBase = `basename "$InputT2Vol"`;
  5332. pushd $T2InVolDir > /dev/null
  5333. set T2InVolDir = `pwd`;
  5334. popd > /dev/null
  5335. set InputT2Vol = "$T2InVolDir/$T2InVolBase";
  5336. set DoConvertT2Input = 1;
  5337. breaksw
  5338. case "-t2max"
  5339. case "-T2max"
  5340. case "-T2_max"
  5341. if( $#argv < 1) goto arg1err;
  5342. set T2max = "$argv[1]"; shift;
  5343. breaksw
  5344. case "-FLAIR"
  5345. case "-flair"
  5346. if( $#argv < 1) goto arg1err;
  5347. set InputFlairVol = "$argv[1]"; shift;
  5348. if(! -e "$InputFlairVol") then
  5349. echo "ERROR: cannot find $InputFlairVol"
  5350. goto error_exit;
  5351. endif
  5352. if(! -r "$InputFlairVol") then
  5353. echo "ERROR: $InputFlairVol exists but is not readable"
  5354. goto error_exit;
  5355. endif
  5356. set FlairInVolDir = `dirname "$InputFlairVol"`;
  5357. set FlairInVolBase = `basename "$InputFlairVol"`;
  5358. pushd $FlairInVolDir > /dev/null
  5359. set FlairInVolDir = `pwd`;
  5360. popd > /dev/null
  5361. set InputFlairVol = "$FlairInVolDir/$FlairInVolBase";
  5362. set DoConvertFlairInput = 1;
  5363. breaksw
  5364. # flags -long, -no-orig-pial and -uselongbasectrlvol are all associated
  5365. # with longitudinal processing
  5366. case "-long":
  5367. case "-longitudinal":
  5368. set longitudinal = 1;
  5369. set NoRandomness = 1;
  5370. if ( $#argv < 2) goto arg1err;
  5371. # get the subject name to use for timepoint
  5372. set tpNid = $argv[1]; shift;
  5373. set tpNid = `basename $tpNid`; # remove trailing /
  5374. # get the subject to use for the base subject
  5375. set longbaseid = $argv[1]; shift;
  5376. set longbaseid = `basename $longbaseid`; # remove trailing /
  5377. # and create subjid to reflect its longitudinal relation to longbaseid
  5378. set subjid = ${tpNid}.long.${longbaseid}
  5379. breaksw
  5380. case "-uselongbasectrlvol":
  5381. set UseLongbaseCtrlVol = 1;
  5382. breaksw
  5383. case "-uselongbasewmedits":
  5384. set UseLongbaseWMedits = 1;
  5385. breaksw
  5386. case "-noasegfusion":
  5387. set UseAsegFusion = 0;
  5388. breaksw
  5389. case "-addtp":
  5390. # 'fake'-add a new timepoint
  5391. set DoAddTp = 1;
  5392. breaksw
  5393. case "-base-affine":
  5394. set DoAffineBase = 1;
  5395. # don't break here, but also switch on -base:
  5396. case "-base":
  5397. if ( $#argv < 1) goto arg1err;
  5398. set subjid = $argv[1]; shift;
  5399. set subjid = `basename $subjid`; # removes trailing /
  5400. set DoCreateBaseSubj = 1;
  5401. set NoRandomness = 1;
  5402. breaksw
  5403. case "-base-init":
  5404. set DoCreateBaseInput = 1;
  5405. breaksw
  5406. case "-nobase-init":
  5407. set DoCreateBaseInput = 0;
  5408. breaksw
  5409. case "-base-tp":
  5410. case "-tp":
  5411. if ( $#argv < 1) goto arg1err;
  5412. set basetpid = $argv[1]; shift;
  5413. set basetpid = `basename $basetpid`; # removes trailing /
  5414. set BaseSubjsList = ($BaseSubjsList $basetpid);
  5415. if($DoCreateBaseSubj) then
  5416. if ("$basetpid" == "$subjid") then
  5417. echo "ERROR: you need to specify a new ID for the base/template. "
  5418. echo "It cannot be one of the time points."
  5419. echo "Find more info at:"
  5420. echo "http://surfer.nmr.mgh.harvard.edu/fswiki/LongitudinalProcessing"
  5421. exit 1;
  5422. endif
  5423. endif
  5424. breaksw
  5425. case "-base-invol":
  5426. if ( $#argv < 1) goto arg1err;
  5427. set BaseSubjInvol = $argv[1]; shift;
  5428. breaksw
  5429. case "-motioncor":
  5430. case "-mc":
  5431. set DoMotionCor = 1;
  5432. breaksw
  5433. case "-nomotioncor":
  5434. case "-nomc":
  5435. set DoMotionCor = 0;
  5436. breaksw
  5437. case "-robust-motioncor":
  5438. case "-motioncor-robust":
  5439. set DoMotionCor = 1;
  5440. set DoRobustMotionCor = 1;
  5441. breaksw
  5442. case "-norobust-motioncor":
  5443. case "-nomotioncor-robust":
  5444. set DoRobustMotionCor = 0;
  5445. breaksw
  5446. case "-flirt-motioncor":
  5447. case "-motioncor-flirt":
  5448. set DoMotionCor = 1;
  5449. set DoRobustMotionCor = 0;
  5450. breaksw
  5451. case "-3T":
  5452. case "-3t":
  5453. set UseYa3tTalAtlas = 1;
  5454. set DoNuIntensityCor3T = 1;
  5455. breaksw
  5456. case "-talairach":
  5457. set DoTalairach = 1;
  5458. breaksw
  5459. case "-talairach-nu":
  5460. set DoTalairach = 1;
  5461. set DoTalairachUseNu = 1;
  5462. breaksw
  5463. case "-notalairach":
  5464. case "-no-talairach":
  5465. set DoTalairach = 0;
  5466. set DoTalCheck = 0;
  5467. breaksw
  5468. case "-use-mritotal":
  5469. set UseMincMritotal = 1;
  5470. breaksw
  5471. case "-schwartzya3t-atlas":
  5472. set UseYa3tTalAtlas = 1;
  5473. breaksw
  5474. case "-custom-tal-atlas":
  5475. if ( $#argv < 1) goto arg1err;
  5476. set CustomTalAtlas = $argv[1]; shift;
  5477. breaksw
  5478. case "-tal-check":
  5479. case "-talairach-check":
  5480. case "-talcheck":
  5481. set DoTalCheck = 1;
  5482. breaksw;
  5483. case "-notal-check":
  5484. case "-notalairach-check":
  5485. case "-no-tal-check":
  5486. case "-no-talairach-check":
  5487. case "-notalcheck":
  5488. case "-no-talcheck":
  5489. set DoTalCheck = 0;
  5490. breaksw;
  5491. case "-deface":
  5492. set DoDeface = 1;
  5493. breaksw
  5494. case "-nodeface":
  5495. set DoDeface = 0;
  5496. breaksw
  5497. # note: norm3diters and normmaxgrads is applied to both runs of
  5498. # mri_normalize. use -norm1-b, -norm1-n, -norm2-b, -norm2-n to
  5499. # distinguish -b and -n of the two mri_normalize runs
  5500. case "-norm3diters":
  5501. if ( $#argv < 1) goto arg1err;
  5502. set Norm3dIters = $argv[1]; shift;
  5503. breaksw
  5504. case "-normmaxgrad":
  5505. if ( $#argv < 1) goto arg1err;
  5506. set NormMaxGrad = $argv[1]; shift;
  5507. breaksw
  5508. case "-norm1-b":
  5509. if ( $#argv < 1) goto arg1err;
  5510. set Norm1_b = $argv[1]; shift;
  5511. breaksw
  5512. case "-norm1-n":
  5513. if ( $#argv < 1) goto arg1err;
  5514. set Norm1_n = $argv[1]; shift;
  5515. breaksw
  5516. case "-norm2-b":
  5517. if ( $#argv < 1) goto arg1err;
  5518. set Norm2_b = $argv[1]; shift;
  5519. breaksw
  5520. case "-norm2-n":
  5521. if ( $#argv < 1) goto arg1err;
  5522. set Norm2_n = $argv[1]; shift;
  5523. breaksw
  5524. case "-normalization":
  5525. set DoNormalization = 1;
  5526. breaksw
  5527. case "-nonormalization":
  5528. set DoNormalization = 0;
  5529. breaksw
  5530. case "-normalization2":
  5531. set DoNormalization2 = 1;
  5532. breaksw
  5533. case "-nonormalization2":
  5534. set DoNormalization2 = 0;
  5535. breaksw
  5536. case "-usecontrolpoints":
  5537. set UseControlPoints = 1;
  5538. breaksw
  5539. case "-maskbfs":
  5540. set DoMaskBFS = 1;
  5541. breaksw
  5542. case "-nomaskbfs":
  5543. set DoMaskBFS = 0;
  5544. breaksw
  5545. case "-skullstrip":
  5546. set DoSkullStrip = 1;
  5547. breaksw
  5548. case "-noskullstrip":
  5549. set DoSkullStrip = 0;
  5550. breaksw
  5551. case "-multistrip":
  5552. set DoMultiStrip = 1;
  5553. set DoSkullStrip = 1;
  5554. set DoCleanPFH = 1;
  5555. breaksw
  5556. case "-nomultistrip":
  5557. set DoMultiStrip = 0;
  5558. breaksw
  5559. case "-watershed":
  5560. echo $argv[1];
  5561. if ( $#argv < 1 ) goto arg1err;
  5562. switch($argv[1])
  5563. case "nowatershed":
  5564. set WaterShed = 0; breaksw;
  5565. case "normal":
  5566. set WaterShed = 1; breaksw;
  5567. case "watershedonly":
  5568. set WaterShed = 2; breaksw;
  5569. case "watershedtemplate":
  5570. set WaterShed = 3; breaksw;
  5571. case "atlas":
  5572. set WaterShed = 4; breaksw;
  5573. default:
  5574. echo "ERROR: -watershed argument $argv[1] unrecognized."
  5575. echo "Valid arguments are: atlas, nowatershed, normal, watershedonly,"
  5576. echo "and watershedtemplate."
  5577. goto error_exit;
  5578. breaksw;
  5579. endsw
  5580. shift;
  5581. breaksw
  5582. case "-wsless":
  5583. set WSLess = 1; breaksw
  5584. case "-wsmore":
  5585. set WSMore = 1; breaksw
  5586. case "-wsatlas":
  5587. set WSAtlas = 1; breaksw
  5588. case "-no-wsatlas":
  5589. set WSAtlas = 0; breaksw
  5590. case "-wsthresh":
  5591. if ( $#argv < 1) goto arg1err;
  5592. set WSPctPreFlood = $argv[1]; shift;
  5593. breaksw
  5594. case "-wsseed":
  5595. if ( $#argv < 3) goto arg3err;
  5596. set WSSeedPoint = ($argv[1] $argv[2] $argv[3]);
  5597. shift;shift;shift;
  5598. breaksw
  5599. case "-wsgcaatlas":
  5600. set WSGcaAtlas = 1; breaksw
  5601. case "-nowsgcaatlas":
  5602. case "-no-wsgcaatlas":
  5603. set WSGcaAtlas = 0; breaksw
  5604. case "-wstalxfm":
  5605. set WSUseTalXfm = 1; breaksw
  5606. case "-no-wstalxfm":
  5607. set WSUseTalXfm = 0; breaksw
  5608. case "-wscopy":
  5609. set WSCopy = 1; breaksw
  5610. case "-gcut":
  5611. set DoGcut = 1;
  5612. breaksw
  5613. case "-no-gcut":
  5614. case "-nogcut":
  5615. set DoGcut = 0;
  5616. breaksw
  5617. case "-nuintensitycor":
  5618. case "-nu_correct":
  5619. set DoNuIntensityCor = 1;
  5620. breaksw
  5621. case "-nonuintensitycor":
  5622. set DoNuIntensityCor = 0;
  5623. breaksw
  5624. case "-nuintensitycor-mask":
  5625. set DoNuIntensityCor = 1;
  5626. set UseMaskNuCorrect = 1;
  5627. breaksw
  5628. case "-nuintensitycor-nomask":
  5629. set DoNuIntensityCor = 1;
  5630. set UseMaskNuCorrect = 0;
  5631. breaksw
  5632. case "-nuintensitycor-mask-dilate":
  5633. set DoNuIntensityCor = 1;
  5634. set UseMaskNuCorrect = 1;
  5635. if ( $#argv < 1) goto arg1err;
  5636. set DilateMaskNuCorrect = $argv[1]; shift;
  5637. breaksw
  5638. case "-nuintensitycor-mask-nodilate":
  5639. set DoNuIntensityCor = 1;
  5640. set UseMaskNuCorrect = 1;
  5641. set DilateMaskNuCorrect = ();
  5642. breaksw
  5643. case "-nuintensitycor-3T":
  5644. case "-nuintensitycor-3t":
  5645. set DoNuIntensityCor = 1;
  5646. set DoNuIntensityCor3T = 1;
  5647. breaksw
  5648. case "-numakeuchar":
  5649. set DoNuMakeUchar = 1;
  5650. breaksw
  5651. case "-no-numakeuchar":
  5652. case "-nonumakeuchar":
  5653. set DoNuMakeUchar = 0;
  5654. breaksw
  5655. case "-gcareg":
  5656. set DoGCAReg = 1;
  5657. breaksw
  5658. case "-nogcareg":
  5659. set DoGCAReg = 0;
  5660. breaksw
  5661. case "-careginv":
  5662. set DoCARegInv = 1;
  5663. breaksw
  5664. case "-nocareginv":
  5665. set DoCARegInv = 0;
  5666. breaksw
  5667. case "-canorm":
  5668. set DoCANormalize = 1;
  5669. breaksw
  5670. case "-nocanorm":
  5671. set DoCANormalize = 0;
  5672. breaksw
  5673. case "-canorm-usecps":
  5674. set DoCANormalize = 1;
  5675. set UseCPsWithCaNorm = 1;
  5676. breaksw
  5677. case "-careg":
  5678. set DoCAReg = 1;
  5679. breaksw
  5680. case "-nocareg":
  5681. set DoCAReg = 0;
  5682. breaksw
  5683. case "-seg-wlo"
  5684. if( $#argv < 1) goto arg1err;
  5685. set WMSeg_wlo = (-wlo $argv[1]); shift;
  5686. breaksw
  5687. case "-seg-ghi"
  5688. if( $#argv < 1) goto arg1err;
  5689. set WMSeg_ghi = (-ghi $argv[1]); shift;
  5690. breaksw
  5691. case "-ca-align":
  5692. set UseCAAlign = (-align);
  5693. breaksw
  5694. case "-no-ca-align":
  5695. set UseCAAlign = ();
  5696. breaksw
  5697. case "-ca-align-after":
  5698. set UseCAAlignAfter = (-align-after);
  5699. breaksw
  5700. case "-no-ca-align-after":
  5701. set UseCAAlignAfter = ();
  5702. breaksw
  5703. case "-rmneck":
  5704. set DoRemoveNeck = 1;
  5705. breaksw
  5706. case "-normneck":
  5707. set DoRemoveNeck = 0;
  5708. breaksw
  5709. case "-skull-lta":
  5710. set DoSkullLTA = 1;
  5711. breaksw
  5712. case "-noskull-lta":
  5713. set DoSkullLTA = 0;
  5714. breaksw
  5715. case "-calabel":
  5716. set DoCALabel = 1;
  5717. breaksw
  5718. case "-nocalabel":
  5719. set DoCALabel = 0;
  5720. breaksw
  5721. case "-asegmerge":
  5722. set DoASegMerge = 1;
  5723. breaksw
  5724. case "-no-asegmerge":
  5725. # Note: this will be overriden if DoCALabel=1
  5726. set DoASegMerge = 0;
  5727. breaksw
  5728. case "-subcortseg":
  5729. set DoGCAReg = 1;
  5730. set DoRemoveNeck = 0;
  5731. set DoSkullLTA = 0;
  5732. set DoCANormalize = 1;
  5733. set DoCAReg = 1;
  5734. set DoCALabel = 1;
  5735. set DoSegStats = 0;
  5736. breaksw
  5737. case "-nosubcortseg":
  5738. set DoGCAReg = 0;
  5739. set DoRemoveNeck = 0;
  5740. set DoSkullLTA = 0;
  5741. set DoCANormalize = 0;
  5742. set DoCAReg = 0;
  5743. set DoCALabel = 0;
  5744. set DoSegStats = 0;
  5745. set NoNormMGZ = 1;
  5746. breaksw
  5747. case "-noaseg":
  5748. set UseAseg = 0;
  5749. set DoGCAReg = 0;
  5750. set DoRemoveNeck = 0;
  5751. set DoSkullLTA = 0;
  5752. set DoCANormalize = 0;
  5753. set DoCAReg = 0;
  5754. set DoCALabel = 0;
  5755. set DoSegStats = 0;
  5756. set NoNormMGZ = 1;
  5757. set DoAParc2ASeg = 0;
  5758. set DoAPas2ASeg = 0;
  5759. set DoWMParc = 0;
  5760. set DoCortRibbonVolMask = 0;
  5761. breaksw
  5762. case "-noaseg-inorm2":
  5763. set NoAsegInorm2 = 1;
  5764. breaksw
  5765. case "-gca":
  5766. if ( $#argv < 1) goto arg1err;
  5767. set GCA = $argv[1]; shift;
  5768. breaksw
  5769. case "-twm":
  5770. if ( $#argv < 1) goto arg1err;
  5771. set UseTWMControlPoints = 1;
  5772. set TWMControlPointsFile = $argv[1]; shift;
  5773. if(! -e "$TWMControlPointsFile") then
  5774. echo "ERROR: cannot find $TWMControlPointsFile"
  5775. goto error_exit;
  5776. endif
  5777. breaksw
  5778. case "-gca-skull":
  5779. if ( $#argv < 1) goto arg1err;
  5780. set GCASkull = $argv[1]; shift;
  5781. breaksw
  5782. case "-gca-dir":
  5783. if ( $#argv < 1) goto arg1err;
  5784. set GCADIR = $argv[1]; shift;
  5785. breaksw
  5786. case "-gcs":
  5787. if ( $#argv < 1) goto arg1err;
  5788. set GCS = $argv[1]; shift;
  5789. breaksw
  5790. case "-gcs-dir":
  5791. if ( $#argv < 1) goto arg1err;
  5792. set GCSDIR = $argv[1]; shift;
  5793. breaksw
  5794. case "-segmentation":
  5795. set DoSegmentation = 1;
  5796. breaksw
  5797. case "-nosegmentation":
  5798. set DoSegmentation = 0;
  5799. breaksw
  5800. case "-fill":
  5801. set DoFill = 1;
  5802. breaksw
  5803. case "-nofill":
  5804. set DoFill = 0;
  5805. breaksw
  5806. case "-pons-crs":
  5807. if ( $#argv < 3) goto arg3err;
  5808. set PonsSeedCRS = ($argv[1] $argv[2] $argv[3]);
  5809. shift;shift;shift;
  5810. breaksw
  5811. case "-cc-crs":
  5812. if ( $#argv < 3) goto arg3err;
  5813. set CCSeedCRS = ($argv[1] $argv[2] $argv[3]);
  5814. shift;shift;shift;
  5815. breaksw
  5816. case "-lh-crs":
  5817. if ( $#argv < 3) goto arg3err;
  5818. set LHSeedCRS = ($argv[1] $argv[2] $argv[3]);
  5819. shift;shift;shift;
  5820. breaksw
  5821. case "-rh-crs":
  5822. if ( $#argv < 3) goto arg3err;
  5823. set RHSeedCRS = ($argv[1] $argv[2] $argv[3]);
  5824. shift;shift;shift;
  5825. breaksw
  5826. case "-tessellate":
  5827. case "-tess":
  5828. set DoTessellate = 1;
  5829. breaksw
  5830. case "-notessellate":
  5831. case "-notess":
  5832. set DoTessellate = 0;
  5833. breaksw
  5834. case "-smooth1":
  5835. set DoSmooth1 = 1;
  5836. breaksw
  5837. case "-nosmooth1":
  5838. set DoSmooth1 = 0;
  5839. breaksw
  5840. case "-inflate1":
  5841. set DoInflate1 = 1;
  5842. breaksw
  5843. case "-noinflate1":
  5844. set DoInflate1 = 0;
  5845. breaksw
  5846. case "-svinitinflated":
  5847. set SvInitInflated = 1;
  5848. breaksw
  5849. case "-nosvinitinflated":
  5850. set SvInitInflated = 0;
  5851. breaksw
  5852. case "-qsphere":
  5853. set DoQSphere = 1;
  5854. breaksw
  5855. case "-noqsphere":
  5856. set DoQSphere = 0;
  5857. breaksw
  5858. case "-fix":
  5859. set DoFix = 1;
  5860. breaksw
  5861. case "-nofix":
  5862. set DoFix = 0;
  5863. breaksw
  5864. case "-fix-with-ga":
  5865. set FixWithGA = 1;
  5866. breaksw
  5867. case "-fix-with-ga-errflag":
  5868. set DoFix = 1;
  5869. set FixWithGA = 1;
  5870. set FixWithErrFlag = 1;
  5871. breaksw
  5872. case "-no-fix-with-ga":
  5873. set FixWithGA = 0;
  5874. breaksw
  5875. case "-fix-diag-only":
  5876. set DoFix = 1;
  5877. set FixWithGA = 1;
  5878. set FixDiagOnly = 1;
  5879. breaksw
  5880. case "-use-old-fixer":
  5881. set UseOldTopoFix = 1;
  5882. set UseNewTopoFix = 0;
  5883. breaksw
  5884. case "-use-new-fixer":
  5885. set UseOldTopoFix = 0;
  5886. set UseNewTopoFix = 1;
  5887. breaksw
  5888. case "-whitesurfs":
  5889. case "-white":
  5890. set DoWhiteSurfs = 1;
  5891. breaksw
  5892. case "-nowhitesurfs":
  5893. case "-nowhite":
  5894. set DoWhiteSurfs = 0;
  5895. breaksw
  5896. case "-smooth2":
  5897. set DoSmooth2 = 1;
  5898. breaksw
  5899. case "-nosmooth2":
  5900. set DoSmooth2 = 0;
  5901. breaksw
  5902. case "-inflate2":
  5903. set DoInflate2 = 1;
  5904. breaksw
  5905. case "-noinflate2":
  5906. set DoInflate2 = 0;
  5907. breaksw
  5908. case "-curvHK":
  5909. set DoCurvHK = 1;
  5910. breaksw
  5911. case "-nocurvHK":
  5912. set DoCurvHK = 0;
  5913. breaksw
  5914. case "-curvstats":
  5915. set DoCurvStats = 1;
  5916. breaksw
  5917. case "-nocurvstats":
  5918. set DoCurvStats = 0;
  5919. breaksw
  5920. case "-sphere":
  5921. set DoSphere = 1;
  5922. breaksw
  5923. case "-nosphere":
  5924. set DoSphere = 0;
  5925. breaksw
  5926. case "-surfreg":
  5927. set DoSurfReg = 1;
  5928. breaksw
  5929. case "-nosurfreg":
  5930. set DoSurfReg = 0;
  5931. breaksw
  5932. # Specify an average subject, which will have a tif
  5933. # in its directory. Output will be hemi.sphere.avgsubj.reg
  5934. case "-surfreg-to-subject":
  5935. if( $#argv < 1) goto arg1err;
  5936. set SurfRegToSubj = $argv[1]; shift;
  5937. breaksw
  5938. case "-no-surfreg-to-subject":
  5939. set SurfRegToSubj = ();
  5940. breaksw
  5941. case "-jacobian_white":
  5942. set DoJacobianWhite = 1;
  5943. breaksw
  5944. case "-nojacobian_white":
  5945. set DoJacobianWhite = 0;
  5946. breaksw
  5947. case "-jacobian_dist0":
  5948. set DoJacobianDist0 = 1;
  5949. breaksw
  5950. case "-nojacobian_dist0":
  5951. set DoJacobianDist0 = 0;
  5952. breaksw
  5953. case "-contrasurfreg":
  5954. set DoContraSurfReg = 1;
  5955. breaksw
  5956. case "-nocontrasurfreg":
  5957. set DoContraSurfReg = 0;
  5958. breaksw
  5959. case "-contrasurfreg-subj":
  5960. set DoContraSurfRegWithinSubject = 1;
  5961. breaksw
  5962. case "-nocontrasurfreg-subj":
  5963. set DoContraSurfRegWithinSubject = 0;
  5964. breaksw
  5965. case "-avgcurv":
  5966. set DoAvgCurv = 1;
  5967. breaksw
  5968. case "-noavgcurv":
  5969. set DoAvgCurv = 0;
  5970. breaksw
  5971. case "-cortparc":
  5972. set DoCortParc = 1;
  5973. breaksw
  5974. case "-nocortparc":
  5975. set DoCortParc = 0;
  5976. breaksw
  5977. case "-pialsurfs":
  5978. case "-pial":
  5979. set DoPialSurfs = 1;
  5980. breaksw
  5981. case "-nopialsurfs":
  5982. case "-nopial":
  5983. set DoPialSurfs = 0;
  5984. breaksw
  5985. case "-pial-noaparc":
  5986. case "-pial_noaparc":
  5987. set DoPialSurfs = 1;
  5988. set PialNoAparc = 1;
  5989. breaksw
  5990. # backward compatibility with single-run mris_make_surfaces:
  5991. case "-finalsurfs":
  5992. set DoWhiteSurfs = 1;
  5993. set DoPialSurfs = 0;
  5994. set DoSurfVolume = 1;
  5995. breaksw
  5996. case "-nofinalsurfs":
  5997. set DoWhiteSurfs = 0;
  5998. set DoPialSurfs = 0;
  5999. breaksw
  6000. case "-surfvolume":
  6001. set DoSurfVolume = 1;
  6002. breaksw;
  6003. case "-cortribbon":
  6004. set DoCortRibbonVolMask = 1;
  6005. breaksw
  6006. case "-nocortribbon":
  6007. set DoCortRibbonVolMask = 0;
  6008. breaksw
  6009. case "-parcstats":
  6010. set DoParcStats = 1;
  6011. breaksw
  6012. case "-noparcstats":
  6013. set DoParcStats = 0;
  6014. breaksw
  6015. case "-cortparc2":
  6016. set DoCortParc2 = 1;
  6017. breaksw
  6018. case "-nocortparc2":
  6019. set DoCortParc2 = 0;
  6020. breaksw
  6021. case "-parcstats2":
  6022. set DoParcStats2 = 1;
  6023. breaksw
  6024. case "-noparcstats2":
  6025. set DoParcStats2 = 0;
  6026. breaksw
  6027. case "-cortparc3":
  6028. set DoCortParc3 = 1;
  6029. breaksw
  6030. case "-nocortparc3":
  6031. set DoCortParc3 = 0;
  6032. breaksw
  6033. case "-parcstats3":
  6034. set DoParcStats3 = 1;
  6035. breaksw
  6036. case "-noparcstats3":
  6037. set DoParcStats3 = 0;
  6038. breaksw
  6039. case "-pctsurfcon":
  6040. set DoPctSurfCon = 1;
  6041. breaksw
  6042. case "-nopctsurfcon":
  6043. case "-no-pctsurfcon":
  6044. set DoPctSurfCon = 0;
  6045. breaksw
  6046. case "-hyporelabel":
  6047. set DoRelabelHypos = 1;
  6048. breaksw
  6049. case "-nohyporelabel":
  6050. set DoRelabelHypos = 0;
  6051. breaksw
  6052. case "-aparc2aseg":
  6053. set DoAParc2ASeg = 1;
  6054. breaksw
  6055. case "-noaparc2aseg":
  6056. set DoAParc2ASeg = 0;
  6057. breaksw
  6058. case "-apas2aseg":
  6059. set DoAPas2ASeg = 1;
  6060. breaksw
  6061. case "-noapas2aseg":
  6062. set DoAPas2ASeg = 0;
  6063. breaksw
  6064. case "-aparc+aseg-stats":
  6065. set DoAParcASegStats = 1;
  6066. breaksw
  6067. case "-no-aparc+aseg-stats":
  6068. set DoAParcASegStats = 0;
  6069. breaksw
  6070. case "-segstats":
  6071. set DoSegStats = 1;
  6072. breaksw
  6073. case "-nosegstats":
  6074. set DoSegStats = 0;
  6075. breaksw
  6076. case "-wmparc":
  6077. set DoWMParc = 1;
  6078. breaksw
  6079. case "-nowmparc":
  6080. set DoWMParc = 0;
  6081. breaksw
  6082. case "-balabels":
  6083. case "-ba_labels":
  6084. case "-ba-labels":
  6085. case "-label_ba":
  6086. case "-label_BA":
  6087. set DoBaLabels = 1;
  6088. breaksw;
  6089. case "-nobalabels":
  6090. case "-noba_labels":
  6091. case "-noba-labels":
  6092. case "-nolabel_ba":
  6093. case "-nolabel_BA":
  6094. case "-no_ba_labels":
  6095. case "-no-ba-labels":
  6096. case "-no_label_ba":
  6097. case "-no_label_BA":
  6098. set DoBaLabels = 0;
  6099. breaksw;
  6100. case "-label_v1":
  6101. case "-label_V1":
  6102. case "-label-v1":
  6103. case "-label-V1":
  6104. set DoLabelV1 = 1;
  6105. breaksw;
  6106. case "-label_exvivo_ec_avg":
  6107. case "-label-exvivo-ec-avg":
  6108. case "-label_exvivo_EC_avg":
  6109. case "-label-exvivo-EC-avg":
  6110. set DoLabelExvivoEC = 1;
  6111. breaksw;
  6112. case "-nolabel_exvivo_ec_avg":
  6113. case "-nolabel-exvivo-ec-avg":
  6114. case "-nolabel_exvivo_EC_avg":
  6115. case "-nolabel-exvivo-EC-avg":
  6116. case "-no_label_exvivo_ec_avg":
  6117. case "-no-label-exvivo-ec-avg":
  6118. case "-no_label_exvivo_EC_avg":
  6119. case "-no-label-exvivo-EC-avg":
  6120. set DoLabelExvivoEC = 0;
  6121. breaksw;
  6122. #---------------------------------------------------#
  6123. # Note: end of flags for recon-all stages above,
  6124. # below are 'autorecon' and other multi-stage flags
  6125. #---------------------------------------------------#
  6126. case "-all":
  6127. case "-autorecon-all":
  6128. set DoCreateBaseInput = 1;
  6129. set DoMotionCor = 1;
  6130. set DoTalairach = 1;
  6131. set DoTalCheck = 1;
  6132. set DoNormalization = 1;
  6133. set DoSkullStrip = 1;
  6134. set DoNuIntensityCor = 1;
  6135. set DoGCAReg = 1;
  6136. set DoRemoveNeck = 0;
  6137. set DoSkullLTA = 0;
  6138. set DoCANormalize = 1;
  6139. set DoCAReg = 1;
  6140. set DoCALabel = 1;
  6141. set DoNormalization2 = 1;
  6142. set DoMaskBFS = 1;
  6143. set DoSegmentation = 1;
  6144. set DoFill = 1;
  6145. set DoTessellate = 1;
  6146. set DoSmooth1 = 1;
  6147. set DoInflate1 = 1;
  6148. set DoQSphere = 1;
  6149. set DoFix = 1;
  6150. set DoWhiteSurfs = 1;
  6151. set DoSmooth2 = 1;
  6152. set DoInflate2 = 1;
  6153. set DoCurvHK = 1;
  6154. set DoCurvStats = 1;
  6155. set DoSphere = 1;
  6156. set DoSurfReg = 1;
  6157. set DoContraSurfReg = 0;
  6158. set DoAvgCurv = 1;
  6159. set DoJacobianWhite = 1;
  6160. set DoCortParc = 1;
  6161. set DoPialSurfs = 1;
  6162. set DoCortRibbonVolMask = 1;
  6163. set DoParcStats = 1;
  6164. set DoCortParc2 = 1;
  6165. set DoParcStats2 = 1;
  6166. set DoCortParc3 = 1;
  6167. set DoParcStats3 = 1;
  6168. set DoPctSurfCon = 1;
  6169. set DoRelabelHypos = 1;
  6170. set DoAParc2ASeg = 1;
  6171. set DoAPas2ASeg = 1;
  6172. set DoSegStats = 1;
  6173. set DoWMParc = 1;
  6174. set DoBaLabels = 1;
  6175. breaksw
  6176. case "-autorecon1":
  6177. set DoCreateBaseInput = 1;
  6178. set DoMotionCor = 1;
  6179. set DoTalairach = 1;
  6180. set DoTalCheck = 1;
  6181. set DoNormalization = 1;
  6182. set DoSkullStrip = 1;
  6183. set DoNuIntensityCor = 1;
  6184. breaksw
  6185. case "-gcatrain-iter":
  6186. if($#argv < 2) goto arg2err;
  6187. set gcafile = $argv[1]; shift;
  6188. if(! -e $gcafile) then
  6189. echo "ERROR: cannot find $gcafile"
  6190. exit 1;
  6191. endif
  6192. set gcafile = `getfullpath $gcafile`
  6193. set GCA = `basename $gcafile`
  6194. set GCADIR = `dirname $gcafile`
  6195. set GCAOutputName = $argv[1]; shift;
  6196. set DoGCAReg = 1;
  6197. set DoRemoveNeck = 0;
  6198. set DoSkullLTA = 0;
  6199. set DoCANormalize = 1;
  6200. set DoCAReg = 1;
  6201. set DoCALabel = 0;
  6202. set DoSegStats = 0;
  6203. breaksw
  6204. case "-gcareg-iters":
  6205. if($#argv < 1) goto arg1err;
  6206. set GCARegIterations = $argv[1]; shift;
  6207. breaksw
  6208. case "-gcareg-tol":
  6209. if($#argv < 1) goto arg1err;
  6210. set GCARegTol = $argv[1]; shift;
  6211. breaksw
  6212. case "-autorecon2":
  6213. set DoGCAReg = 1;
  6214. set DoRemoveNeck = 0;
  6215. set DoSkullLTA = 0;
  6216. set DoCANormalize = 1;
  6217. set DoCAReg = 1;
  6218. set DoCALabel = 1;
  6219. set DoSegStats = 0;
  6220. set DoNormalization2 = 1;
  6221. set DoMaskBFS = 1;
  6222. set DoSegmentation = 1;
  6223. set DoFill = 1;
  6224. set DoTessellate = 1;
  6225. set DoSmooth1 = 1;
  6226. set DoInflate1 = 1;
  6227. set DoQSphere = 1;
  6228. set DoFix = 1;
  6229. set DoSmooth2 = 1;
  6230. set DoInflate2 = 1;
  6231. set DoWhiteSurfs = 1;
  6232. set DoCurvHK = 1;
  6233. set DoCurvStats = 1;
  6234. breaksw
  6235. case "-autorecon2-volonly":
  6236. set DoGCAReg = 1;
  6237. set DoRemoveNeck = 0;
  6238. set DoSkullLTA = 0;
  6239. set DoCANormalize = 1;
  6240. set DoCAReg = 1;
  6241. set DoCALabel = 1;
  6242. set DoSegStats = 0;
  6243. set DoNormalization2 = 1;
  6244. set DoMaskBFS = 1;
  6245. set DoSegmentation = 1;
  6246. set DoFill = 1;
  6247. breaksw
  6248. case "-autorecon2-perhemi":
  6249. case "-autorecon2-surfonly":
  6250. case "-autorecon2-surfsonly":
  6251. set DoTessellate = 1;
  6252. set DoSmooth1 = 1;
  6253. set DoInflate1 = 1;
  6254. set DoQSphere = 1;
  6255. set DoFix = 1;
  6256. set DoWhiteSurfs = 1;
  6257. set DoSmooth2 = 1;
  6258. set DoInflate2 = 1;
  6259. set DoSegStats = 0;
  6260. set DoCurvHK = 1;
  6261. set DoCurvStats = 1;
  6262. breaksw
  6263. case "-autorecon2-inflate1":
  6264. set DoGCAReg = 1;
  6265. set DoRemoveNeck = 0;
  6266. set DoSkullLTA = 0;
  6267. set DoCANormalize = 1;
  6268. set DoCAReg = 1;
  6269. set DoCALabel = 1;
  6270. set DoSegStats = 0;
  6271. set DoNormalization2 = 1;
  6272. set DoMaskBFS = 1;
  6273. set DoSegmentation = 1;
  6274. set DoFill = 1;
  6275. set DoTessellate = 1;
  6276. set DoSmooth1 = 1;
  6277. set DoInflate1 = 1;
  6278. breaksw
  6279. case "-autorecon2-cp":
  6280. case "-autorecon2-noaseg":
  6281. case "-autorecon2-wm":
  6282. set DoNormalization2 = 1;
  6283. set DoSegmentation = 1;
  6284. set DoFill = 1;
  6285. set DoTessellate = 1;
  6286. set DoSmooth1 = 1;
  6287. set DoInflate1 = 1;
  6288. set DoQSphere = 1;
  6289. set DoFix = 1;
  6290. set DoMaskBFS = 1;
  6291. set DoWhiteSurfs = 1;
  6292. set DoSmooth2 = 1;
  6293. set DoInflate2 = 1;
  6294. set DoSegStats = 0;
  6295. set DoCurvHK = 1;
  6296. set DoCurvStats = 1;
  6297. breaksw
  6298. case "-autorecon-pial":
  6299. set DoMaskBFS = 1;
  6300. set DoWhiteSurfs = 1;
  6301. set DoSmooth2 = 1;
  6302. set DoInflate2 = 1;
  6303. set DoSegStats = 1;
  6304. set DoCurvHK = 1;
  6305. set DoCurvStats = 1;
  6306. set DoSphere = 1;
  6307. set DoSurfReg = 1;
  6308. set DoContraSurfReg = 0;
  6309. set DoAvgCurv = 1;
  6310. set DoJacobianWhite = 1;
  6311. set DoCortParc = 1;
  6312. set DoPialSurfs = 1;
  6313. set DoPctSurfCon = 1;
  6314. set DoCortRibbonVolMask = 1;
  6315. set DoParcStats = 1;
  6316. set DoCortParc2 = 1;
  6317. set DoParcStats2 = 1;
  6318. set DoCortParc3 = 1;
  6319. set DoParcStats3 = 1;
  6320. set DoRelabelHypos = 1;
  6321. set DoAParc2ASeg = 1;
  6322. set DoAPas2ASeg = 1;
  6323. set DoWMParc = 1;
  6324. set DoBaLabels = 1;
  6325. breaksw
  6326. case "-autorecon3":
  6327. set DoSphere = 1;
  6328. set DoSurfReg = 1;
  6329. set DoContraSurfReg = 0;
  6330. set DoAvgCurv = 1;
  6331. set DoJacobianWhite = 1;
  6332. set DoCortParc = 1;
  6333. set DoPialSurfs = 1;
  6334. set DoCortRibbonVolMask = 1;
  6335. set DoParcStats = 1;
  6336. set DoCortParc2 = 1;
  6337. set DoParcStats2 = 1;
  6338. set DoCortParc3 = 1;
  6339. set DoParcStats3 = 1;
  6340. set DoPctSurfCon = 1;
  6341. set DoRelabelHypos = 1;
  6342. set DoAParc2ASeg = 1;
  6343. set DoAPas2ASeg = 1;
  6344. set DoSegStats = 1;
  6345. set DoWMParc = 1;
  6346. set DoBaLabels = 1;
  6347. breaksw
  6348. # skips unnecessary steps (sphere reg) in autorecon3 when refining pial surface only
  6349. case "-autorecon3-T2pial":
  6350. case "-T2pial-only":
  6351. set DoT2pial = 1;
  6352. set DoCortRibbonVolMask = 1;
  6353. set DoParcStats = 1;
  6354. set DoCortParc2 = 1;
  6355. set DoParcStats2 = 1;
  6356. set DoCortParc3 = 1;
  6357. set DoParcStats3 = 1;
  6358. set DoPctSurfCon = 1;
  6359. set DoRelabelHypos = 1;
  6360. set DoAParc2ASeg = 1;
  6361. set DoAPas2ASeg = 1;
  6362. set DoSegStats = 1;
  6363. set DoWMParc = 1;
  6364. set DoBaLabels = 1;
  6365. breaksw
  6366. case "-autorecon-hemi":
  6367. if ( $#argv < 1) goto arg1err;
  6368. set hemilist = $argv[1]; shift;
  6369. if($hemilist != lh && $hemilist != rh) then
  6370. echo "ERROR: hemi = $hemilist, must be either lh or rh"
  6371. goto error_exit;
  6372. endif
  6373. set LF_DEFAULT_NAME = "recon-all-${hemilist}.log"
  6374. set SF_DEFAULT_NAME = "recon-all-status-${hemilist}.log"
  6375. set CF_DEFAULT_NAME = "recon-all-${hemilist}.cmd"
  6376. set DoTessellate = 1;
  6377. set DoSmooth1 = 1;
  6378. set DoInflate1 = 1;
  6379. set DoQSphere = 1;
  6380. set DoFix = 1;
  6381. set DoSmooth2 = 1;
  6382. set DoInflate2 = 1;
  6383. set DoWhiteSurfs = 1;
  6384. set DoCurvHK = 1;
  6385. set DoCurvStats = 1;
  6386. set DoSphere = 1;
  6387. set DoSurfReg = 1;
  6388. set DoContraSurfReg = 0;
  6389. set DoAvgCurv = 1;
  6390. set DoJacobianWhite = 1;
  6391. set DoCortParc = 1;
  6392. set DoPialSurfs = 1;
  6393. set DoCortRibbonVolMask = 0;
  6394. set DoParcStats = 1;
  6395. set DoCortParc2 = 1;
  6396. set DoParcStats2 = 1;
  6397. set DoCortParc3 = 1;
  6398. set DoParcStats3 = 1;
  6399. set DoPctSurfCon = 1;
  6400. set DoRelabelHypos = 1;
  6401. set DoAParc2ASeg = 0;
  6402. set DoAPas2ASeg = 0;
  6403. set DoWMParc = 0;
  6404. set DoSegStats = 0;
  6405. set DoBaLabels = 1;
  6406. breaksw
  6407. #-------------------------------------------------#
  6408. # below are utility flags and special modifiers
  6409. #-------------------------------------------------#
  6410. case "-hemi":
  6411. if ( $#argv < 1) goto arg1err;
  6412. set hemilist = $argv[1]; shift;
  6413. if($hemilist != lh && $hemilist != rh) then
  6414. echo "ERROR: hemi = $hemilist, must be either lh or rh"
  6415. goto error_exit;
  6416. endif
  6417. breaksw
  6418. # This is a temporary flag to test how changing the way the vertex
  6419. # area is computed in mrisurf.c affects a recon. It is set by default!
  6420. case "-fixvertexarea"
  6421. setenv FIX_VERTEX_AREA;
  6422. breaksw
  6423. case "-nofixvertexarea"
  6424. unsetenv FIX_VERTEX_AREA;
  6425. breaksw
  6426. case "-norandomness":
  6427. set NoRandomness = 1;
  6428. breaksw
  6429. case "-randomness":
  6430. set NoRandomness = 0;
  6431. breaksw
  6432. case "-no-emreg":
  6433. set NoEMReg = 1;
  6434. breaksw
  6435. case "-emreg":
  6436. set NoEMReg = 0;
  6437. breaksw
  6438. # -th3 turns on new volume calc for mris_anat_stats
  6439. case "-th3":
  6440. set TH3Flag = 1
  6441. breaksw
  6442. case "-no-th3":
  6443. set TH3Flag = 0
  6444. breaksw
  6445. case "-rng-seed":
  6446. set NoRandomness = 1;
  6447. set RngSeed = $argv[1]; shift;
  6448. breaksw
  6449. case "-expert":
  6450. if( $#argv < 1) goto arg1err;
  6451. set XOptsFile = $argv[1]; shift;
  6452. fsr-checkxopts $XOptsFile
  6453. if($status) goto error_exit;
  6454. set XOptsFile = `getfullpath $XOptsFile`
  6455. breaksw
  6456. case "-xopts-use"
  6457. set XOptsUse = 1; # Use pre-existing xopts
  6458. breaksw
  6459. case "-xopts-clean"
  6460. set XOptsClean = 1; # Delete pre-existing xopts
  6461. breaksw
  6462. case "-xopts-overwrite"
  6463. set XOptsOverwrite = 1; # Overwrite pre-existing xopts
  6464. breaksw
  6465. case "-termscript"
  6466. if( $#argv < 1) goto arg1err;
  6467. set ts = $argv[1]; shift
  6468. which $ts >& /dev/null
  6469. if($status) then
  6470. echo "ERROR: termination script $ts does not exist in your path"
  6471. exit 1;
  6472. endif
  6473. set TermScriptList = ($TermScriptList $ts);
  6474. breaksw
  6475. case "-clean":
  6476. set DoCleanCSDF = 1;
  6477. set DoCleanCW256 = 1;
  6478. set DoCleanTal = 1;
  6479. set DoCleanLta = 1;
  6480. set DoCleanCP = 1;
  6481. set DoCleanTWM = 1;
  6482. set DoCleanSeed = 1;
  6483. set DoCleanPFH = 1;
  6484. set DoCleanBM = 1;
  6485. set DoCleanASeg = 1;
  6486. set DoCleanWM = 1;
  6487. set DoCleanBFSE = 1;
  6488. set DoCleanXopts = 1;
  6489. set DoCleanT2 = 1;
  6490. set DoCleanFLAIR = 1;
  6491. breaksw
  6492. case "-clean-xopts":
  6493. set DoCleanXopts = 1;
  6494. breaksw
  6495. case "-clean-cw256":
  6496. set DoCleanCW256 = 1;
  6497. breaksw
  6498. case "-clean-cp":
  6499. set DoCleanCP = 1;
  6500. breaksw
  6501. case "-clean-twm":
  6502. set DoCleanTWM = 1;
  6503. breaksw
  6504. case "-clean-wm":
  6505. set DoCleanWM = 1;
  6506. breaksw
  6507. case "-clean-cpwm":
  6508. case "-clean-wmcp":
  6509. set DoCleanWM = 1;
  6510. set DoCleanCP = 1;
  6511. breaksw
  6512. case "-clean-seed":
  6513. set DoCleanSeed = 1;
  6514. breaksw
  6515. case "-clean-tal":
  6516. set DoCleanTal = 1;
  6517. breaksw
  6518. case "-clean-lta":
  6519. set DoCleanLta = 1;
  6520. breaksw
  6521. case "-clean-pfh":
  6522. set DoCleanPFH = 1;
  6523. breaksw
  6524. case "-clean-bm":
  6525. set DoCleanBM = 1;
  6526. breaksw
  6527. case "-clean-aseg":
  6528. set DoCleanASeg = 1;
  6529. breaksw
  6530. case "-clean-bfse":
  6531. set DoCleanBFSE = 1;
  6532. breaksw
  6533. case "-clean-T2":
  6534. set DoCleanT2 = 1;
  6535. breaksw
  6536. case "-clean-FLAIR":
  6537. set DoCleanFLAIR = 1;
  6538. breaksw
  6539. case "-superclean":
  6540. case "-super-clean":
  6541. set DoSuperClean = 1;
  6542. breaksw
  6543. case "-waitfor":
  6544. if ( $#argv < 1) goto arg1err;
  6545. set WaitForFile = $argv[1]; shift;
  6546. breaksw
  6547. case "-notify":
  6548. if ( $#argv < 1) goto arg1err;
  6549. set NotifyFile = $argv[1]; shift;
  6550. breaksw
  6551. case "-mail":
  6552. if ( $#argv < 1) goto arg1err;
  6553. set mailuser = $argv[1]; shift;
  6554. breaksw
  6555. case "-status":
  6556. if ( $#argv < 1) goto arg1err;
  6557. set SF = $argv[1]; shift;
  6558. breaksw
  6559. case "-noappendlog":
  6560. set AppendLog = 0;
  6561. breaksw
  6562. case "-noappendstatus":
  6563. set AppendStatus = 0;
  6564. breaksw
  6565. case "-noappend":
  6566. set AppendLog = 0;
  6567. set AppendStatus = 0;
  6568. breaksw
  6569. case "-done":
  6570. if ( $#argv < 1) goto arg1err;
  6571. set DoneFile = $argv[1]; shift;
  6572. rm -f $DoneFile
  6573. breaksw
  6574. case "-log":
  6575. if ( $#argv < 1) goto arg1err;
  6576. set LF = $argv[1]; shift;
  6577. breaksw
  6578. case "-nolog":
  6579. set LF = /dev/null
  6580. breaksw
  6581. case "-csurfdir":
  6582. if ( $#argv < 1) goto arg1err;
  6583. setenv FREESURFER_HOME $argv[1]; shift;
  6584. if(! -e $FREESURFER_HOME) then
  6585. echo "ERROR: cannot find $FREESURFER_HOME"
  6586. goto error_exit;
  6587. endif
  6588. pushd $FREESURFER_HOME > /dev/null
  6589. setenv FREESURFER_HOME `pwd`;
  6590. breaksw
  6591. case "-patch":
  6592. if ( $#argv < 1) goto arg1err;
  6593. set PatchDir = $argv[1]; shift;
  6594. if(! -e $PatchDir) then
  6595. echo "ERROR: cannot find patch $PatchDir"
  6596. exit 1;
  6597. endif
  6598. set path = ($PatchDir $path)
  6599. breaksw
  6600. case "-dontrun":
  6601. set RunIt = 0;
  6602. breaksw
  6603. case "-onlyversions":
  6604. set DoVersionsOnly = 1;
  6605. breaksw
  6606. case "-allowcoredump":
  6607. limit coredumpsize unlimited
  6608. breaksw
  6609. case "-no-isrunning":
  6610. set DoIsRunning = 0;
  6611. breaksw
  6612. case "-chunk":
  6613. setenv FS_USE_MRI_CHUNK 1
  6614. breaksw
  6615. case "-no-chunk":
  6616. unsetenv FS_USE_MRI_CHUNK
  6617. breaksw
  6618. case "-force":
  6619. echo "ERROR: -force is no longer used. You can continue an analysis on an"
  6620. echo " existing subject by omitting -force AND all -i flags."
  6621. exit 1;
  6622. set Force = 1;
  6623. breaksw
  6624. case "-verbose":
  6625. set verbose = 1;
  6626. breaksw
  6627. case "-echo":
  6628. set echo = 1;
  6629. breaksw
  6630. case "-debug":
  6631. set verbose = 1;
  6632. set echo = 1;
  6633. breaksw
  6634. case "-umask":
  6635. if ( $#argv < 1) goto arg1err;
  6636. umask $1; shift;
  6637. breaksw
  6638. case "-grp":
  6639. if ( $#argv < 1) goto arg1err;
  6640. set grp = $argv[1];
  6641. set curgrp = `id -gn`;
  6642. if($grp != $curgrp) then
  6643. echo "ERROR: current group ($curgrp) does not equal specified group $grp"
  6644. goto error_exit;
  6645. endif
  6646. breaksw
  6647. case "-cm":
  6648. set ConformMin = 1;
  6649. echo "INFO: all volumes are conformed to the min voxel size"
  6650. breaksw
  6651. case "-conform-dc":
  6652. set ConformKeepDC = 1;
  6653. echo "INFO: keeping DC when conforming"
  6654. breaksw
  6655. case "-hires":
  6656. set HiRes = 1;
  6657. set ConformMin = 1;
  6658. echo "INFO: hi-res volumes are conformed to the min voxel size"
  6659. # per testing by Natalia Zaretskaya, Mar 2015, the flags which
  6660. # normally disable the aseg steps are no longer necessary (which
  6661. # means aseg.mgz can be created with hi-res data).
  6662. breaksw
  6663. case "-use-aseg":
  6664. set UseAseg = 1;
  6665. breaksw
  6666. case "-no-use-aseg":
  6667. set UseAseg = 0;
  6668. breaksw
  6669. case "-noneg":
  6670. set UseNoNeg = 1;
  6671. breaksw
  6672. case "-nothicken":
  6673. set NoThicken = 1;
  6674. breaksw
  6675. case "-uncompress":
  6676. set UnCompress = 1;
  6677. breaksw
  6678. case "-bigventricles":
  6679. set BigVentricles = 1;
  6680. breaksw
  6681. case "-nobigventricles":
  6682. set BigVentricles = 0;
  6683. breaksw
  6684. case "-secondpassrenorm":
  6685. set DoSecondPassRenorm = 1;
  6686. breaksw
  6687. case "-mprage":
  6688. set IsMPRAGE = 1;
  6689. breaksw;
  6690. case "-no-mprage":
  6691. set IsMPRAGE = 0;
  6692. breaksw;
  6693. case "-washu_mprage":
  6694. set IsWashuMPRAGE = 1;
  6695. breaksw;
  6696. case "-cw256":
  6697. set DoConformWidth256 = 1;
  6698. breaksw;
  6699. case "-nowmsa":
  6700. set NoWMSA = 1;
  6701. breaksw;
  6702. case "-avgcurvtifpath":
  6703. if ( $#argv < 1) goto arg1err;
  6704. set AvgCurvTifPath = $argv[1]; shift;
  6705. breaksw
  6706. case "-avgcurvtif":
  6707. if ( $#argv < 1) goto arg1err;
  6708. set AvgCurvTif = $argv[1]; shift;
  6709. breaksw
  6710. case "-qcache":
  6711. set DoQdecCache = 1;
  6712. breaksw;
  6713. case "-smooth-cortex-only"
  6714. set SmoothCortexOnly = 1;
  6715. breaksw;
  6716. case "-no-smooth-cortex-only"
  6717. set SmoothCortexOnly = 0;
  6718. breaksw;
  6719. case "-measure":
  6720. if ( $#argv < 1) goto arg1err;
  6721. if ( $UserMeasureList ) then
  6722. set measurelist = ($measurelist $argv[1]); shift;
  6723. else
  6724. set measurelist = $argv[1]; shift;
  6725. set UserMeasureList = 1; # allow for multiple instances of -measure
  6726. endif
  6727. breaksw
  6728. case "-measuredir":
  6729. if ( $#argv < 1) goto arg1err;
  6730. set measuredir = $argv[1]; shift;
  6731. breaksw
  6732. case "-fwhm":
  6733. if ( $#argv < 1) goto arg1err;
  6734. set fwhmlist = $argv[1]; shift;
  6735. breaksw
  6736. case "-target":
  6737. if ( $#argv < 1) goto arg1err;
  6738. set target = $argv[1]; shift;
  6739. breaksw
  6740. case "-vno_match_check":
  6741. case "-vno_check":
  6742. case "-vno-check":
  6743. set DoVnoMatchCheck = 1;
  6744. breaksw;
  6745. case "-make"
  6746. if ( $#argv < 1) goto arg1err;
  6747. set DoMakefile = 1;
  6748. set MakefileTarget = $argv[1]; shift;
  6749. breaksw;
  6750. case "-time":
  6751. set DoTime = 1;
  6752. breaksw;
  6753. case "-notime":
  6754. set DoTime = 0;
  6755. breaksw;
  6756. case "-lgi":
  6757. case "-lGI":
  6758. case "-localGI":
  6759. set DoLocalGyriIndex = 1;
  6760. breaksw;
  6761. case "-use-concat-lta-tal":
  6762. set UseConcatLtaTal = 1;
  6763. breaksw;
  6764. case "-show-edits":
  6765. case "-show_edits":
  6766. case "-showedits":
  6767. set DoShowEdits = 1;
  6768. breaksw;
  6769. case "-use-cuda":
  6770. case "-use_cuda":
  6771. case "-use-gpu":
  6772. case "-use_gpu":
  6773. set UseCuda = 1;
  6774. # then set LD_LIBRARY_PATH to distributed cuda libs
  6775. source $FREESURFER_HOME/bin/cuda_setup
  6776. breaksw;
  6777. case "-get-cuda":
  6778. case "-get-gpu":
  6779. case "-show-cuda":
  6780. case "-show-gpu":
  6781. set GetCuda = 1; # info dump in check_params section below
  6782. # then set LD_LIBRARY_PATH to distributed cuda libs
  6783. source $FREESURFER_HOME/bin/cuda_setup
  6784. breaksw;
  6785. case "-parallel":
  6786. set DoParallel = 1;
  6787. if ( ! $OMP_NUM_SET ) then
  6788. # the user can override this thread count with -openmp
  6789. setenv OMP_NUM_THREADS 4
  6790. setenv FS_OMP_NUM_THREADS 4 # support for re-entrant recon-all
  6791. endif
  6792. # override: -itkthreads <num_threads>
  6793. setenv ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS 4
  6794. breaksw
  6795. case "-openmp":
  6796. case "-threads"
  6797. case "-nthreads"
  6798. if ( $#argv < 1) goto arg1err;
  6799. setenv OMP_NUM_THREADS $argv[1]; shift;
  6800. setenv FS_OMP_NUM_THREADS $OMP_NUM_THREADS # re-entrant recon-all
  6801. set OMP_NUM_SET = 1
  6802. breaksw;
  6803. case "-itkthreads":
  6804. # located after -parallel so as to allow threadcount override
  6805. if ( $#argv < 1) goto arg1err;
  6806. setenv ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS $argv[1]; shift;
  6807. breaksw;
  6808. # hippocampal subfield processing (in vivo atlas, Dickerson data)
  6809. case "-hippo-subfields":
  6810. echo "ERROR: This form of hippocampal subfield segmentation"
  6811. echo "is deprecated. Use -hippocampal-subfields-<T1/T1T2/T2>"
  6812. goto error_exit;
  6813. breaksw;
  6814. # hippocampal subfield processing (ex vivo atlas, only T1)
  6815. case "-hippocampal-subfields-T1":
  6816. set DoHippoSF_T1 = 1;
  6817. breaksw;
  6818. # hippocampal subfield processing (ex vivo atlas, multispectral)
  6819. case "-hippocampal-subfields-T1T2":
  6820. set DoHippoSF_T1T2 = 1;
  6821. if( $#argv < 2) goto arg2err;
  6822. set T2volHippoSF = "$argv[1]"; shift;
  6823. set UserSuffix = "$argv[1]"; shift;
  6824. breaksw;
  6825. case "-hippocampal-subfields-T2":
  6826. set DoHippoSF_T2 = 1;
  6827. if( $#argv < 2) goto arg2err;
  6828. set T2volHippoSF = "$argv[1]"; shift;
  6829. set UserSuffix = "$argv[1]"; shift;
  6830. breaksw;
  6831. # processing of brainstem substructures
  6832. case "-brainstem-structures":
  6833. set DoBSsubst = 1;
  6834. breaksw;
  6835. case "-cubic":
  6836. set UseCubic = 1;
  6837. breaksw
  6838. case "-nocubic":
  6839. case "-no-cubic":
  6840. case "-no_cubic":
  6841. set UseCubic = 0;
  6842. breaksw
  6843. case "-fix_mtl":
  6844. case "-fix-mtl":
  6845. set UseFixMtl = 1;
  6846. breaksw
  6847. case "-nofix_mtl":
  6848. case "-nofix-mtl":
  6849. case "-no_fix_mtl":
  6850. case "-no-fix-mtl":
  6851. set UseFixMtl = 0;
  6852. breaksw
  6853. case "-T2pial":
  6854. case "-t2pial":
  6855. set DoT2pial = 1;
  6856. breaksw
  6857. case "-noT2pial":
  6858. case "-no-T2pial":
  6859. case "-no_T2pial":
  6860. case "-no-t2pial":
  6861. case "-no_t2pial":
  6862. set DoT2pial = 0;
  6863. breaksw
  6864. case "-FLAIRpial":
  6865. case "-flairpial":
  6866. set DoFLAIRpial = 1;
  6867. breaksw
  6868. case "-noFLAIRpial":
  6869. case "-no-FLAIRpial":
  6870. case "-no_FLAIRpial":
  6871. case "-no-flairpial":
  6872. case "-no_flairpial":
  6873. set DoFLAIRpial = 0;
  6874. breaksw
  6875. case "-bbr-init-coreg"
  6876. set BBRInit = coreg;
  6877. breaksw
  6878. case "-bbr-init-fsl"
  6879. set BBRInit = fsl;
  6880. breaksw
  6881. case "-bbr-init-spm"
  6882. set BBRInit = spm;
  6883. breaksw
  6884. case "-bbr-init-rr"
  6885. set BBRInit = rr;
  6886. breaksw
  6887. case "-bbr-init-header"
  6888. set BBRInit = header;
  6889. breaksw
  6890. case "-bbr-init-best"
  6891. set BBRInit = best;
  6892. breaksw
  6893. default:
  6894. echo ERROR: Flag $flag unrecognized.
  6895. echo $cmdline
  6896. goto error_exit;
  6897. breaksw
  6898. endsw
  6899. end
  6900. #-------------------------------------------------#
  6901. goto parse_args_return;
  6902. #-------------------------------------------------#
  6903. #-------------------------------------------------#
  6904. arg1err:
  6905. #-------------------------------------------------#
  6906. echo "ERROR: flag $flag requires one argument"
  6907. exit 1
  6908. #-------------------------------------------------#
  6909. arg2err:
  6910. #-------------------------------------------------#
  6911. echo "ERROR: flag $flag requires two argument"
  6912. exit 1
  6913. #-------------------------------------------------#
  6914. arg3err:
  6915. #-------------------------------------------------#
  6916. echo "ERROR: flag $flag requires three arguments"
  6917. exit 1
  6918. #-------------------------------------------------#
  6919. check_params:
  6920. #-------------------------------------------------#
  6921. if($DoT2pial && $DoFLAIRpial) then
  6922. echo "Cannot specify both T2 and FLAIR for pial correction."
  6923. goto error_exit;
  6924. endif
  6925. if($DoHippoSF_T1T2 || $DoHippoSF_T2) then
  6926. if(! -e "$T2volHippoSF") then
  6927. echo "ERROR: cannot find $T2volHippoSF"
  6928. goto error_exit;
  6929. endif
  6930. if (-d "$T2volHippoSF") then
  6931. echo "ERROR: You cannot give the hippocampal subfield segmentation a folder as an input. It must be an image file."
  6932. goto error_exit;
  6933. endif
  6934. if(! -r "$T2volHippoSF") then
  6935. echo "ERROR: $T2volHippoSF exists but is not readable"
  6936. goto error_exit;
  6937. endif
  6938. set InVolDir = `dirname "$T2volHippoSF"`;
  6939. set InVolBase = `basename "$T2volHippoSF"`;
  6940. pushd $InVolDir > /dev/null
  6941. set InVolDir = `pwd`;
  6942. popd > /dev/null
  6943. set T2volHippoSF = "$InVolDir/$InVolBase";
  6944. endif
  6945. if($UseCuda || $GetCuda) then
  6946. # test a binary
  6947. echo "Testing for CUDA device:"
  6948. $FREESURFER_HOME/bin/mri_em_register_cuda --version \
  6949. | grep -v "\-\-all\-info"
  6950. if ($status) goto error_exit;
  6951. echo ""
  6952. # print version of installed driver
  6953. if ( -e /proc/driver/nvidia/version) then
  6954. echo "NVIDIA driver version info:"
  6955. cat /proc/driver/nvidia/version | grep NVIDIA
  6956. echo ""
  6957. endif
  6958. if ($GetCuda) then
  6959. $FREESURFER_HOME/bin/cudadetect
  6960. if ($status) goto error_exit;
  6961. exit 0;
  6962. endif
  6963. endif
  6964. if(! $DoVersionsOnly) then
  6965. if($#subjid != 1) then
  6966. echo "ERROR: must specify a subject id"
  6967. exit 1;
  6968. endif
  6969. if(! $?SUBJECTS_DIR ) then
  6970. echo "ERROR: environment variable SUBJECTS_DIR not set"
  6971. echo " this can be done by setting it in the shell before"
  6972. echo " executing recon-all or by using the -sd flag"
  6973. exit 1;
  6974. endif
  6975. if(! -e $SUBJECTS_DIR ) then
  6976. echo "ERROR: SUBJECTS_DIR $SUBJECTS_DIR does not exist."
  6977. exit 1;
  6978. endif
  6979. # Get the full path #
  6980. pushd $SUBJECTS_DIR > /dev/null
  6981. setenv SUBJECTS_DIR `$PWD`;
  6982. popd > /dev/null
  6983. set subjdir = $SUBJECTS_DIR/$subjid
  6984. if($TH3Flag) set TH3Opt = "-th3"
  6985. if(! $TH3Flag) set TH3Opt = "-no-th3"
  6986. #------------ Longitudinal ---------------#
  6987. if($longitudinal) then
  6988. # assert that $tpNid does not contain .long.
  6989. set haslong = `echo $tpNid | grep "\.long\."`
  6990. if ( "$haslong" != "" ) then
  6991. echo ""
  6992. echo "ERROR: Detected \'.long.\' in a subject id!
  6993. echo ""
  6994. echo " If you are trying to run or re-run a longitudinal time point"
  6995. echo " please specify the following parameters:"
  6996. echo ""
  6997. echo " \' -long <tpNid> <templateid> \'"
  6998. echo ""
  6999. echo " where <tpNid> is the time point id (SAME as cross sectional"
  7000. echo " ID) and <templateid> is the ID created in the -base run."
  7001. echo " The directory <tpNid>.long.<templateid> will be created"
  7002. echo " automatically or used for output, if it already exists."
  7003. echo ""
  7004. echo " If you are running a \'-base\' please specify a different name."
  7005. echo " Usage of \'.long.\' is reserved for the automatically created"
  7006. echo " longitudinal output."
  7007. echo ""
  7008. exit 1;
  7009. endif
  7010. #make sure cross sectional tpNid exists:
  7011. if ( ! -e ${SUBJECTS_DIR}/${tpNid} ) then
  7012. echo ""
  7013. echo "ERROR: Cross sectional tpNid: ${SUBJECTS_DIR}/${tpNid}"
  7014. echo " does not exist!"
  7015. echo ""
  7016. exit 1;
  7017. endif
  7018. # check if base/template specified
  7019. if($#longbaseid != 1) then
  7020. echo ""
  7021. echo "ERROR: Specify the <templateid> for this subject template "
  7022. echo " (created during the -base run):"
  7023. echo ""
  7024. echo " \' -long <tpNid> <templateid> \'"
  7025. echo ""
  7026. exit 1;
  7027. endif
  7028. # Error if longbaseid contains .long.
  7029. set haslong = `echo $longbaseid | grep "\.long\."`
  7030. if ( "$haslong" != "" ) then
  7031. echo ""
  7032. echo "ERROR: The <templateid> may not contain .long. (reserved for"
  7033. echo " automatic output of a longitudinal time point)."
  7034. echo " Specify the <templateid> for this subject template "
  7035. echo " (created during the -base run):"
  7036. echo ""
  7037. echo " \' -long <tpNid> <templateid> \'"
  7038. echo ""
  7039. exit 1;
  7040. endif
  7041. set longbasedir = $SUBJECTS_DIR/$longbaseid
  7042. if(! -e $longbasedir) then
  7043. echo "ERROR: cannot find base/template dir: $longbasedir"
  7044. echo ""
  7045. exit 1;
  7046. endif
  7047. if ( ! -e ${longbasedir}/${BaseSubjsListFname}) then
  7048. echo "ERROR: file ${longbasedir}/${BaseSubjsListFname} does not exist!"
  7049. echo ""
  7050. exit 1;
  7051. else
  7052. set found_tpNid = 0
  7053. set found_longbaseid = 0
  7054. foreach f (`cat ${longbasedir}/${BaseSubjsListFname}`)
  7055. if (${f} == ${tpNid}) set found_tpNid = 1
  7056. if (${f} == ${longbaseid}) set found_longbaseid = 1
  7057. end
  7058. if ( ! $found_tpNid && ! $DoAddTp ) then
  7059. echo "ERROR: $tpNid is not in ${longbasedir}/${BaseSubjsListFname}"
  7060. echo ""
  7061. exit 1
  7062. endif
  7063. # check that baseid is not the same as any of the timepoint subj IDs
  7064. if ( $found_longbaseid ) then
  7065. echo "ERROR: Template/base ID cannot be the same as a time point ID"
  7066. echo " (in ${longbasedir}/${BaseSubjsListFname})"
  7067. echo ""
  7068. echo " Find more info at:"
  7069. echo " http://surfer.nmr.mgh.harvard.edu/fswiki/LongitudinalProcessing"
  7070. echo ""
  7071. exit 1
  7072. endif
  7073. endif
  7074. else # ================= if cross run or base ==========================
  7075. # make sure $subjid does not contain .long.
  7076. set haslong = `echo $subjid | grep "\.long\."`
  7077. set hasxhemi = `echo $subjid | grep xhemi`
  7078. if ( "$haslong" != "" && "$hasxhemi" == "" ) then
  7079. echo ""
  7080. echo "ERROR: Are you trying to run or re-run a longitudinal time point?"
  7081. echo " If so, please specify the following parameters:"
  7082. echo ""
  7083. echo " \' -long <tpNid> <templateid> \'"
  7084. echo ""
  7085. echo " where <tpNid> is the time point id (SAME as cross sectional"
  7086. echo " ID) and <templateid> is the ID created in the -base run."
  7087. echo " The directory <tpNid>.long.<templateid> will be created"
  7088. echo " automatically or used for output, if it already exists."
  7089. echo ""
  7090. exit 1;
  7091. endif
  7092. endif
  7093. # error if base subject is run as a regular subject:
  7094. if ( ! $DoCreateBaseSubj ) then
  7095. if ( -e $subjdir/$BaseSubjsListFname ) then
  7096. echo ""
  7097. echo "ERROR: It appears that this subject ID is an existing"
  7098. echo " base/template from longitudinal processing (-base):"
  7099. echo " $subjid"
  7100. echo " If you are trying to re-run a -base template you"
  7101. echo " need to pass the -base and all -tp flags: "
  7102. echo ""
  7103. echo " \' -base <templateid> -tp <tpNid> ... -all \'"
  7104. echo ""
  7105. echo " (Instead of -all you can pass other flags, such"
  7106. echo " as -autorecon2 -autorecon3 to run only parts.)"
  7107. exit 1;
  7108. endif
  7109. endif
  7110. # error if existing regular (cross run) is run as base
  7111. if ( $DoCreateBaseSubj && -e $subjdir) then
  7112. if ( ! -e $subjdir/$BaseSubjsListFname ) then
  7113. echo ""
  7114. echo "ERROR: It appears that the -base templateID that you passed:"
  7115. echo " -base $subjid"
  7116. echo " is an existing regular (cross sectional) run!"
  7117. echo " Please make sure you pass a new name (not one of"
  7118. echo " the time points) for the template with -base."
  7119. echo " For example, if you are trying to create a -base:"
  7120. echo ""
  7121. echo " \' -base BertTemplate -tp Bert1 -tp Bert2 ... \'"
  7122. echo ""
  7123. exit 1;
  7124. endif
  7125. endif
  7126. #---------------------------------------------------------#
  7127. if($#InputList == 0) then
  7128. if(! $DoCreateBaseSubj) then
  7129. if($longitudinal) mkdir -p ${subjdir}
  7130. if(! -e $subjdir) then
  7131. echo "ERROR: cannot find $subjdir"
  7132. exit 1;
  7133. endif
  7134. if(! -w $subjdir) then
  7135. echo "ERROR: you do not have write permission to $subjdir"
  7136. exit 1;
  7137. endif
  7138. endif
  7139. else # An input was passed
  7140. if( -e $subjdir) then
  7141. echo "ERROR: You are trying to re-run an existing subject with (possibly)"
  7142. echo " new input data (-i). If this is truly new input data, you should delete"
  7143. echo " the subject folder and re-run, or specify a different subject name."
  7144. echo " If you are just continuing an analysis of an existing subject, then "
  7145. echo " omit all -i flags."
  7146. exit 1;
  7147. endif
  7148. mkdir -p $subjdir
  7149. endif
  7150. else
  7151. set subjdir = /tmp
  7152. endif
  7153. if(! $?FREESURFER_HOME ) then
  7154. echo "ERROR: environment variable FREESURFER_HOME not set."
  7155. exit 1;
  7156. endif
  7157. if(! -e $FREESURFER_HOME ) then
  7158. echo "ERROR: FREESURFER_HOME $FREESURFER_HOME does not exist."
  7159. exit 1;
  7160. endif
  7161. if(! -e ${GCADIR}/$GCA ) then
  7162. echo "ERROR: cannot find ${GCADIR}/$GCA" |& tee -a $LF
  7163. exit 1;
  7164. endif
  7165. if(! -e ${GCADIR}/$GCASkull && ($DoSkullLTA || $DoSkullStrip)) then
  7166. echo "ERROR: cannot find ${GCADIR}/$GCASkull" \
  7167. |& tee -a $LF
  7168. exit 1;
  7169. endif
  7170. foreach hemi ($hemilist)
  7171. set avgtif = ${AvgCurvTifPath}/$hemi.${AvgCurvTif};
  7172. if(! -e $avgtif) then
  7173. echo "ERROR: cannot find $avgtif."
  7174. exit 1;
  7175. endif
  7176. set GCSHemi = ${GCSDIR}/$hemi.$GCS
  7177. if(! -e $GCSHemi) then
  7178. echo "ERROR: cannot find $GCSHemi."
  7179. exit 1;
  7180. endif
  7181. set CPAtlas = ${GCSDIR}/$hemi.$GCS
  7182. if(! -e $CPAtlas) then
  7183. echo "ERROR: cannot find $CPAtlas."
  7184. exit 1;
  7185. endif
  7186. end
  7187. if($XOptsUse == 1 && $XOptsClean == 1) then
  7188. echo "ERROR: cannot specify both -xopts-clean and -xopts-use"
  7189. exit(1);
  7190. endif
  7191. if($IsMPRAGE == 1 && $IsWashuMPRAGE == 1) then
  7192. echo "ERROR: cannot specify both -mprage and -washu_mprage"
  7193. exit(1);
  7194. endif
  7195. mkdir -p $subjdir/scripts
  7196. set XOptsPreExist = $subjdir/scripts/expert-options
  7197. if(-e $XOptsPreExist) then
  7198. # There is a pre-existing xopts file
  7199. if($#XOptsFile == 0) then
  7200. # XOpts not passed on cmd line
  7201. if($XOptsUse == 0 && $XOptsClean == 0) then
  7202. echo "ERROR: there is a pre-existing expert options file."
  7203. echo "You must explicitly specify whether to:"
  7204. echo " 1. Use the pre-existing file (-xopts-use)"
  7205. echo " 2. Delete the pre-existing file (-xopts-clean)"
  7206. exit(1);
  7207. endif
  7208. if($XOptsClean == 1) then
  7209. rm -f $XOptsPreExist
  7210. set XOptsFile = ();
  7211. endif
  7212. if($XOptsUse == 1) then
  7213. set XOptsFile = $XOptsPreExist;
  7214. endif
  7215. else
  7216. # XOpts was passed on cmd line, but pre-existing xopts file
  7217. if(! $XOptsOverwrite) then
  7218. echo "ERROR: there is a pre-existing expert options file and"
  7219. echo "you have specified an expert options file on the command-line."
  7220. echo "If you want to use the file specified on the command-line,"
  7221. echo "you must run with -xopts-overwrite, or you may edit the "
  7222. echo "existing file $XOptsFile (and not use the -expert option)."
  7223. exit(1);
  7224. endif
  7225. # If it gets here, then overwrite
  7226. rm -f $XOptsPreExist
  7227. cp $XOptsFile $XOptsPreExist
  7228. if($status) goto error_exit;
  7229. endif
  7230. else
  7231. # No pre-existing file
  7232. if($#XOptsFile != 0) then
  7233. # Expert options file specified on cmd line, make copy
  7234. cp $XOptsFile $XOptsPreExist
  7235. if($status) goto error_exit;
  7236. endif
  7237. endif
  7238. if($#NotifyFile != 0) then
  7239. rm -f $NotifyFile;
  7240. set tmpdir = `dirname $NotifyFile`;
  7241. mkdir -p $tmpdir;
  7242. pushd $tmpdir > /dev/null;
  7243. set tmpdir = `$PWD`;
  7244. set NotifyFile = $tmpdir/`basename $NotifyFile`;
  7245. popd > /dev/null;
  7246. endif
  7247. if($#WaitForFile != 0) then
  7248. set tmpdir = `dirname $WaitForFile`;
  7249. mkdir -p $tmpdir;
  7250. pushd $tmpdir > /dev/null;
  7251. set tmpdir = `$PWD`;
  7252. set WaitForFile = $tmpdir/`basename $WaitForFile`;
  7253. popd > /dev/null;
  7254. endif
  7255. if(! $DoCleanTal && ! $DoCleanCP && ! $DoCleanBM && ! $DoConvertInput && \
  7256. ! $DoCleanASeg && ! $DoCleanWM && ! $DoCleanSeed && ! $DoCleanCW256 && \
  7257. ! $DoCortParc && ! $DoCortParc2 && ! $DoGCAReg && ! $DoCARegInv && \
  7258. ! $DoMotionCor && ! $DoTalairach && ! $DoTalCheck && ! $DoCleanXopts && \
  7259. ! $DoNormalization && ! $#SurfRegToSubj &&\
  7260. ! $DoNormalization2 && ! $DoParcStats && ! $DoParcStats2 && \
  7261. ! $DoVersionsOnly && ! $DoDeface && ! $DoCleanPFH && \
  7262. ! $DoSkullStrip && ! $DoSegmentation && ! $DoNuIntensityCor &&\
  7263. ! $DoFill && ! $DoTessellate && ! $DoAParc2ASeg && ! $DoWMParc && \
  7264. ! $DoSmooth1 && ! $DoInflate1 && ! $DoQSphere && ! $DoRemoveNeck &&\
  7265. ! $DoFix && ! $DoSmooth2 && ! $DoInflate2 && ! $DoSphere &&\
  7266. ! $DoSkullLTA && ! $DoQdecCache && ! $DoVnoMatchCheck &&\
  7267. ! $DoSurfReg && ! $DoContraSurfReg && ! $DoAvgCurv && ! $DoSegStats &&\
  7268. ! $DoMorphRGB && ! $DoWhiteSurfs && ! $DoContraSurfRegWithinSubject &&\
  7269. ! $DoCortRibbonVolMask && ! $DoJacobianWhite && ! $DoJacobianDist0 && \
  7270. ! $DoCANormalize && ! $DoCAReg && ! $DoCALabel && \
  7271. ! $DoMaskBFS && ! $DoAParcASegStats && ! $DoLocalGyriIndex && \
  7272. ! $DoMakefile && ! $DoParallel && ! $DoRelabelHypos && ! $DoCurvHK && \
  7273. ! $DoSurfVolume && ! $DoASegMerge && ! $DoCurvStats && ! $DoLabelV1 && \
  7274. ! $DoCreateBaseSubj && ! $DoBaLabels && ! $DoShowEdits && \
  7275. ! $DoLabelExvivoEC && ! $DoPialSurfs && \
  7276. ! $DoHippoSF_T1 && ! $DoHippoSF_T1T2 && ! $DoHippoSF_T2 && ! $DoBSsubst && \
  7277. ! $DoPctSurfCon && ! $DoT2pial && ! $DoFLAIRpial && \
  7278. ! $DoConvertT2Input && ! $DoConvertFlairInput && ! $DoSuperClean &&\
  7279. ! $DoCortParc3 && ! $DoParcStats3 && ! $DoAPas2ASeg ) then
  7280. echo "ERROR: nothing to do. You must specify an operation to perform by adding"
  7281. echo "flags. Eg, -all, -autorecon1, -autorecon2, -autorecon3, etc."
  7282. exit 1;
  7283. endif
  7284. if($WSMore && $WSLess) then
  7285. echo "ERROR: cannot specify both -wsmore and -wsless"
  7286. exit 1;
  7287. endif
  7288. if( ($WSMore || $WSLess) && $WSPctPreFlood ) then
  7289. echo "ERROR: cannot specify -wsmore or -wsless and -wsthresh"
  7290. exit 1;
  7291. endif
  7292. if($#SurfRegToSubj) then
  7293. if(! -e $SUBJECTS_DIR/$SurfRegToSubj) then
  7294. echo "ERROR: cannot find $SurfRegToSubj"
  7295. exit 1;
  7296. endif
  7297. set AvgTif = $SUBJECTS_DIR/$SurfRegToSubj/$hemi.reg.template.tif
  7298. if(! -e $AvgTif) then
  7299. echo "ERROR: cannot find $AvgTif"
  7300. exit 1;
  7301. endif
  7302. endif
  7303. if($DoParallel == 1 && $#hemilist == 1) then
  7304. echo "ERROR: cannot use -parallel with a single hemi"
  7305. exit(1);
  7306. endif
  7307. #-------------------------------------------------#
  7308. goto check_params_return;
  7309. #-------------------------------------------------#
  7310. #-------------------------------------------------#
  7311. usage_exit:
  7312. #-------------------------------------------------#
  7313. echo ""
  7314. echo "USAGE: $ProgName"
  7315. echo ""
  7316. echo " Required Arguments:";
  7317. echo " -subjid <subjid>"
  7318. echo " -<process directive>"
  7319. echo ""
  7320. echo " Fully-Automated Directive:"
  7321. echo " -all : performs all stages of cortical reconstruction"
  7322. echo " -autorecon-all : same as -all"
  7323. echo ""
  7324. echo " Manual-Intervention Workflow Directives:"
  7325. echo " -autorecon1 : process stages 1-5 (see below)"
  7326. echo " -autorecon2 : process stages 6-23"
  7327. echo " after autorecon2, check white surfaces:"
  7328. echo " a. if wm edit was required, then run -autorecon2-wm"
  7329. echo " b. if control points added, then run -autorecon2-cp"
  7330. echo " c. proceed to run -autorecon3"
  7331. echo " -autorecon2-cp : process stages 12-23 (uses -f w/ mri_normalize, -keep w/ mri_seg)"
  7332. echo " -autorecon2-wm : process stages 15-23"
  7333. echo " -autorecon2-inflate1 : 6-18"
  7334. echo " -autorecon2-perhemi : tess, sm1, inf1, q, fix, sm2, inf2, finalsurf, ribbon"
  7335. echo " -autorecon3 : process stages 24-34"
  7336. echo " if edits made to correct pial, then run -autorecon-pial"
  7337. echo " -hemi ?h : just do lh or rh (default is to do both)"
  7338. echo ""
  7339. echo " Autorecon Processing Stages (see -autorecon# flags above):"
  7340. echo " 1. Motion Correction and Conform"
  7341. echo " 2. NU (Non-Uniform intensity normalization)"
  7342. echo " 3. Talairach transform computation"
  7343. echo " 4. Intensity Normalization 1"
  7344. echo " 5. Skull Strip"
  7345. echo ""
  7346. echo " 6. EM Register (linear volumetric registration)"
  7347. echo " 7. CA Intensity Normalization"
  7348. echo " 8. CA Non-linear Volumetric Registration "
  7349. echo " 9. Remove neck"
  7350. echo " 10. EM Register, with skull"
  7351. echo " 11. CA Label (Aseg: Volumetric Labeling) and Statistics"
  7352. echo ""
  7353. echo " 12. Intensity Normalization 2 (start here for control points)"
  7354. echo " 13. White matter segmentation"
  7355. echo " 14. Edit WM With ASeg"
  7356. echo " 15. Fill (start here for wm edits)"
  7357. echo " 16. Tessellation (begins per-hemisphere operations)"
  7358. echo " 17. Smooth1"
  7359. echo " 18. Inflate1"
  7360. echo " 19. QSphere"
  7361. echo " 20. Automatic Topology Fixer"
  7362. echo " 21. White Surfs (start here for brain edits for pial surf)"
  7363. echo " 22. Smooth2"
  7364. echo " 23. Inflate2"
  7365. echo ""
  7366. echo " 24. Spherical Mapping"
  7367. echo " 25. Spherical Registration "
  7368. echo " 26. Spherical Registration, Contralater hemisphere"
  7369. echo " 27. Map average curvature to subject"
  7370. echo " 28. Cortical Parcellation (Labeling)"
  7371. echo " 29. Cortical Parcellation Statistics"
  7372. echo " 30. Pial Surfs"
  7373. echo " 31. WM/GM Contrast"
  7374. echo " 32. Cortical Ribbon Mask"
  7375. echo " 33. Cortical Parcellation mapped to ASeg"
  7376. echo " 34 Brodmann and exvio EC labels"
  7377. echo ""
  7378. echo " Step-wise Directives"
  7379. echo " See -help"
  7380. echo ""
  7381. echo " Expert Preferences"
  7382. echo " -pons-crs C R S : col, row, slice of seed point for pons, used in fill"
  7383. echo " -cc-crs C R S : col, row, slice of seed point for corpus callosum, used in fill"
  7384. echo " -lh-crs C R S : col, row, slice of seed point for left hemisphere, used in fill"
  7385. echo " -rh-crs C R S : col, row, slice of seed point for right hemisphere, used in fill"
  7386. echo " -nofill : do not use the automatic subcort seg to fill"
  7387. echo " -watershed cmd : control skull stripping/watershed program"
  7388. echo " -wsless : decrease watershed threshold (leaves less skull, but can strip more brain)"
  7389. echo " -wsmore : increase watershed threshold (leaves more skull, but can strip less brain)"
  7390. echo " -wsatlas : use atlas when skull stripping"
  7391. echo " -no-wsatlas : do not use atlas when skull stripping"
  7392. echo " -no-wsgcaatlas : do not use GCA atlas when skull stripping"
  7393. echo " -wsthresh pct : explicity set watershed threshold"
  7394. echo " -wsseed C R S : identify an index (C, R, S) point in the skull"
  7395. echo " -norm3diters niters : number of 3d iterations for mri_normalize"
  7396. echo " -normmaxgrad maxgrad : max grad (-g) for mri_normalize. Default is 1."
  7397. echo " -norm1-b N : in the _first_ usage of mri_normalize, use control "
  7398. echo " point with intensity N below target (default=10.0) "
  7399. echo " -norm2-b N : in the _second_ usage of mri_normalize, use control "
  7400. echo " point with intensity N below target (default=10.0) "
  7401. echo " -norm1-n N : in the _first_ usage of mri_normalize, do N number "
  7402. echo " of iterations"
  7403. echo " -norm2-n N : in the _second_ usage of mri_normalize, do N number "
  7404. echo " of iterations"
  7405. echo " -cm : conform volumes to the min voxel size "
  7406. echo " -no-fix-with-ga : do not use genetic algorithm when fixing topology"
  7407. echo " -fix-diag-only : topology fixer runs until ?h.defect_labels files"
  7408. echo " are created, then stops"
  7409. echo " -seg-wlo wlo : set wlo value for mri_segment and mris_make_surfaces"
  7410. echo " -seg-ghi ghi : set ghi value for mri_segment and mris_make_surfaces"
  7411. echo " -nothicken : pass '-thicken 0' to mri_segment"
  7412. echo " -no-ca-align-after : turn off -align-after with mri_ca_register"
  7413. echo " -no-ca-align : turn off -align with mri_ca_label"
  7414. echo " -deface : deface subject, written to orig_defaced.mgz"
  7415. echo ""
  7416. echo " -expert file : read-in expert options file"
  7417. echo " -xopts-use : use pre-existing expert options file"
  7418. echo " -xopts-clean : delete pre-existing expert options file"
  7419. echo " -xopts-overwrite : overwrite pre-existing expert options file"
  7420. echo " -termscript script : run script before exiting (multiple -termscript flags possible)"
  7421. echo " This can be good for running custom post-processing after recon-all"
  7422. echo " The script must be in your path. The subjid is passed as the only argument"
  7423. echo " The current directory is changed to SUBJECTS_DIR before the script is run"
  7424. echo " The script should exit with 0 unless there is an error"
  7425. echo ""
  7426. echo " -mprage : assume scan parameters are MGH MP-RAGE protocol"
  7427. echo " -washu_mprage : assume scan parameters are Wash.U. MP-RAGE protocol."
  7428. echo " both mprage flags affect mri_normalize and mri_segment,"
  7429. echo " and assumes a darker gm."
  7430. echo " -schwartzya3t-atlas : for tal reg, use special young adult 3T atlas"
  7431. echo ""
  7432. echo " -use-gpu : use GPU versions of mri_em_register, mri_ca_register,"
  7433. echo " mris_inflate and mris_sphere"
  7434. echo ""
  7435. echo " Notification Files (Optional)"
  7436. echo " -waitfor file : wait for file to appear before beginning"
  7437. echo " -notify file : create this file after finishing"
  7438. echo ""
  7439. echo " Status and Log files (Optional)"
  7440. echo " -log file : default is scripts/recon-all.log"
  7441. echo " -status file : default is scripts/recon-all-status.log"
  7442. echo " -noappend : start new log and status files instead of appending"
  7443. echo " -no-isrunning : do not check whether this subject is currently being processed"
  7444. echo ""
  7445. echo " Segmentation of substructures of hippocampus and brainstem"
  7446. echo " -hippocampal-subfields-T1 : segmentation of hippocampal subfields using input T1 scan"
  7447. echo " -hippocampal-subfields-T2 file ID : segmentation using an additional scan (given by file);"
  7448. echo " ID is a user-defined identifier for the analysis"
  7449. echo " -hippocampal-subfields-T1T2 file ID : segmentation using additional scan (given by file) and input T1"
  7450. echo " simultaneously; ID is a user-defined identifier for the analysis"
  7451. echo " -brainstem-structures : segmentation of brainstem structures"
  7452. echo ""
  7453. echo " Other Arguments (Optional)"
  7454. echo " -sd subjectsdir : specify subjects dir (default env SUBJECTS_DIR)"
  7455. echo " -mail username : mail user when done"
  7456. echo " -umask umask : set unix file permission mask (default 002)"
  7457. echo " -grp groupid : check that current group is alpha groupid "
  7458. echo " -onlyversions : print version of each binary and exit"
  7459. echo " -debug : print out lots of info"
  7460. echo " -allowcoredump : set coredump limit to unlimited"
  7461. echo " -dontrun : do everything but execute each command"
  7462. echo " -version : print version of this script and exit"
  7463. echo " -help : voluminous bits of wisdom"
  7464. echo ""
  7465. if(! $PrintHelp) exit 1;
  7466. echo $VERSION
  7467. echo ""
  7468. cat $0 | awk 'BEGIN{prt=0}{if(prt) print $0;if($1 == "BEGINHELP") prt=1}'
  7469. exit 1;
  7470. #---- Everything below here is printed out as part of help -----#
  7471. BEGINHELP
  7472. Performs all, or any part of, the FreeSurfer cortical reconstruction
  7473. process. This help only gives some simple information. For more
  7474. detailed documentation, see https://surfer.nmr.mgh.harvard.edu
  7475. Basic usages:
  7476. 1. Subject dir does not exist:
  7477. recon-all -subject subjectname -i invol1 <-i invol2> -all
  7478. Creates analysis directory $SUBJECTS_DIR/subjectname, converts one or
  7479. more input volumes to MGZ format in subjectname/mri/orig, and runs
  7480. all processing steps. If subjectname exists, then an error is returned
  7481. when -i is used; but this can be overridden with -force (in which
  7482. case any pre-existing source volumes are deleted).
  7483. 2. Manual conversion into mgz:
  7484. mkdir -p $SUBJECTS_DIR/subjectname/mri/orig
  7485. mri_convert invol1 $SUBJECTS_DIR/subjectname/mri/orig/001.mgz
  7486. mri_convert invol2 $SUBJECTS_DIR/subjectname/mri/orig/002.mgz
  7487. recon-all -subject subjectname -all
  7488. If no input volumes are given, then it is assumed that the subject
  7489. directory has already been created and that the raw data already
  7490. exists in MGZ format in subjid/mri/orig as XXX.mgz, where XXX is a
  7491. 3-digit, zero-padded number.
  7492. SUBJECT IDENTIFICATION STRING
  7493. -s subjectname
  7494. -sid subjectname
  7495. -subjid subjectname
  7496. -subject subjectname
  7497. 'subjectname' is the FreeSurfer subject identification string which doubles
  7498. as the name of the reconstruction root directory for this subject. This
  7499. reconstruction should be referenced by this string for all FreeSurfer
  7500. commands and in the register.dat matrix (for functional interfacing).
  7501. SPECIFYING DIRECTIVES
  7502. Directives instruct recon-all which part(s) of the reconstruction
  7503. stream to run. While it is possible to do everything in one shot (using
  7504. the -all flag), there can be some benefits to customizing the
  7505. stream. These benefits include stopping to perform manual editing as
  7506. well as parallelization. Directives are either clustered or step-wise.
  7507. Clustered directives are sets of steps that can be performed by
  7508. specifying a single flag. A step-wise directive refers to a single
  7509. step. Directives accumulate. A step can be removed from a cluster by
  7510. adding -no<step> after the cluster flag. For example, specifying
  7511. -all followed by -notalairach will perform all the reconstruction
  7512. steps except talairaching. However, note that if -notalairach *preceeded*
  7513. -all, talairaching would still be performed.
  7514. CLUSTERED DIRECTIVES
  7515. -all
  7516. -autorecon-all
  7517. Perform all reconstruction steps.
  7518. -autorecon1
  7519. Motion correction through skull strip.
  7520. -autorecon2
  7521. Subcortical segmentation through make white surfaces.
  7522. -autorecon2-cp
  7523. Normalization2 through make final surfaces.
  7524. -autorecon2-wm
  7525. Fill through make white surfaces. Used after editing wm volume after running
  7526. -autorecon2.
  7527. -autorecon-pial
  7528. Makes final surfaces (white and pial). Used after editing brain.finalsurfs
  7529. volume after running -autorecon2. The brain.finalsurfs.mgz volume may be
  7530. edited to fix problems with the pial surface.
  7531. -autorecon3
  7532. Spherical morph, automatic cortical parcellation, pial surf and ribbon mask.
  7533. STEP-WISE DIRECTIVES
  7534. Step-wise directives allow the user to implement a single step in the
  7535. reconstruction process. See also STEP DESCRIPTION SUMMARIES below.
  7536. They also allow users to include/exclude a step from a clustered
  7537. DIRECTIVE. To include a step, use -step (eg, -skullstrip). To exclude
  7538. a step, use -nostep (eg -noskullstrip).
  7539. Run times are approximate for an Intel Xeon E5-2643 64bit 3.4GHz processor:
  7540. -<no>motioncor 2 min
  7541. -<no>talairach < 1 min
  7542. -<no>normalization 2 min
  7543. -<no>skullstrip 15 min
  7544. -<no>nuintensitycor 1 min
  7545. -<no>gcareg 15 min
  7546. -<no>canorm 1 min
  7547. -<no>careg 1 hour
  7548. -<no>careginv 1 min
  7549. -<no>rmneck 1 min
  7550. -<no>skull-lta 12 min
  7551. -<no>calabel 34 min
  7552. -<no>normalization2 3 min
  7553. -<no>maskbfs < 1 min
  7554. -<no>segmentation 1 min
  7555. -<no>fill 1 min
  7556. -<no>tessellate < 1 min per hemisphere
  7557. -<no>smooth1 < 1 min per hemisphere
  7558. -<no>inflate1 1 min per hemisphere
  7559. -<no>qsphere 3 min per hemisphere
  7560. -<no>fix 15 min per hemisphere
  7561. -<no>white 3 min per hemisphere
  7562. -<no>smooth2 < 1 min per hemisphere
  7563. -<no>inflate2 < 1 min per hemisphere
  7564. -<no>curvHK < 1 min per hemisphere
  7565. -<no>curvstats < 1 min per hemisphere
  7566. -<no>sphere 40 min per hemisphere
  7567. -<no>surfreg 50 min per hemisphere
  7568. -<no>jacobian_white < 1 min per hemisphere
  7569. -<no>avgcurv < 1 min per hemisphere
  7570. -<no>cortparc 1 min per hemisphere
  7571. -<no>pial 4 min per hemisphere
  7572. -<no>surfvolune < 1 min per hemisphere
  7573. -<no>cortribbon 15 min
  7574. -<no>parcstats < 1 min per hemisphere
  7575. -<no>cortparc2 1 min per hemisphere
  7576. -<no>parcstats2 < 1 min per hemisphere
  7577. -<no>cortparc3 1 min per hemisphere
  7578. -<no>parcstats3 < 1 min per hemisphere
  7579. -<no>pctsurfcon < 1 min per hemisphere
  7580. -<no>hyporelabel < 1 min per hemisphere
  7581. -<no>aparc2aseg 1 min
  7582. -<no>apas2aseg 1 min
  7583. -<no>segstats 3 min
  7584. -<no>wmparc 7 min
  7585. -<no>balabels 5 min per hemisphere
  7586. -all 7 hours both hemipheres
  7587. If -parallel is specified, runtime is reduced to 3 hours.
  7588. SEGMENTATION OF HIPPOCAMPAL SUBFIELDS
  7589. The following flags can be used to obtain a segmentation of the hippocampal subfields.
  7590. The method is described in [17], and you can find further information here:
  7591. http://surfer.nmr.mgh.harvard.edu/fswiki/HippocampalSubfields
  7592. -hippocampal-subfields-T1
  7593. It uses the T1 scan which the recon-all stream has processed at 1 mm resolution or higher (with -cm).
  7594. -hippocampal-subfields-T2 file ID
  7595. Instead of the main T1 scan, it uses an additional scan ('file'), typically (but not necessarily)
  7596. a T2 volume with higher resolution, at least in the coronal plane. It also requires a second
  7597. argument ('ID'), which uniquely identifies the output in the mri directory; this is useful when
  7598. different additional volumes are tried in this mode, in order to prevent files from being overwritten
  7599. -hippocampal-subfields-T1T2 file ID
  7600. This mode is very similar to the previous one, with the only difference that the main T1 and the
  7601. additional volumes are used simultaneously in the segmentation.
  7602. SEGMENTATION OF BRAINSTEM STRUCTURES
  7603. -brainstem-structures
  7604. Performs segmentation of brains structures (medulla, pons, midbrain, SCP) on the T1 scan which the
  7605. recon-all stream has processed, at 1 mm or higher resolution (with -cm). The method is described in [18];
  7606. you can read more at: http://surfer.nmr.mgh.harvard.edu/fswiki/BrainstemSubstructures
  7607. EXPERT PREFERENCES
  7608. -pons-crs C R S
  7609. Specify a seed point for the pons during the fill operation. This is
  7610. used to cut the brain stem from brain. By default, this point will be
  7611. determined automatically. It should only be specified if there is a
  7612. cut failure. To determine what this point should be, find the center
  7613. of the pons in the T1 volume (in tkmedit) and record the column, row,
  7614. and slice. Creates a file called scripts/seed-ponscrs.man.dat
  7615. with the CRS.
  7616. -cc-crs C R S
  7617. Specify a seed point for the corpus callosum during the fill
  7618. operation. This is used to help separate the hemispheres. By default,
  7619. this point will be determined automatically. It should only be
  7620. specified if there is a cut failure. To determine what this point
  7621. should be, find the center of the CC in the T1 volume (in tkmedit) and
  7622. record the column, row, and slice. Creates a file called
  7623. scripts/seed-cccrs.man.dat with the CRS.
  7624. -lh-crs C R S
  7625. Specify a seed point for the left hemisphere during the fill
  7626. operation. This is used to help identify the left hemisphere. By
  7627. default, this point will be determined automatically. It should only
  7628. be specified if there is a cut failure. To determine what this point
  7629. should be, find a point in the white matter mass of the left
  7630. hemisphere in the T1 volume (in tkmedit) and record the column, row,
  7631. and slice. Creates a file called scripts/seed-cccrs.man.dat with the
  7632. CRS. Remember that tkmedit displays the volume in radiological
  7633. convention (ie, left is right).
  7634. -rh-crs C R S
  7635. Same as -lh-crs but for the right hemisphere. Creates a file called
  7636. scripts/seed-rhcrs.man.dat with the CRS.
  7637. -watershed cmd
  7638. This controls how the skull stripping will be performed. Legal values are
  7639. normal (the default), atlas, nowatershed, watershedonly, and watershedtemplate.
  7640. -wsmore/-wsless
  7641. Increase/decrease the preflooding height (threshold) when skull
  7642. stripping. -wsmore will expand the skull surface; -wsless will shrink
  7643. the skull surface. See also -wsthresh.
  7644. -wsthresh pctheight
  7645. Explicitly set the preflooding height when skull stripping.
  7646. -wsseed R C S
  7647. Supply a point in the volume that the user believes to be in the white
  7648. matter. By default, this point will be determined automatically. It
  7649. should only be specified if there is a strip failure. To determine
  7650. what this point should be, find a point in the white matter using
  7651. tkmedit and record the Volume Index values (NOT the XYZ coordinates).
  7652. -no-wsgcaatlas
  7653. Disable usage of the GCA atlas when running mri_watershed skull-stripping.
  7654. The default is to use the GCA atlas to locate anatomy aiding skull-strip.
  7655. -gca gcafile
  7656. Specify the name of the gaussian classifier array (GCA) file
  7657. to be used with GCA registration and automatic subcortical
  7658. segmentation. It must be found in the FREESURFER_HOME/average directory (or
  7659. use -gca-dir to specify an alternate path).
  7660. The Default is RB_all_YYYY-MM-DD.gca located in
  7661. FREESURFER_HOME/average. This has no effect unless the GCA registration
  7662. or subcortical segmentation stages are to be performed.
  7663. -gca-skull gcafile
  7664. Specify the name of the gaussian classifier array (GCA) file to be used with
  7665. registration with skull. It must be found in the FREESURFER_HOME/average
  7666. directory (or use -gca-dir to specify an alternate path).
  7667. The default is RB_all_withskull_YYYY-MM-DD.gca located in
  7668. FREESURFER_HOME/average.
  7669. -gcs gcsfile
  7670. Specify the name of the gaussian classifier surface atlas (GCS) file
  7671. to be used for the cortical parcellation stage. It must be found in the
  7672. FREESURFER_HOME/average directory (or use -gcs-dir to specify an alternate
  7673. path). The default is named
  7674. curvature.buckner40.filled.desikan_killiany.2007-06-20.gcs and is located in
  7675. FREESURFER_HOME/average.
  7676. -twm twmfile
  7677. Where (twmfile) is a control.dat format file (a point set in freeview)
  7678. with points manually selected to be in the white matter inferior to
  7679. hippocampus in the temporal lobe. This option is passed to mri_ca_register.
  7680. -nuiterations
  7681. Number of iterations in the non-uniform intensity correction.
  7682. Default is 1.
  7683. -norm3diters niters
  7684. Use niters 3d normalization iterations (passes as -n to _both_ runs of
  7685. mri_normalize).
  7686. -normmaxgrad maxgrad
  7687. Passes "-g maxgrad" to _both_ runs of mri_normalize. Max grad default is 1.
  7688. -norm1-b N
  7689. In the _first_ usage of mri_normalize (during creation of T1.mgz), use
  7690. control point with intensity N below target (default=10.0)
  7691. -norm1-n N
  7692. In the _first_ usage of mri_normalize, do N number of iterations
  7693. -norm2-b N
  7694. In the _second_ usage of mri_normalize (during creation of brain.mgz), use
  7695. control point with intensity N below target (default=10.0)
  7696. -norm2-n N
  7697. In the _second_ usage of mri_normalize, do N number of iterations
  7698. -noaseg
  7699. Skips subcortical segmentation steps (same as -nosubcortseg), and does
  7700. not use aseg.presurf.mgz for inorm2, wm segmentation, or filling.
  7701. Use this flag for brains that do not support usage of Freesurfers subcortical
  7702. segmentation, such as baby brains, or non-human primates.
  7703. -noaseg-inorm2
  7704. Does not use aseg.presurf.mgz for the second mri_normalize step.
  7705. -bigventricles
  7706. If a subject has enlarged ventricles due to atrophy, include the -bigventricles
  7707. flag with the -autorecon2 stage in order to prevent surfaces extending into
  7708. the ventricle regions. The flag directly affects the binary mri_ca_register,
  7709. and mris_make_surfaces indirectly via aseg.presurf.mgz.
  7710. -norandomness
  7711. The random number generator used by certain binaries is seeded with the
  7712. same number, thus producing identical results from run to run.
  7713. -cw256
  7714. Include this flag after -autorecon1 if images have a FOV > 256. The
  7715. flag causes mri_convert to conform the image to dimensions of 256^3.
  7716. -notal-check
  7717. Skip the automatic failure detection of Talairach alignment.
  7718. -qcache
  7719. Produce the pre-cached files required by the Qdec utility, allowing rapid
  7720. analysis of group data. These files are created by running mris_preproc,
  7721. which creates smoothed surface data files sampled to the 'fsaverage'
  7722. common-space surface. By default, the surface data for thickness, curv, sulc,
  7723. area and jacobian_white are smoothed at 0, 5, 10, 15, 20, and 25 mm FWHM.
  7724. If just one set of surface data needs to be processed, then the option
  7725. -measure <surfmeas> can follow -qcache, where <surfmeas> is one of: thickness,
  7726. curv, sulc, area, jacobian_white or any surface measure. Multiple instances
  7727. of -measure <meas> is supported. The -measuredir option allows
  7728. specifying a directory other than the default of surf. Another option is
  7729. -fwhm <num> where <num> is a value in mm. Also, -target <name> allows
  7730. specifying a common-space target other than fsaverage (the default).
  7731. qcache is also a target for make, eg. recon-all -make qcache
  7732. See also: http://surfer.nmr.mgh.harvard.edu/fswiki/Qdec
  7733. -smooth-cortex-only
  7734. Only applies with -qcache. Only smooth data if it is part of the ?h.cortex.label.
  7735. This prevents values in the medial wall (which are meaningless) from being
  7736. smoothed into cortical areas. This is the default and you will have to turn
  7737. it off with -no-smooth-cortex-only.
  7738. -no-smooth-cortex-only
  7739. Allow medial wall values to smooth into cortex.
  7740. -make target
  7741. Runs recon-all through 'make', the standard utility used to create a file
  7742. only if its dependencies are out-of-date. This -make option makes use of the
  7743. file recon-all.makefile, where the dependency chain is specified.
  7744. A 'target' argument must be specified. The valid targets are:
  7745. all
  7746. autorecon1
  7747. autorecon2
  7748. autorecon2-volonly
  7749. autorecon2-perhemi
  7750. autorecon3
  7751. qcache
  7752. These targets correspond to their flag equivalents in recon-all. The
  7753. difference in behaviour is that files are created only if the file does not
  7754. exist or if an input file used to create it has a newer date than the file
  7755. in need of creation. It is also possible to supply the full pathname to a
  7756. particular file as a target.
  7757. The flag -dontrun can also be specified to show the commands that will run
  7758. without excuting them.
  7759. -lgi
  7760. -lGI
  7761. -localGI
  7762. Computes local measurements of pial-surface gyrification at thousands of
  7763. points over the cortical surface. See reference [13] for details.
  7764. -label_v1
  7765. Create a label of V1, based on Hinds et al., NeuroImage 39 (2008) 1585-1599.
  7766. -balabels
  7767. -ba-labels
  7768. -ba_labels
  7769. Creates Brodmann area labels of BA1, BA2, BA3a, BA3b, BA4a, BA4p, BA6, BA44,
  7770. BA45, V1, V2, and V5/MT (and perirhinal) by mapping labels from the
  7771. 'fsaverage' subject, which must exist within the SUBJECTS_DIR.
  7772. Based on:
  7773. "Cortical Folding Patterns and Predicting Cytoarchitecture", Fischl et al.,
  7774. Cerebral Cortex 2007.
  7775. -use-gpu
  7776. Use the GPU versions of the binaries mri_em_register, mri_ca_register,
  7777. mris_inflate, and mris_sphere.
  7778. EXPERT OPTIONS FILE
  7779. While the expert preferences flags supported by recon-all cover most of
  7780. the instances where special flags need to be passed to a FreeSurfer binary,
  7781. to allow passing an arbitrary flag to a binary, recon-all supports the
  7782. reading of a user-created file containing special options to include in
  7783. the command string (in addition to, not in place of). The file should
  7784. contain as the first item the name of the command, and the items following
  7785. it on rest of the line will be passed as the extra options. For example,
  7786. if a file called expert.opts is created containing these lines:
  7787. mri_em_register -p .5
  7788. mris_topo_fixer -asc
  7789. then the option "-p .5" will be passed to mri_em_register, and "-asc"
  7790. will be passed to mris_topo_fixer. The name of the expert options file
  7791. is passed to recon-all with the -expert flag, eg.
  7792. recon-all -expert expert.opts
  7793. When an expert options is passed, it will be copied to scripts/expert-options.
  7794. Future calls to recon-all, the user MUST explicitly specify how to treat this file.
  7795. Options are (1) use the file (-xopts-use), or (2) delete it (-xopts-clean). If
  7796. this file exsts and the user specifies another expert options file, then
  7797. the user must also specify -xopts-overwrite.
  7798. The following FreeSurfer binaries will accept an expert option:
  7799. talairach_avi
  7800. mri_normalize
  7801. mri_watershed
  7802. mri_em_register
  7803. mri_ca_normalize
  7804. mri_ca_register
  7805. mri_remove_neck
  7806. mri_ca_label
  7807. mri_segstats
  7808. mri_mask
  7809. mri_segment
  7810. mri_edit_wm_with_aseg
  7811. mri_pretess
  7812. mri_fill
  7813. mri_tessellate
  7814. mris_smooth
  7815. mris_inflate
  7816. mris_sphere
  7817. mris_fix_topology
  7818. mris_topo_fixer
  7819. mris_remove_intersection
  7820. mris_make_surfaces
  7821. mris_surf2vol
  7822. mris_register
  7823. mris_jacobian
  7824. mrisp_paint
  7825. mris_ca_label
  7826. mris_anatomical_stats
  7827. mri_aparc2aseg
  7828. NOTIFICATION FILES
  7829. Notification files allow the user to cascade invocations to recon-all,
  7830. with one invocation waiting until another one terminates. This is done
  7831. by specifying a file that must exist before an invocation can precede
  7832. (-waitfor) and/or specifying a file that is created when an invocation
  7833. terminates (-notify). This type of interprocess communication can
  7834. allow users to parallelize the stream. If this is to be done, note
  7835. that each hemisphere can be run separately by specifying the -hemi
  7836. flag.
  7837. LOG AND STATUS FILES
  7838. By default, log and status files are created in subjid/scripts. The
  7839. log file contains all the output from all the programs that have been
  7840. run during the invocation to recon-all. The status file has a list of
  7841. all the programs that have been run and the time at which each
  7842. started. The log file is intended to be a record of what was done
  7843. whereas the status file allows the user to easily see where in the
  7844. stream a currently running process is. The log file should be sent
  7845. with all bug reports. By default, these files are called recon-all.log
  7846. and recon-all-status.log, but this can be changed with the -log and
  7847. -status options. By default, the log and status are appended to. New
  7848. log and status files can be forced with the -noappend flag.
  7849. OTHER ARGUMENTS
  7850. -sd subjectsdir
  7851. This allows the user to specify the root of the FreeSufer subjects
  7852. directory. If unspecified, the environment variable SUBJECTS_DIR
  7853. is used.
  7854. -mail username
  7855. Send email to username when the process terminates.
  7856. STEP DESCRIPTION SUMMARIES
  7857. Motion Correction (-<no>motioncor)
  7858. When there are multiple source volumes, this step will correct for
  7859. small motions between them and then average them together. The input
  7860. are the volumes found in file(s) mri/orig/XXX.mgz. The output will be
  7861. the volume mri/orig.mgz. If no runs are found, then it looks for
  7862. a volume in mri/orig (or mri/orig.mgz). If that volume is there, then
  7863. it is used in subsequent processes as if it was the motion corrected
  7864. volume. If no volume is found, then the process exits with errors.
  7865. The motion correction step uses a robust registration [14] procedure
  7866. to produce highly accurate registrations of the brain, ignoring outlier
  7867. regions, such as differen cropping planes, jaw, neck, eye movement etc.
  7868. Talairach (-<no>talairach)
  7869. This computes the affine transform from the orig volume to the MNI305
  7870. atlas using Avi Snyders 4dfp suite of image registration tools,
  7871. through a FreeSurfer script called talairach_avi. Several of the downstream
  7872. programs use talairach coordinates as seed points. You can/should check
  7873. how good the talairach registration is using
  7874. "tkregister2 --s subjid --fstal-avi". You must have an "fsaverage" subject in
  7875. your SUBJECTS_DIR. tkregister2 allows you to compare the orig volume
  7876. against the talairach volume resampled into the orig space. If you modify
  7877. the registration, it will change the talairach.xfm file. Your edits will
  7878. be *not* be overwritten unless you run recon-all specifying -clean-tal.
  7879. Run "tkregister2 --help" for more information.
  7880. Creates the files mri/transform/talairach.auto.xfm and talairach.xfm.
  7881. The flag -tal-check will check the registration against known-good transforms.
  7882. Adding the flag -use-mritotal after -talairach will use the MINC program
  7883. mritotal (see Collins, et al., 1994) to perform the transform.
  7884. Normalization (-<no>normalization)
  7885. Performs intensity normalization of the orig volume and places the
  7886. result in mri/T1.mgz. Attempts to correct for fluctuations in
  7887. intensity that would otherwise make intensity-based segmentation much
  7888. more difficult. Intensities for all voxels are scaled so that the mean
  7889. intensity of the white matter is 110. If there are problems with the
  7890. normalization, users can add control points. See also Normalization2.
  7891. Skull Strip (-<no>skullstrip)
  7892. Removes the skull from mri/T1.mgz and stores the result in
  7893. mri/brainmask.auto.mgz and mri/brainmask.mgz.
  7894. Runs the mri_watershed program. If the strip fails, users can specify
  7895. seed points (-wsseed) or change the threshold (-wsthresh, -wsmore, -wsless).
  7896. The -autorecon1 stage ends here.
  7897. NU Intensity Correction (-<no>nuintensitycor)
  7898. Non-parametric Non-uniform intensity Normalization (N3), corrects for
  7899. intensity non-uniformity in MR data, making relatively few assumptions
  7900. about the data. This runs the MINC tool 'nu_correct'. By default, one
  7901. iteration of nu_correct is run. The flag -nuiterations specification
  7902. of some other number of iterations.
  7903. Automatic Subcortical Segmentation (-<no>subcortseg)
  7904. This is done in six stages. (1) GCA linear registration
  7905. (-gcareg). This is an initial registration to a template. (2)
  7906. Canonical Normalization (-canorm), (3) Canonical Registration
  7907. (-careg). (4) Neck removal (-rmneck), (5) Registration, w/skull
  7908. (-skull-lta), and (6) Subcortical labeling (-calabel).
  7909. The stages are listed next.
  7910. EM (GCA) Registration (-<no>gcareg)
  7911. Computes transform to align the mri/nu.mgz volume to the default GCA atlas
  7912. found in FREESURFER_HOME/average (see -gca flag for more info).
  7913. Creates the file mri/transforms/talairach.lta.
  7914. The -autorecon2 stage starts here.
  7915. CA Normalize (-<no>canorm)
  7916. Further normalization, based on GCA model.
  7917. Creates mri/norm.mgz.
  7918. Note: -canorm-usecps will enable usage of control points during normalization.
  7919. CA Register (-<no>careg)
  7920. Computes a nonlinear transform to align with GCA atlas.
  7921. Creates the file mri/transform/talairach.m3z.
  7922. CA Register Inverse (-<no>careginv)
  7923. Computes the inverse of the nonlinear transform to align with GCA
  7924. atlas. Creates the files mri/transform/talairach.m3z.{x,y,z}.mgz.
  7925. Remove neck (-<no>rmneck)
  7926. The neck region is removed from the NU-corrected volume mri/nu.mgz.
  7927. Makes use of transform computed from prior CA Register stage.
  7928. Creates the file mri/nu_noneck.mgz.
  7929. EM Registration, with Skull (-<no>skull-lta)
  7930. Computes transform to align volume mri/nu_noneck.mgz with GCA volume
  7931. possessing the skull.
  7932. Creates the file mri/transforms/talairach_with_skull_2.lta.
  7933. CA Label (-<no>calabel)
  7934. Labels subcortical structures, based in GCA model.
  7935. Creates the files mri/aseg.auto.mgz and mri/aseg.presurf.mgz.
  7936. ASeg Stats (-<no>segstats)
  7937. Computes statistics on the segmented subcortical structures found
  7938. in mri/aseg.mgz. Writes output to file stats/aseg.stats.
  7939. Normalization2 (-<no>normalization)
  7940. Performs a second (major) intensity correction using only the brain
  7941. volume as the input (so that it has to be done after the skull strip).
  7942. Intensity normalization works better when the skull has been removed.
  7943. Creates a new brain.mgz volume. The -autorecon2-cp stage begins here.
  7944. If -noaseg flag is used, then aseg.presurf.mgz is not used by mri_normalize.
  7945. WM Segmentation (-<no>segmentation)
  7946. Attempts to separate white matter from everything else. The input is
  7947. mri/brain.mgz, and the output is mri/wm.mgz. Uses intensity,
  7948. neighborhood, and smoothness constraints. This is the volume that is
  7949. edited when manually fixing defects. Calls mri_segment,
  7950. mri_edit_wm_with_aseg, and mri_pretess. To keep previous edits, run
  7951. with -keep. If -noaseg is used, them mri_edit_wm_aseg is skipped.
  7952. Cut/Fill (-<no>fill)
  7953. This creates the subcortical mass from which the orig surface is
  7954. created. The mid brain is cut from the cerebrum, and the hemispheres
  7955. are cut from each other. The left hemisphere is binarized to 255.
  7956. The right hemisphere is binarized to 127. The input is mri/wm.mgz
  7957. and the output is mri/filled.mgz. Calls mri_fill. If the cut fails,
  7958. then seed points can be supplied (see -cc-crs, -pons-crs, -lh-crs,
  7959. -rh-crs). The actual points used for the cutting planes in the
  7960. corpus callosum and pons can be found in scripts/ponscc.cut.log.
  7961. The stage -autorecon2-wm begins here. This is the last stage of
  7962. volumetric processing. If -noaseg is used, then aseg.presurf.mgz is
  7963. not used by mri_fill.
  7964. Tessellation (-<no>tessellate)
  7965. This is the step where the orig surface (ie, surf/?h.orig.nofix) is
  7966. created. The surface is created by covering the filled hemisphere with
  7967. triangles. Runs mri_tessellate. The places where the points of the
  7968. triangles meet are called vertices. Creates the file surf/?h.orig.nofix
  7969. Note: the topology fixer will create the surface ?h.orig.
  7970. Orig Surface Smoothing (-<no>smooth1, -<no>smooth2)
  7971. After tesselation, the orig surface is very jagged because each
  7972. triangle is on the edge of a voxel face and so are at right angles to
  7973. each other. The vertex positions are adjusted slightly here to reduce
  7974. the angle. This is only necessary for the inflation processes.
  7975. Creates surf/?h.smoothwm(.nofix). Calls mris_smooth. Smooth1 is the step
  7976. just after tessellation, and smooth2 is the step just after topology
  7977. fixing.
  7978. Inflation (-<no>inflate1, -<no>inflate2)
  7979. Inflation of the surf/?h.smoothwm(.nofix) surface to create
  7980. surf/?h.inflated. The inflation attempts to minimize metric distortion
  7981. so that distances and areas are perserved (ie, the surface is not
  7982. stretched). In this sense, it is like inflating a paper bag and not a
  7983. balloon. Inflate1 is the step just after tessellation, and inflate2
  7984. is the step just after topology fixing. Calls mris_inflate. Creates
  7985. ?h.inflated, ?h.sulc, ?h.curv, and ?h.area.
  7986. QSphere (-<no>qsphere)
  7987. This is the initial step of automatic topology fixing. It is a
  7988. quasi-homeomorphic spherical transformation of the inflated surface designed
  7989. to localize topological defects for the subsequent automatic topology fixer.
  7990. Calls mris_sphere. Creates surf/?h.qsphere.nofix.
  7991. Automatic Topology Fixer (-<no>fix)
  7992. Finds topological defects (ie, holes in a filled hemisphere) using
  7993. surf/?h.qsphere.nofix, and changes the orig surface (surf/?h.orig.nofix)
  7994. to remove the defects. Changes the number of vertices. All the defects
  7995. will be removed, but the user should check the orig surface in the volume
  7996. to make sure that it looks appropriate. Calls mris_topo_fixer.
  7997. Creates surf/?h.orig (by iteratively fixing surf/?h.orig.nofix).
  7998. White Surface (-<no>white)
  7999. Creates the ?h.white surfacees as well as the curvature file (?h.curv).
  8000. The white surface is created by "nudging" the orig surface so that it
  8001. closely follows the white-gray intensity gradient as found in the T1 volume.
  8002. Calls mris_make_surfaces. See also "Pial Surface" and "Final Surfaces".
  8003. Spherical Inflation (-<no>sphere)
  8004. Inflates the orig surface into a sphere while minimizing metric
  8005. distortion. This step is necessary in order to register the surface
  8006. to the spherical atlas. (also known as the spherical morph). Calls
  8007. mris_sphere. Creates surf/?h.sphere. The -autorecon3 stage begins here.
  8008. Ipsilateral Surface Registation (Spherical Morph) (-<no>surfreg)
  8009. Registers the orig surface to the spherical atlas through
  8010. surf/?h.sphere. The surfaces are first coarsely registered by aligning
  8011. the large scale folding patterns found in ?h.sulc and then fine tuned
  8012. using the small-scale patterns as in ?h.curv.
  8013. Calls mris_register. Creates surf/?h.sphere.reg.
  8014. Jacobian (-<no>jacobian_white)
  8015. Computes how much the white surface was distorted in order to register
  8016. to the spherical atlas during the -surfreg step. Creates ?h.jacobian_white
  8017. (a curv formatted file). This step follows the surface registration step.
  8018. Surface Registation, maximal distortion, with Jacobian (-<no>jacobian_dist0)
  8019. Run spherical registration with no metric distortion penalty. This will
  8020. cause surface geometry to align regardless of the amount of distortion
  8021. induced (ie, distance contraints are turned off). The distortion will then
  8022. be quantified by the Jacobian of the transform. Creates ?h.jacobian_dist0 (a
  8023. curv formatted file) and ?h.sphere.dist0.jacobian.reg (a surface file). This
  8024. step is not run automatically because it can add about an hour per hemi.
  8025. Note: the file ?h.jacobian_white (see prior help text) is the Jacobian of
  8026. the white surface to spherical atlas alignment from -surfreg.
  8027. Contralateral Surface Registation (Spherical Morph) (-<no>contrasurfreg)
  8028. Same as ipsilateral but registers to the contralateral atlas.
  8029. Creates lh.rh.sphere.reg and rh.lh.sphere.reg.
  8030. Average Curvature (-<no>avgcurv)
  8031. Resamples the average curvature from the atlas to that of the subject.
  8032. Allows the user to display activity on the surface of an individual
  8033. with the folding pattern (ie, anatomy) of a group. Calls mrisp_paint.
  8034. Creates surf/?h.avg_curv.
  8035. Cortical Parcellation (-<no>cortparc, -<no>cortparc2, -<no>cortparc3 )
  8036. Assigns a neuroanatomical label to each location on the cortical surface.
  8037. Incorporates both geometric information derived from the cortical model
  8038. (sulcus and curvature), and neuroanatomical convention.
  8039. Calls mris_ca_label. -cortparc creates label/?h.aparc.annot,
  8040. -cortparc2 creates /label/?h.aparc.a2009s.annot, and
  8041. -cortparc3 creates /label/?h.aparc.DKTatlas40.annot.
  8042. Pial Surface (-<no>pial)
  8043. Creates the ?h.pial surfaces as well as the thickness file (?h.thickness).
  8044. The pial surface is created by expanding the white surface so that it closely
  8045. follows the gray-CSF intensity gradient as found in the T1 volume. The
  8046. cortical parcellation is also used to refine the surface in certain areas.
  8047. Calls mris_make_surfaces. See also "Final Surfaces".
  8048. Final Surfaces (-<no>finalsurfs)
  8049. !!! DEPRECATED !!! This flag is intended to emulate the old-style single-run
  8050. mris_make_surfaces, where the white and pial surfaces are created at the same
  8051. time without aid from the cortical parcellation data.
  8052. WM/GM Contrast (-<no>pctsurfcon)
  8053. Computes the vertex-by-vertex percent contrast between white and gray matter.
  8054. The computation is:
  8055. 100*(W-G)
  8056. pct = ---------
  8057. 0.5*(W+G)
  8058. The white matter is sampled 1mm below the white surface. The gray matter is
  8059. sampled 30% the thickness into the cortex. The volume that is sampled is
  8060. rawavg.mgz. The output is stored in the surf dir of the given subject as
  8061. ?h.w-g.pct.mgh. Non-cortical regions (medial wall) are zeroed.
  8062. A stats file named ?h.w-g.pct.stats is also computed.
  8063. Surface Volume (-surfvolume)
  8064. Creates the ?h.volume file by first creating the ?h.mid.area file by
  8065. adding ?h.area(.white) to ?h.area.pial, then dividing by two. Then
  8066. ?h.volume is created by multiplying ?.mid.area with ?h.thickness.
  8067. This step is also run at the end of the -pial step.
  8068. Cortical Ribbon Mask (-<no>cortribbon)
  8069. Creates binary volume masks of the cortical ribbon, ie, each voxel is
  8070. either a 1 or 0 depending upon whether it falls in the ribbon or not.
  8071. Saved as ?h.ribbon.mgz. Uses mgz regardless of whether the -mgz
  8072. option is used.
  8073. Parcellation Statistics (-<no>parcstats, -<no>parcstats2, -<no>parcstats3)
  8074. Runs mris_anatomical_stats to create a summary table of cortical
  8075. parcellation statistics for each structure, including 1. structure
  8076. name 2. number of vertices 3. total wm surface area (mm^2) 4. total gray
  8077. matter volume (mm^3) 5. average cortical thickness (mm) 6. standard
  8078. error of cortical thickness (mm) 7. integrated rectified mean wm
  8079. curvature 8. integrated rectified Gaussian wm curvature 9. folding index
  8080. 10. intrinsic curvature index.
  8081. For -parcstats, the file is saved in stats/?h.aparc.stats.
  8082. For -parcstats2, the file is saved in stats/?h.aparc.${DESTRIEUX_NAME}.stats.
  8083. For -parcstats3, the file is saved in stats/?h.aparc.${DKTATLAS_NAME}.stats.
  8084. Curvature Statistics (-<no>curvstats)
  8085. Runs mris_curvature_stats to create a summary file (stats/?h.curv.stats)
  8086. of cortical curvature statistics.
  8087. LONGITUDINAL PROCESSING
  8088. The longitudinal processing scheme aims to incorporate the subject-wise
  8089. correlation of longitudinal data into the processing stream in order to
  8090. increase sensitivity and repeatability, see [14-16]. Care is taken to
  8091. avoid introduction of asymmetry-induced bias.
  8092. Here is a summary of the longitudinal workflow, where tpN refers to the
  8093. name of one timepoint of subject data, and longbase refers to the name
  8094. given to the base subject of a collection of timepoints:
  8095. 1) cross-sectionally process tpN subjects (the default workflow):
  8096. recon-all -s tp1 -i path_to_tp1_dicom -all
  8097. recon-all -s tp2 -i path_to_tp2_dicom -all
  8098. 2) create and process the unbiased base (subject template):
  8099. recon-all -base longbase -tp tp1 -tp tp2 -all
  8100. 3) longitudinally process tpN subjects:
  8101. recon-all -long tp1 longbase -all
  8102. recon-all -long tp2 longbase -all
  8103. 4) do comparisons on results from 3), e.g. calculate differences
  8104. between tp2.long.longbase - tp1.long.longbase
  8105. Note that the longitudinal processing stream always produces output subject
  8106. data containing .long. in the name (to help distinguish from the default
  8107. stream).
  8108. Notice that the -all flag is included in the -base and -long calls above.
  8109. A work directive flag is required.
  8110. Other flags:
  8111. -uselongbasectrlvol
  8112. With -long: Switch on use of control-points from the base in the long
  8113. runs for intensity normalization (T1.mgz).
  8114. -uselongbasewmedits
  8115. With -long: Optionally transfer WM edits from base/template.
  8116. Default: map WM edits from corresponding cross run.
  8117. -no-orig-pial
  8118. If the orig pial surface data is not available, then specify this flag so that
  8119. mris_make_surfaces does not attempt to use it.
  8120. -noasegfusion
  8121. Do not create 'fused' aseg from the longbase timepoints, which would normally
  8122. be used to initialize the ca_labeling. Instead, initialize using the longbase
  8123. aseg.mgz.
  8124. -addtp
  8125. If a new timepoint needs to be added to a longitudinal run where a base subject
  8126. has already been created (from prior timepoints), then the -addtp command
  8127. can be added to the -long command in order to 'fix-up' the longitudinal
  8128. stream to accept the new timepoint. Note that the base subject is *not*
  8129. recomputed using the new timepoint. This potentially introduces a bias, and it
  8130. is recommended to NOT add a time point this way! Instead recreate the base
  8131. from all time points and run all longitudinals again.
  8132. See the LongitudinalProcessing wiki page.
  8133. Example:
  8134. recon-all -long <tpNsubjid> <longbasesubjid> -addtp -all
  8135. In this example, 'tnNsubjid' is the subject name (assumed processed in the
  8136. cross-sectional stream) to add as a new timepoint and upon which to run
  8137. the longitudinal stream (creating <tpNsubjid>.long.<longbasesubjid>).
  8138. USING IMAGES FROM A 3T SCANNER
  8139. The -3T flag enables two specific options in recon-all for images acquired with
  8140. a 3T scanner: 3T-specific NU intensity correction parameters are used in the
  8141. Non-Uniform normalization stage, and the Schwartz 3T atlas is used for
  8142. Talairach alignment.
  8143. T2 OR FLAIR TO IMPROVE PIAL SURFACES
  8144. Pial surfaces can be improved using the different contrast in T2 or FLAIR
  8145. images. The original pial surfaces without T2/FLAIR data are saved as
  8146. ?h.woT2.pial or ?h.woFLAIR.pial, and new ?h.pial surfaces are created. One
  8147. example where this is useful is when there is dura in the brainmask.mgz that
  8148. isn't removed by skull stripping. The flags for these commands are:
  8149. -T2 <input T2 volume> or -FLAIR <input FLAIR volume>
  8150. (Specify the path to the T2 or FLAIR image to use)
  8151. -T2pial or -FLAIRpial
  8152. (Create new pial surfaces using T2 or FLAIR images)
  8153. An example of running a subject through Freesurfer with a T2 image is:
  8154. recon-all -s subjectname -i /path/to/input -T2 /path/to/T2_input -T2pial -all
  8155. T2 or FLAIR images can also be used with Freesurfer subjects that have already
  8156. been processed without them. Note that autorecon3 should also be re-ran to
  8157. compute statistics based on the new surfaces. For example:
  8158. recon-all -s subjectname -T2 /path/to/T2_volume -T2pial -autorecon3
  8159. MANUAL CHECKING AND EDITING OF SURFACES
  8160. To manually edit segmenation, run the following command (make sure
  8161. that your SUBJECTS_DIR environment variable is properly set).
  8162. tkmedit subjid wm.mgz -aux T1.mgz
  8163. The surfaces can be loaded through the menu item
  8164. File->LoadMainSurface. To enable editing, set Tools->EditVoxels. It
  8165. may also be convenient to bring up the reconstruction toolbar with
  8166. View->ToolBars->Reconstruction. Alt-C toggles between the main (wm)
  8167. and auxiliary (T1) volumes. Middle clicking will set a voxel value to
  8168. 255; left clicking will set a voxel value to 0. Only edit the wm
  8169. volume. When finished, File->SaveMainVolume.
  8170. To view the inflated surface simultaneosly with the volume, run the
  8171. following command from a different shell:
  8172. tksurfer subjid lh inflated
  8173. To goto a point on the surface inside the volume, click on the point
  8174. and hit SavePoint (icon looks like a floppy disk), then, in tkmedit,
  8175. hit GotoSavedPoint (icon looks like an open file).
  8176. Be sure to see the tutorials found at:
  8177. https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial
  8178. TOUCH FILES
  8179. This script creates a directory called "touch". Each time a stage is
  8180. run a "touch file" is created (eg, skull_strip.touch). This will be
  8181. used in the future to automatically determine which stages need to be
  8182. run or re-run. The modification time of the touch file is important.
  8183. The content is irrelevent, though it often contains a command-line.
  8184. FLATTENING
  8185. Flattening is not actually done in this script. This part just documents
  8186. how one would go about performing the flattening. First, load the subject
  8187. surface into tksurfer:
  8188. tksurfer subjid lh inflated
  8189. Load the curvature through the File->Curvature->Load menu (load
  8190. lh.curv). This should show a green/red curvature pattern. Red = sulci.
  8191. Right click before making a cut; this will clear previous points. This
  8192. is needed because it will string together all the previous places you
  8193. have clicked to make the cut. To make a line cut, left click on a line
  8194. of points. Make the points fairly close together; if they are too far
  8195. appart, the cut fails. After making your line of points, execute the
  8196. cut by clicking on the Cut icon (scissors with an open triangle for a
  8197. line cut or scissors with a closed triangle for a closed cut). To make
  8198. a plane cut, left click on three points to define the plane, then left
  8199. click on the side to keep. Then hit the CutPlane icon.
  8200. Fill the patch. Left click in the part of the surface that you want to
  8201. form your patch. Then hit the Fill Uncut Area button (icon = filled
  8202. triangle). This will fill the patch with white. The non-patch area
  8203. will be unaccessible through the interface. Save the patch through
  8204. File->Patch->SaveAs. For whole cortex, save it to something like
  8205. lh.cort.patch.3d. For occipital patches, save it to lh.occip.patch.3d.
  8206. Cd into the subject surf directory and run
  8207. mris_flatten -w N -distances Size Radius lh.patch.3d lh.patch.flat
  8208. where N instructs mris_flatten to write out an intermediate surface
  8209. every N interations. This is only useful for making movies; otherwise
  8210. set N=0. Size is maximum number of neighbors; Radius radius (mm) in
  8211. which to search for neighbors. In general, the more neighbors that are
  8212. taken into account, the less the metric distortion but the more
  8213. computationally intensive. Typical values are Size=12 for large
  8214. patches, and Size=20 for small patches. Radius is typically 7.
  8215. Note: flattening may take 12-24 hours to complete. The patch can be
  8216. viewed at any time by loading the subjects inflated surface, then
  8217. loading the patch through File->Patch->LoadPatch...
  8218. GETTING HELP
  8219. See https://surfer.nmr.mgh.harvard.edu
  8220. Send email to freesurfer@nmr.mgh.harvard.edu
  8221. REFERENCES
  8222. See https://www.zotero.org/freesurfer
  8223. [1] Collins, DL, Neelin, P., Peters, TM, and Evans, AC. (1994)
  8224. Automatic 3D Inter-Subject Registration of MR Volumetric Data in
  8225. Standardized Talairach Space, Journal of Computer Assisted Tomography,
  8226. 18(2) p192-205, 1994 PMID: 8126267; UI: 94172121
  8227. [2] Cortical Surface-Based Analysis I: Segmentation and Surface
  8228. Reconstruction Dale, A.M., Fischl, Bruce, Sereno, M.I.,
  8229. (1999). Cortical Surface-Based Analysis I: Segmentation and Surface
  8230. Reconstruction. NeuroImage 9(2):179-194
  8231. [3] Fischl, B.R., Sereno, M.I.,Dale, A. M. (1999) Cortical
  8232. Surface-Based Analysis II: Inflation, Flattening, and Surface-Based
  8233. Coordinate System. NeuroImage, 9, 195-207.
  8234. [4] Fischl, Bruce, Sereno, M.I., Tootell, R.B.H., and Dale, A.M.,
  8235. (1999). High-resolution inter-subject averaging and a coordinate
  8236. system for the cortical surface. Human Brain Mapping, 8(4): 272-284
  8237. [5] Fischl, Bruce, and Dale, A.M., (2000). Measuring the Thickness of
  8238. the Human Cerebral Cortex from Magnetic Resonance Images. Proceedings
  8239. of the National Academy of Sciences, 97:11044-11049.
  8240. [6] Fischl, Bruce, Liu, Arthur, and Dale, A.M., (2001). Automated
  8241. Manifold Surgery: Constructing Geometrically Accurate and
  8242. Topologically Correct Models of the Human Cerebral Cortex. IEEE
  8243. Transactions on Medical Imaging, 20(1):70-80
  8244. [7] Non-Uniform Intensity Correction.
  8245. http://www.nitrc.org/projects/nu_correct/
  8246. [8] Fischl B, Salat DH, Busa E, Albert M, Dieterich M, Haselgrove C,
  8247. van der Kouwe A, Killiany R, Kennedy D, Klaveness S, Montillo A,
  8248. Makris N, Rosen B, Dale AM. Whole brain segmentation: automated
  8249. labeling of neuroanatomical structures in the human
  8250. brain. Neuron. 2002 Jan 31;33(3):341-55.
  8251. [9] Bruce Fischl, Andre van der Kouwe, Christophe Destrieux, Eric
  8252. Halgren, Florent Segonne, David H. Salat, Evelina Busa, Larry
  8253. J. Seidman, Jill Goldstein, David Kennedy, Verne Caviness, Nikos
  8254. Makris, Bruce Rosen, and Anders M. Dale. Automatically Parcellating
  8255. the Human Cerebral Cortex. Cerebral Cortex January 2004; 14:11-22.
  8256. [10] Fischl B, Salat DH, van der Kouwe AJW, Makris N, Ségonne F, Dale
  8257. AM. Sequence-Independent Segmentation of Magnetic Resonance Images.
  8258. NeuroImage 23 Suppl 1, S69-84.
  8259. [11] Segonne F, Dale, AM, Busa E, Glessner M, Salvolini U, Hahn HK,
  8260. Fischl B, A Hybrid Approach to the Skull-Stripping Problem in MRI.
  8261. NeuroImage, 22, pp. 1160-1075, 2004
  8262. [12] Han et al., Reliability of MRI-derived measurements of human
  8263. cerebral cortical thickness: The effects of field strength, scanner
  8264. upgrade and manufacturer, (2006) NeuroImage, 32(1):180-194.
  8265. [13] Schaer et al., A Surface-based Approach to Quantify Local Cortical
  8266. Gyrification (2007) IEEE Transactions on Medical Imaging.
  8267. [14] Martin Reuter, H Diana Rosas, Bruce Fischl.
  8268. Highly Accurate Inverse Consistent Registration: A Robust Approach.
  8269. NeuroImage 53(4), 1181-1196, 2010. http://dx.doi.org/10.1016/j.neuroimage.2010.07.020
  8270. [15] Martin Reuter, Bruce Fischl.
  8271. Avoiding Asymmetry-Induced Bias in Longitudinal Image Processing.
  8272. NeuroImage 51(1), 19-21, 2011. http://dx.doi.org/10.1016/j.neuroimage.2011.02.076
  8273. [16] Martin Reuter, Nicholas J Schmansky, H Diana Rosas, Bruce Fischl.
  8274. Within-Subject Template Estimation for Unbiased Longitudinal Image Analysis.
  8275. NeuroImage 61(4), 1402-1418, 2012. http://dx.doi.org/10.1016/j.neuroimage.2012.02.084
  8276. [17] Iglesias, J.E., Augustinack, J.C., Nguyen, K., Player, C.M., Player, A., Wright,
  8277. M., Roy, N., Frosch, M.P., McKee, A.C., Wald, L.L., Fischl, B., and Van Leemput, K.,
  8278. A computational atlas of the hippocampal formation using ex vivo, ultra-high resolution
  8279. MRI: Application to adaptive segmentation of in vivo MRI. Neuroimage 115, 2015, 117-137.
  8280. http://dx.doi.org/10.1016/j.neuroimage.2015.04.042
  8281. [18] Iglesias, J.E., Van Leemput, K., Bhatt, P., Casillas, C., Dutt, S., Schuff, N.,
  8282. Truran-Sacrey, D., Boxer, A., and Fischl, B., Bayesian segmentation of brainstem
  8283. structures in MRI. Neuroimage 113, 2015, 184-195.
  8284. http://dx.doi.org/10.1016/j.neuroimage.2015.02.065