8#include "tpcclibConfig.h"
22static char *info[] = {
23 "Compute the plasma-to-blood ratio curve used in b2plasma and p2blood",
25 "The hematocrit (HCr, HCT) is normally between 0.40-0.51 in men and 0.36-0.47",
26 "in women. Note that HCr is lower in small vessels in tissue.",
27 "Sample times are autointerpolated from 0 to endtime (min)",
28 "with decreasing sample frequency.",
30 "Usage: @P [Options] tracer HCr endtime ratiofile",
35 "The following PET tracers for human studies are supported:",
37 " ratio is assumed to follow a population average curve.",
39 " ratio is assumed to follow a population average curve.",
41 " ratio is assumed to follow a population average curve",
42 " (unpublished measurements from eight 70-min PET studies).",
44 " ratio is assumed to rise from zero with slope 0.00888",
45 " (unpublished measurement from 10 subjects).",
47 " ratio is assumed to be 0.8 in the beginning and to rise with",
48 " slope 0.0012/min (Phelps ME et al. Ann Neurol 1979;6:371-388).",
50 " ratio is assumed to follow equation R(t)=(Rmax*t)/(Th+t),",
51 " where Rmax=1.446 and Th=83.56 (unpublished results).",
53 " ratio is assumed to follow an average curve based on two",
54 " subjects with assumed HCR=0.43.",
56 " ratio is assumed to be 1.23 in the beginning and to decrease slowly",
57 " with slope 0.00123/min (Hawkins et al., JNM 1992;33:633-642.).",
59 " ratio is assumed to follow a population average curve.",
61 " concentration in red blood cells is assumed to be zero.",
63 " ratio is assumed to rise from zero with slope 0.00398",
64 " (unpublished measurement from 7 subjects).",
66 " concentration is the same in RBC and plasma water.",
68 " ratio is assumed to follow a population average curve",
69 " (unpublished measurement from 6 subjects studied twice).",
71 " ratio is assumed to follow a population average curve",
72 " (unpublished measurement from 8 subjects).",
73 " PBR28HAB, PBR28MAB, PBR28LAB",
74 " ratio is assumed to follow a binding-type specific population average",
75 " curve (unpublished measurements from 90-min PET studies).",
77 " ratio is assumed to follow a population average curve",
78 " (unpublished measurements from ten 70-min PET studies).",
80 " ratio is assumed to follow a population average curve,",
81 " currently based on 15 subjects.",
83 " ratio is assumed to follow a curve based on one",
84 " subject with measured HCr.",
86 " ratio is assumed to follow a population average curve,",
87 " currently based on 11 subjects.",
89 " ratio is assumed to follow a population average curve,",
90 " currently based on 7 subjects.",
91 "For mice and rats (these conversion do not utilize hematocrit):",
93 " plasma-to-blood ratio is assumed to follow the function published by",
94 " Yu AS et al. J Nucl Med 2009;50(6):966-973.",
96 " plasma-to-blood ratio is assumed to follow the function published by",
97 " Huang et al. J Nucl Med 2017;58(4):611-616.",
99 " plasma-to-blood ratio is assumed to follow the function published by",
100 " Weber et al. Eur J Nucl Med 2002;29(3):319-s323.",
102 "Codes for tracers that have below mentioned properties:",
104 " concentration in red blood cells is assumed to be zero.",
106 " concentration is the same in RBC and plasma water.",
109 "Example: estimate blood curve from measured FDG plasma TAC:",
110 " @P FDG i3344ap.kbq 0.38 90 i3344ab.kbq",
112 "See also: b2plasma, p2blood, b2rbc, bpr2cpr, tacinv, tac2svg, tacformat",
114 "Keywords: simulation, blood, plasma, software testing",
133int main(
int argc,
char **argv)
135 int ai, help=0, version=0, verbose=1;
138 char ofile[FILENAME_MAX], *cptr;
143 double aiendtime=nan(
"");
149 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
153 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
154 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
156 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
161 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
169 fprintf(stderr,
"Error: invalid tracer code '%s'.\n", argv[ai]);
177 HCR=
atof_dpi(argv[ai]);
if(HCR>1.0) HCR/=100.0;
178 if(HCR<0.01 || HCR>1.0) {
179 fprintf(stderr,
"Error: bad HCr %g.\n", HCR);
return(1);}
187 fprintf(stderr,
"Error: invalid end time %s.\n", argv[ai]);
return(1);}
192 if(ai<argc) {strcpy(ofile, argv[ai]); ai++;}
196 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
202 fprintf(stderr,
"Error: missing command-line argument; try %s --help\n",
209 printf(
"aiendtime := %g\n", aiendtime);
210 printf(
"ofile := %s\n", ofile);
211 printf(
"HCR := %.2f\n", HCR);
212 printf(
"tracer := %d\n", tracer);
222 c=0.0; d=0.02; rnr=1;
223 while(c+d<aiendtime && rnr<9999) {c+=d; d*=1.05; rnr++;}
224 d=aiendtime-c; c=aiendtime; rnr++;
227 fprintf(stderr,
"Memory allocation error.\n");
233 c=0.0; d=0.02; fi=0; data.
x[fi++]=c;
234 while(c+d<aiendtime && rnr<9999) {c+=d; d*=1.05; data.
x[fi++]=c;}
235 d=aiendtime-c; c=aiendtime; data.
x[fi++]=c; data.
frameNr=fi;
247 if(verbose>1) printf(
"calculating ratio curve\n");
249 ratio_type=0;
if(verbose>2) printf(
"trying RBC/plasma ratio\n");
253 ratio_type=1;
if(verbose>2) printf(
"trying plasma/blood ratio\n");
257 fprintf(stderr,
"Error (%d): cannot calculate ratio.\n", ret);
260 if(verbose>2) printf(
"ratio_type := %d\n", ratio_type);
261 if(ratio_type==1 && verbose>1)
262 fprintf(stderr,
"Note: HCr is not used in conversion.\n");
264 if(ratio_type==0) strcpy(tmp,
"RBC-to-plasma");
265 else strcpy(tmp,
"plasma-to-blood");
266 for(fi=0; fi<data.
frameNr; fi++)
267 printf(
"%s[%g] := %.3f\n", tmp, data.
x[fi], data.
voi[0].
y2[fi]);
272 if(verbose>1) printf(
"calculating plasma/blood curve\n");
273 for(fi=0; fi<data.
frameNr; fi++)
274 data.
voi[0].
y[fi]=1.0/(1.0-HCR*(1.0-data.
voi[0].
y2[fi]));
276 for(fi=0; fi<data.
frameNr; fi++)
284 if(verbose>1) printf(
"writing %s\n", ofile);
288 fprintf(stderr,
"Error in writing '%s': %s\n", ofile,
dfterrmsg);
291 if(verbose>0) printf(
"Plasma-to-blood curve written in %s\n", ofile);
double atof_dpi(char *str)
int dftSetmem(DFT *data, int frameNr, int voiNr)
int dftWrite(DFT *data, char *filename)
void dftUnitToDFT(DFT *dft, int dunit)
Header file for libtpccurveio.
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
int rbc_plasma_ratio(int tracer, double *t, double *r, int nr)
int tracer_code(char *tracer)
int plasma_to_blood_ratio(int tracer, double *t, double *r, int nr)
Header file for pbconv.c.
char voiname[MAX_REGIONSUBNAME_LEN+1]
char name[MAX_REGIONNAME_LEN+1]