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
Choose Language Hide Translation Bar
tarkan_bih
Level III

Variables not being passed between scripts

Hi, 

I am using a script from the following post to try and expand on the heatmap that is created from the script. The script in its current form does a heatmap for all of the columns together but I would like a separate heatmap PER column. In other words I would like to find the min, mid and max for a certain column then apply a heat map only on that column then do the same thing for the next column and continue. 

 

Attached are the following

1. sample_base_table.jmp: This is sample set of data that is being extracted from.

2. extract_cols.jsl: this it the script that summarizes the data to be used for the heatmap script

3. heatmap.jsl: this script does the heatmap for the specified columns

 

Issues:

When I run extract_cols.jsl I get 4 new datatables named "Untitled X". Then when I run heatmap.jsl it only is able to create a heat map for the last Untitled X table created. I don't understand why this is... When I look the debugger code it says "could not find column in access or evaluation of 'Column' ". However, I print the column being used "Median(Values, Mango)" and it shows up so I am not sure what is happening (see output picture below).

 

tarkan_bih_0-1625857258101.png

 

Improvements/Future Work:

Ideally after I can figure out why only last data table created is updated I would like to concatenate all of these 4 heatmap columns of fruits into one data table that also has the Countries and fruit info contained as well. In other words I am generating 4 (32x3) tables and I would like to generate 1 (6x32) table (4 fruit heatmap + countries column + locations column). Currently the way I am doing is with JMP Query Builder to do the column concatenation. 

5 REPLIES 5
txnelson
Super User

Re: Variables not being passed between scripts

You are specifying 

Names Default To Here( 1 );

which creates a separate memory namespace for that specific script.  That is, in your extract_cols script, there is a list named "fruit".  If in your heatmap script you specified

myFruit = fruit[1];

your heatmap script would not know anything about your variable called fruit.

 

In your heatmap script, you set the variable "dt" equal to the current data table.  From your description, you are running the headmap script right after running the extract_cols script.  At any given time in JMP, there is only 1 data table that is the current active data table.  Therefore when you specify

dt = Current Data Table();

the heatmap script gets the current active data table, which would be the last data table that you created in the extract_cols script

If you need to pass the original data table reference to the second script, and possibly the other 4 data table references, one way of doing this is to create a separate namespace and to place the references into that namespace.  Here is a modification to your script creates the namespace and places the data table references into it.

Names Default To Here( 1 );
Clear Symbols();
dt = Current Data Table();

if(isnamespace("trans")==0, trans = new namespace("trans"));
trans:theList = {};
insert into(theList,dt);

fruit = {"Apple","Banana","Mango","Orange"};
For(i = 1, i <= N Items(fruit), i++,
obj = dt << Tabulate(
	Set Format( Uniform Format( 10, 0 ) ),
	Add Table(
		Column Table(
			Statistics( Median ),
			Grouping Columns( :fruits ),
			Analysis Columns( :Values )
		),
		Row Table( Grouping Columns( :Countries, :locations ) )
	),
	Local Data Filter(
		Add Filter(
			columns( :fruits),
			Where( :fruits == fruit[i] ),
			Display( :fruits, N Items( 14 ) )
		)
	)
);
trans:theList[i+1] = obj<< make into data table;
Current Report() << Close Window
);

Then you can reference the namespace in your heatmap script to get the primary table reference or any of the data table references that were saved in the namespace.

Names Default To Here( 1 );
Clear Symbols();
dt = trans:thelist[1];

dt << Begin Data Update;

///////////////////////////////////
// Setting Variables for script ///
//rev_scale = "Reverse Scale";
rev_scale =0;
mean_median = 1; //mean=0, median=1
print(mean_median);
///////////////////////////////////


//gets all columns that are continous and stores that in a list as strings.
colList = dt << get column names( continuous, string );
print(colList);
// Create a temporary subset where the columns are the column list, selects all rows, 
// invisible makes it so you don't see the datatable on screen since it is temporary
dtsub = dt << subset(columns(colList), selected rows(0),invisible);

// Move the data into a matrix this will be used later to get min, max, median|mean 
allData = dtsub << get as matrix;

// Close the no longer needed temporary data table
close(dtsub, nosave);

// Calculate the statistics across the full data matrix
myMax = Maximum(allData);
myMin = Minimum(allData);

if(mean_median == 0,
	myMid = Mean(allData),
	myMid = Median(allData)
);

print(myMax);
print(myMin);
print(myMid);
print(colList);
// Run for loop over data table with the min, max and median|mean calculated from above
// gradient color scheme needs to be set.
if(rev_scale == 1,
	For( i = 1, i <= N Items( colList ), i++, 
		Eval(
			Substitute(
					Expr(
						Column( __col__ ) <<
						set property(
							"color gradient",
							{"Green Yellow Red",
							Range( {__Max__, __Min__, __Mid__} ),"Reverse Scale"}
						) << Color Cell by Value( 1 );
					),
				Expr( __col__ ), colList[i],
				Expr( __Max__ ), myMax,
				Expr( __Min__ ), myMin,
				Expr( __Mid__ ), myMid
			)
		);
	);
,
	For( i = 1, i <= N Items( colList ), i++, 

		Eval(
			Substitute(
					Expr(
						Column( __col__ ) <<
						//Column( colList[i] ) <<
						set property(
							"color gradient",
							{"Green Yellow Red",
							Range( {__Max__, __Min__, __Mid__} )}
						) << Color Cell by Value( 1 );
					),
				Expr( __col__ ), colList[i],
				Expr( __Max__ ), myMax,
				Expr( __Min__ ), myMin,
				Expr( __Mid__ ), myMid
			)
		);
	);
);

 

 

 

 

Jim
tarkan_bih
Level III

Re: Variables not being passed between scripts

Thanks for the input!

When I run the updated extract_cols script you provided I get the following error message below about L-value access...

 

tarkan_bih_0-1625866473565.png

 

txnelson
Super User

Re: Variables not being passed between scripts

my error, change

insert into(theList,dt);

to

insert into(trans:theList,dt);

theList does not exist......but trans:theList does

Jim
tarkan_bih
Level III

Re: Variables not being passed between scripts

Thanks that fixed it!

 

So when I run the heatmap script I get the message below. When I change

 dt= trans:thelist[5] 

it works but again only for the last data table created. Also this namespace concept is new to me. Let me try to summarize what this is doing and can you confirm if my understanding is correct? So by using namespace in the script we are able to saving all the data table names (and more importantly the column names and value of that data table) into a list trans which we then call in the heatmap script.

 

tarkan_bih_1-1625870256630.png

 

 

txnelson
Super User

Re: Variables not being passed between scripts

If you hover over trans:theList or if you specify

show(trans:theList);

in your script it will show you what is in the list.  What you will see are 5 entries.  The first one will be

Data Table( 'the name of your initial data table");

Each entry after that will be the pointer to the data table filter by, Apple, then Banana, then Mango, and finally Orange.

It does not contain the data, just a pointer to it.  The column names, etc. are retrieved from the actual data table.

 

You need to take the time to read the Scripting Guide available from the JMP Documentation Library, under the Help pull down menu.

 

Jim