Example #1
0
  /**
   * ************************** readDataFile **************************** * Reads the input file and
   * gets the number of taxa and alignment * length * *
   * *********************************************************************
   */
  public static void getHeader(String infilenameComplete) {
    // needs the complete path to the file
    try {
      TextInputStream in = new TextInputStream(infilenameComplete);
      String line = in.readLine();
      in.close();
      StringTokenizer reader = new StringTokenizer(line);
      options.setNumTaxa(Integer.parseInt(reader.nextToken()));
      options.setNumSites(Integer.parseInt(reader.nextToken()));
    } catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(
          new JFrame(),
          "Could not read the input alignment",
          "jModelTest error",
          JOptionPane.ERROR_MESSAGE);
    }

    if (options.getNumTaxa() <= 4)
      JOptionPane.showMessageDialog(
          new JFrame(),
          "The number of taxa does not seem to be correct: " + options.getNumTaxa(),
          "jModelTest error",
          JOptionPane.ERROR_MESSAGE);

    if (options.getNumSites() <= 1)
      JOptionPane.showMessageDialog(
          new JFrame(),
          "The number of sites does not seem to be correct: " + options.getNumTaxa(),
          "jModelTest error",
          JOptionPane.ERROR_MESSAGE);
  }
Example #2
0
public abstract class AlignmentReader {
  private static ApplicationOptions options = ApplicationOptions.getInstance();;

  /**
   * ************************** readDataFile **************************** * Reads the input file and
   * gets the number of taxa and alignment * length * *
   * *********************************************************************
   */
  public static void getHeader(String infilenameComplete) {
    // needs the complete path to the file
    try {
      TextInputStream in = new TextInputStream(infilenameComplete);
      String line = in.readLine();
      in.close();
      StringTokenizer reader = new StringTokenizer(line);
      options.setNumTaxa(Integer.parseInt(reader.nextToken()));
      options.setNumSites(Integer.parseInt(reader.nextToken()));
    } catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(
          new JFrame(),
          "Could not read the input alignment",
          "jModelTest error",
          JOptionPane.ERROR_MESSAGE);
    }

    if (options.getNumTaxa() <= 4)
      JOptionPane.showMessageDialog(
          new JFrame(),
          "The number of taxa does not seem to be correct: " + options.getNumTaxa(),
          "jModelTest error",
          JOptionPane.ERROR_MESSAGE);

    if (options.getNumSites() <= 1)
      JOptionPane.showMessageDialog(
          new JFrame(),
          "The number of sites does not seem to be correct: " + options.getNumTaxa(),
          "jModelTest error",
          JOptionPane.ERROR_MESSAGE);
  }

  /**
   * Creates an alignment instance.
   *
   * @param out the out
   * @param pr the pushback reader which contains the alignment
   * @param debug the debug state
   * @return the alignment
   * @throws AlignmentParseException the alignment parse exception
   * @throws IOException Signals that an I/O exception has occured.
   */
  public static Alignment createAlignment(PrintWriter out, PushbackReader pr, boolean debug)
      throws AlignmentParseException, IOException {

    if (debug) {
      out.println("");
      out.println("**********************************************************");
      out.println("  Reading alignment...");
    }
    Alignment alignment = null;
    try {
      alignment = new ReadAlignment(pr);
    } catch (pal.alignment.AlignmentParseException e) {
      throw new AlignmentParseException(e.getMessage());
    }

    List<String> seqNames = new ArrayList<String>(alignment.getSequenceCount());
    for (int i = 0; i < alignment.getSequenceCount(); i++) {
      seqNames.add(alignment.getIdentifier(i).getName());
    }

    String currString;
    int size = alignment.getSequenceCount();
    for (int i = 0; i < size; i++) {
      currString = seqNames.get(i);
      for (int j = i + 1; j < size; j++) {
        if (seqNames.get(j).equals(currString)) {
          throw new AlignmentParseException(
              "ERROR: There are duplicated taxa names in the alignment: " + currString);
        }
      }
    }

    if (debug) {
      for (int i = 0; i < alignment.getSequenceCount(); i++) {
        out.println("    Sequence #" + (i + 1) + ": " + alignment.getIdentifier(i).getName());
      }
      out.println(
          "   Alignment contains "
              + alignment.getSequenceCount()
              + " sequences of length "
              + alignment.getSiteCount());
      out.println("");
      out.println("**********************************************************");
      out.println("");
    }

    return alignment;
  }
} // class AlignmentReader