コード例 #1
0
  public void process(JSONRequestContext jsonRequestContext) {
    ResourceDAO resourceDAO = DAOFactory.getInstance().getResourceDAO();
    ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
    WorkResourceDAO workResourceDAO = DAOFactory.getInstance().getWorkResourceDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();

    String name = jsonRequestContext.getRequest().getParameter("name");
    Long resourceId =
        NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("resource"));
    Double hourlyCost =
        NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("hourlyCost"));
    Double costPerUse =
        NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("costPerUse"));
    Long version = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("version"));
    String tagsText = jsonRequestContext.getString("tags");

    Set<Tag> tagEntities = new HashSet<Tag>();
    if (!StringUtils.isBlank(tagsText)) {
      List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
      for (String tag : tags) {
        if (!StringUtils.isBlank(tag)) {
          Tag tagEntity = tagDAO.findByText(tag.trim());
          if (tagEntity == null) tagEntity = tagDAO.create(tag);
          tagEntities.add(tagEntity);
        }
      }
    }

    WorkResource workResource = workResourceDAO.findById(resourceId);
    if (!version.equals(workResource.getVersion()))
      throw new SmvcRuntimeException(
          PyramusStatusCode.CONCURRENT_MODIFICATION,
          Messages.getInstance()
              .getText(
                  jsonRequestContext.getRequest().getLocale(),
                  "generic.errors.concurrentModification"));

    ResourceCategory resourceCategory =
        resourceCategoryDAO.findById(
            NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("category")));

    workResourceDAO.update(workResource, name, resourceCategory, costPerUse, hourlyCost);
    resourceDAO.setResourceTags(workResource, tagEntities);

    jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
  }
コード例 #2
0
 /**
  * Returns the value as a {@link Double} value. The returned value will be <code>0</code> or
  * <code>1</code> if the {@link #value} is a boolean value. If {@link #value} can not be converted
  * into a number, a {@link NumberFormatException} is thrown.
  *
  * @return {@link #value} as {@link Double}
  */
 public double getValueAsDouble() {
   if (NumberUtils.isNumber(value)) {
     return NumberUtils.createDouble(value);
   }
   if (isBooleanValue(value)) {
     return BooleanUtils.toBoolean(value) ? 1 : 0;
   }
   throw new NumberFormatException();
 }
コード例 #3
0
  // For example, here is a line from the 5kb chr1 MAPQGE30 raw observed contact matrix
  // (GM12878_combined/5kb_resolution_intrachromosomal/chr1/MAPQGE30/chr1_5kb.RAWobserved):
  // 40000000 40100000 59.0
  private static void processRawContactInformation(
      String fileToRead,
      double minValue,
      ArrayList<DesiredChrContact> contactsToCheck,
      boolean intra)
      throws IOException {

    // Check if sorted version is available
    // If not make sorted available.
    if (!Gpio.exists(fileToRead + ".sorted")) {
      if (intra) {
        umcg.genetica.io.chrContacts.SortIntraChrContacts.readNonSortedWriteSorted(
            fileToRead, fileToRead + ".sorted");
      } else {
        umcg.genetica.io.chrContacts.SortInterChrContacts.readNonSortedWriteSorted(
            fileToRead, fileToRead + ".sorted");
      }
    }

    int numberToBeMatched = 0;

    LineIterator it = FileUtils.lineIterator(new File(fileToRead + ".sorted"), "UTF-8");

    try {
      while (it.hasNext()) {
        String[] parts = StringUtils.split(it.nextLine(), '\t');

        int posChr1 = org.apache.commons.lang.math.NumberUtils.createInteger(parts[0]);
        int posChr2 = org.apache.commons.lang.math.NumberUtils.createInteger(parts[1]);

        while (numberToBeMatched < contactsToCheck.size()) {
          if (posChr1 < contactsToCheck.get(numberToBeMatched).getChrLocationSmaller()) {
            break;
          } else if (posChr1 == contactsToCheck.get(numberToBeMatched).getChrLocationSmaller()) {
            if (posChr2 < contactsToCheck.get(numberToBeMatched).getChrLocationLarger()) {
              break;
            }
            if (posChr2 == contactsToCheck.get(numberToBeMatched).getChrLocationLarger()) {
              double contact = org.apache.commons.lang.math.NumberUtils.createDouble(parts[2]);
              if (contact >= minValue) {
                contactsToCheck.get(numberToBeMatched).setContact();
                numberToBeMatched++;
              } else {
                numberToBeMatched++;
              }
            } else if (posChr2 > contactsToCheck.get(numberToBeMatched).getChrLocationLarger()) {
              numberToBeMatched++;
            }
          } else if (posChr1 > contactsToCheck.get(numberToBeMatched).getChrLocationSmaller()) {
            numberToBeMatched++;
          }
        }
      }
    } finally {
      LineIterator.closeQuietly(it);
    }
  }
