示例#1
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;
  }
示例#2
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;
  }