예제 #1
0
  /**
   * Loads a gene database from a stream.
   *
   * @param reader Input stream
   * @throws IOException
   * @throws FileFormatException
   */
  public boolean read(Reader reader, IProgressNotifier notifier)
      throws IOException, FileFormatException {
    if (notifier != null) notifier.setText("loading genes ...");

    clear();

    LineNumberReader in = new LineNumberReader(reader);

    boolean header = true;
    long geneCount = 0;
    Band band = new Band();

    while (in.ready()) {
      if (notifier != null && notifier.isCancelled()) {
        clear();
        return false;
      }
      String line = in.readLine();
      if (header) {
        header = false;
        continue;
      }
      line.trim();

      String[] L = line.split("\t");

      if (L.length < 13)
        throw new FileFormatException("Not enough columns in line " + in.getLineNumber());

      if (L[11].compareToIgnoreCase("GENE") == 0 && L[12].compareToIgnoreCase("reference") == 0) {
        long gene_id;
        String gene_name;
        Interval interval;

        // parse line
        String[] lst = L[1].split("[|]");
        if (lst.length != 1) continue;

        try {
          band.setChromosome(lst[0]);
        } catch (IllegalArgumentException e) {
          continue;
        }

        interval = new Interval();
        interval.from = Long.parseLong(L[2]);
        interval.to = Long.parseLong(L[3]);
        if (!L[10].startsWith("GeneID:"))
          throw new FileFormatException("Error in line " + in.getLineNumber() + " illegal gene id");
        gene_id = Long.parseLong(L[10].split(":")[1]);
        gene_name = L[9];

        // insert new gene
        if (band.chromosome < 1 || band.chromosome > genes.length)
          throw new FileFormatException(
              "Error in line " + in.getLineNumber() + " illegal chromosome");

        Marker m = new Marker();

        m.interval = interval;
        m.info = new GeneInfo(gene_id, gene_name);

        genes[band.chromosome - 1].add(m);

        ++geneCount;
        if ((notifier != null) && (geneCount % 100 == 0))
          notifier.setText(
              "loading genes ... (" + (geneCount / 1000) + "." + ((geneCount % 1000) / 100) + "k)");
      }
    }
    return true;
  }