diff --git a/water_input.bat b/water_input.bat new file mode 100644 index 0000000000000000000000000000000000000000..23a25660b8f6c5591cfb9b08a962f39c7b11613b --- /dev/null +++ b/water_input.bat @@ -0,0 +1,400 @@ +@echo off +setLocal EnableExtensions EnableDelayedExpansion + +REM Script name, version and copyright +set PROGRAM=water_input 3.0.1 (c) 2005-2016 Turku PET Centre + +REM ABSS calibration file +set CALFILE=S:\Lab\plasma\bsampler_calibration\pump_cal.dat + +REM Default parameters +set TUBE_DISPERSION=2.5 +set BIOL_DISPERSION=5.0 +set FIT=no + +REM Check user input +if "%1" == "" goto USER_INFO +if "%1" == "-help" goto USER_INFO +if "%1" == "--help" goto USER_INFO +if "%1" == "-h" goto USER_INFO +if "%1" == "-history" goto VERSION_HISTORY +if "%1" == "--history" goto VERSION_HISTORY +if "%1" == "-v" goto VERSION_INFO +if "%1" == "-version" goto VERSION_INFO +if "%1" == "--version" goto VERSION_INFO + + +REM Get options if any +:MOREOPTIONS +REM @echo "%1" %1 +set var1=%1 +set var2=!var1:~0,1! +REM @echo !var2! +if "!var2!" NEQ "-" goto NOMOREOPTIONS +shift +REM @echo === Option !var1! +set var1=!var1:-=! +REM @echo !var1! +for /f "tokens=1,2 delims=:/ " %%a in ("%var1%") do set opti=%%a&set oval=%%b +REM @echo !opti! ja sen arvo on !oval! +if "%opti%" == "disp" ( + set BIOL_DISPERSION=%oval% + goto MOREOPTIONS +) +if "%opti%" == "DISP" ( + set BIOL_DISPERSION=%oval% + goto MOREOPTIONS +) +if "%opti%" == "cr" ( + set CRFILE=%oval% + if not exist !CRFILE! ( + @echo Error: Countrate file does not exist: !CRFILE! + exit /b 1 + ) + goto MOREOPTIONS +) +if "%opti%" == "CR" ( + set CRFILE=%oval% + if not exist !CRFILE! ( + @echo Error: Countrate file does not exist: !CRFILE! + exit /b 1 + ) + goto MOREOPTIONS +) +if "%opti%" == "img" ( + set IMGFILE=%oval% + imgunit --silent !IMGFILE! > !IMGFILE!.unit + if not !errorlevel!==0 ( + @echo Error: invalid image !IMGFILE! + exit /b 1 + ) + goto MOREOPTIONS +) +if "%opti%" == "IMG" ( + set IMGFILE=%oval% + imgunit --silent !IMGFILE! > !IMGFILE!.unit + if not !errorlevel!==0 ( + @echo Error: invalid image !IMGFILE! + exit /b 1 + ) + goto MOREOPTIONS +) +if "%opti%" == "fit" ( + set FIT=%oval% + goto MOREOPTIONS +) +if "%opti%" == "FIT" ( + set FIT=%oval% + goto MOREOPTIONS +) + +@echo. +@echo Invalid command-line option -%var1% +@echo Get instructions with option -help +exit /b 1 + + +:NOMOREOPTIONS + +REM Check user input again +if "%2" == "" ( + @echo Missing command-line parameters; get instructions with option -help + exit /b 1 +) +if "%3" NEQ "" ( + @echo Invalid command-line parameters; get instructions with option -help + exit /b 1 +) +if "%FIT%" == "YES" ( + set FIT=yes +) +if "%FIT%" == "NO" ( + set FIT=no +) + +REM Get and check input files +set ABSSFILE=%1 +if not exist %ABSSFILE% ( + @echo Error: ABSS file does not exist: %ABSSFILE% + exit /b 1 +) + +REM Get output filename +set OUTFILE=%2 + + +@echo Physiological dispersion is set to %BIOL_DISPERSION% +@echo Countrate file: %CRFILE% +@echo ABBS file: %ABSSFILE% +@echo Output file: %OUTFILE% + + +REM Get the unit of image file if available and save blood data in the +REM same units if possible +if exist %IMGFILE%.unit ( + iftlist %IMGFILE%.unit unit +) + + +REM Preprocess countrate data if necessary +if "%CRFILE%" NEQ "" ( + tocr -copy %CRFILE% O-15 %CRFILE%.tmp + if not !errorlevel!==0 ( + @echo Error in countrate file processing. + exit /b 1 + ) +) + +REM Conversion of ABSS data format, calibration, and decay correction +absscal -c=%CALFILE% -i=O-15 -decay=on %ABSSFILE% %OUTFILE%.tmp +if not %errorlevel%==0 ( + @echo Error in ABSS file conversion. + exit /b 1 +) + +REM Correct data for dispersion +if "%FIT%" NEQ "yes" ( + disp4dft -L off %OUTFILE%.tmp %TUBE_DISPERSION% %OUTFILE%.tmp2 + if not !errorlevel!==0 ( + @echo Error in 1st dispersion correction. + exit /b 1 + ) + disp4dft -L off %OUTFILE%.tmp2 %BIOL_DISPERSION% %OUTFILE%.tmp3 + if not !errorlevel!==0 ( + @echo Error in 2nd dispersion correction. + exit /b 1 + ) +) else ( + fit_sinf -tau1=%BIOL_DISPERSION% -tau2=%TUBE_DISPERSION% -dcfit=%OUTFILE%.tmp3 %OUTFILE%.tmp %OUTFILE%.tmp4 + if not !errorlevel!==0 ( + @echo Error in dispersion correction and fitting. + exit /b 1 + ) +) + +REM Delay correction if countrate data was given +REM Plot the final TAC with or without countrate +if exist %CRFILE%.tmp ( + fitdelay -timeunit=sec -log -o=%OUTFILE% %OUTFILE%.tmp3 %CRFILE%.tmp 120 + if not !errorlevel!==0 ( + @echo Error in delay conversion. + exit /b 1 + ) + tacren %OUTFILE% 1 Blood + dftscale --silent --force -x1=0 -x2=120 %OUTFILE% %CRFILE%.tmp %CRFILE%.scaled + tacren --silent %CRFILE%.scaled 1 Count_rate + tac2svg -legend=no %OUTFILE%.svg -l %OUTFILE% %CRFILE%.scaled + if not !errorlevel!==0 ( + @echo Error: cannot plot corrected blood TAC. + exit /b 1 + ) +) else ( + @echo Note: time delay not corrected. + copy /Y %OUTFILE%.tmp3 %OUTFILE% + tacren --silent %OUTFILE% 1 Blood + tac2svg -legend=no %OUTFILE%.svg -l %OUTFILE% + if not !errorlevel!==0 ( + @echo Error: cannot plot corrected blood TAC. + exit /b 1 + ) +) +call svg2png %OUTFILE%.svg + +goto PASSED + + +:VERSION_INFO +@echo %PROGRAM% +goto END + +REM Information for user +:USER_INFO +@echo. +@echo %PROGRAM% +@echo. +@echo Blood pump (ABSS) data preprocessing for [O-15]water PET study. +@echo Resulting blood TAC is calibrated and corrected for physical decay +@echo and optionally for time delay, if countrate file is given. +@echo http://www.turkupetcentre.net/petanalysis/model_radiowater.html +@echo. +@echo If ABSS collection or PET scan was not started at the same time, +@echo you must correct the time difference manually to the blood TAC +@echo made by this script. Use program tactime for the correction. +@echo. +@echo Verify the result by looking the created *.svg or *.png plot. +@echo. +@echo Usage: water_input [options] ABSSfile Outputfile +@echo. +@echo Options: +@echo -CR:countratefile +@echo Filename for countrate data; if not given, then delay correction +@echo is not done; some perfusion calculation software can do +@echo delay correction later. +@echo -DISP:dispersion +@echo Physiological dispersion constant can be set using this option; +@echo By default it is set to 5.0 s. +@echo -FIT:YES or -FIT:NO +@echo Dispersion can be corrected by simultaneously fitting a function to +@echo the blood TAC (yes), or without fitting (no, default). +@echo -h or --help +@echo Print this text and exit. +@echo -v or --version +@echo Print script version and exit. +@echo. +@echo Example: +@echo water_input -cr:us755fat.dft us755_blo.lis us755blood.dat +@echo. +@echo See also: imghead, tacmean, imgflow, imgbfh2o, fit_h2o, tacunit +@echo Keywords: perfuson blood, input, ABSS, radiowater +@echo. +goto END + +:VERSION_HISTORY +@echo Version history: +@echo 1.0.0 2005-04-29 Vesa Oikonen +@echo First created. +@echo 1.1.0 2005-05-10 VO +@echo Both dispersion corrections are done before delay fitting, +@echo because dispersion may lead to apparent delay. +@echo 1.1.1 2005-06-20 VO +@echo Versions added to program calls. +@echo 1.2.0 2005-06-23 VO +@echo Biological dispersion constant can be specified as an extra +@echo argument. Default is 5. +@echo The existence of pump calibration file is checked. +@echo Pump calibration file will also be searched from network disk, +@echo if not found in current working directory. +@echo Big changes in info text. +@echo Delay fit time changed from 120 to 150 s. +@echo 1.2.1 2005-11-09 VO +@echo Location of pump calibration file was changed. +@echo Uses fitdelay 1.9.1 instead of 1.9.0. +@echo 2.0.0 2006-03-15 Kaisa Sederholm +@echo Converted to vbscript +@echo 2.0.1 2006-04-06 KS +@echo Added scaling of countrate curve (crscale) before plotting. +@echo 2.0.2 2006-04-12 KS +@echo Added option -o into fitdelay +@echo 2.0.3 2006-04-13 KS +@echo Changed so that temporary files are written to +@echo the same directory as the output file instead of +@echo same directory where original blood data is. +@echo Default dispersion constant is now automatically written in the +@echo textbox. +@echo 2.0.4 2006-05-09 KS +@echo Now checking that InputBox doesn't give null string and +@echo that the given string is numeric +@echo 2006-05-22 KS +@echo Minor corrections in displaying file browser for receiving +@echo the PET image name +@echo 2.0.5 2006-06-29 KS +@echo Changed so that gives a warning if dft2ps failes, instead of +@echo ending the whole program. +@echo 2.0.6 2006-06-30 KS +@echo Removed version numbers from program calls. +@echo 2.1.0 2006-08-07 KS +@echo Added possibility to give NONE as image input. +@echo Updated version numbers for programs. +@echo 2.1.1 2006-08-09 KS +@echo Changed the default for output data filename. +@echo Gathered file deletions together and added isTest variable. +@echo 2.2.0 2006-08-11 KS +@echo Added program name to ExecAnalysisTool functions arguments. +@echo The name can then be quoted in error messages. +@echo This improves the informativity of error messages. +@echo 2.2.1 2006-10-04 KS +@echo Files .scan_start_time and .timediff +@echo were still written to the directory +@echo where input file exists. Changed to go to output file directory. +@echo 2.2.2 2006-10-20 KS +@echo Updated fitdelay and dfttime version numbers. +@echo 2.3.0 2007-02-15 Kaisa Liukko +@echo Added possibility to give also HR+ count rate curves (*.r) +@echo in which case the program hrpcr is called and it creates a +@echo standard *.cr count rate curve. +@echo Version numbers updated for fitdelay and dft2ps. +@echo 2.4.0 2007-03-23 KL +@echo Changed the program so that now the unit of the blood +@echo file is converted to be the same as in the image file. +@echo 2.4.1 2007-03-29 KL +@echo DeleteFiles function was added and the version number of +@echo blo2kbq was updated. +@echo 2007-05-02 KL +@echo DeleteFiles function call was forgotten from the end of the script +@echo 2.4.2 2007-05-30 KL +@echo Updated disp4dft from 3.1.0 into 3.2.0 +@echo 2.4.3 2007-08-09 KL +@echo Updated fitdelay version. Updated the program so that it can also +@echo deal with HRRT *.hc files. +@echo 2.4.4 2007-08-29 KL +@echo Added option that defines if delay correction is included or not. +@echo 2.4.5 2008-10-13 VO +@echo Calls most recent program versions. +@echo Notifies in case of error with dispersion constant that +@echo user should try decimal comma. +@echo 2.4.6 2008-11-10 VO +@echo Calls most recent program versions. +@echo 2.4.7 2009-02-09 VO +@echo Calls most recent program versions. +@echo In particular, fitdelay 2.0.1 required some changes. +@echo 2.4.8 2009-02-11 VO +@echo Calls new bug correction versions of dft2ps and tocr. +@echo 2.4.9 2009-06-24 VO +@echo Calls new versions of blo2kbq, dftunit and fitdelay. +@echo BIOL_DISPERSION_DEFAULT now has decimal comma. +@echo Correction in user info text. +@echo Warning about output units is not done with MsgBox. +@echo 2.5.0 2009-06-25 VO +@echo Added option tdif. False by default, meaning that any start time +@echo difference is corrected like in previous versions. +@echo 2.5.1 2010-01-21 KL +@echo Calls most recent program versions. +@echo 2.6.0 2010-02-25 KL +@echo Added fit_winp_0_2_0 to fit 6-parameter function to blood data +@echo with option /fit +@echo 2.6.1 2010-03-10 KL +@echo Minor change to deletion of temporary files +@echo 2.6.2 2010-05-21 VO +@echo Calls blo2kbq version 3.8.0. +@echo 2.7.0 2010-06-14 KL +@echo Default of time difference correction changed and possibility to +@echo choose this option is added also to GUI version. +@echo 2.7.1 2010-06-22 KL +@echo Added .txt to the accepted blood file extensions +@echo 3.0.0 2016-01-21 VO +@echo Converted back to BAT from vbscript. +@echo Calls most recent program versions. +@echo Removed option to correct for start time differences because +@echo scanner and ABSS clocks are too often not synchronized and because +@echo many image formats do not contain the scan start time. +@echo 3.0.1 2016-08-09 VO +@echo Calls most recent disp4dft versions. +@echo Program fit_winp is replaced with fit_sinf. +@echo Accepts options in upper-case. +@echo Updated user info. +@echo. +goto END + + +:DEL_TEMP +if exist %IMGFILE%.unit del %IMGFILE%.unit +if exist %CRFILE%.tmp del %CRFILE%.tmp +if exist %CRFILE%.scaled del %CRFILE%.scaled +if exist %OUTFILE%.tmp del %OUTFILE%.tmp +if exist %OUTFILE%.tmp2 del %OUTFILE%.tmp2 +if exist %OUTFILE%.tmp3 del %OUTFILE%.tmp3 +if exist %OUTFILE%.tmp4 del %OUTFILE%.tmp4 +goto END + + +:PASSED +@echo. +@echo Preprocessing done. +@echo Please check the plots in created *.svg or *.png files. +@echo. +goto DEL_TEMP +goto END +:FAILED +exit /b 1 +:END +exit /b 0