예제 #1
0
  /**
   * 1st column is Element (Sequence/OTU/tree leaf), 2nd is taxid
   *
   * @param inFilePath
   * @return
   * @throws IOException
   */
  public static SortedMap<String, Taxon> importElementTaxonomyMap(Path inFilePath)
      throws IOException, XMLStreamException {
    SortedMap<String, Taxon> otuTaxaMap = new TreeMap<>();
    BufferedReader reader = getReader(inFilePath, "Element taxonomy mapping");

    Separator lineSeparator = new Separator("\t");
    String line = reader.readLine();
    while (line != null) {
      if (hasContent(line)) { // not comments or empty
        String[] items = lineSeparator.parse(line);
        if (items.length < 2)
          throw new IllegalArgumentException(
              "Invalid file format for Element taxonomy mapping, line : " + line);
        if (otuTaxaMap.containsKey(items[0]))
          throw new IllegalArgumentException("Find duplicate name for " + items[0]);

        Taxon taxon = TaxonomyPool.getAndAddTaxIdByMemory(items[1]);
        otuTaxaMap.put(items[0], taxon);
      }

      line = reader.readLine();
    }
    reader.close();

    if (otuTaxaMap.size() < 1) throw new IllegalArgumentException("OTU taxonomy map is empty !");

    return otuTaxaMap;
  }
예제 #2
0
  public static TaxonSet importTaxa(Path taxaTSV) throws IOException {
    TaxonSet taxonSet = new TaxonSet();
    BufferedReader reader = getReader(taxaTSV, "taxa");

    Separator lineSeparator = new Separator("\t");
    String line = reader.readLine();
    while (line != null) {
      if (hasContent(line)) { // not comments or empty
        String[] items = lineSeparator.parse(line);
        //                if (items.length < 2)
        //                    throw new IllegalArgumentException("Invalid file format for taxa
        // traits mapping, line : " + line);

        taxonSet.addUniqueElement(items[0]);
      }

      line = reader.readLine();
    }
    reader.close();

    if (taxonSet.size() < 1) throw new IllegalArgumentException("It needs at least one taxon !");

    return taxonSet;
  }