Changeset 3469


Ignore:
Timestamp:
Jun 8, 2007, 4:54:32 PM (16 years ago)
Author:
Johan Enell
Message:

Fixes #606
Fixes #622

Location:
branches/2.3.1/src/plugins/core/net/sf/basedb/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.3.1/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java

    r3462 r3469  
    7272import net.sf.basedb.core.query.Orders;
    7373import net.sf.basedb.util.Enumeration;
    74 import net.sf.basedb.util.RemovableUtil;
    7574import net.sf.basedb.util.XMLUtil;
    7675import net.sf.basedb.util.parser.FlatFileParser;
     
    469468      try
    470469      {
    471         id = Directory.getIdFromPath(dc, path);
    472470        // delete existing
    473         RemovableUtil.removeRecursively(dc, Item.DIRECTORY, Collections.singleton(id), true);
     471        deleteDir(dc, path);
    474472        dc.commit();
    475473        dc = sc.newDbControl();
     
    513511    return dir.delete();
    514512  }
    515    
     513 
     514 
     515  /**
     516   * Deletes all files and subdirectories under dir.
     517   *
     518   * @param dc
     519   * @param dirId
     520   * @return Returnes true if all deletions were succssful
     521   */
     522  private boolean deleteDir(DbControl dc, Path dir)
     523  {
     524    if (dir.getType() == Path.Type.DIRECTORY)
     525    {
     526      Directory d = Directory.getByPath(dc, dir);
     527      for (File f : d.getFiles().list(dc))
     528      {
     529        dc.deleteItem(f);
     530      }
     531      for (Directory subD : d.getSubDirectories().list(dc))
     532      {
     533        if (!deleteDir(dc, subD.getPath()))
     534        {
     535          return false;
     536        }
     537      }
     538      try
     539      {
     540        dc.deleteItem(d);
     541        return true;
     542      }
     543      catch(BaseException e)
     544      {
     545        return false;
     546      }
     547    }
     548    return false;
     549  }
    516550
    517551  @Override
     
    559593    if (command.equals(Request.COMMAND_EXECUTE))
    560594    {
    561       DbControl dc = sc.newDbControl();
    562       int tId = -1;
     595      DbControl dc = null;
    563596      try
    564597      {
     598        dc = sc.newDbControl();
    565599        getManualConfigureParameters();
    566600        getConfigureJobParameters();
    567         progress.display(0, "Exporting data to be used by plugin.");
    568         File stdin = exportData(dc);
    569         copy(stdin, getExecDirectory());
     601 
     602        Transformation trans = null;
     603        File stdin = null;
    570604       
     605        //Export
     606        try
     607        {
     608          BioAssaySet parentBas = getSourceBioAssaySet(dc);
     609          trans = parentBas.newTransformation(Job.getById(dc, job.getId()));
     610          trans.setName(PluginConfiguration.getById(dc, configuration.getId()).getName());
     611          dc.saveItem(trans);
     612          progress.display(0, "Exporting data to be used by plugin.");
     613          stdin = File.getById(dc, exportData());
     614 
     615          copy(stdin, getExecDirectory());
     616        }
     617        catch(Exception e)
     618        {
     619          response.setError("Error during export", Arrays.asList(e));
     620          return;
     621        }
    571622       
    572         progress.display(10, "Running on remote computation server.");
    573         Process p = Runtime.getRuntime().exec(getExecLine(), null, getExecDirectory());
    574 
    575         ByteArrayOutputStream err = new ByteArrayOutputStream();
    576         StreamHandler errorStream = new StreamHandler(new BufferedInputStream(p.getErrorStream()), new BufferedOutputStream(err));
    577 
    578         FileOutputStream out = new FileOutputStream(new java.io.File(getExecDirectory(), "stdout.txt"));
    579         StreamHandler inputStream = new StreamHandler(new BufferedInputStream(p.getInputStream()), new BufferedOutputStream(out));
    580        
    581         StreamHandler outputStream = new StreamHandler(new BufferedInputStream(stdin.getDownloadStream(0)), new BufferedOutputStream(p.getOutputStream()));
    582        
    583         inputStream.start();
    584         errorStream.start();
    585         outputStream.start();
    586         int exitValue = p.waitFor();
    587         err.flush();
    588         out.close();
    589        
    590         if (exitValue == 0)
     623        //Execution
     624        String msg = "";
     625        try
     626        {
     627          progress.display(10, "Running on remote computation server.");
     628          Process p = Runtime.getRuntime().exec(getExecLine(), null, getExecDirectory());
     629 
     630          ByteArrayOutputStream err = new ByteArrayOutputStream();
     631          StreamHandler errorStream = new StreamHandler(new BufferedInputStream(p.getErrorStream()), new BufferedOutputStream(err));
     632 
     633          FileOutputStream out = new FileOutputStream(new java.io.File(getExecDirectory(), "stdout.txt"));
     634          StreamHandler inputStream = new StreamHandler(new BufferedInputStream(p.getInputStream()), new BufferedOutputStream(out));
     635         
     636          FileInputStream in = new FileInputStream(new java.io.File(getExecDirectory(), "stdin.txt"));
     637          StreamHandler outputStream = new StreamHandler(new BufferedInputStream(in), new BufferedOutputStream(p.getOutputStream()));
     638         
     639          inputStream.start();
     640          errorStream.start();
     641          outputStream.start();
     642          int exitValue = p.waitFor();
     643
     644          for(int i = 0; errorStream.isAlive(); ++i)
     645          {
     646            Thread.sleep(1000);
     647            if (i > 300) throw new BaseException("Waited 5 minutes for the errormessage. I give up.");
     648          }
     649                   
     650          err.flush();
     651          msg = err.toString();
     652          out.flush();
     653         
     654          if (exitValue != 0)
     655          {
     656            response.setError(msg, null);
     657            return;
     658          }
     659          else
     660          {
     661            response.setDone(msg);
     662          }
     663        }
     664        catch (Exception e)
     665        {
     666          response.setError("Error during execution", Arrays.asList(e));
     667          return;
     668        }
     669        finally
     670        {
     671          //Copy files
     672          dc.deleteItem(stdin);
     673          importFiles(dc, trans);
     674          if (!deleteDir(getExecDirectory()))
     675          {
     676            response.setError("Could not remove execution directory: "+getExecDirectory().getAbsolutePath(), null);
     677          }
     678        }
     679             
     680        //Import data
     681        try
    591682        {
    592683          progress.display(70, "Importing data from plugin.");
    593           tId = importData();
    594           response.setDone(err.toString());
    595         }
    596         else
    597         {
    598           BioAssaySet parentBas = getSourceBioAssaySet(dc);
    599           Transformation trans = parentBas.newTransformation(Job.getById(dc, job.getId()));
    600           trans.setName(getTransformationName(dc));
    601           dc.saveItem(trans);
     684          importData(dc, trans);
     685          response.setDone(msg);
     686        }
     687        catch (Exception ex)
     688        {
     689          response.setError(ex.getMessage(), Arrays.asList(ex));
     690          return;
     691        }
     692      }
     693      finally
     694      {
     695        if (dc != null)
     696        {
    602697          dc.commit();
    603           tId = trans.getId();
    604           response.setError("Process ended with error: " + exitValue + "\n" + err, null);
    605         }
    606       }
    607       catch (IOException ex)
    608       {
    609         response.setError(ex.getMessage(), Arrays.asList(ex));
    610       }
    611       catch (InterruptedException ex)
    612       {
    613         response.setError(ex.getMessage(), Arrays.asList(ex));
    614       }
    615       finally
    616       {
    617         if (dc != null)
    618698          dc.close();
    619         if (tId != -1)
    620           importFiles(tId);
    621         if (!deleteDir(getExecDirectory()))
    622         {
    623           response.setError("Could not remove execution directory: "+getExecDirectory().getAbsolutePath(), null);
    624699        }
    625700      }
     
    638713   * @return The file where the data is exported to.
    639714   */
    640   private File exportData(DbControl dc)
    641   {
     715  private int exportData()
     716  {
     717    DbControl dc = null;
    642718    try
    643719    {
     720      dc = sc.newDbControl();
    644721      Directory d = getPluginDirectory(dc);
    645722      File file = File.getFile(dc, d, "stdin.txt", true);
    646723      file.setMimeTypeAuto("text/plain", null);
    647       if(!file.isInDatabase()) dc.saveItem(file);
     724      dc.saveItem(file);
    648725     
    649726      BioAssaySet bas = getSourceBioAssaySet(dc);
     
    667744     
    668745      Map<String, String> parameters = new HashMap<String, String>();
    669       for (PluginParameter<?> pp : getJobParameters())
     746      for (PluginParameter<?> pp : getJobParametersFromXML(String.valueOf(configuration.getValue(jobParametersParameter.getName()))))
    670747      {
    671748        String name = pp.getName();
     
    683760        exporter.exportBaseFileMatrix(bas, file, parameters, reporterFields, spotFields, mergeReporters);
    684761      }
    685       return file;
     762      dc.commit();
     763      return file.getId();
    686764    }
    687765    catch (IOException e)
     
    692770    {
    693771      throw new BaseException(e);
     772    }
     773    finally
     774    {
     775      if (dc != null)
     776        dc.close();
    694777    }
    695778  }
     
    706789  {
    707790    DbControl dc = null;
    708     List<AnnotationType> list = null;
     791    List<AnnotationType> list = new ArrayList<AnnotationType>();
    709792    try
    710793    {
    711794      dc = sc.newDbControl();
    712795      Experiment e = super.getCurrentExperiment(dc);
    713       ItemQuery<AnnotationType> query = e.getExperimentalFactors();
    714       query.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
    715       query.order(Orders.asc(Hql.property("name")));
    716       list = query.list(dc);
     796      if (e != null)
     797      {
     798        ItemQuery<AnnotationType> query = e.getExperimentalFactors();
     799        query.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
     800        query.order(Orders.asc(Hql.property("name")));
     801        list = query.list(dc);
     802      }
    717803    }
    718804    finally
     
    11041190   * @throws IOException if there is any error reading from stdou.txt
    11051191   */
    1106   private int importData()
     1192  private int importData(DbControl dc, Transformation t)
    11071193    throws IOException
    11081194  {
    1109 //    int posCnt = 0;
    1110     DbControl dc = null;
    1111     Transformation t = null;
    1112 
    1113     try
    1114     {
    1115       dc = sc.newDbControl();
    1116       Job jobitem = Job.getById(dc, job.getId());
    1117       BioAssaySet parentBas = getSourceBioAssaySet(dc);
    1118       t = parentBas.newTransformation(jobitem);
    1119       t.setName(getTransformationName(dc));
    1120       dc.saveItem(t);
    1121      
    1122       BioAssaySet bas = null;
    1123       SpotBatcher spotBatcher = null;
    1124       PositionBatcher posBatcher = null;
    1125  
    1126       HashMap<String, BioAssay> idMap = new HashMap<String, BioAssay>();
    1127       HashMap<Integer, Integer> posMap = new HashMap<Integer, Integer>();
    1128       HashMap<String, ExtraValueType> evtMap = new HashMap<String, ExtraValueType>();
    1129  
    1130       FlatFileParser ffp = getInitializedFlatFileParser(new FileInputStream(new java.io.File(getExecDirectory(), "stdout.txt")));
    1131      
    1132       while (ffp.hasMoreSections())
    1133       {
    1134         FlatFileParser.Line section = ffp.nextSection();
    1135         ffp.parseHeaders();
     1195    BioAssaySet bas = null;
     1196    SpotBatcher spotBatcher = null;
     1197    PositionBatcher posBatcher = null;
     1198
     1199    HashMap<String, BioAssay> idMap = new HashMap<String, BioAssay>();
     1200    HashMap<Integer, Integer> posMap = new HashMap<Integer, Integer>();
     1201    HashMap<String, ExtraValueType> evtMap = new HashMap<String, ExtraValueType>();
     1202
     1203    File stdout = File.getFile(dc, getPluginDirectory(dc), "stdout.txt", true);
     1204    FlatFileParser ffp = getInitializedFlatFileParser(stdout.getDownloadStream(0));
     1205   
     1206    while (ffp.hasMoreSections())
     1207    {
     1208      FlatFileParser.Line section = ffp.nextSection();
     1209      ffp.parseHeaders();
     1210     
     1211      if (section.name().equals("assays"))
     1212      {
     1213        bas = t.newProduct(null, "new", false);
     1214        bas.setName(getSourceBioAssaySet(dc).getName());
     1215
     1216        List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
     1217        int idCol = columns.indexOf("id");
     1218        int nameCol = columns.indexOf("name");
     1219        int parentCol = columns.indexOf("parents");
     1220
     1221        ffp.setMinDataColumns(columns.size());
     1222
     1223        FlatFileParser.Data dataline = ffp.nextData();
     1224        while (dataline != null)
     1225        {
     1226          String id = dataline.get(idCol);
     1227          String name = dataline.get(nameCol);
     1228          Set<BioAssay> baParents;
     1229          if (parentCol > -1)
     1230          {
     1231            String[] parentIds;
     1232            parentIds = dataline.get(parentCol).split("/");
     1233            baParents = new HashSet<BioAssay>(parentIds.length);
     1234            for (String parent : parentIds)
     1235            {
     1236              baParents.add(BioAssay.getById(dc, new Integer(parent)));
     1237            }
     1238          }
     1239          else
     1240          {
     1241            try
     1242            {
     1243              baParents = Collections.singleton(BioAssay.getById(dc, Integer.parseInt(id)));
     1244            }
     1245            catch (ItemNotFoundException e)
     1246            {
     1247              throw new BaseException("Couldn't find any parent for bioassay "+name, e);
     1248            }
     1249          }
     1250          BioAssay ba = bas.newBioAssay(baParents);
     1251          ba.setName(name);
     1252          idMap.put(id, ba);
     1253          dataline = ffp.nextData();
     1254        }
     1255      }
     1256      else if (section.name().equals("spots"))
     1257      {
     1258        List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
     1259        List<String> assays = Arrays.asList(ffp.getHeader("assays").split("\\t"));
     1260        List<String> assayFields = Arrays.asList(ffp.getHeader("assayFields").split("\\t"));
     1261        List<String> setExtraFloats = new ArrayList<String>();
     1262        if (ffp.getHeader("setExtraFloats") != null)
     1263          setExtraFloats = Arrays.asList(ffp.getHeader("setExtraFloats").split("\\t"));
    11361264       
    1137         if (section.name().equals("assays"))
    1138         {
    1139           bas = t.newProduct("new", "new", false);
    1140           bas.setName(getSourceBioAssaySet(dc).getName());
    1141  
    1142           List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
    1143           int idCol = columns.indexOf("id");
    1144           int nameCol = columns.indexOf("name");
    1145           int parentCol = columns.indexOf("parents");
    1146  
    1147           ffp.setMinDataColumns(columns.size());
    1148  
    1149           FlatFileParser.Data dataline = ffp.nextData();
    1150           while (dataline != null)
    1151           {
    1152             String id = dataline.get(idCol);
    1153             String name = dataline.get(nameCol);
    1154             Set<BioAssay> baParents;
    1155             if (parentCol > -1)
     1265        if (bas == null)
     1266        {
     1267          bas = t.newProduct(null, "new", false);
     1268        }
     1269        spotBatcher = bas.getSpotBatcher();
     1270//        posBatcher = bas.getPositionBatcher();
     1271
     1272        for (String assayId : assays)
     1273        {
     1274          if (idMap.get(assayId) == null)
     1275          {
     1276            try
    11561277            {
    1157               String[] parentIds;
    1158               parentIds = dataline.get(parentCol).split("/");
    1159               baParents = new HashSet<BioAssay>(parentIds.length);
    1160               for (String parent : parentIds)
    1161               {
    1162                 baParents.add(BioAssay.getById(dc, new Integer(parent)));
    1163               }
     1278              BioAssay parent = BioAssay.getById(dc, Integer.parseInt(assayId));
     1279              BioAssay ba = bas.newBioAssay(parent);
     1280              idMap.put(assayId, ba);
    11641281            }
    1165             else
     1282            catch (ItemNotFoundException e)
    11661283            {
    1167               try
    1168               {
    1169                 baParents = Collections.singleton(BioAssay.getById(dc, Integer.parseInt(id)));
    1170               }
    1171               catch (ItemNotFoundException e)
    1172               {
    1173                 throw new BaseException("Couldn't find any parent for bioassay "+name);
    1174               }
     1284              throw new BaseException("Couldn't find any parent for bioassay "+assayId);
    11751285            }
    1176             BioAssay ba = bas.newBioAssay(baParents);
    1177             ba.setName(name);
    1178             idMap.put(id, ba);
    1179             dataline = ffp.nextData();
    1180           }
    1181         }
    1182         else if (section.name().equals("spots"))
    1183         {
    1184           List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
    1185           List<String> assays = Arrays.asList(ffp.getHeader("assays").split("\\t"));
    1186           List<String> assayFields = Arrays.asList(ffp.getHeader("assayFields").split("\\t"));
    1187           List<String> setExtraFloats = new ArrayList<String>();
    1188           if (ffp.getHeader("setExtraFloats") != null)
    1189             setExtraFloats = Arrays.asList(ffp.getHeader("setExtraFloats").split("\\t"));
    1190          
    1191           if (bas == null)
    1192           {
    1193             bas = t.newProduct(null, "new", false);
    1194           }
    1195           spotBatcher = bas.getSpotBatcher();
    1196           posBatcher = bas.getPositionBatcher();
    1197  
    1198           for (String assayId : assays)
    1199           {
    1200             if (idMap.get(assayId) == null)
    1201             {
    1202               try
    1203               {
    1204                 BioAssay parent = BioAssay.getById(dc, Integer.parseInt(assayId));
    1205                 BioAssay ba = bas.newBioAssay(parent);
    1206                 idMap.put(assayId, ba);
    1207               }
    1208               catch (ItemNotFoundException e)
    1209               {
    1210                 throw new BaseException("Couldn't find any parent for bioassay "+assayId);
    1211               }
    1212             }
    1213           }
    1214          
    1215           ffp.setMinDataColumns(columns.size() - 1 + assays.size() * assayFields.size());
    1216          
    1217           boolean intCols = true;
    1218  
    1219           int posCol = columns.indexOf("position");
    1220           int repCol = columns.indexOf("reporter");
    1221           int dataCol = columns.indexOf("assayData");
    1222           int[] intCol = new int[bas.getRawDataType().getChannels()];
    1223           for (int i = 0; i < intCol.length; ++i)
    1224           {
    1225             int col = assayFields.indexOf("intensity"+(i+1));
    1226             if (col != -1)
    1227             {
    1228               intCol[i] = col;
    1229             }
    1230             else
    1231             {
    1232               intCols = false;
    1233             }
    1234           }
    1235           int mCol = assayFields.indexOf("l2ratio1_2");
    1236           int aCol = assayFields.indexOf("l10intgmean1_2");
    1237           int[] extraFloatsCol = new int[setExtraFloats.size()];
    1238  
    1239           if (dataCol > -1)
    1240           {
    1241             if (!intCols && (mCol > -1 && aCol > -1))
    1242             {
    1243               intCols = false;
    1244             }
    1245             else if (!intCols)
     1286          }
     1287        }
     1288       
     1289        ffp.setMinDataColumns(columns.size() - 1 + assays.size() * assayFields.size());
     1290       
     1291        boolean intCols = true;
     1292
     1293        int posCol = columns.indexOf("position");
     1294        int repCol = columns.indexOf("reporter");
     1295        int dataCol = columns.indexOf("assayData");
     1296        int[] intCol = new int[bas.getRawDataType().getChannels()];
     1297        for (int i = 0; i < intCol.length; ++i)
     1298        {
     1299          int col = assayFields.indexOf("intensity"+(i+1));
     1300          if (col != -1)
     1301          {
     1302            intCol[i] = col;
     1303          }
     1304          else
     1305          {
     1306            intCols = false;
     1307          }
     1308        }
     1309        int mCol = assayFields.indexOf("l2ratio1_2");
     1310        int aCol = assayFields.indexOf("l10intgmean1_2");
     1311        int[] extraFloatsCol = new int[setExtraFloats.size()];
     1312
     1313        if (dataCol > -1)
     1314        {
     1315          if (!intCols && (mCol > -1 && aCol > -1))
     1316          {
     1317            intCols = false;
     1318          }
     1319          else if (!intCols)
     1320          {
     1321            throw new BaseException(
     1322              "Can't find the intensity column(s) or l2ratio1_2/l10intgmean1_2. No data could be imported.");
     1323          }
     1324          for (int i = 0; i < setExtraFloats.size(); i++)
     1325          {
     1326            int col = assayFields.indexOf(setExtraFloats.get(i));
     1327            if (col < 0)
    12461328            {
    12471329              throw new BaseException(
    1248                 "Can't find the intensity column(s) or l2ratio1_2/l10intgmean1_2. No data could be imported.");
     1330                "Can't find the column " + setExtraFloats.get(i) + ". No data could be inmported.");
    12491331            }
    1250             for (int i = 0; i < setExtraFloats.size(); i++)
     1332            extraFloatsCol[i] = col + dataCol;
     1333          }
     1334        }
     1335        else
     1336        {
     1337          throw new BaseException("Can't find the column 'assayData' in header assayFields.");
     1338        }
     1339
     1340        for (int i = 0; i < intCol.length; ++i)
     1341          intCol[i] += dataCol;
     1342        aCol += dataCol;
     1343        mCol += dataCol;
     1344       
     1345        List<SpotExtraValueBatcher<Float>> evBatcher = new ArrayList<SpotExtraValueBatcher<Float>>(setExtraFloats.size());
     1346        for (int i = 0; i < setExtraFloats.size(); i++)
     1347        {
     1348          String name = setExtraFloats.get(i);
     1349          ExtraValueType evt = evtMap.get(name);
     1350          if (evt == null)
     1351          {
     1352            try
    12511353            {
    1252               int col = assayFields.indexOf(setExtraFloats.get(i));
    1253               if (col < 0)
     1354              evt = ExtraValueType.getByExternalId(dc, name);
     1355            }
     1356            catch (ItemNotFoundException e)
     1357            {
     1358              evt = ExtraValueType.getNew(dc, name, Type.FLOAT);
     1359              evt.setName(name);
     1360              dc.saveItem(evt);
     1361            }
     1362            evtMap.put(name, evt);
     1363          }
     1364          evBatcher.add(i, bas.getSpotExtraValueBatcher(Float.class, evt, Job.getById(dc, job.getId())));
     1365        }
     1366       
     1367        while (ffp.hasMoreData())
     1368        {
     1369          FlatFileParser.Data dataline = ffp.nextData();
     1370          int index = 0;
     1371          for (String assayId : assays)
     1372          {
     1373            BioAssay ba = idMap.get(assayId);
     1374            try
     1375            {
     1376              float[] intensities = new float[intCol.length];
     1377              Integer reporter = dataline.get(repCol) == null ? null : new Integer(dataline.get(repCol));
     1378              Integer position = dataline.get(posCol) == null ? null : new Integer(dataline.get(posCol));
     1379
     1380              if (intCols)
    12541381              {
    1255                 throw new BaseException(
    1256                   "Can't find the column " + setExtraFloats.get(i) + ". No data could be inmported.");
     1382                for (int i = 0; i < intCol.length; ++i)
     1383                  intensities[i] = dataline.get(intCol[i] + index) == null ? Float.NaN : new Float(dataline.get(intCol[i] + index));
    12571384              }
    1258               extraFloatsCol[i] = col + dataCol;
     1385              else
     1386              {
     1387                float a = dataline.get(aCol + index) == null ? Float.NaN : new Float(dataline.get(aCol + index));
     1388                float m = dataline.get(mCol + index) == null ? Float.NaN : new Float(dataline.get(mCol + index));
     1389
     1390                // int2 = 10^a / 2^(0.5*m)
     1391                // int1 = int2 * 2^m
     1392                intensities[1] = new Float(Math.pow(10, a) / Math.pow(2, 0.5 * m));
     1393                intensities[0] = new Float(intensities[1] * Math.pow(2, m));
     1394              }
     1395
     1396              spotBatcher.insert(ba.getDataCubeColumnNo(), position, intensities);
     1397             
     1398//              if (posMap.containsKey(position))
     1399//              {
     1400//                if (!posMap.get(position).equals(reporter))
     1401//                  throw new BaseException("Invalid data. Position, "+position+", occures twice with different reporter data.");
     1402//               
     1403//              }
     1404//              else
     1405//              {
     1406//                posMap.put(position, reporter);
     1407//                posBatcher.insert(position, Reporter.getById(dc, reporter));
     1408//              }
     1409              for (int i = 0; i < evBatcher.size(); i++)
     1410              {
     1411                try
     1412                {
     1413                  Float ev = new Float(dataline.get(extraFloatsCol[i] + index));
     1414                  evBatcher.get(i).insert(ba.getDataCubeColumnNo(), position, ev);
     1415                }
     1416                catch (NumberFormatException e)
     1417                {}
     1418              }
     1419              index += assayFields.size();
    12591420            }
    1260           }
    1261           else
    1262           {
    1263             throw new BaseException("Can't find the column 'assayData' in header assayFields.");
    1264           }
    1265  
    1266           for (int i = 0; i < intCol.length; ++i)
    1267             intCol[i] += dataCol;
    1268           aCol += dataCol;
    1269           mCol += dataCol;
    1270          
    1271           List<SpotExtraValueBatcher<Float>> evBatcher = new ArrayList<SpotExtraValueBatcher<Float>>(setExtraFloats.size());
    1272           for (int i = 0; i < setExtraFloats.size(); i++)
    1273           {
    1274             String name = setExtraFloats.get(i);
    1275             ExtraValueType evt = evtMap.get(name);
    1276             if (evt == null)
    1277             {
    1278               try
    1279               {
    1280                 evt = ExtraValueType.getByExternalId(dc, name);
    1281               }
    1282               catch (ItemNotFoundException e)
    1283               {
    1284                 evt = ExtraValueType.getNew(dc, name, Type.FLOAT);
    1285                 evt.setName(name);
    1286                 dc.saveItem(evt);
    1287               }
    1288               evtMap.put(name, evt);
    1289             }
    1290             evBatcher.add(i, bas.getSpotExtraValueBatcher(Float.class, evt, jobitem));
    1291           }
    1292          
    1293           while (ffp.hasMoreData())
    1294           {
    1295             FlatFileParser.Data dataline = ffp.nextData();
    1296             int index = 0;
    1297             for (String assayId : assays)
    1298             {
    1299               BioAssay ba = idMap.get(assayId);
    1300               try
    1301               {
    1302                 float[] intensities = new float[intCol.length];
    1303                 Integer reporter = dataline.get(repCol) == null ? null : new Integer(dataline.get(repCol));
    1304                 Integer position = dataline.get(posCol) == null ? null : new Integer(dataline.get(posCol));
    1305  
    1306                 if (intCols)
    1307                 {
    1308                   for (int i = 0; i < intCol.length; ++i)
    1309                     intensities[i] = dataline.get(intCol[i] + index) == null ? Float.NaN : new Float(dataline.get(intCol[i] + index));
    1310                 }
    1311                 else
    1312                 {
    1313                   float a = dataline.get(aCol + index) == null ? Float.NaN : new Float(dataline.get(aCol + index));
    1314                   float m = dataline.get(mCol + index) == null ? Float.NaN : new Float(dataline.get(mCol + index));
    1315  
    1316                   // int2 = 10^a / 2^(0.5*m)
    1317                   // int1 = int2 * 2^m
    1318                   intensities[1] = new Float(Math.pow(10, a) / Math.pow(2, 0.5 * m));
    1319                   intensities[0] = new Float(intensities[1] * Math.pow(2, m));
    1320                 }
    1321  
    1322                 spotBatcher.insert(ba.getDataCubeColumnNo(), position, intensities);
    1323                
    1324                 if (posMap.containsKey(position))
    1325                 {
    1326                   if (!posMap.get(position).equals(reporter))
    1327                     throw new BaseException("Invalid data. Position, "+position+", occures twice with different reporter data.");
    1328                  
    1329                 }
    1330                 else
    1331                 {
    1332                   posMap.put(position, reporter);
    1333                   posBatcher.insert(position, Reporter.getById(dc, reporter));
    1334                 }
    1335                 for (int i = 0; i < evBatcher.size(); i++)
    1336                 {
    1337                   try
    1338                   {
    1339                     Float ev = new Float(dataline.get(extraFloatsCol[i] + index));
    1340                     evBatcher.get(i).insert(ba.getDataCubeColumnNo(), position, ev);
    1341                   }
    1342                   catch (NumberFormatException e)
    1343                   {}
    1344                 }
    1345                 index += assayFields.size();
    1346               }
    1347               catch (NumberFormatException e)
    1348               {}
    1349             }
    1350           }
    1351         }
    1352       }
    1353       // save bas
    1354       if (bas != null)
    1355       {
    1356         dc.saveItem(bas);
    1357         for (BioAssay ba : idMap.values())
    1358         {
    1359           dc.saveItem(ba);
    1360         }
    1361       }
    1362       dc.commit();
    1363     }
    1364     finally
    1365     {
    1366       if (dc != null)
    1367         dc.close();
     1421            catch (NumberFormatException e)
     1422            {}
     1423          }
     1424        }
     1425      }
     1426    }
     1427    // save bas
     1428    if (bas != null)
     1429    {
     1430      dc.saveItem(bas);
     1431      for (BioAssay ba : idMap.values())
     1432      {
     1433        dc.saveItem(ba);
     1434      }
    13681435    }
    13691436   
     
    13741441 
    13751442
    1376   private void importFiles(int transformationId)
    1377   {
    1378     DbControl dc = null;
     1443  private void importFiles(DbControl dc, Transformation trans)
     1444  {
     1445    DbControl mydc = null;
    13791446    try
    13801447    {
    1381       dc = sc.newDbControl();
    1382       Directory homeDirectory = getPluginDirectory(dc);
    1383       importTempFiles(dc, getExecDirectory().listFiles(), homeDirectory);
    1384       dc.commit();
    1385       dc.close();
    1386      
    1387       dc = sc.newDbControl();
    1388       Transformation t = Transformation.getById(dc, transformationId);
    1389       for(File f : homeDirectory.getFiles().list(dc))
    1390       {
    1391         AnyToAny ata = AnyToAny.getNew(dc, t, f, f.getPath().toString(), false);
    1392         dc.saveItem(ata);
    1393       }
    1394       for(Directory d : homeDirectory.getSubDirectories().list(dc))
    1395       {
    1396         AnyToAny ata = AnyToAny.getNew(dc, t, d, d.getPath().toString(), false);
    1397         dc.saveItem(ata);
    1398       }
    1399       dc.commit();
     1448      mydc = sc.newDbControl();
     1449      Directory homeDirectory = getPluginDirectory(mydc);
     1450      importTempFiles(mydc, getExecDirectory().listFiles(), homeDirectory);
     1451      mydc.commit();
    14001452    }
    14011453    finally
    14021454    {
    1403       if (dc != null)
    1404       {
    1405         dc.close();
    1406       }
     1455      if (mydc != null)
     1456        mydc.close();
     1457    }
     1458   
     1459    Directory homeDirectory = getPluginDirectory(dc);
     1460    for(File f : homeDirectory.getFiles().list(dc))
     1461    {
     1462      AnyToAny ata = AnyToAny.getNew(dc, trans, f, f.getPath().toString(), false);
     1463      dc.saveItem(ata);
     1464    }
     1465    for(Directory d : homeDirectory.getSubDirectories().list(dc))
     1466    {
     1467      AnyToAny ata = AnyToAny.getNew(dc, trans, d, d.getPath().toString(), false);
     1468      dc.saveItem(ata);
    14071469    }
    14081470  }
     
    14381500        importTempFiles(dc, f.listFiles(), newDirectory);
    14391501      }
    1440       f.delete();
    14411502    }
    14421503  }
     
    16671728          StringParameterType t = new StringParameterType(255, defaultValue, true, 1, new Integer(options), 1, enums);
    16681729          parameter = new PluginParameter<String>(name, commonName, "", t);
    1669           jobParameters.add(parameter);
    16701730          break;
    16711731        }
     
    16801740      }
    16811741      return parameter;
     1742    }
     1743   
     1744    public final String getCommonName()
     1745    {
     1746      return commonName;
     1747    }
     1748
     1749    public final String getDefaultValue()
     1750    {
     1751      return defaultValue;
     1752    }
     1753
     1754    public final Enumeration<String, String> getEnumOptions()
     1755    {
     1756      return enumOptions;
     1757    }
     1758
     1759    public final String getName()
     1760    {
     1761      return name;
     1762    }
     1763
     1764    public final String getOptions()
     1765    {
     1766      return options;
     1767    }
     1768
     1769    public final int getPosition()
     1770    {
     1771      return position;
     1772    }
     1773
     1774    public final boolean isRemoved()
     1775    {
     1776      return removed;
     1777    }
     1778
     1779    public final Base1JobParameterType getType()
     1780    {
     1781      return type;
    16821782    }
    16831783
  • branches/2.3.1/src/plugins/core/net/sf/basedb/plugins/BioAssaySetExporter.java

    r3451 r3469  
    262262    if (!parameters.isEmpty())
    263263    {
    264       for (String key : parameters.keySet())
     264      Set<String> keys = new HashSet<String>(parameters.keySet());
     265      if (keys.remove("section"))
     266      {
     267        out.println("section\t"+parameters.get("section"));
     268      }
     269      for (String key : keys)
    265270      {
    266271        out.println(key+"\t"+parameters.get(key));
Note: See TracChangeset for help on using the changeset viewer.