@Override
  public Set<File> generateFilePaths(SequencerPoolPartition partition) throws SubmissionException {
    Set<File> filePaths = new HashSet<File>();
    if ((partition.getSequencerPartitionContainer().getRun().getFilePath()) == null) {
      throw new SubmissionException("No valid run filepath!");
    }

    Pool<? extends Poolable> pool = partition.getPool();
    if (pool == null) {
      throw new SubmissionException("partition.getPool=null!");
    } else {
      Collection<Experiment> experiments = pool.getExperiments();
      if (experiments.isEmpty()) {
        throw new SubmissionException("Collection or experiments is empty");
      } else {
        Collection<? extends Dilution> libraryDilutions = pool.getDilutions();
        if (libraryDilutions.isEmpty()) {
          throw new SubmissionException("Collection of libraryDilutions is empty");
        } else {
          for (Dilution l : libraryDilutions) {
            Set<File> files = generateFilePath(partition, l);
            filePaths.addAll(files);
          }
        }
      }
    }
    return filePaths;
  }
 @Override
 public Set<File> generateFilePath(SequencerPoolPartition partition, Dilution l)
     throws SubmissionException {
   Pool<? extends Poolable> pool = partition.getPool();
   if (pool != null) {
     if (pool.getExperiments() != null) {
       Collection<Experiment> experiments = pool.getExperiments();
       Experiment experiment = experiments.iterator().next();
       StringBuilder filePath = new StringBuilder();
       if (!"".equals(basePath)) {
         filePath.append(
             partition.getSequencerPartitionContainer().getRun().getFilePath()
                 + "/Data/Intensities/BaseCalls/PAP/Project_"
                 + experiment.getStudy().getProject().getAlias()
                 + "/Sample_"
                 + l.getLibrary().getName()
                 + "/"
                 + l.getLibrary().getName());
       } else {
         filePath.append(
             basePath
                 + "/"
                 + experiment.getStudy().getProject().getAlias()
                 + "/Sample_"
                 + l.getLibrary().getName()
                 + "/"
                 + l.getLibrary().getName());
       }
       if (l.getLibrary().getTagBarcodes() != null && !l.getLibrary().getTagBarcodes().isEmpty()) {
         filePath.append("_");
         for (TagBarcode tb : l.getLibrary().getTagBarcodes().values()) {
           filePath.append(tb.getSequence());
         }
       }
       filePath.append("_L00" + partition.getPartitionNumber() + "*.fastq.gz");
       Set<File> files = new HashSet<File>();
       files.add(new File(filePath.toString()));
       return files;
     } else {
       throw new SubmissionException("partition.getPool=null!");
     }
   } else {
     throw new SubmissionException("Collection of experiments is empty");
   }
 }
