Exemplo n.º 1
0
  /**
   * Decodes data encoded using {@link #toHex(byte[],int,int) toHex}.
   *
   * @param hex data to be converted
   * @param start offset
   * @param len count
   * @throws IOException if input does not represent hex encoded value
   * @since 1.29
   */
  public static byte[] fromHex(char[] hex, int start, int len) throws IOException {

    if (hex == null) throw new IOException("null");

    int i = hex.length;
    if (i % 2 != 0) throw new IOException("odd length");
    byte[] magic = new byte[i / 2];
    for (; i > 0; i -= 2) {
      String g = new String(hex, i - 2, 2);
      try {
        magic[(i / 2) - 1] = (byte) Integer.parseInt(g, 16);
      } catch (NumberFormatException ex) {
        throw new IOException(ex.getLocalizedMessage());
      }
    }

    return magic;
  }
Exemplo n.º 2
0
  private void processFrames(Element element) {
    NodeList elements = element.getChildNodes();
    if (elements.getLength() > 0) {
      Map<String, ReferenceFrame> frames = new HashMap();
      for (ReferenceFrame f : FrameManager.getFrames()) {
        frames.put(f.getName(), f);
      }
      List<ReferenceFrame> reorderedFrames = new ArrayList();

      for (int i = 0; i < elements.getLength(); i++) {
        Node childNode = elements.item(i);
        if (childNode.getNodeName().equalsIgnoreCase(SessionElement.FRAME.getText())) {
          String frameName = getAttribute((Element) childNode, SessionAttribute.NAME.getText());

          ReferenceFrame f = frames.get(frameName);
          if (f != null) {
            reorderedFrames.add(f);
            try {
              String chr = getAttribute((Element) childNode, SessionAttribute.CHR.getText());
              final String startString =
                  getAttribute((Element) childNode, SessionAttribute.START.getText())
                      .replace(",", "");
              final String endString =
                  getAttribute((Element) childNode, SessionAttribute.END.getText())
                      .replace(",", "");
              int start = ParsingUtils.parseInt(startString);
              int end = ParsingUtils.parseInt(endString);
              org.broad.igv.feature.Locus locus = new Locus(chr, start, end);
              f.jumpTo(locus);
            } catch (NumberFormatException e) {
              e.printStackTrace(); // To change body of catch statement use File | Settings |
              // File Templates.
            }
          }
        }
      }
      if (reorderedFrames.size() > 0) {
        FrameManager.setFrames(reorderedFrames);
      }
    }
    IGV.getInstance().resetFrames();
  }