Changeset 998
- Timestamp:
- Mar 27, 2009, 11:05:43 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/qQuantileNormalization.java
r993 r998 52 52 import java.io.FileReader; // Jari, remove this? 53 53 import java.io.IOException; 54 import java.io.PrintWriter; // Jari, remove this? 54 55 import java.sql.SQLException; 55 56 import java.util.EnumSet; … … 101 102 102 103 104 105 // This function will be rewritten when the BASE core plug-in 106 // BioAssaySetExporter is refactored, see tickets 107 // http://base.thep.lu.se/ticket/742, 108 // http://base.thep.lu.se/ticket/1256, and 109 // http://baseplugins.thep.lu.se/ticket/183. 110 private void exportData() 111 throws IOException 112 { 113 if (debug_output) System.err.println("qQN: exportData()"); 114 FileOutputStream os = new FileOutputStream(new File(getExecDirectory(), 115 subprocess_stdin)); 116 BioAssaySetExporter base=new BioAssaySetExporter(); 117 try 118 { 119 base.exportPlainMatrix(sourceBAS, os, null); 120 } 121 catch (SQLException e) 122 { 123 e.printStackTrace(); 124 // response.setError(e.getMessage(), Arrays.asList(e)); 125 } 126 127 // creating a meta-data file to track the information in the plain 128 // matrix file created above. This will be removed when BASE 129 // BioAssaySetExporter is refactored. Of course, the current 130 // meta-data file is highly specific for the needs here, but this 131 // use case should be covered hete. Or, way not fall back on a 132 // BASEfile? 133 134 // The query must be the same as the one done in BASE core plug-in 135 // BioAssaySetExporter::exportPlainMatrix. This will be removed 136 // when http://base.thep.lu.se/ticket/1256 and consequently 137 // http://baseplugins.thep.lu.se/ticket/183 are fixed. 138 DbControl dc=sc.newDbControl(); 139 DynamicSpotQuery query=sourceBAS.getSpotData(); 140 query.select(Dynamic.select(VirtualColumn.POSITION)); 141 query.select(Dynamic.select(VirtualColumn.COLUMN)); 142 int nof_channels=sourceBAS.getRawDataType().getChannels(); 143 for (int i=1; i<=nof_channels; ++i) 144 query.select(Dynamic.select(VirtualColumn.channel(i))); 145 query.order(Orders.asc(Dynamic.column(VirtualColumn.POSITION))); 146 query.order(Orders.asc(Dynamic.column(VirtualColumn.COLUMN))); 147 try { 148 DynamicResultIterator spotData = query.iterate(dc); 149 int column_position=spotData.getIndex(VirtualColumn.POSITION.getName()); 150 int[] column_channel=new int[nof_channels]; 151 for (int i=0; i<nof_channels; ++i) 152 column_channel[i]=spotData.getIndex(VirtualColumn.channel(i+1).getName()); 153 154 PrintWriter output = new PrintWriter(getExecDirectory() + 155 java.io.File.separator + metadata); 156 157 // first line in meta data is assay column numbers in BASE data cube 158 List<BioAssay> sourceAssays = sourceBAS.getBioAssays().list(dc); 159 int nofAssays=sourceAssays.size(); 160 for (int i=0; i<nofAssays; ++i) 161 { 162 if (i>0) output.print('\t'); 163 output.print(sourceAssays.get(i).getDataCubeColumnNo()); 164 } 165 output.println(); 166 167 // write positions needed for storing result in BASE. 168 int position=0; 169 while (spotData.hasNext()) 170 { 171 int prev_position=position; 172 SqlResult item = spotData.next(); 173 position=item.getInt(column_position); 174 if (position!=prev_position) output.println(position); 175 } 176 output.close(); 177 } 178 catch (SQLException e) 179 { 180 // response.setError(e.getMessage(), Arrays.asList(e)); 181 throw new BaseException(e); 182 } 183 finally 184 { 185 if (dc != null) 186 dc.close(); 187 } 188 } 189 190 103 191 protected void runBinary() 104 192 throws InterruptedException, IOException 105 193 { 106 if (debug_output) System.err.println("runBinary(qQN)"); 107 try 108 { 109 subprocess_stdin="in.data"; 110 subprocess_stdout="out.data"; 111 FileOutputStream os = new FileOutputStream(new File(getExecDirectory(), 112 subprocess_stdin)); 113 BioAssaySetExporter base=new BioAssaySetExporter(); 114 base.exportPlainMatrix(sourceBAS, os, null); 115 String[] cmd = { "qQN" }; 116 execute(cmd); 117 } 118 catch (SQLException e) 119 { 120 e.printStackTrace(); 121 // response.setError(e.getMessage(), Arrays.asList(e)); 122 } 194 if (debug_output) System.err.println("qQN: runBinary()"); 195 subprocess_stdin="in.data"; 196 subprocess_stdout="out.data"; 197 metadata="meta.data"; 198 exportData(); 199 String[] cmd = { "qQN" }; 200 execute(cmd); 123 201 } 124 202 … … 146 224 SpotBatcher batcher = child.getSpotBatcher(); 147 225 148 // The query must be the same as the one done in BASE core 149 // plug-in BioAssaySetExporter::exportPlainMatrix. This will be 150 // removed when http://base.thep.lu.se/ticket/1256 and 151 // consequently http://baseplugins.thep.lu.se/ticket/183 are 152 // fixed. 153 DynamicSpotQuery query=sourceBAS.getSpotData(); 154 query.select(Dynamic.select(VirtualColumn.POSITION)); 155 query.select(Dynamic.select(VirtualColumn.COLUMN)); 156 int nof_channels=sourceBAS.getRawDataType().getChannels(); 157 for (int i=1; i<=nof_channels; ++i) 158 query.select(Dynamic.select(VirtualColumn.channel(i))); 159 query.order(Orders.asc(Dynamic.column(VirtualColumn.POSITION))); 160 query.order(Orders.asc(Dynamic.column(VirtualColumn.COLUMN))); 161 DynamicResultIterator spotData = query.iterate(dc); 162 int column_position=spotData.getIndex(VirtualColumn.POSITION.getName()); 163 int[] column_channel=new int[nof_channels]; 164 for (int i=0; i<nof_channels; ++i) 165 column_channel[i]=spotData.getIndex(VirtualColumn.channel(i+1).getName()); 166 167 List<BioAssay> sourceAssays = sourceBAS.getBioAssays().list(dc); 168 int nofAssays=sourceAssays.size(); 169 short[] column=new short[nofAssays]; 170 for (int i=0; i<nofAssays; ++i) 171 column[i]=sourceAssays.get(i).getDataCubeColumnNo(); 172 226 BufferedReader metainput = 227 new BufferedReader(new FileReader(getExecDirectory() + 228 java.io.File.separator + metadata)); 173 229 BufferedReader input = 174 230 new BufferedReader(new FileReader(getExecDirectory() + 175 231 java.io.File.separator + 176 232 subprocess_stdout)); 177 String line; 178 int position=0; 179 while ((line = input.readLine()) != null) 233 234 // first line in meta data is assay column numbers in BASE data cube 235 String inputline=metainput.readLine(); 236 String[] lineSplit = inputline.split("\\s"); 237 Short[] column=new Short[lineSplit.length]; 238 for (int i=0; i<lineSplit.length; ++i) 239 column[i]=Short.parseShort(lineSplit[i]); 240 while ((inputline = input.readLine()) != null) 180 241 { 181 int prev_position=position; 182 while (position==prev_position) 183 { 184 if (!spotData.hasNext()) 185 throw new BaseException("File/database size mismatch"); 186 SqlResult item = spotData.next(); 187 position=item.getInt(column_position); 188 } 189 String[] lineSplit = line.split("\\s"); 190 if (lineSplit.length != nofAssays) 242 lineSplit = inputline.split("\\s"); 243 if (lineSplit.length != column.length) 191 244 throw new BaseException("File/bioassay set size mismatch"); 192 for (int i=0; i<nofAssays; ++i) 245 if ((inputline = metainput.readLine()) == null) 246 throw new BaseException("Data and result file size mismatch"); 247 int position = Integer.parseInt(inputline); 248 for (int i=0; i<column.length; ++i) 193 249 { 194 250 // C/C++ style string nan's (Java expects NaN) will cause a
Note: See TracChangeset
for help on using the changeset viewer.