Changeset 3528


Ignore:
Timestamp:
Oct 5, 2015, 11:03:44 AM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #812: Pilot report wizard

Print out molecular subtype scores and other values. The values are currently randomly generated.

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  
    108108 
    109109  private BaseFont defaultFont;
     110  private BaseFont boldFont;
    110111 
    111112  /**
     
    119120    this.reader = null;
    120121    this.defaultFont = getDefaultFont();
     122    this.boldFont = getBoldFont();
    121123  }
    122124 
     
    136138    this.creator = info.get("Creator");
    137139    this.defaultFont = getDefaultFont();
     140    this.boldFont = getBoldFont();
    138141  }
    139142 
     
    214217 
    215218  /**
     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  /**
    216240    Add text to the document.
    217241   
     
    233257 
    234258  /**
     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  /**
    235278    Draw grid line around the page. Major grid is 50pt, with minor at every 10pt and
    236279    ticks at every 2pt.
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/pdf/PilotReportWorker.java

    r3525 r3528  
    1414import java.util.Map;
    1515
    16 import com.itextpdf.text.BaseColor;
    1716import com.itextpdf.text.Element;
    18 import com.itextpdf.text.pdf.PdfContentByte;
    19 import com.itextpdf.text.pdf.StringUtils;
    2017
    2118import net.sf.basedb.core.BioMaterial;
     
    2421import net.sf.basedb.core.Extract;
    2522import net.sf.basedb.core.Sample;
    26 import net.sf.basedb.core.StringUtil;
    2723import net.sf.basedb.reggie.Reggie;
    2824import net.sf.basedb.reggie.Site;
     
    3329import net.sf.basedb.reggie.dao.RnaQc;
    3430import net.sf.basedb.reggie.dao.Subtype;
    35 import net.sf.basedb.reggie.logo.Logo;
    3631import net.sf.basedb.reggie.r.PilotReport;
    3732import net.sf.basedb.reggie.r.RResult;
    3833import 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;
    4234
    4335/**
     
    4537  generates a PDF document with the plots and other information.
    4638 
    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).
    4842
    4943  @author nicklas
     
    6559  private static final float MARGIN_LEFT = 14;
    6660 
    67   /* PLOT POSITIONS */
    68   // Left X of plots
    69   private static final float PLOT_X = 355; //309;
    70   // Bottom Y of first plot
    71   private static final float PLOT_START_Y = 474.5f; //588;
    72   // Distance between plots
    73   private static final float PLOT_DELTA_Y = 89.5f; //124;
    74   // Size of plots
    75   private static final float PLOT_WIDTH = 160; //270;
    76   private static final float PLOT_HEIGHT = 80; //97;
    77 
    7861  /* TEXT POSITIONS */
    7962  // Left X of text columns
     
    9073  private static final float TEXT_Y4 = 718;
    9174  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 
    9397  private PilotReport script;
    9498  private String config;
     
    142146    Site site = Site.findByCaseName(raw.getName());
    143147   
     148   
     149   
    144150    PdfUtil pdfUtil = null;
    145151    try
     
    150156      pdfUtil.importPdf(new FileInputStream(pdfTemplatePath), 0, 0,  1.0f, 1.0f);
    151157      //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      
    165158     
    166159      // Patient and sample information
     
    200193      if (site != Site.UNKNOWN) pdfUtil.addText(site.getName(), 12, Element.ALIGN_LEFT, TEXT_X5, TEXT_Y5);
    201194     
     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     
    202243      // Extra info at bottom
    203244      pdfUtil.addText(raw.getName(), 8, Element.ALIGN_RIGHT, MARGIN_RIGHT, 10);
Note: See TracChangeset for help on using the changeset viewer.