private TreeMap<Integer, Domain> collapseRepeats(TreeMap<Integer, Domain> doms) { TreeMap<Integer, Domain> collpasedDomains = new TreeMap<Integer, Domain>(); ArrayList<Domain> domainHolding = new ArrayList<Domain>(); Domain lastDom = null; for (Domain cDom : doms.values()) { if (lastDom == null) { domainHolding.add(cDom); lastDom = cDom; continue; } if (lastDom.ID.equals(cDom.ID)) domainHolding.add(cDom); else { if (domainHolding.size() >= repNo) { Domain firstRepDom = domainHolding.get(0); Domain d = new Domain(lastDom.ID, firstRepDom.aliFrom, lastDom.aliTo, -1, -1, -1); d.setComment("collapsed " + domainHolding.size() + " instances"); collpasedDomains.put(d.aliFrom, d); } else { for (Domain d : domainHolding) collpasedDomains.put(d.aliFrom, d); } domainHolding.clear(); domainHolding.add(cDom); } lastDom = cDom; } if (domainHolding.size() >= repNo) { Domain firstRepDom = domainHolding.get(0); Domain d = new Domain(lastDom.ID, firstRepDom.aliFrom, lastDom.aliTo, -1, -1, -1); d.setComment("collapsed " + domainHolding.size() + " instances"); collpasedDomains.put(d.aliFrom, d); } else { for (Domain d : domainHolding) collpasedDomains.put(d.aliFrom, d); } return collpasedDomains; }
private TreeMap<Integer, Domain> mergeHits(TreeMap<Integer, Domain> doms) { Domain lastDom = null, mergedDom = null; int lastStart = 0; int numOfMerged = 1; // n merge operations means n+1 merged domains TreeMap<Integer, Domain> modifedDoms = new TreeMap<Integer, Domain>(); for (int startPos : doms.keySet()) { Domain curDom = doms.get(startPos); if (lastDom != null) { // if the same domain type... if (lastDom.getID().equals(curDom.getID())) { // ... check if split hits present if ((lastDom.getHmmTo() < curDom.getHmmFrom()) && (lastDom.getAliTo() < curDom.getAliFrom())) { numOfMerged += 1; // if we alread started a merged domain, extend if (mergedDom != null) { mergedDom.setAliTo(curDom.getAliTo()); mergedDom.setComment(numOfMerged + " merged hits"); } // else start new merged Domain else { mergedDom = new Domain( curDom.getID(), lastDom.getAliFrom(), // from beginning of last domain curDom.getAliTo(), // to end of current domain lastDom.getHmmFrom(), curDom.getHmmTo(), -1); // evalue? mergedDom.setComment(numOfMerged + " merged hits"); } } // last domain ID is the same, but hits are not split else { modifedDoms.put(lastStart, lastDom); } } // last domain ID is different from current domain ID else { // first add merged domain, if present if (mergedDom != null) { modifedDoms.put(mergedDom.aliFrom, mergedDom); } // all is well - we will keep the last domain else { modifedDoms.put(lastStart, lastDom); } mergedDom = null; numOfMerged = 1; } } lastStart = startPos; lastDom = curDom; } if (mergedDom != null) { mergedDom.setComment(numOfMerged + " merged hits"); modifedDoms.put(mergedDom.aliFrom, mergedDom); } // all is well - we will keep the last domain else modifedDoms.put(lastStart, lastDom); return modifedDoms; }