/** * Returns a list of resource URIs that contain the given {@link Pattern}(s). This is * useful to obtain, e.g., all KEGG resources this term points to. * * @param patterns * an arbitrary number of {@link Pattern}(s), e.g., * {@code http://identifiers.org/kegg.reaction/R.*}, {@code .*kegg.*} or just {@code kegg} that * are matched to all resources using an OR-operation, i.e., * if just one of the patterns matches a resource, this resource will * appear in the returned list. * @return A list of all resources that contain the given pattern. This list * can be empty, but never {@code null}. The order of the resources * in that list will be identical to the order in this term. * @see Pattern * @see Matcher#find() */ public List<String> filterResources(Pattern... patterns) { List<String> selectedResources = new ArrayList<String>(); for (int i = 0; i < getResourceCount(); i++) { String resource = getResourceURI(i); for (Pattern pattern : patterns) { Matcher matcher = pattern.matcher(resource); if (matcher.find()) { selectedResources.add(resource); break; } } } return selectedResources; }
@Override public TreeNode getChildAt(int childIndex) { if (childIndex < getResourceCount()) { return new TreeNodeAdapter(getResourceURI(childIndex), this); } else if (childIndex == getResourceCount()) { return new TreeNodeAdapter(listOfNestedCVTerms, this); } else { throw new IndexOutOfBoundsException(Integer.toString(childIndex)); } }
/** * Creates a {@link CVTerm} instance from a given {@link CVTerm}. * * @param term the {@link CVTerm} to clone */ public CVTerm(CVTerm term) { super(term); type = term.getQualifierType(); switch (type) { case MODEL_QUALIFIER: qualifier = term.getModelQualifierType(); break; case BIOLOGICAL_QUALIFIER: qualifier = term.getBiologicalQualifierType(); break; default: // UNKNOWN qualifier = null; break; } resourceURIs = new ArrayList<String>(); for (int i = 0; i < term.getResourceCount(); i++) { String resource = term.getResourceURI(i); if (resource != null) { resourceURIs.add(new String(term.getResourceURI(i))); } } }
/** * Writes all the MIRIAM annotations of the {@link CVTerm} in 'buffer' * * @param indent * @param buffer */ public void toXML(String indent, StringBuffer buffer) { StringTools.append(buffer, "<", type.getElementNameEquivalent(), ":", getQualifier().getElementNameEquivalent(), ">\n", indent, "<rdf:Bag>\n"); if (resourceURIs != null) { for (int i = 0; i < getResourceCount(); i++) { StringTools.append(buffer, indent, indent, "<rdf:li rdf:resource=\"", getResourceURI(i), "\"/>\n"); } } StringTools.append(buffer, indent, "</rdf:Bag>\n", "</", type.getElementNameEquivalent(), ":", getQualifier().getElementNameEquivalent(), ">\n"); }