cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
JD23
Level II

How to script calibration curve

Hi, my level of scripting is really basic and I hope you can help me.

How do I write a script to achieve the following?

I have a table with the known concentrations of the calibrators. In each assay (one table per assay) I have the signal of several unknowns as well as the signal for the calibrators, it is basically an internal calibration curve for each assay.

Is it possible to create a script that takes the values from the table of the known concentrations, plots them against their signals for that specific assay (assay table) and then uses the linear regression to calculate the concentration of the unknowns?

Thanks in advance for the help!

24 REPLIES 24

Re: How to script calibration curve

The index is now only used for the iteration count. The specific sample lables would be captured in a list prior to the iteration.

 

// handle each sample set separately
sample = List( "001-AAA", "002-AAA", "003-AAA" );
For( s = 1, s <= 3, s++,
	// isolate sample
	combined
		<< Select Where( :Sample == sample[s] )
		<< Invert Row Selection
		<< Exclude;
JD23
Level II

Re: How to script calibration curve

Perfect!

Thank you for everything Mark!

JD23
Level II

Re: How to script calibration curve

This is the last request, I promise!

 

How should I rewrite this part so that the script is a bit more generic and can be applied to any set of samples, regardless of their names? For example, instead of writing:

 

sample = List( "001-AAA", "002-AAA", "003-AAA", "004-AAA");

 

can we code to make a summary of the Sample column and fetch those entries to make the List?

 

It would also be great if it was possible to plot the calibration curves with the Bivariate function and have them show up in the end so that we can have a visual of the fit that was performed. 

 

 

 

 

Re: How to script calibration curve

 

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 );
);

 

JD23
Level II

Re: How to script calibration curve

This is perfect! I can't thank you enough Mark.