Beispiel #1
0
  /**
   * Combines a list of clusters and a list of interfaces, taking the union.
   *
   * @param requestedIfacesStr
   * @param requestedClusterStr
   * @param ifaceList
   * @return
   */
  public static IntervalSet parseInterfaceListWithClusters(
      String ifaceStr, String clusterStr, List<Interface> ifaceList) {
    // If one of interfaces and clusters is specified, return it
    // If either are '*', return null (all)
    // If both are specified, return their union
    if (ifaceStr == null) {
      if (clusterStr == null) {
        // If neither are specified, return all
        return new IntervalSet(Interval.INFINITE_INTERVAL);
      }
      // Only clusters specified
      if (clusterStr.equals('*')) return new IntervalSet(Interval.INFINITE_INTERVAL);

      IntervalSet clusterSet = new IntervalSet(clusterStr);
      return mapClusters(clusterSet, ifaceList);
    } else {
      if (clusterStr == null) {
        // Only interfaces specified
        return new IntervalSet(ifaceStr);
      }
      // Both specified
      if (ifaceStr.equals('*') || clusterStr.equals('*'))
        return new IntervalSet(Interval.INFINITE_INTERVAL);
      IntervalSet clusterSet = new IntervalSet(clusterStr);
      IntervalSet interfaces = mapClusters(clusterSet, ifaceList);
      interfaces.addAll(new IntervalSet(ifaceStr));
      return interfaces.getMergedIntervalSet();
    }
  }
Beispiel #2
0
 /**
  * Expand a list of interface cluster numbers to a full list of interfaces
  *
  * @param clusters
  * @param ifaceList
  * @return
  */
 private static IntervalSet mapClusters(IntervalSet clusters, Collection<Interface> ifaceList) {
   SortedSet<Integer> interfaces = new TreeSet<>();
   for (Interface iface : ifaceList) {
     if (clusters.contains(iface.getClusterId())) {
       // Only interfaces specified
       interfaces.add(iface.getInterfaceId());
     }
   }
   return new IntervalSet(interfaces);
 }
Beispiel #3
0
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // TODO add type=interface/assembly as parameter, so that assemblies can also be supported

    String jobId = request.getParameter(FileDownloadServlet.PARAM_ID);
    String requestedIfacesStr = request.getParameter(PARAM_INTERFACES);
    String requestedClusterStr = request.getParameter(PARAM_CLUSTERS);
    String size = request.getParameter(JmolViewerServlet.PARAM_SIZE);
    String format = request.getParameter(PARAM_FORMAT);

    logger.info(
        "Requested Lattice Graph page for jobId={},interfaces={},clusters={},format={}",
        jobId,
        requestedIfacesStr,
        requestedClusterStr,
        format);

    PrintWriter outputStream = null;

    try {
      LatticeGraphServletInputValidator.validateLatticeGraphInput(
          jobId, requestedIfacesStr, requestedClusterStr, format);

      PdbInfo pdbInfo = getPdbInfo(jobId);
      String input = pdbInfo.getInputName();
      // String inputPrefix = pdbInfo.getTruncatedInputName();

      // job directory on local filesystem
      File dir = DirLocatorUtil.getJobDir(new File(destination_path), jobId);

      // Construct filename for AU cif file
      File auFile = getAuFileName(dir, input, atomCachePath);

      String inputFileNameNoGz = auFile.getName();
      if (auFile.getName().endsWith(".gz")) {
        inputFileNameNoGz = auFile.getName().substring(0, auFile.getName().lastIndexOf(".gz"));
      } else if (auFile.getName().endsWith(".GZ")) {
        inputFileNameNoGz = auFile.getName().substring(0, auFile.getName().lastIndexOf(".GZ"));
      }
      // the URL has no gz at the end because it's served as plain text via content-encoding: gzip
      String auURI = DirLocatorUtil.getJobUrlPath(resultsLocation, jobId) + "/" + inputFileNameNoGz;

      List<Interface> ifaceList = getInterfaceList(pdbInfo);

      // TODO better to filter interfaces here before construction, or afterwards?
      IntervalSet requestedIntervals =
          parseInterfaceListWithClusters(requestedIfacesStr, requestedClusterStr, ifaceList);
      Collection<Integer> requestedIfaces = requestedIntervals.getIntegerSet();

      String title = jobId + " - Lattice Graph";
      if (requestedIfaces != null && !requestedIfaces.isEmpty()) {
        title += " for interfaces " + requestedIfacesStr;
      }

      outputStream = new PrintWriter(response.getOutputStream());
      // String molviewerurl = properties.getProperty("urlNglJs");

      if (format != null && format.equalsIgnoreCase("json")) {
        LatticeGraphPageGenerator.generateJSONPage(
            dir, input, auFile, ifaceList, requestedIfaces, outputStream);
      } else {
        String nglJsUrl = properties.getProperty("urlNglJs");
        if (nglJsUrl == null || nglJsUrl.equals("")) {
          logger.info(
              "The URL for NGL js is not set in config file. Will use the js file inside the ewui war");
          nglJsUrl =
              JmolViewerServlet
                  .DEFAULT_NGL_URL; // we set it to the js file within the war, the leading '/' is
          // important to point to the right path here
        }
        // Request URL, with format=json
        StringBuffer jsonURL = request.getRequestURL();
        Map<String, String[]> query = new LinkedHashMap<>(request.getParameterMap());
        query.put("format", new String[] {"json"});
        jsonURL
            .append('?')
            .append(
                query
                    .entrySet()
                    .stream()
                    .<String>flatMap(
                        entry -> Arrays.stream(entry.getValue()).map(s -> entry.getKey() + "=" + s))
                    .collect(Collectors.joining("&")));
        LatticeGraphPageGenerator.generateHTMLPage(
            dir,
            input,
            auFile,
            auURI,
            title,
            size,
            jsonURL.toString(),
            ifaceList,
            requestedIfaces,
            outputStream,
            nglJsUrl);
        // TODO start generating JSON now, since we know that request is coming
      }

    } catch (ValidationException e) {
      response.sendError(
          HttpServletResponse.SC_PRECONDITION_FAILED,
          "Input values are incorrect: " + e.getMessage());
    } catch (IOException e) {
      response.sendError(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Error during preparation of Lattice Graph page.");
      logger.error("Error during preparation of Lattice Graph page.", e);
    } catch (DaoException e) {
      response.sendError(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Error during preparation of Lattice Graph page.");
      logger.error("Error during preparation of Lattice Graph page.", e);
    } catch (StructureException e) {
      response.sendError(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Error during preparation of Lattice Graph page.");
      logger.error("Error during preparation of Lattice Graph page.", e);
    } catch (Exception e) {
      response.sendError(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Error during preparation of Lattice Graph page.");
      logger.error("Error during preparation of Lattice Graph page.", e);
    } finally {
      if (outputStream != null) {
        try {
          outputStream.close();
        } catch (Throwable t) {
        }
      }
    }
  }