Пример #1
0
  /** Compares all values to whats already in the database returns the number of errors found. */
  private void checkCreate(
      String id_or_alias,
      String ind,
      String variable,
      String value,
      String date,
      String ref,
      String comm,
      int suid) {

    // ResultSet rset;
    int nrErrors = 0;
    String identity = null;
    try {
      // First if no IDENTITY was sent, we need to get it through alias!

      if (id_or_alias.equalsIgnoreCase("ALIAS")
          && (ind != null)
          && (!ind.trim().equalsIgnoreCase(""))) {
        identity = db.getIdentity(ind);
      } else {
        identity = ind;
      }

      // compare to database, is this unique? (can it be inserted?)
      if (!db.isPhenotypeUnique(variable, identity)) {
        // the phenotype exists
        String Message =
            " The Phenotype [V="
                + variable
                + ", I="
                + identity
                + "] already exists, cannot be created.";
        errorList.add(Message);
        nrErrors++;
      }

      // Does the individual exist?
      if (db.isIndividualUnique(identity)) {
        // the Individual does not exist
        String Message = " The Individual with " + id_or_alias + " " + ind + " does not exist.";
        errorList.add(Message);
      }

      // does variable exist?
      if (db.isVariableUnique(variable)) {
        // the variable does not exist
        String Message = " Variable " + variable + " does not exist";
        errorList.add(Message);
      }
    } catch (Exception e) {
      // Flag for error and set the errMessage if it has not been set
      e.printStackTrace(System.err);
    }
  }
Пример #2
0
  private boolean checkValues(
      String identity, String variable, String value, String date, String ref, String comm) {
    boolean ret = true;

    if (identity == null || identity.trim().equals("")) {
      errorList.add("Unable to read Identity/Alias.");
      ret = false;
    } else if (identity.length() > 11) {
      errorList.add("Identity/Alias [" + identity + "] exceeds 11 characters.");
      ret = false;
    }

    if (variable == null || variable.trim().equals("")) {
      errorList.add("Unable to read variable.");
      ret = false;
    } else if (variable.length() > 20) {
      errorList.add("Variable [" + variable + "] exceeds 20 characters.");
      ret = false;
    }

    if (value == null || value.trim().equals("")) {
      errorList.add("Unable to read value.");
      ret = false;
    }

    if (value != null && value.length() > 20) {
      errorList.add("Value [" + value + "] exceeds 20 characters.");
      ret = false;
    }

    if (!(date == null || date.trim().equals(""))) {
      try {
        java.util.Date temp = java.sql.Date.valueOf(date);
      } catch (Exception e) {
        errorList.add("Date not in the format 'YYYY-MM-DD'");
        ret = false;
      }
    }

    if (ref != null && ref.length() > 32) {
      errorList.add("Reference [" + ref + "] exceeds 32 characters.");
      ret = false;
    }

    if (comm != null && comm.length() > 256) {
      errorList.add("Comment exceeds 256 characters.");
      ret = false;
    }
    return ret;
  }
Пример #3
0
  /** Checks if the phenotype exists Makes certain the genotype can be updated */
  private void checkUpdate(
      String id_or_alias,
      String ind,
      String variable,
      String value,
      String date,
      String ref,
      String comm,
      int suid,
      Vector deviationMessages,
      Vector databaseValues,
      char delim) {
    // ResultSet rset;
    String identity = null;
    boolean match = false;

    try {

      // First if no IDENTITY was sent, we need to get it through alias!
      if (id_or_alias.equalsIgnoreCase("ALIAS")
          && ind != null
          && !ind.trim().equalsIgnoreCase("")) {
        identity = db.getIdentity(ind);
      } else identity = ind;

      // compare to database, does genotype exist? can it be updated..
      if (db.isPhenotypeUnique(variable, identity)) {
        String Message = "The Phenotype does not exist, cannot be updated.";
        errorList.add(Message);
      }
      // rset.close();
    } // try
    catch (Exception e) {
      // Flag for error and set the errMessage if it has not been set
      e.printStackTrace(System.err);
    }
  }
