Changeset 3535


Ignore:
Timestamp:
Oct 8, 2015, 2:09:21 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #812: Pilot report wizard

Parse the *.txt files containing the score for each plot. The score is converted to text (Låg/Hög?, Negativ/Positiv?) depending on if the score is lower or higher than 0. If no txt file is available N/A is written instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/pdf/PilotReportWorker.java

    r3533 r3535  
    11package net.sf.basedb.reggie.pdf;
    22
     3import java.io.BufferedReader;
    34import java.io.File;
    45import java.io.FileInputStream;
     6import java.io.FileReader;
    57import java.io.IOException;
    68import java.io.InputStream;
     
    2325import net.sf.basedb.core.Extract;
    2426import net.sf.basedb.core.Sample;
     27import net.sf.basedb.core.Type;
    2528import net.sf.basedb.reggie.Reggie;
    2629import net.sf.basedb.reggie.Site;
     
    211214     
    212215      // Plots
    213       float y = PLOT_START_Y;
     216      float yPlot = PLOT_START_Y;
    214217      float yText = PLOT_TEXT_START_Y;
    215218      String[] plots = { "GGI", "ESR1", "PGR", "ERBB2", "MKI67" };
    216219      String[] lowHigh = { "Låg", "Hög" };
    217       String[] positiveNegative = { "Negativ", "Positiv" };
     220      String[] negativePositive = { "Negativ", "Positiv" };
    218221      for (int plotNo = 0; plotNo < plots.length; plotNo++)
    219222      {
    220         // TODO - the text is from a random number!
    221         String[] options = plotNo == 0 || plotNo == 4 ? lowHigh : positiveNegative;
    222         pdfUtil.addText(options[Math.random() > 0.5 ? 0 : 1], 14, Element.ALIGN_LEFT, PLOT_TEXT_X, yText);
     223        String plot = plots[plotNo];
     224        File plotTxt = new File(workDir, plot+".txt");
     225        float plotScore = parsePlotScore(plotTxt);
     226        String[] options = plotNo == 0 || plotNo == 4 ? lowHigh : negativePositive;
     227        pdfUtil.addText(Float.isNaN(plotScore) ? "N/A" : options[plotScore < 0 ? 0 : 1], 14, Element.ALIGN_LEFT, PLOT_TEXT_X, yText);
    223228        yText -= PLOT_DELTA_Y;
    224229
    225         String plot = plots[plotNo];
    226         File f2 = new File(workDir, plot+".pdf");
    227         if (f2.exists())
     230        File plotPdf = new File(workDir, plot+".pdf");
     231        if (plotPdf.exists())
    228232        {
    229           pdfUtil.importPdf(new FileInputStream(f2), PLOT_X, y, 1.0f, 1.0f);
    230           y -= PLOT_DELTA_Y;
     233          pdfUtil.importPdf(new FileInputStream(plotPdf), PLOT_X, yPlot, 1.0f, 1.0f);
    231234        }
     235        yPlot -= PLOT_DELTA_Y;
    232236      }
    233237     
     
    291295  }
    292296 
     297  private float parsePlotScore(File plotScore)
     298    throws IOException
     299  {
     300    BufferedReader reader = null;
     301    float score = Float.NaN;
     302    if (plotScore.exists())
     303    {
     304      try
     305      {
     306        reader = new BufferedReader(new FileReader(plotScore));
     307        score = (float)Type.FLOAT.parseString(reader.readLine());
     308      }
     309      finally
     310      {
     311        FileUtil.close(reader);
     312      }
     313    }
     314    return score;
     315  }
     316 
    293317  /**
    294318    Add personal information to the pilot report.
Note: See TracChangeset for help on using the changeset viewer.