cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
Matt_1
Level I

Get 3rd Y axis only for certain columns (working with loops)

Hi there, 

I got stuck on a problem and would be grateful for some advice:

 

We analyze samples and get population A, B, C, D and E for each sample.

The information for A can be divided into "%" and "count" , same for B,C,D and E. 

 

We import the data and the columns named "A 1" to "E 1" represent the "%" values, the ones called "A 2" to "E 2" represent the "Count" values. 

 

Since the import will always be the same, writing a script to generate graphs with 2 Y axis ("%" and "count") for each population type (A, B, C etc.) was manageable. See the code below.

 

The Problem: Sometimes we get an additional read out for some of our populations. E.g. only population B and E will have a third information called "fluorescence". These will be imported as columns "B 3" and "E 3" into the same table. 

Since these populations may vary from import to import, I need to write a script which is able to identify "B 3" as a member of the "B"s and creates a 3rd Y axis in the population "B" graph (and the same for "E 3" in this example). But for this I am not smart/experienced enough.

 

Of course, I tried to rearrange the table, create new rows instead of new columns and work with "wrap". But there we have no autoscale for each Y axis. Also tried an associate array for the three information types but failed due to the lack of coding experience.

 

Maybe one of you has an idea, that could be helpful, thanks

 

Names Default To Here( 1 );

dt = Current Data Table();
dt << clear select; 

win = New Window( "Test", Outline Box( "", hb = V List Box() ) );

loopstart = Contains(dt << get column names, Column("A 1"));
loopend = (Contains(dt << get column names, Column("A 2")))-1;
icounts = (loopend+1)-loopstart; 

For( i = loopstart, i <= loopend, i++,
		
	
	gb = Graph Builder(
		Size( 1500, 900 ),
		Show Control Panel( 0 ),
		Grid Color( "Black" ),
		Graph Spacing( 2 ),
	
		Legend Position( "Bottom" ), 
	
		Variables( X( :Group ), Y( Eval( i ) ), Y( Eval( i + icounts ) ), Color( :Subjects ) ), 
		Elements( Position( 1, 1 ), Points( X, Y, Legend( 11 ) ), Box Plot( X, Y, Legend( 13 ) ) ), 
		Elements( Position( 1, 2 ), Points( X, Y, Legend( 12 ) ), Box Plot( X, Y, Legend( 14 ) ) ), 
		
	SendToReport(
			Dispatch( {}, "Graph Builder", OutlineBox, {Set Title( "DATA" ), Image Export Display( Normal )} ),
			Dispatch( {}, "graph title", TextEditBox, {Set Text( "Title" )}, {Set Font Size( 16 )} ),
			Dispatch( {}, "Y title", TextEditBox, {Set Font Size( 14 ), Set Font Style( "bold" ), Set Text( " [%]" )} ),
			Dispatch( {}, "Y1 title", TextEditBox, {Set Font Size( 14 ), Set Font Style( "bold" ), Set Text( " Count" )} ), 
			Dispatch( {}, "X title", TextEditBox, {Set Font Size( 14 ), Set Font Style( "bold" )} ), 
			
		
			Dispatch(
				{},
				"400",
				LegendBox,
				{Set wrap( 12 ), Set Title( "" ), font( "Segoe UI", 12, "Plain" ), Legend Position(
					{11, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1], 13, [-1], 12, [-1], 14, [-1] 
					}
				), Orientation( "Vertical" )}
			)
		)
	);
	
	hb << Append( Report( gb ) << child );
	hb << append( Page Break Box() );
	
	gb << close window;
	
	
);
1 REPLY 1
txnelson
Super User

Re: Get 3rd Y axis only for certain columns (working with loops)

Here is some pretty ugly code, but it seems to provide to you what you need

txnelson_0-1679326412547.png

Names Default To Here( 1 );

dt = Current Data Table();
dt << clear select; 

win = New Window( "Test", Outline Box( "", hb = V List Box() ) );

loopstart = Contains( dt << get column names, Column( "A 1" ) );
loopend = (Contains( dt << get column names, Column( "A 2" ) )) - 1;
fluorB3 = Contains( dt << get column names, Column( "B 3" ) );
fluorE3 = Contains( dt << get column names, Column( "E 3" ) );
icounts = (loopend + 1) - loopstart; 

