TPCCLIB
Loading...
Searching...
No Matches
logan.c
Go to the documentation of this file.
1
9/*****************************************************************************/
10#include "tpcclibConfig.h"
11/*****************************************************************************/
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <math.h>
16/*****************************************************************************/
17#include "tpcextensions.h"
18#include "tpctac.h"
19#include "tpcpar.h"
20#include "tpcli.h"
21#include "tpctacmod.h"
22#include "tpclinopt.h"
23/*****************************************************************************/
24
25/*****************************************************************************/
26static char *info[] = {
27 "NOT YET FUNCTIONAL",
28 " ",
29 "Calculate the distribution volume (Vt) or distribution volume ratio (DVR)",
30 "using multiple-time graphical analysis (MTGA) for reversible PET",
31 "ligands (Logan plot) (1,2,3) from regional PET time-activity curves (TACs).",
32 " ",
33 "Usage: @P [options] tacfile input starttime endtime resultfile",
34 " ",
35 "Options:",
36 " -k2=<reference region k2>",
37 " With reference region input, the population average of reference",
38 " region k2 (or k2/(1+k5/k6) in 3-compartment model) is set.",
39 " -BPnd",
40 " With reference input, BPnd (=DVR-1) is reported instead of DVR",
41 " -BPnd=<reference region name>",
42 " With plasma input, BPnd can be calculated as DVroi/DVref-1",
43 " -DVR=<reference region name>",
44 " With plasma input, DVR can be calculated as DVroi/DVref",
45 " -BPp=<reference region name>",
46 " With plasma input, BPp can be calculated as DVroi-DVref",
47 " -sd=<y|n>",
48 " Standard deviations are saved (y, default) or not saved (n) in results.",
49 " -mid[=<y|n>]",
50 " Mid frame times are used (y) or not used (n, default) even if frame",
51 " start and end times are available.",
52 " -svg=<Filename>",
53 " Plots are written in specified file in Scalable Vector Graphics (SVG) 1.1",
54 " format; specification in https://www.w3.org/TR/SVG/",
55 " -plotdata=<Filename>",
56 " Data for plots is written in specified file in XHTML table format for",
57 " easy importing in Excel or OpenOffice spreadsheet, where the data can",
58 " be viewed; if filename extension is .dft, data is written in DFT format",
59 " -C | -M | -P | -R",
60 " Options for selecting the least-squares line fit method:",
61 " -C for Traditional regression model",
62 " -M for Median of two-point slopes and intercepts (Cornish-Bowden)",
63 " -P for Perpendicular regression model (4)",
64 " -R for Iterative method (York 1966, Lybanon 1984, Reed 1992); default",
65 " If tissue file contains weights, the iterative method (-R) is weighted.",
66 " With other fitting methods the weights are not used.",
67 " With options -C and -R program can automatically find the linear plot",
68 " range, if fit start time is set to zero.",
69 " -stdoptions", // List standard options like --help, -v, etc
70 " ",
71 "Example 1:",
72 "Tissue curves are in ut2345.dft and plasma curve in ut2345ap.dat;",
73 "fitted data range is from 10 to 60 min; standard deviations are not needed:",
74 " @P -nosd ut2345.dft ut2345ap.dat 10 60 ut2345.res",
75 " ",
76 "Example 2:",
77 "Tissue curves in ut1234.dft, including reference region 'cer'; reference",
78 "tissue k2 is assumed to equal 0.163; plot is saved for viewing in",
79 "ut1234pplot.svg:",
80 " @P -svg=ut2345lplot.svg ut2345.dft cer -k2=0.163 20 60 ut2345.res",
81 " ",
82 "References:",
83 "1. Logan J, Fowler JS, Volkow ND, Wolf AP, Dewey SL, Schlyer DJ,",
84 " MacGregor RR, Hitzemann R, Bendriem B, Gatley SJ, Christman DR.",
85 " Graphical analysis of reversible radioligand binding from time-activity",
86 " measurements applied to [N-11C-methyl]-(-)-cocaine PET studies in human",
87 " subjects. J Cereb Blood Flow Metab 1990; 10: 740-747.",
88 "2. Logan J, Fowler JS, Volkow ND, Wang GJ, Ding YS, Alexoff DL.",
89 " Distribution volume ratios without blood sampling from graphical",
90 " analysis of PET data. J Cereb Blood Flow Metab. 1996; 16: 834-840.",
91 "3. Logan J. Graphical analysis of PET data applied to reversible and",
92 " irreversible tracers. Nucl Med Biol 2000; 27:661-670.",
93 "4. Varga J & Szabo Z. Modified regression model for the Logan plot.",
94 " J Cereb Blood Flow Metab 2002; 22:240-244.",
95 " ",
96 "See also: imgdv, fitk4, lhsoldv, patlak, rescoll, res2html",
97 " ",
98 "Keywords: TAC, modelling, Vt, DVR",
99 0};
100/*****************************************************************************/
101
102/*****************************************************************************/
103/* Turn on the globbing of the command line, since it is disabled by default in
104 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
105 In Unix&Linux wildcard command line processing is enabled by default. */
106/*
107#undef _CRT_glob
108#define _CRT_glob -1
109*/
110int _dowildcard = -1;
111/*****************************************************************************/
112
113/*****************************************************************************/
117int main(int argc, char **argv)
118{
119 int ai, help=0, version=0, verbose=1;
120 char tacfile[FILENAME_MAX], inpfile[FILENAME_MAX], resfile[FILENAME_MAX], svgfile[FILENAME_MAX];
121 double k2; // reference tissue k2; NaN if not applied
122 int save_stat=1; // 0=do not save, 1=save SD and/or other fit statistics
123 double tstart=nan(""), tstop=nan(""); // fit start and end times
124
125 /*
126 * Get arguments
127 */
128 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
129 tacfile[0]=inpfile[0]=resfile[0]=svgfile[0]=(char)0;
130 k2=tstart=tstop=nan("");
131 /* Options */
132 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
133 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
134 char *cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(!*cptr) continue;
135 if(strncasecmp(cptr, "SVG=", 4)==0) {
136 strlcpy(svgfile, cptr+4, FILENAME_MAX); if(strlen(svgfile)>0) continue;
137 } else if(strncasecmp(cptr, "K2=", 3)==0) {
138 k2=atofVerified(cptr+3); if(!isnan(k2)) continue;
139 } else if(strncasecmp(cptr, "SD=", 3)==0) {
140 save_stat=tpcYesNo(cptr+3); if(save_stat>=0) continue;
141 }
142 fprintf(stderr, "Error: invalid option '%s'\n", argv[ai]);
143 return(1);
144 } else break; // later arguments may start with '-'
145
146 TPCSTATUS status; statusInit(&status);
147 statusSet(&status, __func__, __FILE__, __LINE__, TPCERROR_OK);
148 status.verbose=verbose-3;
149
150 /* Print help or version? */
151 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
152 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
153 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
154
155 /* Process other arguments, starting from the first non-option */
156 if(ai<argc) strlcpy(tacfile, argv[ai++], FILENAME_MAX);
157 if(ai<argc) strlcpy(inpfile, argv[ai++], FILENAME_MAX);
158 if(ai<argc) {
159 if(atofCheck(argv[ai], &tstart)) {
160 fprintf(stderr, "Error: invalid start time '%s'.\n", argv[ai]); return(1);}
161 ai++;
162 }
163 if(ai<argc) {
164 if(atofCheck(argv[ai], &tstop)) {
165 fprintf(stderr, "Error: invalid stop time '%s'.\n", argv[ai]); return(1);}
166 ai++;
167 }
168 if(ai<argc) strlcpy(resfile, argv[ai++], FILENAME_MAX);
169 if(ai<argc) {
170 fprintf(stderr, "Error: invalid argument '%s'.\n", argv[ai]);
171 return(1);
172 }
173 /* Did we get all the information that we need? */
174 if(!resfile[0]) {
175 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
176 return(1);
177 }
178 /* Is something wrong? */
179 if(!isnan(tstart) && !isnan(tstop) && tstop<=tstart) {
180 fprintf(stderr, "Error: illegal time range %g-%g\n", tstart, tstop);
181 return(1);
182 }
183
184
185 /* In verbose mode print arguments and options */
186 if(verbose>1) {
187 printf("tacfile := %s\n", tacfile);
188 printf("inpfile := %s\n", inpfile);
189 printf("resfile := %s\n", resfile);
190 printf("svgfile := %s\n", svgfile);
191 if(!isnan(k2)) printf("k2 := %g\n", k2);
192 printf("tstart := %g\n", tstart);
193 printf("tstop := %g\n", tstop);
194 printf("save_stat := %d\n", save_stat);
195 }
196
197
198 /*
199 * Read tissue and input data
200 */
201 if(verbose>0) printf("reading tissue and input data\n");
202 TAC tac, input; tacInit(&tac); tacInit(&input);
203 int fitSampleNr;
204 double fitdur;
205 if(tstop>0.01) fitdur=tstop; else fitdur=1.0E+10;
206
207 if(tacReadModelingData(tacfile, inpfile, NULL, NULL, &fitdur, 0,
208 &fitSampleNr, &tac, &input, &status)!=TPCERROR_OK) {
209 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
210 tacFree(&tac); tacFree(&input); return(2);
211 }
212 if(verbose>2) {
213 printf("fileformat := %s\n", tacFormattxt(tac.format));
214 printf("tacNr := %d\n", tac.tacNr);
215 printf("tac.sampleNr := %d\n", tac.sampleNr);
216 printf("input.sampleNr := %d\n", input.sampleNr);
217 printf("fitSampleNr := %d\n", fitSampleNr);
218 printf("xunit := %s\n", unitName(tac.tunit));
219 printf("yunit := %s\n", unitName(tac.cunit));
220 printf("fitdur := %g s\n", fitdur);
221 }
222
223
224
225 tacFree(&tac); tacFree(&input);
226 return 0;
227}
228/*****************************************************************************/
229
230/*****************************************************************************/
231/*****************************************************************************/
232
233/*****************************************************************************/
double atofVerified(const char *s)
Definition decpoint.c:75
int atofCheck(const char *s, double *v)
Definition decpoint.c:94
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:47
int tpcYesNo(const char *s)
Definition proginfo.c:459
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition proginfo.c:169
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:339
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:114
void statusInit(TPCSTATUS *s)
Definition statusmsg.c:104
char * errorMsg(tpcerror e)
Definition statusmsg.c:68
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition stringext.c:632
Definition tpctac.h:87
unit cunit
Definition tpctac.h:105
tacformat format
Definition tpctac.h:93
int sampleNr
Definition tpctac.h:89
unit tunit
Definition tpctac.h:109
int tacNr
Definition tpctac.h:91
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
void tacFree(TAC *tac)
Definition tac.c:106
void tacInit(TAC *tac)
Definition tac.c:24
char * tacFormattxt(tacformat c)
Definition tacio.c:98
int tacReadModelingData(const char *tissuefile, const char *inputfile1, const char *inputfile2, const char *inputfile3, double *fitdur, int cutInput, int *fitSampleNr, TAC *tis, TAC *inp, TPCSTATUS *status)
Read tissue and input data for modelling.
Header file for library libtpcextensions.
@ TPCERROR_OK
No error.
char * unitName(int unit_code)
Definition units.c:143
Header file for libtpcli.
Header file for libtpclinopt.
Header file for libtpcpar.
Header file for library libtpctac.
Header file for libtpctacmod.