Browse code

handle time channel scaling properly

mikejiang authored on 18/05/2021 18:04:30
Showing 3 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: CytoML
2 2
 Type: Package
3 3
 Title: A GatingML Interface for Cross Platform Cytometry Data Sharing
4
-Version: 2.3.4
4
+Version: 2.3.5
5 5
 Date: 2016-04-15
6 6
 Author: Mike Jiang, Jake Wagner
7 7
 Maintainer: Mike Jiang <wjiang2@fhcrc.org>
... ...
@@ -11,7 +11,7 @@ License: file LICENSE
11 11
 License_restricts_use: yes
12 12
 LazyData: TRUE
13 13
 Imports:
14
-    cytolib(>= 2.3.9),
14
+    cytolib(>= 2.3.10),
15 15
     flowCore (>= 1.99.10),
16 16
     flowWorkspace (>= 4.1.8),
17 17
     openCyto (>= 1.99.2),
... ...
@@ -442,26 +442,33 @@ public:
442 442
 
443 443
 
444 444
 				gh->transform_gate();
445
-				// add the scaleTrans for the implicit time transformation based on $TIMESTEP in FCS
446
-				// This reproduces some of the logic of cytolib::CytoFrame::scale_time_channel
447 445
 				string time_channel = "time";
448
-				auto idx = frptr->get_col_idx(time_channel, ColType::channel);
449
-				if(idx >= 0){
450
-					EVENT_DATA_TYPE timestep = frptr->get_time_step(time_channel);
451
-					if(g_loglevel>=GATING_HIERARCHY_LEVEL)
452
-					PRINT("Adding transformation to multiply "+time_channel+" by :"+ to_string(timestep) + "\n");
453
-
454
-					shared_ptr<scaleTrans> timeTrans(new scaleTrans(timestep));
455
-
456
-					timeTrans->setGateOnlyFlag(false);
457
-					timeTrans->setName(time_channel);
458
-					timeTrans->setChannel(time_channel);
459
-					timeTrans->setType(SCALE);
460
-
461
-					trans_local lTrans = gh->getLocalTrans();
462
-					lTrans.addTrans(time_channel, timeTrans);
463
-					gh->addTransMap(lTrans.getTransMap());
446
+				if (!gh->getLocalTrans().getTran(
447
+				    time_channel))  // only use timestep when time transform is not
448
+				  // present
449
+				{
450
+				  // add the cytolib::scaleTrans for the implicit time transformation
451
+				  // based on $TIMESTEP in FCS This reproduces some of the logic of
452
+				  // cytolib::CytoFrame::scale_time_channel
453
+				  auto idx = frptr->get_col_idx(time_channel, ColType::channel);
454
+  				if(idx >= 0){
455
+  					EVENT_DATA_TYPE timestep = frptr->get_time_step(time_channel);
456
+  					if(g_loglevel>=GATING_HIERARCHY_LEVEL)
457
+  					PRINT("Adding transformation to multiply "+time_channel+" by :"+ to_string(timestep) + "\n");
458
+  
459
+  					shared_ptr<scaleTrans> timeTrans(new scaleTrans(timestep));
460
+  
461
+  					timeTrans->setGateOnlyFlag(false);
462
+  					timeTrans->setName(time_channel);
463
+  					timeTrans->setChannel(time_channel);
464
+  					timeTrans->setType(SCALE);
465
+  
466
+  					trans_local lTrans = gh->getLocalTrans();
467
+  					lTrans.addTrans(time_channel, timeTrans);
468
+  					gh->addTransMap(lTrans.getTransMap());
469
+  				}
464 470
 				}
471
+				
465 472
 				gh->shift_gate();
466 473
 				gh->transform_data(fr);
467 474
 				gh->extendGate(fr, config_const.gate_extend_trigger_value);
... ...
@@ -849,18 +849,40 @@ public:
849 849
 				//only meaningful for scaling ellipsoidGate from 256 back to raw
850 850
 				if(g_loglevel>=GATING_SET_LEVEL)
851 851
 					COUT<<"flin func:"<<pname<<endl;
852
-//				double minRange=atof(transNode.getProperty("minRange").c_str());
853
-				double maxRange=atof(transNode.getProperty("maxRange").c_str());
854
-				if(maxRange==0)
855
-					maxRange = 1;
856
-
857
-				shared_ptr<scaleTrans> curTran(new scaleTrans(maxRange,maxRange));
858
-
859
-				curTran->setName("");
860
-				curTran->setChannel(pname);
861
-
862
-				curTp[curTran->getChannel()]=curTran;
863
-
852
+				auto gain = transNode.getProperty("gain");
853
+				
854
+				if (boost::to_lower_copy(pname) == "time") {
855
+				  if (gain !=
856
+          "1") {  // cytolib::EVENT_DATA_TYPEmust skip adding it when gain == 1 since $TIMESTEP should
857
+				    // be used for scaling time channel in that case
858
+				    
859
+				    auto scale_factor = stof(gain);
860
+				    
861
+				    std::shared_ptr<cytolib::scaleTrans> curTran(
862
+				        new cytolib::scaleTrans(scale_factor));
863
+				    curTran->setName("");
864
+				    curTran->setChannel(pname);
865
+				    curTran->setGateOnlyFlag(false);
866
+				    curTran->setDataOnlyFlag(true);
867
+				    curTp[pname] = curTran;
868
+				  }
869
+				} else {  // need it for ellipsoid gate rescaling
870
+				  // and only meaningful for scaling cytolib::ellipsoidGate from 256 back
871
+				  // minRange=atof(transNode.getProperty("minRange").c_str());to raw
872
+				  cytolib::EVENT_DATA_TYPE maxRange =
873
+				    atof(transNode.getProperty("transforms:maxRange").c_str());
874
+				  if (maxRange == 0) maxRange = 1;
875
+				  
876
+				  std::shared_ptr<cytolib::scaleTrans> curTran(
877
+				      new cytolib::scaleTrans(maxRange, maxRange));
878
+				  
879
+				  curTran->setName("");
880
+				  curTran->setChannel(pname);
881
+				  curTran->setGateOnlyFlag(true);
882
+				  curTran->setDataOnlyFlag(false);
883
+				  curTp[pname] = curTran;
884
+				}
885
+				
864 886
 			}else if(transType.compare("log")==0){
865 887
 				if(g_loglevel>=GATING_SET_LEVEL)
866 888
 					COUT<<"flog func:"<<pname<<endl;