Exemplo n.º 1
0
  /**
   * Check the headers of the Phenotype matrix file
   *
   * @param titles
   * @param errorMessages
   * @param suid
   * @return
   */
  private boolean checkMatrixTitles(String[] titles, Vector errorMessages) {
    boolean errorFound = false;
    String errorStr = null;
    try {

      if (titles.length < 2) errorFound = true;
      else if (!(titles[0].equals("IDENTITY") || titles[0].equals("ALIAS"))) {
        errorFound = true;
      }
      if (errorFound) {
        errorStr =
            " Illegal headers.\n"
                + "# Required file headers: IDENTITY/ALIAS VARIABLE1 VARIABLE2 ...\n"
                + "# Headers found in file: ";
        for (int j = 0; j < titles.length; j++) {
          errorStr = errorStr + " " + titles[j];
        }
        errorMessages.addElement(errorStr);
      }

      // now we check that the variables in header exists
      for (int i = 1; i < titles.length; i++) {
        if (db.isVariableUnique(titles[i])) {
          errorFound = true;
          errorStr = "Variable " + titles[i] + " does not exist.";
          errorMessages.addElement(errorStr);
        }
      }
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
    return errorFound;
  }
Exemplo n.º 2
0
  /**
   * @param fileOut
   * @param errorMessages
   * @param warningMessages
   * @param deviationMessages
   * @param databaseValues
   * @param ind
   * @param delimeter
   * @param marker
   * @param allele1
   * @param allele2
   * @param raw1
   * @param raw2
   * @param ref
   * @param comm
   */
  private void writeTitleErrors(FileWriter fileOut, Vector titleError) {

    try {

      if (titleError.size() > 0) {
        fileOut.write("#--------------------------------------------------\n");
        for (int i = 0; i < titleError.size(); i++) {
          fileOut.write("#" + (String) titleError.elementAt(i) + "\n");
        }
        fileOut.write("#--------------------------------------------------\n");
      }
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }
Exemplo n.º 3
0
  /**
   * Check the titles if they are valid.
   *
   * <p>There should be 8 columns { {IDENTITY | ALIAS} , VARIABLE , VALUE, DATE, REFERENCE, COMMIT }
   *
   * @param titles
   * @param errorMessages
   * @return
   */
  private boolean checkListTitles(String[] titles, Vector errorMessages) {
    // Check the file header
    boolean errorFound = false;
    String errorStr = null;

    if (titles.length != 6) // 8
    errorFound = true;
    else if (!(titles[0].equals("IDENTITY") || titles[0].equals("ALIAS"))
        || !titles[1].equals("VARIABLE")
        || !titles[2].equals("VALUE")
        || !titles[3].equals("DATE")
        || !titles[4].equals("REFERENCE")
        || !titles[5].equals("COMMENT")) errorFound = true; // ref=6, comm=7

    if (errorFound) {
      errorStr =
          " Illegal headers.\n"
              + // <BR>
              "# Required file headers: IDENTITY/ALIAS VARIABLE VALUE DATE REFERENCE COMMENT \n"
              + "# Headers found in file: ";

      for (int j = 0; j < titles.length; j++) {
        errorStr = errorStr + " " + titles[j];
      }
      errorMessages.addElement(errorStr);
    }
    return errorFound;
  }
Exemplo n.º 4
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);
    }
  }
Exemplo n.º 5
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);
    }
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 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;
  }