// PathVisio, // a tool for data visualization and analysis using Biological Pathways // Copyright 2006-2011 BiGCaT Bioinformatics // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // package org.pathvisio.desktop.gex; import java.util.List; import org.bridgedb.IDMapperException; import org.bridgedb.Xref; import org.pathvisio.core.model.PathwayElement; import org.pathvisio.gui.BackpageTextProvider.BackpageHook; /** * Backpage hook to show gene expression data in tabular format. * Only used in Standalone application. */ public class BackpageExpression implements BackpageHook { private final GexManager gexManager; public BackpageExpression (GexManager gexManager) { this.gexManager = gexManager; } /** * Gets all available expression data for the given gene id and returns a string * containing this data in a HTML table * @param idc the {@link Xref} containing the id and code of the geneproduct to look for * @return String containing the expression data in HTML format or a string displaying a * 'no expression data found' message in HTML format */ private static String getDataString(Xref idc, CachedData gex) throws IDMapperException { String noDataFound = "

No expression data found"; String exprInfo = "

Gene id on mapp: " + idc.getId() + ""; String colNames = "
Sample name"; if(!gex.isConnected()) return noDataFound; List pwData = gex.syncGet(idc); if(pwData == null) return noDataFound; for(ReporterData d : pwData){ colNames += "" + d.getXref().getId(); } String dataString = ""; for(Sample s : gex.getOrderedSamples()) { dataString += "
" + s.getName(); for(ReporterData d : pwData) { dataString += "" + d.getSampleData(s); } } return exprInfo + colNames + dataString + "
"; } public String getHtml(PathwayElement e) { return getHtml(e, gexManager.getCachedData()); } public static String getHtml(PathwayElement e, CachedData gex) { String text = ""; try { //Get the expression data information if available if(gex != null) { text += "

Expression data

"; text += getDataString(e.getXref(), gex); } } catch (IDMapperException ex) { text += "Exception occured while getting cross-references
" + ex.getMessage(); } return text; } }