예제 #3
0
  @Test
  public void testPools() {
    try {
      int expected = getDataSet().getTable("Pool").getRowCount();

      int actual = getPoolDAO().count();

      TestCase.assertEquals("Wrong number of Pools", expected, actual);
      System.out.println("Expected number of Pools: " + expected + ", actual: " + actual);

      for (Pool d : random(getPoolDAO(), actual, 1)) {
        TestCase.assertNotNull(d);
        TestCase.assertNotNull(d.getId());
      }
    } catch (Exception e) {
      e.printStackTrace();
      TestCase.fail();
    }
  }
  @Override
  public Set<File> generateFilePaths(SequencerPoolPartition partition) throws SubmissionException {
    log.debug("Generating filepaths for partition " + partition.getId());
    Set<File> filePaths = new HashSet<File>();

    Pool pool = partition.getPool();
    if (pool == null) {
      throw new SubmissionException("partition.getPool=null!");
    } else {
      Collection<Experiment> experiments = pool.getExperiments();
      if (experiments.isEmpty()) {
        throw new SubmissionException("Collection or experiments is empty");
      } else {
        Collection<LibraryDilution> libraryDilutions = pool.getDilutions();
        if (libraryDilutions.isEmpty()) {
          throw new SubmissionException("Collection or libraryDilutions is empty");
        } else {
          for (Experiment e : experiments) {
            StringBuilder filePath = new StringBuilder();

            filePath.append(partition.getSequencerPartitionContainer().getRun().getFilePath());
            filePath.append("/Data/Intensities/BaseCalls/PAP/Project_");
            filePath.append(e.getStudy().getProject().getAlias());
            filePath.append("/Sample_");

            for (LibraryDilution l : libraryDilutions) {
              // filePath.append(l.getLibrary().getName()+"/");
              /*
                      +l.getLibrary().getName()+"_"+l.getLibrary().getTagBarcode().getSequence());
              filePath.append("L00"+lane.getPartitionNumber())
              */
              String folder = filePath.toString() + l.getLibrary().getName() + "/*.fastq.gz";
              // System.out.println(folder);
              File file = new File(folder);
              filePaths.add(file);
            }
          }
        }
      }
    }
    return (filePaths);
  }
  @Override
  public File generateFilePath(SequencerPoolPartition partition, LibraryDilution l)
      throws SubmissionException {
    log.debug("Generating filepaths for partition " + partition.getId());

    Pool pool = partition.getPool();
    if (pool != null) {
      if (pool.getExperiments() != null) {

        Collection<Experiment> experiments = pool.getExperiments();
        Experiment experiment = experiments.iterator().next();
        // String filePath =
        // lane.getFlowcell().getRun().getFilePath()+"/Data/Intensities/BaseCalls/PAP/Project_"+
        String filePath =
            partition.getSequencerPartitionContainer().getRun().getFilePath()
                + "/Data/Intensities/BaseCalls/PAP/Project_"
                + experiment.getStudy().getProject().getAlias()
                + "/Sample_"
                + l.getLibrary().getName()
                + "/"
                + l.getLibrary().getName()
                + "_"
                + l.getLibrary().getTagBarcode().getSequence()
                + "_L00"
                + partition.getPartitionNumber()
                + "*.fastq.gz";
        // System.out.println(filePath);
        File file = new File(filePath);
        return (file);
      } else {
        throw new SubmissionException("partition.getPool=null!");
      }
    } else {
      throw new SubmissionException("Collection of experiments is empty");
    }
  }
  public JSONObject saveImportedElements(HttpSession session, JSONObject json) {
    if (json.has("elements")) {
      Plate currentPlate = null;
      Pool currentPool = null;

      try {
        String description = json.getString("description");
        String creationDate = json.getString("creationDate");
        String plateMaterialType = null;
        if (json.has("plateMaterialType") && !json.getString("plateMaterialType").equals("")) {
          plateMaterialType = json.getString("plateMaterialType");
        }

        JSONObject elements = json.getJSONObject("elements");
        JSONArray pools = JSONArray.fromObject(elements.get("pools"));
        JSONArray savedPlates = new JSONArray();
        ObjectMapper mapper = new ObjectMapper();

        for (JSONArray innerPoolList : (Iterable<JSONArray>) pools) {
          for (JSONObject pool : (Iterable<JSONObject>) innerPoolList) {
            log.info(pool.toString());

            PlatePool platePool =
                mapper.readValue(pool.toString(), new TypeReference<PlatePool>() {});
            currentPool = platePool;

            for (Plate<LinkedList<Library>, Library> plate : platePool.getPoolableElements()) {
              JSONObject j = new JSONObject();

              //              if (json.has("tagBarcode")) {
              //                String tagBarcode = json.getString("tagBarcode");
              //
              // plate.setTagBarcode(requestManager.listAllTagBarcodesByStrategyName());
              //              }

              if (plate.getDescription() == null) {
                plate.setDescription(description);
              }

              if (plate.getCreationDate() == null) {
                // plate.setCreationDate(DateFormat.getInstance().parse(creationDate));
              }

              if (plate.getPlateMaterialType() == null && plateMaterialType != null) {
                plate.setPlateMaterialType(PlateMaterialType.valueOf(plateMaterialType));
              }
              log.info("Saving plate: " + plate.toString());
              currentPlate = plate;
              long plateId = requestManager.savePlate(plate);
              j.put("plateId", plateId);
              savedPlates.add(j);
              currentPlate = null;
            }

            log.info("Saving pool: " + pool.toString());
            requestManager.savePool(platePool);
            currentPool = null;
          }
        }
        JSONObject resp = new JSONObject();
        resp.put("plates", savedPlates);
        return resp;
      } catch (IOException e) {
        if (currentPool != null) {
          log.error(
              "Error saving pool elements on new plate save. Deleting pool "
                  + currentPool.toString());
          // clear out child elements to make sure plate meets delete requirements
          currentPool.getPoolableElements().clear();
          try {
            requestManager.deletePool(currentPool);
          } catch (IOException e1) {
            log.error("Cannot delete pool. Nothing left to do.");
            e1.printStackTrace();
          }
        }

        if (currentPlate != null) {
          log.error(
              "Error saving plate elements on new plate save. Deleting plate "
                  + currentPlate.toString());
          // clear out child elements to make sure plate meets delete requirements
          currentPlate.getElements().clear();
          try {
            requestManager.deletePlate(currentPlate);
          } catch (IOException e1) {
            log.error("Cannot delete plate. Nothing left to do.");
            e1.printStackTrace();
          }
        }

        log.error("Caused by...");
        e.printStackTrace();
        return JSONUtils.SimpleJSONError("Cannot save imported plate: " + e.getMessage());
      }
    } else {
      return JSONUtils.SimpleJSONError("No valid plates available to save");
    }
  }