Пример #4
0
  /**
   * @param fileOut
   * @param errorMessages
   * @param warningMessages
   * @param deviationMessages
   * @param databaseValues
   * @param newAlleles
   * @param ind
   * @param delim
   * @param marker
   * @param allele1
   * @param allele2
   */
  private void writeMatrixErrors(
      FileWriter fileOut,
      Vector deviationMessages,
      Vector databaseValues,
      Vector values,
      String ind,
      char delim,
      String variable,
      String value) {
    try {
      // if row contains comments
      if (errorList.size() > 0 || deviationMessages.size() > 0 || warningList.size() > 0) {
        fileOut.write("#--------------------------------------------------------\n");
      }
      if (errorList.size() > 0) {
        for (int i = 0; i < errorList.size(); i++) {
          fileOut.write("#" + (String) errorList.get(i) + "\n");
        }
      }

      if (warningList.size() > 0) {
        for (int i = 0; i < warningList.size(); i++) {
          fileOut.write("#" + (String) warningList.get(i) + "\n");
        }
      }

      if (deviationMessages.size() > 0) {
        for (int i = 0; i < deviationMessages.size(); i++) {
          fileOut.write("#" + (String) deviationMessages.elementAt(i) + "\n");
        }
        // write database values
        fileOut.write("#" + ind);
        for (int i = 0; i < databaseValues.size(); i++) {
          fileOut.write(delim + (String) databaseValues.elementAt(i));
        }
        fileOut.write("\n");
      }
      // write row from file:
      if (errorList.size() > 0) {
        fileOut.write("#");
      }
      fileOut.write(ind);

      for (int i = 0; i < values.size(); i++) {
        fileOut.write(delim + (String) values.elementAt(i));
      }
      fileOut.write("\n");

      /*
      for (int i=0;i<newAlleles.size();i++)
      {
          fileOut.write(delim+(String)newAlleles.elementAt(i));
      }
      fileOut.write("\n");
      */

      // fileOut.write(delim+allele1);
      // fileOut.write(delim+allele2);
      // fileOut.write("\n");

      if (errorList.size() > 0 || deviationMessages.size() > 0 || warningList.size() > 0) {
        fileOut.write("#--------------------------------------------------------\n");
      }
    } // try
    catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }
Пример #5
0
  public String checkMatrix(
      FileParser fp, Vector fatalErrors, FileWriter fileOut, char delimiter, String indId) {

    String errMsg = "";
    // String ind, marker = "", allele1 = "", allele2 = ""; //, raw1, raw2; //, //ref; //, comm;
    String ind = "", variable = "", value = "";
    // String alleles[];

    int nrErrors = 0;
    int nrWarnings = 0;
    int nrDeviations = 0;

    /*
    Vector errorMessages = new Vector();
    Vector warningMessages = new Vector();
    Vector deviationMessages = new Vector();
    Vector databaseValues = new Vector();
    */

    DbImportFile dbInFile = new DbImportFile();
    String statusStr;
    double status;
    double status_last = 0.0;

    int dataRows = fp.dataRows();
    String titles[] = fp.columnTitles();
    String variables[] = new String[titles.length - 1];
    for (int i = 0; i < variables.length; i++) variables[i] = titles[i + 1];

    Vector deviationMessages = null;
    Vector databaseValues = null;
    Vector newAlleles = null;
    Vector values = null;

    warningList = new ArrayList();
    errorList = new ArrayList();

    for (int row = 0; row < fp.dataRows(); row++) {
      deviationMessages = new Vector();
      databaseValues = new Vector();
      values = new Vector();

      ind = fp.getValue(indId, row);

      // newAlleles = new Vector();

      // check the whole row
      for (int mNum = 0; mNum < variables.length; mNum++) {
        // String old_alleles[]=null;
        variable = variables[mNum];
        value = fp.getValue(variable, row);

        // Add the values for error writing
        values.add(value);

        // check that values exist, have correct length etc
        checkValues(ind, variable, value, null, null, null);

        if (updateMethod.equals("CREATE"))
          checkCreate(titles[0], ind, variable, value, null, null, null, sampleUnitId);
        else if (updateMethod.equals("UPDATE"))
          checkUpdate(
              titles[0],
              ind,
              variable,
              value,
              null,
              null,
              null,
              sampleUnitId,
              deviationMessages,
              databaseValues,
              delimiter);
        else if (updateMethod.equals("CREATE_OR_UPDATE"))
          checkCreateOrUpdate(
              titles[0],
              ind,
              variable,
              value,
              null,
              null,
              null,
              sampleUnitId,
              deviationMessages,
              databaseValues,
              delimiter);
      } // for markers

      nrErrors += errorList.size();
      nrDeviations += deviationMessages.size();
      nrWarnings += warningList.size();

      writeMatrixErrors(
          fileOut, deviationMessages, databaseValues, values, ind, delimiter, variable, value);

      /*
      //newAlleles= new Vector();
      databaseValues = new Vector();
      errorMessages=new Vector();
      warningMessages=new Vector();
      deviationMessages=new Vector();
      */
      /*
       * Set the status of the import, visible to the user
       */
      status = (new Double(row * 100 / (1.0 * dataRows))).doubleValue();
      if (status_last + 5 < status) {
        status_last = status;
        statusStr = Integer.toString((new Double(status)).intValue()) + "%";
        dbInFile.setStatus(conn_viss, ifid, statusStr);
      }
      errorList.clear();
      warningList.clear();
    } // for rows

    if (nrErrors > 0) errMsg = "ERROR: Import of the genotypes failed.";
    else if (nrWarnings > 0) errMsg = "WARNING: Some warnings exist in the import file";
    else errMsg = "Genotype file is correct";
    errMsg += "\nDeviations:" + nrDeviations + "\nWarnings:" + nrWarnings + "\nErrors:" + nrErrors;

    return errMsg;
  }
