Changeset 3531
- Timestamp:
- Oct 5, 2015, 1:27:26 PM (7 years ago)
- 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 14 14 import net.sf.basedb.core.DynamicRawDataQuery; 15 15 import net.sf.basedb.core.DynamicResultIterator; 16 import net.sf.basedb.core.File; 17 import net.sf.basedb.core.FileSetMember; 16 18 import net.sf.basedb.core.ItemQuery; 17 19 import net.sf.basedb.core.RawBioAssay; … … 126 128 127 129 /** 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 /** 128 146 Calculate sum of fpkm values for the given genes. 129 147 @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 196 196 String[] subtypeNames = { "LumA", "LumB", "HER2", "Basal", "Normal" }; 197 197 float[] subtypeScore = new float[5]; 198 float maxVal = Float.NEGATIVE_INFINITY;198 int maxIndex = 0; 199 199 for (int i = 0; i < 5; i++) 200 200 { 201 201 subtypeScore[i] = (float)(Math.random()*2-1); 202 if (subtypeScore[i] > maxVal) maxVal = subtypeScore[i];202 if (subtypeScore[i] > subtypeScore[maxIndex]) maxIndex = i; 203 203 } 204 204 205 for (int i = 0; i < 5; i++) 205 206 { 206 if ( Float.compare(maxVal, subtypeScore[i]) == 0)207 if (i == maxIndex) 207 208 { 208 209 pdfUtil.addBoldText(twoDecimals.format(subtypeScore[i]), 12, Element.ALIGN_LEFT, SUBTYPE_X2+i*SUBTYPE_XX, SUBTYPE_Y2); … … 215 216 } 216 217 217 218 218 // Plots 219 219 float y = PLOT_START_Y; … … 221 221 File workDir = result.getWorkDir(); 222 222 String[] lowHigh = { "Låg", "Hög" }; 223 String[] positiveNegative = { "Negativ e", "Positive" };223 String[] positiveNegative = { "Negativ", "Positiv" }; 224 224 225 225 for (int plotNo = 0; plotNo < 5; plotNo++) -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/r/PilotReport.java
r3506 r3531 1 1 package net.sf.basedb.reggie.r; 2 2 3 import java.io.FileOutputStream; 3 4 import java.io.IOException; 5 import java.io.InputStream; 6 import java.io.OutputStream; 4 7 import java.util.ArrayList; 5 8 import java.util.Arrays; … … 7 10 import java.util.Map; 8 11 9 12 import net.sf.basedb.core.DataFileType; 10 13 import net.sf.basedb.core.DbControl; 14 import net.sf.basedb.core.File; 15 import net.sf.basedb.core.ItemNotFoundException; 11 16 import net.sf.basedb.reggie.Reggie; 12 17 import net.sf.basedb.reggie.XmlConfig; 18 import net.sf.basedb.reggie.dao.Datafiletype; 13 19 import net.sf.basedb.reggie.dao.Rawbioassay; 14 20 import net.sf.basedb.reggie.pdf.PdfUtil; 21 import net.sf.basedb.util.FileUtil; 15 22 import net.sf.basedb.util.Values; 16 23 … … 102 109 public Result run(DbControl dc, Rawbioassay raw) 103 110 { 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 } 104 116 105 117 // Calculate sum(fpkm) for given genes … … 115 127 String values = Values.getString(v, ",", true); 116 128 String caseName = checkValidScriptParameter(raw.getName()); 129 117 130 scanB.setParameter("value", "c(" + values + ")"); 118 131 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)); 121 135 return result; 122 136 } … … 126 140 { 127 141 public final Rawbioassay raw; 142 public final File fpkmFile; 128 143 public final List<String> genes; 129 144 … … 131 146 Creates a new result object for the given raw bioassay. 132 147 */ 133 public Result(Rawbioassay raw, List<String> genes)148 public Result(Rawbioassay raw, File fpkmFile, List<String> genes) 134 149 { 135 150 super(); 136 151 this.raw = raw; 152 this.fpkmFile = fpkmFile; 137 153 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 } 138 173 } 139 174 -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/r/RResult.java
r3506 r3531 2 2 3 3 import java.io.File; 4 import java.io.IOException; 4 5 5 6 import net.sf.basedb.util.FileUtil; … … 78 79 } 79 80 } 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 {} 80 90 81 91 void setExitStatus(int exitStatus) -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/r/RScriptDefinition.java
r3506 r3531 128 128 } 129 129 130 if (logger.isDebugEnabled())131 {132 logger.debug("Running R: " + rCmd.toString());133 }134 135 130 String rscript_path = Reggie.getConfig().getRequiredConfig("rscript/path", null); 136 ProcessBuilder builder = new ProcessBuilder(137 rscript_path,138 "-e",139 rCmd.toString()140 );141 131 142 System.out.println("Calling: " + rCmd.toString());143 144 132 try 145 133 { … … 157 145 isGenerated = true; 158 146 } 147 148 // Replace ${workdir} with current working directory 149 String cmd = rCmd.toString().replace("${workdir}", dir.getAbsolutePath().replace('\\', '/')); 159 150 if (logger.isDebugEnabled()) 160 151 { 152 logger.debug("Running R: " + cmd); 161 153 logger.debug("Working directory: " + dir); 162 154 } 163 155 156 ProcessBuilder builder = new ProcessBuilder(rscript_path, "-e", cmd); 164 157 builder.directory(dir); 165 158 result.setWorkDir(dir, isGenerated); 159 result.loadFilesToWorkDir(); 166 160 167 161 Process proc = builder.start();
Note: See TracChangeset
for help on using the changeset viewer.