<commit_before>Ext.namespace('Gemma');

/**
 * 
 * Grid to display expression experiments with differential evidence for each probe (e.g., for a single gene).
 * 
 * $Id$
 */
Gemma.ProbeLevelDiffExGrid = Ext.extend(Ext.grid.GridPanel, {

	autoExpandColumn : 'efs',
	height : 300,
	loadMask : true,
	stateful : false,
	viewConfig : {
// forceFit : true
	},

	readMethod : DifferentialExpressionSearchController.getDifferentialExpression,

	convertEE : function(s) {
		return s.shortName;
	},

	convertEF : function(s) {
		return s[0].name;
	},

	initComponent : function() {

		Ext.apply(this, {
					record : Ext.data.Record.create([{
								name : "expressionExperiment",
								sortType : this.convertEE
							}, {
								name : "probe"
							}, {
								name : "experimentalFactors",
								sortType : this.convertEF
							}, {
								name : "metThreshold",
								type : "boolean"
							}, {
								name : "fisherContribution",
								type : "boolean"
							}, {
								name : "p",
								type : "float"
							}])
				});

			this.searchInGridField = new Ext.form.TextField({
					enableKeyEvents : true,
					emptyText : 'Filter',
					tooltip : "Text typed here will ",
					listeners : {
						"keyup" : {
							fn : this.searchForText.createDelegate(this),
							scope : this,
							options : {
								delay : 100
							}
						}
					}
				});
				
		if (this.pageSize) {
			Ext.apply(this, {
						store : new Gemma.PagingDataStore({
									proxy : new Ext.data.DWRProxy(this.readMethod),
									reader : new Ext.data.ListRangeReader({}, this.record),
									pageSize : this.pageSize,
									sortInfo : {
										field : "p",
										direction : "ASC"
									}
								})
					});
			Ext.apply(this, {
						bbar : new Gemma.PagingToolbar({
									pageSize : this.pageSize,
									store : this.store,
									items : ['->', {
												xtype : 'button',
												handler : this.clearFilter.createDelegate(this),
												scope : this,
												cls : 'x-btn-text',
												text : 'Reset filter'
											}, ' ', this.searchInGridField]
								})
					});
		} else {
			// nonpaging
			Ext.apply(this, {
						store : new Ext.data.Store({
									proxy : new Ext.data.DWRProxy(this.readMethod),
									reader : new Ext.data.ListRangeReader({}, this.record),
									sortInfo : {
										field : "p",
										direction : "ASC"
									}
								})
					});
					
		
					Ext.apply(this, {
						bbar : new Ext.Toolbar({
									items : ['->', {
												xtype : 'button',
												handler : this.clearFilter.createDelegate(this),
												scope : this,
												cls : 'x-btn-text',
												text : 'Reset filter'
											}, ' ', this.searchInGridField]
								})
					});
		}

		Ext.apply(this, {
			columns : [{
						id : 'expressionExperiment',
						header : "Dataset",
						dataIndex : "expressionExperiment",
						toolTip : "The study/expression experiment the result came from",
						sortable : true,
						renderer : Gemma.ProbeLevelDiffExGrid.getEEStyler()
					}, {
						id : 'visualize',
						hidden : true,
						header : "Visualize",
						dataIndex : "visualize",
						renderer : this.visStyler.createDelegate(this),
						tooltip : "Link for visualizing raw data",
						sortable : false,
						width : 30

					}, {
						id : 'expressionExperimentName',
						header : "Name",
						width : 100,
						dataIndex : "expressionExperimentName",
						toolTip : "The experiment name (abbreviated)",
						sortable : true,
						renderer : function(value, metadata, record, row, col, ds) {
							return Ext.util.Format.ellipsis(record.get('expressionExperiment').name, 20);
						}.createDelegate(this)
					}, {
						id : 'probe',
						header : "Probe",
						dataIndex : "probe",
						width : 80,
						toolTip : "The specific probe; shown in color if it was used for the Meta-P-value computation",
						renderer : Gemma.ProbeLevelDiffExGrid.getProbeStyler(),
						sortable : true
					}, {
						id : 'efs',
						header : "Factor",
						toolTip : "The factor that was examined",
						dataIndex : "experimentalFactors",
						renderer : Gemma.ProbeLevelDiffExGrid.getEFStyler(),
						sortable : true
					}, {
						id : 'p',
						header : "Sig. (q-value)",
						toolTip : "The significance measure of the result for the probe, shown in color if it met your threshold",
						dataIndex : "p",
						width : 80,
						renderer : function(p, metadata, record) {
							if (record.get("metThreshold")) {
								metadata.css = "metThreshold"; // typo.css
							}
							if (p < 0.001) {
								return sprintf("%.3e", p);
							} else {
								return sprintf("%.3f", p);
							}
						},
						sortable : true
					}]
		});

		Gemma.ProbeLevelDiffExGrid.superclass.initComponent.call(this);

			this.on("cellclick", this.rowClickHandler.createDelegate(this), this);

	},

		searchForText : function(button, keyev) {
		var text = this.searchInGridField.getValue();
		if (text.length < 2) {
			this.clearFilter();
			return;
		}
		this.getStore().filterBy(this.getSearchFun(text), this, 0);
	},

	clearFilter : function() {
		this.getStore().clearFilter();
	},

	getSearchFun : function(text) {
		var value = new RegExp(Ext.escapeRe(text), 'i');
		return function(r, id) {
			var obj = r.data;
			return value.match(obj.expressionExperiment.name) || value.match(obj.expressionExperiment.shortName);
		}
	},
	
	getEEIds : function() {
		var result = [];
		this.store.each(function(rec) {
					result.push(rec.get("id"));
				});<commit_msg>Bug1731 Error message if a gene has no differential data for showGenePage , show error message<commit_after>Ext.namespace('Gemma');

/**
 * 
 * Grid to display expression experiments with differential evidence for each probe (e.g., for a single gene).
 * 
 * $Id$
 */
Gemma.ProbeLevelDiffExGrid = Ext.extend(Ext.grid.GridPanel, {

	autoExpandColumn : 'efs',
	height : 300,
	loadMask : true,
	stateful : false,
	viewConfig : {
// forceFit : true
	},
	
	readMethod : DifferentialExpressionSearchController.getDifferentialExpression,

	convertEE : function(s) {
		return s.shortName;
	},

	convertEF : function(s) {
		return s[0].name;
	},

	initComponent : function() {
			
		Ext.apply(this, {
					record : Ext.data.Record.create([{
								name : "expressionExperiment",
								sortType : this.convertEE
							}, {
								name : "probe"
							}, {
								name : "experimentalFactors",
								sortType : this.convertEF
							}, {
								name : "metThreshold",
								type : "boolean"
							}, {
								name : "fisherContribution",
								type : "boolean"
							}, {
								name : "p",
								type : "float"
							}])
				});

			this.searchInGridField = new Ext.form.TextField({
					enableKeyEvents : true,
					emptyText : 'Filter',
					tooltip : "Text typed here will ",
					listeners : {
						"keyup" : {
							fn : this.searchForText.createDelegate(this),
							scope : this,
							options : {
								delay : 100
							}
						}
					}
				});
				
		if (this.pageSize) {
			Ext.apply(this, {
						store : new Gemma.PagingDataStore({
									proxy : new Ext.data.DWRProxy(this.readMethod),
									reader : new Ext.data.ListRangeReader({}, this.record),
									pageSize : this.pageSize,
									sortInfo : {
										field : "p",
										direction : "ASC"
									}
								})
					});
			Ext.apply(this, {
						bbar : new Gemma.PagingToolbar({
									pageSize : this.pageSize,
									store : this.store,
									items : ['->', {
												xtype : 'button',
												handler : this.clearFilter.createDelegate(this),
												scope : this,
												cls : 'x-btn-text',
												text : 'Reset filter'
											}, ' ', this.searchInGridField]
								})
					});
		} else {
			// nonpaging
			Ext.apply(this, {
						store : new Ext.data.Store({
									proxy : new Ext.data.DWRProxy(this.readMethod),
									reader : new Ext.data.ListRangeReader({}, this.record),
									sortInfo : {
										field : "p",
										direction : "ASC"
									}
								})
					});
					
		
					Ext.apply(this, {
						bbar : new Ext.Toolbar({
									items : ['->', {
												xtype : 'button',
												handler : this.clearFilter.createDelegate(this),
												scope : this,
												cls : 'x-btn-text',
												text : 'Reset filter'
											}, ' ', this.searchInGridField]
								})
					});
		}

		Ext.apply(this, {
			columns : [{
						id : 'expressionExperiment',
						header : "Dataset",
						dataIndex : "expressionExperiment",
						toolTip : "The study/expression experiment the result came from",
						sortable : true,
						renderer : Gemma.ProbeLevelDiffExGrid.getEEStyler()
					}, {
						id : 'visualize',
						hidden : true,
						header : "Visualize",
						dataIndex : "visualize",
						renderer : this.visStyler.createDelegate(this),
						tooltip : "Link for visualizing raw data",
						sortable : false,
						width : 30

					}, {
						id : 'expressionExperimentName',
						header : "Name",
						width : 100,
						dataIndex : "expressionExperimentName",
						toolTip : "The experiment name (abbreviated)",
						sortable : true,
						renderer : function(value, metadata, record, row, col, ds) {
							return Ext.util.Format.ellipsis(record.get('expressionExperiment').name, 20);
						}.createDelegate(this)
					}, {
						id : 'probe',
						header : "Probe",
						dataIndex : "probe",
						width : 80,
						toolTip : "The specific probe; shown in color if it was used for the Meta-P-value computation",
						renderer : Gemma.ProbeLevelDiffExGrid.getProbeStyler(),
						sortable : true
					}, {
						id : 'efs',
						header : "Factor",
						toolTip : "The factor that was examined",
						dataIndex : "experimentalFactors",
						renderer : Gemma.ProbeLevelDiffExGrid.getEFStyler(),
						sortable : true
					}, {
						id : 'p',
						header : "Sig. (q-value)",
						toolTip : "The significance measure of the result for the probe, shown in color if it met your threshold",
						dataIndex : "p",
						width : 80,
						renderer : function(p, metadata, record) {
							if (record.get("metThreshold")) {
								metadata.css = "metThreshold"; // typo.css
							}
							if (p < 0.001) {
								return sprintf("%.3e", p);
							} else {
								return sprintf("%.3f", p);
							}
						},
						sortable : true
					}]
		});

		Gemma.ProbeLevelDiffExGrid.superclass.initComponent.call(this);

			this.on("cellclick", this.rowClickHandler.createDelegate(this), this);
			//once the store is loaded validate to see if it has any records and pass delegate reference to store
			this.store.on("load", this.validate.createDelegate(this));			
			
	},
	
	
	
	/**
	 * Checks if store contains any results if not print message indicating that there are no
	 * differential analyses for this taxon. Triggered on load event firing.
	 */
	validate : function() {	
		if(this.store.getCount()==0){
			//taxon from hidden field in jsp.
			var scientificNameTaxon = dwr.util.getValue("taxonScientificName");
			this.handleError("No gene differential analysis is available for " 	+ scientificNameTaxon);					
		}
	},
	
	
	
	/**
	 * Print error message called when application throws and exception or error message set on result.
	 */
	handleError : function(errorMessage) {
		Ext.DomHelper.applyStyles("diffExpression-msg", "height: 2.2em");
		Ext.DomHelper.overwrite("diffExpression-msg", [{
			tag : 'img',
			src : '/Gemma/images/icons/warning.png'
		},
		{
			tag : 'span',
			html : "&nbsp;&nbsp;" + errorMessage					
		}]);	
		
	},
	
	
	
	searchForText : function(button, keyev) {
		var text = this.searchInGridField.getValue();
		if (text.length < 2) {
			this.clearFilter();
			return;
		}
		this.getStore().filterBy(this.getSearchFun(text), this, 0);
	},

	clearFilter : function() {
		this.getStore().clearFilter();
	},

	getSearchFun : function(text) {
		var value = new RegExp(Ext.escapeRe(text), 'i');
		return function(r, id) {
			var obj = r.data;
			return value.match(obj.expressionExperiment.name) || value.match(obj.expressionExperiment.shortName);
		}
	},
	
	getEEIds : function() {
		var result = [];
		this.store.each(function(rec) {
					result.push(rec.get("id"));
				});
{'fraction_non_alphanumeric': 0.13449625040756438, 'fraction_numerical': 0.004809259863058363, 'mean_word_length': 2.175207039337474, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1918709', 'n_tokens_mistral': 5644, 'n_tokens_neox': 3758, 'n_words': 840}