For( i = loopstart, i <= loopend, i++, 
		
	If( (Column( i ) << get name == "B 1" & fluorB3 > 0) | (Column( i ) << get name == "E 1" & fluorE3 > 0),
		If( Column( i ) << get name == "B 1",
			fluorcounts = fluorB3,
			fluorcounts = fluorE3
		);
		gb = Graph Builder(
			Size( 1517, 788 ),
			Show Control Panel( 0 ),
			Legend Position( "Bottom" ),
			Grid Color( "Black" ),
			Graph Spacing( 2 ),
			Variables( X( :Group ), Y( Eval( i ) ), Y( Eval( i + icounts ) ), Y( Eval( fluorcounts ) ), Color( :Subjects ) ),
			Elements( Position( 1, 1 ), Points( X, Y, Legend( 11 ) ), Box Plot( X, Y, Legend( 13 ) ) ),
			Elements( Position( 1, 2 ), Points( X, Y, Legend( 12 ) ), Box Plot( X, Y, Legend( 14 ) ) ),
			Elements( Position( 1, 3 ), Points( X, Y, Legend( 15 ) ), Box Plot( X, Y, Legend( 16 ) ) ),
			SendToReport(
				Dispatch( {}, "Graph Builder", OutlineBox, {Set Title( "DATA" ), Image Export Display( Normal )} ),
				Dispatch( {}, "400", ScaleBox, {Legend Model( 12, Base( 0, 0, 0, Item ID( "Car", 1 ) ) )} ),
				Dispatch( {}, "graph title", TextEditBox, {Set Text( "Title" )} ),
				Dispatch( {}, "X title", TextEditBox, {Set Font Size( 14 ), Set Font Style( "Bold" )} ),
				Dispatch( {}, "Y title", TextEditBox, {Set Text( " [%]" ), Set Font Size( 14 ), Set Font Style( "Bold" )} ),
				Dispatch( {}, "Y 1 title", TextEditBox, {Set Text( " Count" ), Set Font Size( 14 ), Set Font Style( "Bold" )} ),
				Dispatch( {}, "Y 2 title", TextEditBox, {Set Text( " Fluor" ), Set Font Size( 14 ), Set Font Style( "Bold" )} ),
				Dispatch(
					{},
					"400",
					LegendBox,
					{font( "Segoe UI", 12, "Plain" ), Orientation( "Vertical" ), Set Wrap( 12 ),
					Legend Position(
						{11, [0, 1, 2, 3], 13, [-1, -1, -1, -1, -1, -3], 12, [-1, -3, -3, -3], 14, [-1, -1, -1, -1, -1, -3], 15, [-1, -1,
						-1, -1, -1, -3], 16, [-1, -1, -1, -1, -1, -3]}
					)}
				)
			)
		);
	, 

		gb = Graph Builder(
			Size( 1500, 900 ),
			Show Control Panel( 0 ),
			Grid Color( "Black" ),
			Graph Spacing( 2 ), 
	
			Legend Position( "Bottom" ), 
	
			Variables( X( :Group ), Y( Eval( i ) ), Y( Eval( i + icounts ) ), Color( :Subjects ) ),
			Elements( Position( 1, 1 ), Points( X, Y, Legend( 11 ) ), Box Plot( X, Y, Legend( 13 ) ) ),
			Elements( Position( 1, 2 ), Points( X, Y, Legend( 12 ) ), Box Plot( X, Y, Legend( 14 ) ) ), 
		
			SendToReport(
				Dispatch( {}, "Graph Builder", OutlineBox, {Set Title( "DATA" ), Image Export Display( Normal )} ),
				Dispatch( {}, "graph title", TextEditBox, {Set Text( "Title" )}, {Set Font Size( 16 )} ),
				Dispatch( {}, "Y title", TextEditBox, {Set Font Size( 14 ), Set Font Style( "bold" ), Set Text( " [%]" )} ),
				Dispatch( {}, "Y1 title", TextEditBox, {Set Font Size( 14 ), Set Font Style( "bold" ), Set Text( " Count" )} ),
				Dispatch( {}, "X title", TextEditBox, {Set Font Size( 14 ), Set Font Style( "bold" )} ), 
			
		
				Dispatch(
					{},
					"400",
					LegendBox,
					{Set wrap( 12 ), Set Title( "" ), font( "Segoe UI", 12, "Plain" ), Legend Position(
						{11, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1], 13, [-1], 12, [-1], 14, [-1]}
					), Orientation( "Vertical" )}
				)
			)
		)
	);
	hb << Append( Report( gb ) << child );
	hb << append( Page Break Box() );
	
	gb << close window;
	
);
Jim