Changeset 3531


Ignore:
Timestamp:
Oct 5, 2015, 1:27:26 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #812: Pilot report wizard

Prepared the script for sending the FPKM file as input to the pilot report R script.

Location:
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Rawbioassay.java

    r2918 r3531  
    1414import net.sf.basedb.core.DynamicRawDataQuery;
    1515import net.sf.basedb.core.DynamicResultIterator;
     16import net.sf.basedb.core.File;
     17import net.sf.basedb.core.FileSetMember;
    1618import net.sf.basedb.core.ItemQuery;
    1719import net.sf.basedb.core.RawBioAssay;
     
    126128 
    127129  /**
     130    Get the file of the given type.
     131    @since 3.7
     132  */
     133  public File getFile(DbControl dc, Datafiletype fileType)
     134  {
     135    RawBioAssay item = getItem();
     136    File f = null;
     137    if (item.hasFileSet())
     138    {
     139      FileSetMember member = item.getFileSet().getMember(fileType.load(dc));
     140      if (member != null) f = member.getFile();
     141    }
     142    return f;
     143  }
     144 
     145  /**
    128146    Calculate sum of fpkm values for the given genes.
    129147    @return A map with key=gene and value=sum of fpkm
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/pdf/PilotReportWorker.java

    r3528 r3531  
    196196      String[] subtypeNames = { "LumA", "LumB", "HER2", "Basal", "Normal" };
    197197      float[] subtypeScore = new float[5];
    198       float maxVal = Float.NEGATIVE_INFINITY;
     198      int maxIndex = 0;
    199199      for (int i = 0; i < 5; i++)
    200200      {
    201201        subtypeScore[i] = (float)(Math.random()*2-1);
    202         if (subtypeScore[i] > maxVal) maxVal = subtypeScore[i];
     202        if (subtypeScore[i] > subtypeScore[maxIndex]) maxIndex = i;
    203203      }
     204     
    204205      for (int i = 0; i < 5; i++)
    205206      {
    206         if (Float.compare(maxVal, subtypeScore[i]) == 0)
     207        if (i == maxIndex)
    207208        {
    208209          pdfUtil.addBoldText(twoDecimals.format(subtypeScore[i]), 12, Element.ALIGN_LEFT, SUBTYPE_X2+i*SUBTYPE_XX, SUBTYPE_Y2);
     
    215216      }
    216217     
    217      
    218218      // Plots
    219219      float y = PLOT_START_Y;
     
    221221      File workDir = result.getWorkDir();
    222222      String[] lowHigh = { "Låg", "Hög" };
    223       String[] positiveNegative = { "Negative", "Positive" };
     223      String[] positiveNegative = { "Negativ", "Positiv" };
    224224     
    225225      for (int plotNo = 0; plotNo < 5; plotNo++)
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/r/PilotReport.java

    r3506 r3531  
    11package net.sf.basedb.reggie.r;
    22
     3import java.io.FileOutputStream;
    34import java.io.IOException;
     5import java.io.InputStream;
     6import java.io.OutputStream;
    47import java.util.ArrayList;
    58import java.util.Arrays;
     
    710import java.util.Map;
    811
    9 
     12import net.sf.basedb.core.DataFileType;
    1013import net.sf.basedb.core.DbControl;
     14import net.sf.basedb.core.File;
     15import net.sf.basedb.core.ItemNotFoundException;
    1116import net.sf.basedb.reggie.Reggie;
    1217import net.sf.basedb.reggie.XmlConfig;
     18import net.sf.basedb.reggie.dao.Datafiletype;
    1319import net.sf.basedb.reggie.dao.Rawbioassay;
    1420import net.sf.basedb.reggie.pdf.PdfUtil;
     21import net.sf.basedb.util.FileUtil;
    1522import net.sf.basedb.util.Values;
    1623
     
    102109  public Result run(DbControl dc, Rawbioassay raw)
    103110  {
     111    File fpkmFile = raw.getFile(dc, Datafiletype.FPKM);
     112    if (fpkmFile == null)
     113    {
     114      throw new ItemNotFoundException(Datafiletype.FPKM.getName() + " for raw bioassay " + raw.getName());
     115    }
    104116       
    105117    // Calculate sum(fpkm) for given genes
     
    115127    String values = Values.getString(v, ",", true);
    116128    String caseName = checkValidScriptParameter(raw.getName());
     129   
    117130    scanB.setParameter("value", "c(" + values + ")");
    118131    scanB.setParameter("case", "'"+caseName+"'");
    119 
    120     Result result = run(new Result(raw, genes));
     132    scanB.setParameter("fpkm", "'${workdir}/"+fpkmFile.getName()+"'");
     133   
     134    Result result = run(new Result(raw, fpkmFile, genes));
    121135    return result;
    122136  }
     
    126140  {
    127141    public final Rawbioassay raw;
     142    public final File fpkmFile;
    128143    public final List<String> genes;
    129144   
     
    131146      Creates a new result object for the given raw bioassay.
    132147    */
    133     public Result(Rawbioassay raw, List<String> genes)
     148    public Result(Rawbioassay raw, File fpkmFile, List<String> genes)
    134149    {
    135150      super();
    136151      this.raw = raw;
     152      this.fpkmFile = fpkmFile;
    137153      this.genes = genes;
     154    }
     155
     156    @Override
     157    protected void loadFilesToWorkDir()
     158      throws IOException
     159    {
     160      InputStream in = null;
     161      OutputStream out = null;
     162      try
     163      {
     164        in = fpkmFile.getDownloadStream(0);
     165        out = new FileOutputStream(new java.io.File(getWorkDir(), fpkmFile.getName()));
     166        FileUtil.copy(in, out);
     167      }
     168      finally
     169      {
     170        FileUtil.close(in);
     171        FileUtil.close(out);
     172      }
    138173    }
    139174   
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/r/RResult.java

    r3506 r3531  
    22
    33import java.io.File;
     4import java.io.IOException;
    45
    56import net.sf.basedb.util.FileUtil;
     
    7879    }
    7980  }
     81 
     82  /**
     83    Called before the script is started and allows the
     84    result object to upload files that are needed by
     85    the script to the working directory.
     86  */
     87  protected void loadFilesToWorkDir()
     88    throws IOException
     89  {}
    8090 
    8191  void setExitStatus(int exitStatus)
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/r/RScriptDefinition.java

    r3506 r3531  
    128128    }
    129129   
    130     if (logger.isDebugEnabled())
    131     {
    132       logger.debug("Running R: " + rCmd.toString());
    133     }
    134    
    135130    String rscript_path = Reggie.getConfig().getRequiredConfig("rscript/path", null);
    136     ProcessBuilder builder = new ProcessBuilder(
    137       rscript_path,
    138       "-e",
    139       rCmd.toString()
    140     );
    141131
    142     System.out.println("Calling: " + rCmd.toString());
    143    
    144132    try
    145133    {
     
    157145        isGenerated = true;
    158146      }
     147     
     148      // Replace ${workdir} with current working directory
     149      String cmd = rCmd.toString().replace("${workdir}", dir.getAbsolutePath().replace('\\', '/'));
    159150      if (logger.isDebugEnabled())
    160151      {
     152        logger.debug("Running R: " + cmd);
    161153        logger.debug("Working directory: " + dir);
    162154      }
    163 
     155     
     156      ProcessBuilder builder = new ProcessBuilder(rscript_path, "-e", cmd);
    164157      builder.directory(dir);
    165158      result.setWorkDir(dir, isGenerated);
     159      result.loadFilesToWorkDir();
    166160     
    167161      Process proc = builder.start();
Note: See TracChangeset for help on using the changeset viewer.