Beispiel #1
0
 private static void assertEqualList(List<?> a, Collection<?> b) {
   if (a.size() == b.size()) {
     for (Object x : a) {
       if (!b.contains(x))
         throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
     }
     return;
   }
   throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
 }
Beispiel #2
0
  private void processResources(Session session, Element element, HashMap additionalInformation) {
    dataFiles = new ArrayList();
    missingDataFiles = new ArrayList();
    NodeList elements = element.getChildNodes();
    process(session, elements, additionalInformation);

    if (missingDataFiles.size() > 0) {
      StringBuffer message = new StringBuffer();
      message.append("<html>The following data file(s) could not be located.<ul>");
      for (ResourceLocator file : missingDataFiles) {
        if (file.isLocal()) {
          message.append("<li>");
          message.append(file.getPath());
          message.append("</li>");
        } else {
          message.append("<li>Server: ");
          message.append(file.getServerURL());
          message.append("  Path: ");
          message.append(file.getPath());
          message.append("</li>");
        }
      }
      message.append("</ul>");
      message.append("Common reasons for this include: ");
      message.append("<ul><li>The session or data files have been moved.</li> ");
      message.append(
          "<li>The data files are located on a drive that is not currently accessible.</li></ul>");
      message.append("</html>");

      MessageUtils.showMessage(message.toString());
    }
    if (dataFiles.size() > 0) {

      final List<String> errors = new ArrayList<String>();

      // Load files concurrently -- TODO, put a limit on # of threads?
      List<Thread> threads = new ArrayList(dataFiles.size());
      long t0 = System.currentTimeMillis();
      int i = 0;
      List<Runnable> synchronousLoads = new ArrayList<Runnable>();
      for (final ResourceLocator locator : dataFiles) {

        final String suppliedPath = locator.getPath();
        final String relPath = fullToRelPathMap.get(suppliedPath);

        Runnable runnable =
            new Runnable() {
              public void run() {
                List<Track> tracks = null;
                try {
                  tracks = igv.load(locator);
                  for (Track track : tracks) {
                    if (track == null) {
                      log.info("Null track for resource " + locator.getPath());
                      continue;
                    }

                    String id = track.getId();
                    if (id == null) {
                      log.info("Null track id for resource " + locator.getPath());
                      continue;
                    }

                    if (relPath != null) {
                      id = id.replace(suppliedPath, relPath);
                    }

                    List<Track> trackList = trackDictionary.get(id);
                    if (trackList == null) {
                      trackList = new ArrayList();
                      trackDictionary.put(id, trackList);
                    }
                    trackList.add(track);
                  }
                } catch (Exception e) {
                  log.error("Error loading resource " + locator.getPath(), e);
                  String ms =
                      "<b>" + locator.getPath() + "</b><br>&nbs;p&nbsp;" + e.toString() + "<br>";
                  errors.add(ms);
                }
              }
            };

        boolean isAlignment =
            locator.getPath().endsWith(".bam")
                || locator.getPath().endsWith(".entries")
                || locator.getPath().endsWith(".sam");

        // Run synchronously if in batch mode or if there are no "track" elments, or if this is an
        // alignment file
        if (isAlignment || Globals.isBatch() || !hasTrackElments) {
          synchronousLoads.add(runnable);
        } else {
          Thread t = new Thread(runnable);
          threads.add(t);
          t.start();
        }
        i++;
      }
      // Wait for all threads to complete
      for (Thread t : threads) {
        try {
          t.join();
        } catch (InterruptedException ignore) {
        }
      }

      // Now load data that must be loaded synchronously
      for (Runnable runnable : synchronousLoads) {
        runnable.run();
      }

      long dt = System.currentTimeMillis() - t0;
      log.debug("Total load time = " + dt);

      if (errors.size() > 0) {
        StringBuffer buf = new StringBuffer();
        buf.append("<html>Errors were encountered loading the session:<br>");
        for (String msg : errors) {
          buf.append(msg);
        }
        MessageUtils.showMessage(buf.toString());
      }
    }
    dataFiles = null;
  }