Names Default to Here( 1 );
// check for sufficient tables
n tables = N Table();
If( n tables < 2,
Throw( "Two data tables are required for this analysis" )
);
tables = List();
For( t = 1, t <= n tables, t++,
Insert Into( tables, Eval( Data Table( t ) << Get Name ) );
);
// identify the calibration and unknown data tables
dlg = New Window( "Assay Unknown Samples", << Modal,
H List Box(
lb = List Box( tables ),
Line Up Box( N Col( 2 ),
Button Box( "Calibrator Table",
sel = lb << Get Selected;
cal lb << Append( sel );
),
cal lb = List Box( {},
N Lines( 1 )
),
Button Box( "Unknown Table",
sel = lb << Get Selected;
unk lb << Append( sel );
),
unk lb = List Box( {},
N Lines( 1 )
)
)
),
H List Box(
Button Box( "OK",
cal table = cal lb << Get Items;
Show( cal table );
unk table = unk lb << Get Items;
Show( unk table );
),
Button Box( "Cancel" )
)
);
If( dlg["Button"] == -1,
Throw( "User cancelled" )
);
// unload the dialog
cal table = Data Table( cal table[1] );
unk table = Data Table( unk table[1] );
// include AU 2 values for calibrators from calibration table
combined = cal table << Join( With( unk table ),
Copy formula( 0 ),
Select With( :Sample, :Peps, :AU 1 ),
Select( :AU 2 ),
By Matching Columns( :Peps = :Peps ),
Drop Multiples( 0, 0 ),
Include Nonmatches( 0, 1 ),
Preserve Main Table Order( 0 )
);
Close( cal table, No Save );
Close( unk table, No Save );
// distinquish peps
Current Data Table( combined );
combined << New Column( "Status", "Character", "Nominal" );
For Each Row(
:Status = If( 1 <= Num( Regex( :Peps, "\w{3}(\d+)", "\1" ) ) <= 29, "Calibrator", "Unknown" );
);
// placeholders for matching information
combined
<< New Column( "Predicted AU 2", "Numeric", "Continuous" )
<< New Column( "Lower 95%", "Numeric", "Continuous" )
<< New Column( "Upper 95%", "Numeric", "Continuous" );
// handle each sample set separatelySummarize( sample = By( combined:Sample ) );
Summarize( sample list = By( combined:Sample ) );
For( s = 1, s <= N Items( sample list ), s++,
// isolate sample
combined
<< Select Where( :Sample == sample list[s] )
<< Invert Row Selection
<< Exclude;
// fit the calibration curve for this sample
dlg = combined << Fit Model(
Y( :AU 1 ),
Effects( :AU 2 ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
Where( :Status == "Calibrator" )
);
fit = dlg << Run;
// access report layer
fit rep = fit << Report;
title = fit rep[OutlineBox(1)] << Get Title;
fit rep[OutlineBox(1)] << Set Title( title || ", Sample = " || sample list[s] );
// determine the assay for the unknown samples from the calibration curve
For Each Row(
If( Not( Excluded( Row State( Row() ) ) ),
fit << Inverse Prediction( Response( :AU 1[] ) );
);
);
// remove extraneous string column box that interferes with making combined data table
(fit rep << XPath( "//StringColBox[StringColBoxHeader=\!"Type of CI\!"]")) << Delete;
// extract the assays into a new data table
assays = fit rep["Inverse Prediction"][TableBox(1)] << Make Combined Data Table;
// fit << Close Window;
// prepare predicted values for join
assays
<< Delete Columns( Column( assays, 1 ) )
<< New Column( "Sample", "Character", "NominaL" )
<< New Column( "Peps", "Character", "NominaL" );
Current Data Table( combined );
r = 1;
For Each Row(
If( Not( Excluded( Row State( Row() ) ) ),
assays:Sample[r] = combined:Sample;
assays:Peps[r] = combined:Peps;
r++;
);
);
combined << Clear Row States;
combined << Update(
With( assays ),
Match Columns(
:Sample = :Sample,
:Peps = :Peps
)
);
Close( assays, No Save );
);