Пример #6
0
  private void writeListErrors(
      FileWriter fileOut,
      Vector deviationMessages,
      Vector databaseValues,
      String ind,
      char delimeter,
      String variable,
      String value,
      String date,
      String ref,
      String comm) {

    try {

      if (errorList.size() > 0 || deviationMessages.size() > 0 || warningList.size() > 0) {
        fileOut.write("#--------------------------------------------------\n");
      }
      if (errorList.size() > 0) {
        for (int i = 0; i < errorList.size(); i++) {
          fileOut.write("#" + (String) errorList.get(i) + "\n");
        }
      }
      if (warningList.size() > 0) {
        for (int i = 0; i < warningList.size(); i++) {
          fileOut.write("#" + (String) warningList.get(i) + "\n");
        }
      }

      if (deviationMessages.size() > 0) {
        for (int i = 0; i < deviationMessages.size(); i++) {
          fileOut.write("#" + (String) deviationMessages.elementAt(i) + "\n");
        }
        // write old values
        fileOut.write("#" + databaseValues.elementAt(0) + "\n");
      }
      // if there are errors, the string is "Outcommented"
      if (errorList.size() > 0) {
        fileOut.write("#");
      }

      // write original string
      fileOut.write(
          ind + delimeter + variable + delimeter + value + delimeter + date + delimeter + ref
              + delimeter + comm + "\n");

      if (errorList.size() > 0 || deviationMessages.size() > 0 || warningList.size() > 0) {
        fileOut.write("#--------------------------------------------------\n");
      }

    } // try
    catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }
Пример #7
0
  // public String checkList(FileParser fp, Vector errorMessages, FileWriter fileOut, char
  // delimiter, String indId)
  public String checkList(FileParser fp, FileWriter fileOut, char delimiter, String indId) {
    // String ind, marker, allele1, allele2, raw1, raw2, ref, comm;
    String ind, variable, value, date, ref, comm;

    String errMsg = "";

    int nrErrors = 0;
    int nrWarnings = 0;
    int nrDeviations = 0;

    int dataRows = fp.dataRows();
    String titles[] = fp.columnTitles();

    DbImportFile dbInFile = new DbImportFile();
    String statusStr;
    double status;
    double status_last = 0.0;

    warningList = new ArrayList();
    errorList = new ArrayList();

    for (int i = 0; i < dataRows; i++) {
      //  Vector errorMessages = new Vector();
      //      Vector warningMessages = new Vector();
      Vector deviationMessages = new Vector();
      Vector databaseValues = new Vector();

      ind = ((FileParser) fp).getValue(indId, i).trim();
      variable = ((FileParser) fp).getValue("VARIABLE", i).trim();
      value = ((FileParser) fp).getValue("VALUE", i).trim();
      date = ((FileParser) fp).getValue("DATE", i).trim();
      ref = ((FileParser) fp).getValue("REF", i).trim();
      comm = ((FileParser) fp).getValue("COMMENT", i).trim();

      // Check for valid data values.
      // Check for length, remove null and so on.
      // Syntax check.

      checkValues(ind, variable, value, date, ref, comm);
      //  checkValues(ind, variable, value, date, ref, comm, fatalErrors);

      // If create updateMethod
      if (updateMethod == null || updateMethod.equals("CREATE"))
        checkCreate(titles[0], ind, variable, value, date, ref, comm, sampleUnitId);

      // If update updateMethod
      else if (updateMethod.equals("UPDATE"))
        checkUpdate(
            titles[0],
            ind,
            variable,
            value,
            date,
            ref,
            comm,
            sampleUnitId,
            deviationMessages,
            databaseValues,
            delimiter);

      // if both update and add
      else if (updateMethod.equals("CREATE_OR_UPDATE"))
        checkCreateOrUpdate(
            titles[0],
            ind,
            variable,
            value,
            date,
            ref,
            comm,
            sampleUnitId,
            deviationMessages,
            databaseValues,
            delimiter);

      nrErrors += errorList.size();
      nrDeviations += deviationMessages.size();
      nrWarnings += warningList.size();

      // write row + all errors encountered to file

      writeListErrors(
          fileOut,
          deviationMessages,
          databaseValues,
          ind,
          delimiter,
          variable,
          value,
          date,
          ref,
          comm);

      /*
       * Set the status of the import, visible to the user
       */
      status = (new Double(i * 100 / (1.0 * dataRows))).doubleValue();
      if (status_last + 5 < status) {
        status_last = status;
        statusStr = Integer.toString((new Double(status)).intValue()) + "%";
        dbInFile.setStatus(conn_viss, ifid, statusStr);
      }

      errorList.clear();
      warningList.clear();
    }

    if (nrErrors > 0) errMsg = "ERROR: Import of the Phenotypes failed.";
    else if (nrWarnings > 0) errMsg = "WARNING: Some warnings exist in the import file";
    else errMsg = "Phenotype file is correct";
    errMsg += "\nDeviations:" + nrDeviations + "\nWarnings:" + nrWarnings + "\nErrors:" + nrErrors;

    return errMsg;
  }