/** * For a collection of items return the count of given class name. * * @param items the Item collection to count * @return the count for a given classname in the collection */ public static int countItemByClass(Collection<Item> items, String className) { Map<String, List> counts = new TreeMap<String, List>(); for (Item item : items) { List<String> clsItems = counts.get(item.getClassName()); if (clsItems == null) { clsItems = new ArrayList<String>(); counts.put(item.getClassName(), clsItems); } clsItems.add(item.getIdentifier()); } return counts.get(className).size(); }
/** * For a collection of items return a string containing counts of each item classname - useful for * degugging tests. * * @param items the Item collection to count * @return a formatted string with counts for each classname in the collection */ public static String countItemClasses(Collection<Item> items) { Map<String, List> counts = new TreeMap<String, List>(); for (Item item : items) { List<String> clsItems = counts.get(item.getClassName()); if (clsItems == null) { clsItems = new ArrayList<String>(); counts.put(item.getClassName(), clsItems); } clsItems.add(item.getIdentifier()); } StringBuffer sb = new StringBuffer(); for (Map.Entry<String, List> entry : counts.entrySet()) { sb.append(entry.getKey() + " - " + entry.getValue().size() + " " + entry.getValue() + ENDL); } return sb.toString(); }
private void setRefsAndCollections(List<String> parents, Item feature) { String clsName = feature.getClassName(); Map<String, String> refsAndCollections = handler.getRefsAndCollections(); if (refsAndCollections != null && refsAndCollections.containsKey(clsName) && parents != null && !parents.isEmpty()) { ClassDescriptor cld = tgtModel.getClassDescriptorByName(tgtModel.getPackageName() + "." + clsName); String refName = refsAndCollections.get(clsName); Iterator<String> parentIter = parents.iterator(); if (cld.getReferenceDescriptorByName(refName, true) != null) { String parent = parentIter.next(); feature.setReference(refName, getRefId(parent)); if (parentIter.hasNext()) { String primaryIdent = feature.getAttribute("primaryIdentifier").getValue(); throw new RuntimeException( "Feature has multiple relations for reference: " + refName + " for feature: " + feature.getClassName() + ", " + feature.getIdentifier() + ", " + primaryIdent); } } else if (cld.getCollectionDescriptorByName(refName, true) != null) { List<String> refIds = new ArrayList<String>(); while (parentIter.hasNext()) { refIds.add(getRefId(parentIter.next())); } feature.setCollection(refName, refIds); } else if (parentIter.hasNext()) { throw new RuntimeException( "No '" + refName + "' reference/collection found in " + "class: " + clsName + " - is map configured correctly?"); } } }
/* @Override necessary */ public void process(GFF3Record record) { Item feature = getFeature(); String clsName = feature.getClassName(); if ("Gene".equals(clsName)) { // move Gene.primaryIdentifier to Gene.secondaryIdentifier // move Gene.symbol to Gene.primaryIdentifier if (feature.getAttribute("primaryIdentifier") != null) { String secondary = feature.getAttribute("primaryIdentifier").getValue(); feature.setAttribute("secondaryIdentifier", secondary); } if (feature.getAttribute("symbol") != null) { String primary = feature.getAttribute("symbol").getValue(); feature.setAttribute("primaryIdentifier", primary); feature.removeAttribute("symbol"); } } }