コード例 #4
0
  /**
   * Turns a string value into a java.lang.Number.
   *
   * <p>First, the value is examined for a type qualifier on the end (<code>'f','F','d','D','l','L'
   * </code>). If it is found, it starts trying to create successively larger types from the type
   * specified until one is found that can represent the value.
   *
   * <p>If a type specifier is not found, it will check for a decimal point and then try
   * successively larger types from <code>Integer</code> to <code>BigInteger</code> and from <code>
   * Float</code> to <code>BigDecimal</code>.
   *
   * <p>If the string starts with <code>0x</code> or <code>-0x</code>, it will be interpreted as a
   * hexadecimal integer. Values with leading <code>0</code>'s will not be interpreted as octal.
   *
   * <p>Returns <code>null</code> if the string is <code>null</code>.
   *
   * <p>This method does not trim the input string, i.e., strings with leading or trailing spaces
   * will generate NumberFormatExceptions.
   *
   * @param str String containing a number, may be null
   * @return Number created from the string
   * @throws NumberFormatException if the value cannot be converted
   */
  public static Number createNumber(String str) throws NumberFormatException {
    if (str == null) {
      return null;
    }
    if (StringUtils.isBlank(str)) {
      throw new NumberFormatException("A blank string is not a valid number");
    }
    if (str.startsWith("--")) {
      // this is protection for poorness in java.lang.BigDecimal.
      // it accepts this as a legal value, but it does not appear
      // to be in specification of class. OS X Java parses it to
      // a wrong value.
      return null;
    }
    if (str.startsWith("0x") || str.startsWith("-0x")) {
      return createInteger(str);
    }
    char lastChar = str.charAt(str.length() - 1);
    String mant;
    String dec;
    String exp;
    int decPos = str.indexOf('.');
    int expPos = str.indexOf('e') + str.indexOf('E') + 1;

    if (decPos > -1) {

      if (expPos > -1) {
        if (expPos < decPos) {
          throw new NumberFormatException(str + " is not a valid number.");
        }
        dec = str.substring(decPos + 1, expPos);
      } else {
        dec = str.substring(decPos + 1);
      }
      mant = str.substring(0, decPos);
    } else {
      if (expPos > -1) {
        mant = str.substring(0, expPos);
      } else {
        mant = str;
      }
      dec = null;
    }
    if (!Character.isDigit(lastChar)) {
      if (expPos > -1 && expPos < str.length() - 1) {
        exp = str.substring(expPos + 1, str.length() - 1);
      } else {
        exp = null;
      }
      // Requesting a specific type..
      String numeric = str.substring(0, str.length() - 1);
      boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
      switch (lastChar) {
        case 'l':
        case 'L':
          if (dec == null
              && exp == null
              && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1))
                  || isDigits(numeric))) {
            try {
              return createLong(numeric);
            } catch (NumberFormatException nfe) {
              // Too big for a long
            }
            return createBigInteger(numeric);
          }
          throw new NumberFormatException(str + " is not a valid number.");
        case 'f':
        case 'F':
          try {
            Float f = NumberUtils.createFloat(numeric);
            if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
              // If it's too big for a float or the float value = 0 and the string
              // has non-zeros in it, then float does not have the precision we want
              return f;
            }

          } catch (NumberFormatException nfe) {
            // ignore the bad number
          }
          // Fall through
        case 'd':
        case 'D':
          try {
            Double d = NumberUtils.createDouble(numeric);
            if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
              return d;
            }
          } catch (NumberFormatException nfe) {
            // ignore the bad number
          }
          try {
            return createBigDecimal(numeric);
          } catch (NumberFormatException e) {
            // ignore the bad number
          }
          // Fall through
        default:
          throw new NumberFormatException(str + " is not a valid number.");
      }
    } else {
      // User doesn't have a preference on the return type, so let's start
      // small and go from there...
      if (expPos > -1 && expPos < str.length() - 1) {
        exp = str.substring(expPos + 1, str.length());
      } else {
        exp = null;
      }
      if (dec == null && exp == null) {
        // Must be an int,long,bigint
        try {
          return createInteger(str);
        } catch (NumberFormatException nfe) {
          // ignore the bad number
        }
        try {
          return createLong(str);
        } catch (NumberFormatException nfe) {
          // ignore the bad number
        }
        return createBigInteger(str);

      } else {
        // Must be a float,double,BigDec
        boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
        try {
          Float f = createFloat(str);
          if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
            return f;
          }
        } catch (NumberFormatException nfe) {
          // ignore the bad number
        }
        try {
          Double d = createDouble(str);
          if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) {
            return d;
          }
        } catch (NumberFormatException nfe) {
          // ignore the bad number
        }

        return createBigDecimal(str);
      }
    }
  }
