Changeset 2481
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/util/parser/FlatFileParser.java
r2409 r2481 797 797 throws IOException 798 798 { 799 if (nextData == null && nextSection == null)799 if (nextData == null) 800 800 { 801 801 boolean done = false; -
trunk/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java
r2462 r2481 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 */2 $Id$ 3 4 Copyright (C) 2006 Johan Enell 5 6 This file is part of BASE - BioArray Software Environment. 7 Available at http://base.thep.lu.se/ 8 9 BASE is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 2 12 of the License, or (at your option) any later version. 13 14 BASE is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 59 Temple Place - Suite 330, 22 Boston, MA 02111-1307, USA. 23 */ 24 24 25 25 package net.sf.basedb.plugins; … … 49 49 import net.sf.basedb.core.PluginConfiguration; 50 50 import net.sf.basedb.core.PluginParameter; 51 import net.sf.basedb.core.PositionBatcher; 51 52 import net.sf.basedb.core.ProgressReporter; 52 53 import net.sf.basedb.core.RawBioAssay; … … 103 104 { 104 105 /** 105 Plugin description106 * Plugin description 106 107 */ 107 108 private static final About about = new AboutImpl( … … 117 118 118 119 /** 119 Parameter definition that asks for the file that should be imported.120 Thisis a required parameter for the job configuration.120 * Parameter definition that asks for the file that should be imported. This 121 * is a required parameter for the job configuration. 121 122 */ 122 123 private static final PluginParameter<File> fileParameter = new PluginParameter<File>( … … 132 133 new StringParameterType(255, null, true)); 133 134 134 /** File configuration parameters * */135 /** File configuration parameters * */ 135 136 private static final String serialFormatParameterName = "serialFormat"; 136 137 … … 153 154 private static final String usedFieldsParameterName = "usedFields"; 154 155 155 /** **/156 157 /** Job parameters * */156 /** * */ 157 158 /** Job parameters * */ 158 159 private static final PluginParameter<BioAssaySet> bioAssaySetParameter = new PluginParameter<BioAssaySet>( 159 160 "bioAssaySet", … … 164 165 private static final String pluginDirectoryParameterName = "pluginDirectory"; 165 166 166 /** **/167 /** * */ 167 168 168 169 private static final String PARSE_CONFIG_FILE = "PARSE_CONFIG_FILE"; … … 175 176 176 177 /** 177 This list holds the job parameters derived from the configuration file.178 * This list holds the job parameters derived from the configuration file. 178 179 */ 179 180 private List<PluginParameter<?>> jobParameters; 180 181 181 182 /** 182 This list holds the configure parameters derived from the headers in the configuration file. 183 * This list holds the configure parameters derived from the headers in the 184 * configuration file. 183 185 */ 184 186 private List<PluginParameter<?>> configureFileParameters; 185 187 186 188 /** 187 This is the directory where the plugin will generate its output.189 * This is the directory where the plugin will generate its output. 188 190 */ 189 191 private java.io.File execDirectory; … … 215 217 int channels = bas.getRawDataType().getChannels(); 216 218 217 // int maxChannels = (Integer) configuration.getValue(maxChannelsParameterName); 218 // int minChannels = (Integer) configuration.getValue(minChannelsParameterName); 219 // if (channels <= minChannels || (channels > maxChannels && maxChannels != 0)) 220 // { 221 // message = about.getName() + " can not work on " + channels + "-channel data."; 222 // } 219 // int maxChannels = (Integer) 220 // configuration.getValue(maxChannelsParameterName); 221 // int minChannels = (Integer) 222 // configuration.getValue(minChannelsParameterName); 223 // if (channels <= minChannels || (channels > maxChannels && 224 // maxChannels != 0)) 225 // { 226 // message = about.getName() + " can not work on " + channels + 227 // "-channel data."; 228 // } 223 229 } 224 230 return message; … … 324 330 325 331 FileOutputStream out = new FileOutputStream(new java.io.File(getExecDirectory(), "stdout.txt")); 326 StreamHandler inputStream = new StreamHandler( 327 new BufferedInputStream(p.getInputStream()), 328 new BufferedOutputStream(out)); 332 StreamHandler inputStream = new StreamHandler(new BufferedInputStream(p.getInputStream()), new BufferedOutputStream(out)); 329 333 330 334 java.io.File stdin = createStdin(dc, source); … … 337 341 outputStream.start(); 338 342 int exitValue = p.waitFor(); 339 343 344 err.flush(); 345 out.close(); 340 346 if (exitValue == 0) 341 347 { 342 out.close();343 348 dc.reattachItem(source); 344 349 Transformation t = source.newTransformation(Job.getById(dc, job.getId())); 345 350 t.setName("Something---"); 346 BioAssaySet bas = t.newProduct(null, "new");347 bas.setName("Something after");348 351 dc.saveItem(t); 349 dc.saveItem(bas); 350 351 createNewBioAssaySet(dc, bas); 352 353 createNewBioAssaySet(dc, t); 352 354 353 355 response.setDone(err.toString()); … … 355 357 else 356 358 { 357 err.flush();358 359 response.setError("Process ended with error: " + exitValue + "\n" + err, null); 359 360 } 360 361 361 362 importTempFiles(dc, getExecDirectory().listFiles(), getPluginDirectory(dc)); 362 363 getExecDirectory().delete(); 364 //TODO: remove stdin.txt and stdout.txt if flags are true 363 365 dc.commit(); 364 366 } … … 388 390 ffp.setDataHeaderRegexp(Pattern.compile("%")); 389 391 ffp.setDataSplitterRegexp(Pattern.compile("\\t")); 390 ffp.setMinDataColumns(8); 391 ffp.setMaxDataColumns(8); 392 392 393 393 ffp.setInputStream(stream); 394 394 return ffp; … … 518 518 519 519 FlatFileParser ffp = getInitializedFlatFileParser(f.getDownloadStream(0)); 520 ffp.setMinDataColumns(8); 520 521 521 522 FlatFileParser.Line section = ffp.nextSection(); … … 548 549 switch (dataline.get(valueTypeCol).charAt(0)) 549 550 { 550 // String parameter551 // String parameter 551 552 case 't': 552 553 { … … 556 557 break; 557 558 } 558 // Integer parameter559 // Integer parameter 559 560 case 'i': 560 561 { … … 565 566 break; 566 567 } 567 // HiddenString parameter568 // HiddenString parameter 568 569 case 'h': 569 570 { … … 573 574 break; 574 575 } 575 // Float parameter576 // Float parameter 576 577 case 'f': 577 578 { … … 582 583 break; 583 584 } 584 // TextField parameter585 // TextField parameter 585 586 case 'a': 586 587 { … … 597 598 break; 598 599 } 599 // Annotation parameter600 // Annotation parameter 600 601 case 'n': 601 602 { … … 603 604 break; 604 605 } 605 // Enum Parameter606 // Enum Parameter 606 607 case 'e': 607 608 { … … 698 699 } 699 700 700 private void createNewBioAssaySet(DbControl dc, BioAssaySet bas)701 private void createNewBioAssaySet(DbControl dc, Transformation t) 701 702 throws IOException 702 703 { 703 SpotBatcher batcher = bas.getSpotBatcher(); 704 705 // File stdout = File.getFile(dc, getPluginDirectory(dc),"stdout.txt", false); 706 HashMap<Integer, BioAssay> idMap = new HashMap<Integer, BioAssay>(); 704 BioAssaySet bas = null; 705 SpotBatcher spotBatcher = null; 706 PositionBatcher posBatcher = null; 707 708 HashMap<String, BioAssay> idMap = new HashMap<String, BioAssay>(); 707 709 708 710 FlatFileParser ffp = getInitializedFlatFileParser(new FileInputStream(new java.io.File(getExecDirectory(), "stdout.txt"))); … … 711 713 FlatFileParser.Line section = ffp.nextSection(); 712 714 ffp.parseHeaders(); 715 713 716 if (section.name().equals("assays")) 714 717 { 718 bas = t.newProduct("new", "new"); 719 bas.setName("Something after"); 720 dc.saveItem(bas); 721 715 722 List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t")); 716 723 int idCol = columns.indexOf("id"); … … 718 725 int parentCol = columns.indexOf("parents"); 719 726 720 if (parentCol > -1 && nameCol > -1 && idCol > -1) 721 { 722 while (ffp.hasMoreData()) 723 { 724 FlatFileParser.Data dataline = ffp.nextData(); 725 Integer id = new Integer(dataline.get(idCol)); 726 String name = dataline.get(nameCol); 727 String[] parentIds = dataline.get(parentCol).split("/"); 728 Set<BioAssay> balist = new HashSet<BioAssay>(parentIds.length); 727 ffp.setMinDataColumns(columns.size()); 728 729 while (ffp.hasMoreData()) 730 { 731 FlatFileParser.Data dataline = ffp.nextData(); 732 733 String id = dataline.get(idCol); 734 String name = dataline.get(nameCol); 735 Set<BioAssay> baParents; 736 if (parentCol > -1) 737 { 738 String[] parentIds; 739 parentIds = dataline.get(parentCol).split("/"); 740 baParents = new HashSet<BioAssay>(parentIds.length); 729 741 for (String parent : parentIds) 730 742 { 731 ba list.add(BioAssay.getById(dc, new Integer(parent)));743 baParents.add(BioAssay.getById(dc, new Integer(parent))); 732 744 } 733 BioAssay ba = bas.newBioAssay(balist); 734 ba.setName(name); 735 dc.saveItem(ba); 736 idMap.put(id, ba); 737 } 738 } 739 else if (nameCol > -1 && idCol > -1) 740 { 741 while (ffp.hasMoreData()) 742 { 743 FlatFileParser.Data dataline = ffp.nextData(); 744 Integer id = new Integer(dataline.get(idCol)); 745 String name = dataline.get(nameCol); 746 BioAssay ba = bas.newBioAssay(BioAssay.getById(dc, id)); 747 ba.setName(name); 748 dc.saveItem(ba); 749 idMap.put(id, ba); 750 } 745 } 746 else 747 { 748 baParents = Collections.singleton(BioAssay.getById(dc, Integer.parseInt(id))); 749 } 750 BioAssay ba = bas.newBioAssay(baParents); 751 ba.setName(name); 752 dc.saveItem(ba); 753 idMap.put(id, ba); 751 754 } 752 755 } 753 756 else if (section.name().equals("spots")) 754 757 { 755 758 spotBatcher = bas.getSpotBatcher(); // TODO: BioAssaySet can be null 756 759 List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t")); 757 760 List<String> assays = Arrays.asList(ffp.getHeader("assays").split("\\t")); 758 761 List<String> assayFields = Arrays.asList(ffp.getHeader("assayFields").split("\\t")); 759 762 763 ffp.setMinDataColumns(columns.size() - 1 + assays.size() * assayFields.size()); 764 ffp.setUseNullIfEmpty(false); 765 760 766 int posCol = columns.indexOf("position"); 761 767 int repCol = columns.indexOf("reporter"); 762 int dataCol = columns.indexOf("assa tData");768 int dataCol = columns.indexOf("assayData"); 763 769 int int1Col = assayFields.indexOf("intensity1"); 764 770 int int2Col = assayFields.indexOf("intensity2"); … … 767 773 boolean intCols = false; 768 774 769 if (int1Col > -1 && int2Col > -1) 770 { 771 intCols = true; 772 } 773 else if (mCol > -1 && aCol > -1) 774 { 775 intCols = false; 775 if (dataCol > -1) 776 { 777 if (int1Col > -1 && int2Col > -1) 778 { 779 intCols = true; 780 int1Col += dataCol; 781 int2Col += dataCol; 782 } 783 else if (mCol > -1 && aCol > -1) 784 { 785 intCols = false; 786 mCol += dataCol; 787 aCol += dataCol; 788 } 789 else 790 { 791 throw new BaseException( 792 "Can't find the columns intensity1/intensity2 or l2ratio1_2/l10intgmean1_2. No data could be inmported."); 793 } 776 794 } 777 795 else 778 796 { 779 throw new BaseException( 780 "Can't find the columns intensity1/intensity2 or l2ratio1_2/l10intgmean1_2. No data could be inmported."); 781 } 782 783 int1Col += dataCol; 784 int2Col += dataCol; 785 797 throw new BaseException("Can't find the column 'assayData' in header assayFields."); 798 } 799 786 800 while (ffp.hasMoreData()) 787 801 { 788 802 FlatFileParser.Data dataline = ffp.nextData(); 789 for (int i = 0; i < assays.size(); i++) 790 { 791 String assayId = assays.get(i); 803 for (String assayId : assays) 804 { 792 805 BioAssay ba = idMap.get(assayId); 793 806 … … 795 808 float int2; 796 809 797 if (intCols)810 try 798 811 { 799 int1 = Float.parseFloat(dataline.get(int1Col)); 800 int2 = Float.parseFloat(dataline.get(int2Col)); 812 int position = Integer.parseInt(dataline.get(posCol)); 813 if (intCols) 814 { 815 int1 = Float.parseFloat(dataline.get(int1Col)); 816 int2 = Float.parseFloat(dataline.get(int2Col)); 817 } 818 else 819 { 820 double a = Double.parseDouble(dataline.get(aCol)); 821 double m = Double.parseDouble(dataline.get(mCol)); 822 823 // int2 = 10^a / 2^(0.5*m) 824 // int1 = int2 * 2^m 825 int2 = (float) (Math.pow(10, a) / Math.pow(2, 0.5 * m)); 826 int1 = (float) (int2 * Math.pow(2, m)); 827 } 828 829 if (!Float.isNaN(int1) && !Float.isNaN(int2)) 830 { 831 spotBatcher.insert(ba.getDataCubeColumnNo(), position, int1, int2); 832 } 801 833 } 802 else 803 { 804 float a = Float.parseFloat(dataline.get(aCol)); 805 float m = Float.parseFloat(dataline.get(mCol)); 806 807 // int2 = 10^a / 2^(0.5*m) 808 // int1 = int2 * 2^m 809 int2 = (float) (Math.pow(10, a) / Math.pow(2, 0.5 * m)); 810 int1 = (float) (int2 * Math.pow(2, m)); 811 } 812 813 batcher.insert(ba.getDataCubeColumnNo(), 1, int1, int2); 814 } 815 } 816 } 817 } 818 batcher.close(); 834 catch (NumberFormatException e) 835 {} 836 } 837 } 838 } 839 } 819 840 } 820 841 … … 862 883 { 863 884 out.println(ba.getId() + "\t" + ba.getName()); 864 // TODO print annotations885 // TODO print annotations 865 886 } 866 887 out.println(); … … 874 895 fields.retainAll(base1columns.keySet()); 875 896 876 String fieldString 877 String columnString = columns.toString().substring(1, columns.toString().length() - 1).replace(", ", "\t") +"\tassayData";897 String fieldString = fields.toString().substring(1, fields.toString().length() - 1).replace(", ", "\t"); 898 String columnString = columns.toString().substring(1, columns.toString().length() - 1).replace(", ", "\t") + "\tassayData"; 878 899 String spotHeader = "section\tspots" + "\nchannels\t" + bas.getRawDataType().getChannels() + "\nassayFields\t" + fieldString + "\ncolumns\t" + columnString; 879 900 if (configuration.getValue(serialFormatParameterName).equals("1")) … … 965 986 base1columns.put("vector", Selects.expression(Dynamic.reporter("vector"), "vector")); 966 987 967 // Spot fields988 // Spot fields 968 989 base1columns.put("intensity1", Selects.expression(Dynamic.column(VirtualColumn.channel(1)), "intensity1")); 969 990 base1columns.put("intensity2", Selects.expression(Dynamic.column(VirtualColumn.channel(2)), "intensity2")); … … 991 1012 Dynamic.column(VirtualColumn.channel(2))), "ratio1_2")); 992 1013 993 // Rawdata fields1014 // Rawdata fields 994 1015 base1columns.put("BCh1Mean", Selects.expression(Dynamic.rawData("ch1BgMean"), "BCh1Mean")); 995 1016 base1columns.put("BCh1Median", Selects.expression(Dynamic.rawData("ch1BgMedian"), "BCh1Median")); … … 1048 1069 1049 1070 /* 1050 CCh1Mean 1051 CCh1Median 1052 CCh2Mean 1053 CCh2Median 1054 MeanRatio 1055 MedianRatio 1071 * CCh1Mean CCh1Median CCh2Mean CCh2Median MeanRatio MedianRatio 1056 1072 */ 1057 1073 … … 1093 1109 private void importTempFiles(DbControl dc, java.io.File[] files, Directory d) 1094 1110 { 1111 // TODO: associate file with job 1095 1112 for (java.io.File f : files) 1096 1113 {
Note: See TracChangeset
for help on using the changeset viewer.