Changeset 3528
- Timestamp:
- Oct 5, 2015, 11:03:44 AM (7 years ago)
- Location:
- extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/pdf
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/pdf/PdfUtil.java
r3503 r3528 108 108 109 109 private BaseFont defaultFont; 110 private BaseFont boldFont; 110 111 111 112 /** … … 119 120 this.reader = null; 120 121 this.defaultFont = getDefaultFont(); 122 this.boldFont = getBoldFont(); 121 123 } 122 124 … … 136 138 this.creator = info.get("Creator"); 137 139 this.defaultFont = getDefaultFont(); 140 this.boldFont = getBoldFont(); 138 141 } 139 142 … … 214 217 215 218 /** 219 Create a bold font for text elements. 220 @see BaseFont for pre-defined font names 221 */ 222 public BaseFont getBoldFont() 223 { 224 if (boldFont == null) 225 { 226 try 227 { 228 URL openSans = PdfUtil.class.getResource("/META-INF/fonts/OpenSans-Bold.ttf"); 229 return BaseFont.createFont("jar:"+openSans.getPath(), BaseFont.IDENTITY_H, true); 230 } 231 catch (IOException | DocumentException ex) 232 { 233 throw new RuntimeException(ex); 234 } 235 } 236 return boldFont; 237 } 238 239 /** 216 240 Add text to the document. 217 241 … … 233 257 234 258 /** 259 Add bold text to the document. 260 261 @param canvas The document canvas 262 @param text The text to add 263 @param fontSize Font size to use 264 @param align Alignment 265 @param x X coordinate in points 266 @param y Y coordinate in points 267 */ 268 public void addBoldText(String text, float fontSize, int align, float x, float y) 269 { 270 if (text == null || text.equals("")) return; 271 canvas.beginText(); 272 canvas.setFontAndSize(boldFont, fontSize); 273 canvas.showTextAligned(align, text, x, y, 0); 274 canvas.endText(); 275 } 276 277 /** 235 278 Draw grid line around the page. Major grid is 50pt, with minor at every 10pt and 236 279 ticks at every 2pt. -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/pdf/PilotReportWorker.java
r3525 r3528 14 14 import java.util.Map; 15 15 16 import com.itextpdf.text.BaseColor;17 16 import com.itextpdf.text.Element; 18 import com.itextpdf.text.pdf.PdfContentByte;19 import com.itextpdf.text.pdf.StringUtils;20 17 21 18 import net.sf.basedb.core.BioMaterial; … … 24 21 import net.sf.basedb.core.Extract; 25 22 import net.sf.basedb.core.Sample; 26 import net.sf.basedb.core.StringUtil;27 23 import net.sf.basedb.reggie.Reggie; 28 24 import net.sf.basedb.reggie.Site; … … 33 29 import net.sf.basedb.reggie.dao.RnaQc; 34 30 import net.sf.basedb.reggie.dao.Subtype; 35 import net.sf.basedb.reggie.logo.Logo;36 31 import net.sf.basedb.reggie.r.PilotReport; 37 32 import net.sf.basedb.reggie.r.RResult; 38 33 import net.sf.basedb.util.MD5; 39 import net.sf.basedb.util.NumberFormatUtil;40 import net.sf.basedb.util.Values;41 import net.sf.basedb.util.formatter.NumberFormatter;42 34 43 35 /** … … 45 37 generates a PDF document with the plots and other information. 46 38 47 TODO - this is currently a partial copy of the GeneReport. 39 TODO - this is currently a mix of data from the Gene report (plots), 40 random values (molecular subtype) and actual information from the 41 database (header section). 48 42 49 43 @author nicklas … … 65 59 private static final float MARGIN_LEFT = 14; 66 60 67 /* PLOT POSITIONS */68 // Left X of plots69 private static final float PLOT_X = 355; //309;70 // Bottom Y of first plot71 private static final float PLOT_START_Y = 474.5f; //588;72 // Distance between plots73 private static final float PLOT_DELTA_Y = 89.5f; //124;74 // Size of plots75 private static final float PLOT_WIDTH = 160; //270;76 private static final float PLOT_HEIGHT = 80; //97;77 78 61 /* TEXT POSITIONS */ 79 62 // Left X of text columns … … 90 73 private static final float TEXT_Y4 = 718; 91 74 private static final float TEXT_Y5 = 690; 92 75 76 // Molecular subtype box 77 private static final float SUBTYPE_Y1 = 616; 78 private static final float SUBTYPE_Y2 = 608; 79 private static final float SUBTYPE_X1 = 156; 80 private static final float SUBTYPE_X2 = 330; 81 private static final float SUBTYPE_XX = 50; 82 83 /* PLOT POSITIONS */ 84 // Left X of plots 85 private static final float PLOT_X = 355; 86 // Bottom Y of first plot 87 private static final float PLOT_START_Y = 474.5f; 88 // Distance between plots 89 private static final float PLOT_DELTA_Y = 89.5f; 90 // Size of plots 91 private static final float PLOT_WIDTH = 160; 92 private static final float PLOT_HEIGHT = 80; 93 // Text releated to plot 94 private static final float PLOT_TEXT_X = 214; 95 private static final float PLOT_TEXT_START_Y = 510; 96 93 97 private PilotReport script; 94 98 private String config; … … 142 146 Site site = Site.findByCaseName(raw.getName()); 143 147 148 149 144 150 PdfUtil pdfUtil = null; 145 151 try … … 150 156 pdfUtil.importPdf(new FileInputStream(pdfTemplatePath), 0, 0, 1.0f, 1.0f); 151 157 //pdfUtil.drawGrid(); 152 153 float y = PLOT_START_Y;154 File workDir = result.getWorkDir();155 for (String gene : result.genes)156 {157 File f2 = new File(workDir, "scanb_"+gene+".pdf");158 if (f2.exists())159 {160 pdfUtil.importPdf(new FileInputStream(f2), PLOT_X, y, 1.0f, 1.0f);161 y -= PLOT_DELTA_Y;162 }163 }164 165 158 166 159 // Patient and sample information … … 200 193 if (site != Site.UNKNOWN) pdfUtil.addText(site.getName(), 12, Element.ALIGN_LEFT, TEXT_X5, TEXT_Y5); 201 194 195 // Molecular subtype 196 String[] subtypeNames = { "LumA", "LumB", "HER2", "Basal", "Normal" }; 197 float[] subtypeScore = new float[5]; 198 float maxVal = Float.NEGATIVE_INFINITY; 199 for (int i = 0; i < 5; i++) 200 { 201 subtypeScore[i] = (float)(Math.random()*2-1); 202 if (subtypeScore[i] > maxVal) maxVal = subtypeScore[i]; 203 } 204 for (int i = 0; i < 5; i++) 205 { 206 if (Float.compare(maxVal, subtypeScore[i]) == 0) 207 { 208 pdfUtil.addBoldText(twoDecimals.format(subtypeScore[i]), 12, Element.ALIGN_LEFT, SUBTYPE_X2+i*SUBTYPE_XX, SUBTYPE_Y2); 209 pdfUtil.addText(subtypeNames[i], 14, Element.ALIGN_LEFT, SUBTYPE_X1, SUBTYPE_Y1); 210 } 211 else 212 { 213 pdfUtil.addText(twoDecimals.format(subtypeScore[i]), 12, Element.ALIGN_LEFT, SUBTYPE_X2+i*SUBTYPE_XX, SUBTYPE_Y2); 214 } 215 } 216 217 218 // Plots 219 float y = PLOT_START_Y; 220 float yText = PLOT_TEXT_START_Y; 221 File workDir = result.getWorkDir(); 222 String[] lowHigh = { "Låg", "Hög" }; 223 String[] positiveNegative = { "Negative", "Positive" }; 224 225 for (int plotNo = 0; plotNo < 5; plotNo++) 226 { 227 String[] options = plotNo == 0 || plotNo == 4 ? lowHigh : positiveNegative; 228 pdfUtil.addText(options[subtypeScore[plotNo] < 0 ? 0 : 1], 14, Element.ALIGN_LEFT, PLOT_TEXT_X, yText); 229 yText -= PLOT_DELTA_Y; 230 231 if (result.genes.size() > plotNo) 232 { 233 String gene = result.genes.get(plotNo); 234 File f2 = new File(workDir, "scanb_"+gene+".pdf"); 235 if (f2.exists()) 236 { 237 pdfUtil.importPdf(new FileInputStream(f2), PLOT_X, y, 1.0f, 1.0f); 238 y -= PLOT_DELTA_Y; 239 } 240 } 241 } 242 202 243 // Extra info at bottom 203 244 pdfUtil.addText(raw.getName(), 8, Element.ALIGN_RIGHT, MARGIN_RIGHT, 10);
Note: See TracChangeset
for help on using the changeset viewer.