コード例 #5
0
  private static void processNormalizedIntraContactInformation(
      String fileToRead,
      String baseName,
      String normMethod,
      String chrSmaller,
      ArrayList<DesiredChrContact> contactsToCheck,
      String resolution,
      double minValue,
      TextFile outWriter)
      throws IOException {

    // ReadIn normalization chr1
    TextFile inputNormChr1 =
        new TextFile(
            baseName + "\\chr" + chrSmaller + "_" + resolution + "." + normMethod, TextFile.R);
    ArrayList<String> normFactorSmallerChr = inputNormChr1.readAsArrayList();
    inputNormChr1.close();

    //        System.out.println("Done reading norm factor 1");
    if (!Gpio.exists(fileToRead + ".sorted")) {
      umcg.genetica.io.chrContacts.SortIntraChrContacts.readNonSortedWriteSorted(
          fileToRead, fileToRead + ".sorted");
    }

    int numberToBeMatched = 0;

    LineIterator it = FileUtils.lineIterator(new File(fileToRead + ".sorted"), "UTF-8");

    try {
      while (it.hasNext()) {
        String[] parts = StringUtils.split(it.nextLine(), '\t');

        int posChr1 = org.apache.commons.lang.math.NumberUtils.createInteger(parts[0]);
        int posChr2 = org.apache.commons.lang.math.NumberUtils.createInteger(parts[1]);

        while (numberToBeMatched < contactsToCheck.size()) {
          if (posChr1 < contactsToCheck.get(numberToBeMatched).getChrLocationSmaller()) {
            break;
          } else if (posChr1 == contactsToCheck.get(numberToBeMatched).getChrLocationSmaller()) {
            if (posChr2 < contactsToCheck.get(numberToBeMatched).getChrLocationLarger()) {
              break;
            }
            if (posChr2 == contactsToCheck.get(numberToBeMatched).getChrLocationLarger()) {

              String factor1Base =
                  normFactorSmallerChr.get((posChr1 / getNumericResolution(resolution)) + 1);
              String factor2Base =
                  normFactorSmallerChr.get((posChr2 / getNumericResolution(resolution)) + 1);

              double factor1;
              double factor2;

              if (StringUtils.isNumeric(factor1Base) && StringUtils.isNumeric(factor2Base)) {
                factor1 = org.apache.commons.lang.math.NumberUtils.createDouble(factor1Base);
                factor2 = org.apache.commons.lang.math.NumberUtils.createDouble(factor2Base);

                double contact =
                    org.apache.commons.lang.math.NumberUtils.createDouble(parts[2])
                        / (factor1 * factor2);
                if (contact >= minValue) {
                  outWriter.writeln(
                      contactsToCheck.get(numberToBeMatched).getSnpName()
                          + "\t"
                          + contactsToCheck.get(numberToBeMatched).getProbeName()
                          + "\t"
                          + posChr1
                          + "\t"
                          + posChr2
                          + "\tContact\t"
                          + contact
                          + "\t"
                          + org.apache.commons.lang.math.NumberUtils.createDouble(parts[2]));
                  numberToBeMatched++;
                } else {
                  outWriter.writeln(
                      contactsToCheck.get(numberToBeMatched).getSnpName()
                          + "\t"
                          + contactsToCheck.get(numberToBeMatched).getProbeName()
                          + "\t"
                          + posChr1
                          + "\t"
                          + posChr2
                          + "\t-\t-\t-");
                  numberToBeMatched++;
                }
              } else {
                System.out.println("Error in files.");
                numberToBeMatched++;
              }
            } else if (posChr2 > contactsToCheck.get(numberToBeMatched).getChrLocationLarger()) {
              outWriter.writeln(
                  contactsToCheck.get(numberToBeMatched).getSnpName()
                      + "\t"
                      + contactsToCheck.get(numberToBeMatched).getProbeName()
                      + "\t"
                      + posChr1
                      + "\t"
                      + posChr2
                      + "\t-\t-\t-");
              numberToBeMatched++;
            }
          } else if (posChr1 > contactsToCheck.get(numberToBeMatched).getChrLocationSmaller()) {
            outWriter.writeln(
                contactsToCheck.get(numberToBeMatched).getSnpName()
                    + "\t"
                    + contactsToCheck.get(numberToBeMatched).getProbeName()
                    + "\t"
                    + posChr1
                    + "\t"
                    + posChr2
                    + "\t-\t-\t-");
            numberToBeMatched++;
          }
        }
      }
    } finally {
      LineIterator.closeQuietly(it);
    }
  }