Exemple #1
0
 @Test
 public void testToString() {
   assertTrue(
       "(ipv4) toString should return expected format",
       domain1.toString().equals("200.193.193.in-addr.arpa(193.193.200.0/24 INADDR not-dashed)"));
   assertTrue(
       "(ipv6) toString should return expected format",
       domain4.toString().equals("2.1.2.1.5.5.5.2.0.2.1.e164.arpa(E164 not-dashed)"));
 }
  // <seq id> <alignment start> <alignment end> <envelope start> <envelope end>
  // <hmm acc> <hmm name> <type> <hmm start> <hmm end> <hmm length> <bit score> <E-value>
  // <significance> <clan>
  public void pfamscan2xdom() {

    TreeMap<Integer, Domain> currentDoms = new TreeMap<Integer, Domain>();
    Pattern comment = Pattern.compile("^#.*");
    Pattern empty = Pattern.compile("^$");

    try {
      FileWriter fw = new FileWriter(outfile);

      String line;
      FileInputStream fis = new FileInputStream(this.domtblout);
      DataInputStream dis = new DataInputStream(fis);
      BufferedReader br = new BufferedReader(new InputStreamReader(dis));
      String currentId = null;
      StringBuilder xdom = new StringBuilder();
      int didField = 6;

      if (accMode) didField = 5;

      while ((line = br.readLine()) != null) {
        if (comment.matcher(line).matches()) continue;
        if (empty.matcher(line).matches()) continue;

        String[] fields = line.split("\\s+");

        // 0 -> protein id
        // 5 -> domain acc
        // 6 -> domain name (id)
        // 12 -> domain evalue
        // 8, 9 -> hmm coord
        // 1, 2 -> align coord
        // 3, 4 -> env coord
        // 15 -> clanid
        String thisId = fields[0];
        Pattern p = Pattern.compile("\\w+.\\d+");
        Matcher m = p.matcher(thisId);
        if (m.find()) {
          String[] pidFields = thisId.split("\\.");
          thisId = pidFields[0];
        }
        if ((currentId != null) && (!thisId.equals(currentId))) {
          if (xdom.length() != 0) {
            fw.write(xdom.toString() + "\n");
            // merge split hits
            if (merge) currentDoms = mergeHits(currentDoms);

            // resolve overlaps
            if (resolveOverlaps) resolveOverlaps(currentDoms, null);

            if (collapse) currentDoms = collapseRepeats(currentDoms);

            // write the rest of the domains
            for (int key : currentDoms.keySet()) {
              Domain cdom = currentDoms.get(key);
              if ((cdom = currentDoms.get(key)) != null) fw.write(cdom.toString() + "\n");
            }
          }
          xdom.setLength(0);
          currentDoms.clear();
        }

        if (xdom.length() == 0) {
          currentId = fields[0];
          p = Pattern.compile("\\w+.\\d+");
          m = p.matcher(currentId);
          if (m.find()) {
            String[] pidFields = currentId.split("\\.");
            currentId = pidFields[0];
          }
          xdom.setLength(0);
          xdom.append(">" + currentId);
        }
        if (evalue != null) if (Double.parseDouble(fields[12]) > evalue) continue;

        // ensure that the version number is removed if we are
        // in acc mode
        String did = fields[didField];
        if (accMode) {
          p = Pattern.compile("PF\\d+.\\d+");
          m = p.matcher(did);
          if (m.find()) {
            String[] didFields = did.split("\\.");
            did = didFields[0];
          }
        }
        if (clanMode) {
          p = Pattern.compile("CL\\d+");
          m = p.matcher(fields[14]);
          if (m.find()) did = fields[14];
        }

        Domain dom =
            new Domain(
                did,
                Integer.parseInt(fields[1]),
                Integer.parseInt(fields[2]),
                Integer.parseInt(fields[8]),
                Integer.parseInt(fields[9]),
                Double.parseDouble(fields[12]));

        currentDoms.put(Integer.parseInt(fields[1]), dom);
      }
      if (xdom.length() != 0) {
        fw.write(xdom.toString() + "\n");
        if (merge) currentDoms = mergeHits(currentDoms);

        if (resolveOverlaps) resolveOverlaps(currentDoms, null);

        if (collapse) currentDoms = collapseRepeats(currentDoms);

        for (int key : currentDoms.keySet()) {
          Domain cdom = currentDoms.get(key);
          if ((cdom = currentDoms.get(key)) != null) fw.write(cdom.toString() + "\n");
        }
      }
      fis.close();
      dis.close();
      br.close();
      fw.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }