@Override protected Attribute retrieveRelationAttribute(AttributeName attributeName) { return parent.getAttribute(attributeName); }
/** * Copies all Attribute from old relation to new relation. * * @param oldR * old ONDEXRelation * @param newR * new ONDEXRelation */ private void copyGDS(ONDEXRelation oldR, ONDEXRelation newR) { // iterate over all old Attribute for (Attribute attribute : oldR.getAttributes()) { // clone old Attribute on new relation only if not yet exists if (newR.getAttribute(attribute.getOfType()) != null) // old Attribute gets overridden newR.deleteAttribute(attribute.getOfType()); else newR.createAttribute(attribute.getOfType(), attribute.getValue(), attribute.isDoIndex()); } } }
private static double getNumber(AttributeName an, ONDEXRelation r) { Attribute attribute = r.getAttribute(an); if (attribute == null) return 0d; else return (Double) attribute.getValue(); }
/** * returns the weight of the given edge. * * @param r_curr * the relation for which to retrieve the edge weight. * @param weightAttributeName * @return the edge weight of the given relation. */ private static double getWeight(ONDEXRelation r_curr, AttributeName weightAttributeName) { double out; Attribute weightAttribute = r_curr.getAttribute(weightAttributeName); out = ((java.lang.Number) weightAttribute.getValue()).doubleValue(); return out; }
/** * retrieves the edge weight for a given relation. This method is used * by the <code>buildMatrices()</code> method. * * @param r_curr The relation from which to extract the edge weight. * @return The edge weight. */ private double getWeight(ONDEXRelation r_curr) { Attribute weightAttribute = r_curr.getAttribute(weightAttributeName); double w; if ((weightAttribute != null) && (weightAttribute.getValue() instanceof Number)) w = ((Number) weightAttribute.getValue()).doubleValue(); else w = 1.0; if (inverse) w = 1.0 - w; return w; }
/** * returns the weight of the given edge. * * @param r_curr the relation for which to retrieve the edge weight. * @return the edge weight of the given relation. */ private double getWeight(ONDEXRelation r_curr) { double out; if (useWeights) { Attribute weightAttribute = r_curr.getAttribute(weightAttributeName); if ((weightAttribute != null) && (weightAttribute.getValue() instanceof Number)) out = ((Number) weightAttribute.getValue()).doubleValue(); else out = 1.0; } else out = 1.0; if (inverse) out = 1.0 - out; return out; }
/** * returns the weight of the given edge. * * @param r_curr the relation for which to retrieve the edge weight. * @return the edge weight of the given relation. */ private double getWeight(ONDEXRelation r_curr) { double out; if (useWeights) { Attribute weightAttribute = r_curr.getAttribute(weightAttributeName); if ((weightAttribute != null) && (weightAttribute.getValue() instanceof Number)) out = ((Number) weightAttribute.getValue()).doubleValue(); else out = 1.0; } else out = 1.0; if (inverse) out = 1.0 - out; return out; }
private static Set<ONDEXRelation> getRelationsWithAttribute(ONDEXGraph graph, ONDEXConcept c, AttributeName an) { BitSet set = new BitSet(); for (ONDEXRelation r : graph.getRelationsOfConcept(c)) { if (r.getFromConcept().equals(r.getToConcept())) continue; if (r.getAttribute(an) != null) set.set(r.getId()); } Set<ONDEXRelation> result = BitSetFunctions.create(graph, ONDEXRelation.class, set); return result; }
/** * @see AbstractContentDisplayPlugin.compileContent() */ @Override public String compileContent(ONDEXEntity e) { if (an != null) { StringBuffer b = new StringBuffer(""); if (e instanceof ONDEXConcept) { ONDEXConcept c = (ONDEXConcept) e; Attribute attribute = c.getAttribute(an); displayStructure(b, attribute); } else if (e instanceof ONDEXRelation) { ONDEXRelation r = (ONDEXRelation) e; Attribute attribute = r.getAttribute(an); displayStructure(b, attribute); } return b.toString(); } else return ""; }
private void copyCVToRelation(ONDEXConcept to, ONDEXRelation relation, AttributeName att) { DataSource dataSource = to.getElementOf(); String[] typeIds = dataSource.getId().split(":"); for (String typeId : typeIds) { Attribute attribute = relation.getAttribute(att); if (attribute == null) { relation.createAttribute(att, typeId, false); } else if (attribute.getValue() instanceof Collection) { Collection collection = (Collection) attribute.getValue(); if (!collection.contains(typeId)) { collection.add(typeId); attribute.setValue(collection); } } else if (!attribute.getValue().equals(typeId)) { List<String> cvs = new ArrayList<String>(2); cvs.add(typeId); cvs.add((String) attribute.getValue()); attribute.setValue(cvs); } } }
public static void exportToCFinder(ONDEXGraph graph, String file, String nodeCV, String attribute) { AttributeName an = graph.getMetaData().getAttributeName(attribute); Set<ONDEXRelation> relations = graph.getRelationsOfAttributeName(an); DataSource dataSource = graph.getMetaData().getDataSource(nodeCV); try { DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); for (ONDEXRelation r : relations) { String[] line = new String[3]; ONDEXConcept to = r.getToConcept(); for (ConceptAccession ac : to.getConceptAccessions()) { if (ac.getElementOf().equals(dataSource)) line[0] = ac.getAccession(); } ONDEXConcept from = r.getFromConcept(); for (ConceptAccession ac : from.getConceptAccessions()) { if (ac.getElementOf().equals(dataSource)) line[1] = ac.getAccession(); } line[2] = r.getAttribute(an).getValue().toString(); bw.write(line[0] + "\t" + line[1] + "\t" + line[2] + "\n"); bw.flush(); } out.close(); } catch (Exception e) { e.printStackTrace(); } }
public static void assignBlastWeight(ONDEXGraph graph) { AttributeName an = graph.getMetaData().getFactory().createAttributeName("BLAST_WEIGHT", Double.class); for (ONDEXRelation r : graph.getRelations()) { Attribute attribute = r.getAttribute(graph.getMetaData().getAttributeName("BLEV")); if (attribute == null) continue; Float score = (float) (double) (Double) attribute.getValue(); Double value = (double) 1f / (1f + (float) Math.exp(((((float) Math.log10(score) + 3f) * 6.66667f) + 10f))); r.createAttribute(an, value, false); } }
public static String assignAverageWeight(ONDEXGraph graph, List<String> atts) { List<AttributeName> ans = new ArrayList<AttributeName>(); String name = ""; for (String a : atts) { ans.add(graph.getMetaData().getAttributeName(a)); if (!name.equals("")) { name = name + ","; } name = name + a; } AttributeName av = graph.getMetaData().getFactory().createAttributeName("COMBINED[" + name + "]", Double.class); for (ONDEXRelation r : graph.getRelations()) { Double sum = 0d; for (AttributeName an : ans) { sum = sum + getNumber(an, r); } Double average = sum / ((double) ans.size()); if (r.getAttribute(av) != null) { r.deleteAttribute(av); } r.createAttribute(av, average, false); } return "COMBINED[" + name + "]"; }
private static void assignCoexWeight(ONDEXGraph graph) { AttributeName an = graph.getMetaData().getFactory().createAttributeName("COEX_WEIGHT", Double.class); for (ONDEXRelation r : graph.getRelations()) { Attribute attribute = r.getAttribute(graph.getMetaData().getAttributeName("Correlation")); if (attribute == null) continue; Double score = (Double) attribute.getValue(); r.createAttribute(an, (Math.abs(score) - 0.6) / 0.4, false); } }
/** * Creates a gds on relation only if it does not already exists * * @param target * - relation * @param newAttribute * - attribute to create * @throws AccessDeniedException * @throws NullValueException */ public static void addNewAttribute(ONDEXRelation target, Attribute newAttribute) throws NullValueException, AccessDeniedException { if (target.getAttribute(newAttribute.getOfType()) == null) target.createAttribute(newAttribute.getOfType(), newAttribute.getValue(), newAttribute.isDoIndex()); }
public static void changeAttributeValue(ONDEXEntity e, AttributeName n, Object value) { if (e instanceof ONDEXConcept) { ONDEXConcept c = (ONDEXConcept) e; boolean doIndex = c.getAttribute(n).isDoIndex(); c.deleteAttribute(n); c.createAttribute(n, value, doIndex); } if (e instanceof ONDEXRelation) { ONDEXRelation r = (ONDEXRelation) e; boolean doIndex = r.getAttribute(n).isDoIndex(); r.deleteAttribute(n); r.createAttribute(n, value, doIndex); } else { throw new IllegalArgumentException( "This method only works with Ondex concepts and relations."); } }
private void populateValues() { vlm.clearList(); Set<Object> objects = new HashSet<Object>(); if (target != null) { if (onConcepts) { for (ONDEXConcept c : graph.getConceptsOfAttributeName(target)) { Attribute attribute = c.getAttribute(target); objects.add(attribute.getValue()); } } else { for (ONDEXRelation r : graph .getRelationsOfAttributeName(target)) { Attribute attribute = r.getAttribute(target); objects.add(attribute.getValue()); } } } // sort array if possible Object[] array = objects.toArray(); Arrays.sort(array); for (Object o : array) { vlm.addObject(o); } vlm.refresh(); values.setEnabled(!vlm.isEmpty()); values.repaint(); this.repaint(); }
public static void removeRelationsWithGDSValue(final OVTK2PropertiesAggregator viewer, String attributeName, double value) { ONDEXGraph graph = viewer.getONDEXJUNGGraph(); ONDEXJUNGGraph jung = viewer.getONDEXJUNGGraph(); AttributeName an = graph.getMetaData().getFactory().createAttributeName(attributeName, Double.class); int n = 0; for (ONDEXRelation r : graph.getRelations()) { Attribute attribute = r.getAttribute(an); if (attribute == null) { jung.setVisibility(r, false); } else if (((Double) attribute.getValue()) == value) { jung.setVisibility(r, false); } else { jung.setVisibility(r, true); n++; } } System.err.println("Relations remaining: " + n); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewer.getVisualizationViewer().getModel().fireStateChanged(); // viewer.validate(); } }); }
/** * Retrieve edge color from stored Attribute values. * * @param graph * ONDEXGraph * @param edgePaint * ONDEXEdgeColors */ public static void loadEdgeColor(ONDEXGraph graph, ONDEXEdgeColors edgePaint) { ONDEXGraphMetaData meta = graph.getMetaData(); // load colour AttributeName anColor = meta.getAttributeName(COLOR); if (anColor != null) { edgePaint.setEdgeColorSelection(EdgeColorSelection.MANUAL); for (ONDEXRelation r : graph.getRelationsOfAttributeName(anColor)) { edgePaint.updateColor(r, (Color) r.getAttribute(anColor).getValue()); } } }
public static void assignCombinedWeight(ONDEXGraph graph) { AttributeName coex = graph.getMetaData().getAttributeName("COEX_WEIGHT"); AttributeName blast = graph.getMetaData().getAttributeName("BLAST_WEIGHT"); AttributeName itwi = graph.getMetaData().getAttributeName("INTERACTION_WEIGHT"); AttributeName tm = graph.getMetaData().getAttributeName("Co-citation_weight"); AttributeName all = graph.getMetaData().getFactory().createAttributeName("COMBINED_WEIGHT", Double.class); for (ONDEXRelation r : graph.getRelations()) { Double value = ((getNumber(coex, r) + getNumber(blast, r) + getNumber(itwi, r) + getNumber(tm, r)) / 4d); if (r.getAttribute(all) != null) { r.deleteAttribute(all); } r.createAttribute(all, value, false); } }