private void addAttribute(Object value, Attribute attribute, ONDEXRelation relation, AttributeName att) { if (value != null) { if (attribute == null) { relation.createAttribute(att, value, false); } else { attribute.setValue(value); } } }
/** * Transform CytoScape graphics to ONDEX from loading appearance. * * @param relation * ONDEXRelation to add attributes to * @throws XMLStreamException * @throws ParsingFailedException */ private void parseRelationGraphics(ONDEXRelation relation) throws XMLStreamException, ParsingFailedException { // <graphics width="1" fill="#0000ff"> Map<String, String> attributes = getAttributes(); if (attributes.get("fill") != null) { // decode colour of relation relation.createAttribute(color, Color.decode(attributes.get("fill")), false); // relations always visible when importing relation.createAttribute(visible, Boolean.TRUE, false); } }
relation.createAttribute(eValue, Double.valueOf(hit.getEValue()), false); relation.createAttribute(bitScore, Double.valueOf(hit.getScore()), false); relation.createAttribute(overlap, Integer.valueOf(hit.getOverlapingLength()), false); relation.createAttribute(frame, Integer.valueOf(hit.getQueryFrame()), false); relation.createAttribute(query_length, Integer.valueOf(hit.getLengthOfQuerySequence()), false); relation.createAttribute(target_length, Integer.valueOf(hit.getLengthOfTargetSequence()), false); relation.createAttribute(coverage, Double.valueOf(hit.geQueryCoverageSequence()), false);
for (Integer relationId : relationIds) { ONDEXRelation relation = graph.getRelation(relationId); relation.createAttribute(specAtt, specificity, false); relation.createAttribute(degreeAtt, (int) numRelations, false);
/** * Adds a weighting to the entity corresponding to the highest weight * evidence * * @param entity the Relation or Concept to add to * @param weightings a map of evidence to weights * @param weightingAtt the weighting attribute */ private void createWeightingsOnEntity(ONDEXEntity entity, Map<EvidenceType, Double> weightings, AttributeName weightingAtt) { Double highestWeighting = null; for (EvidenceType evidence : entity.getEvidence()) { Double weighting = weightings.get(evidence); if (weighting != null) { if (highestWeighting == null || weighting > highestWeighting) { highestWeighting = weighting; } } } if (highestWeighting != null) { if (entity instanceof ONDEXConcept) ((ONDEXConcept) entity).createAttribute(weightingAtt, highestWeighting, false); else if (entity instanceof ONDEXRelation) ((ONDEXRelation) entity).createAttribute(weightingAtt, highestWeighting, false); } }
public void start() throws Exception { AttributeName att = this.graph.getMetaData().createAttributeName("fact", "fact", "Interesting fact", null, String.class, null); for (ONDEXRelation rel : this.graph.getRelations()) { rel.createAttribute(att, "bob", false); } }
private void createAttributes(ONDEXEntity entity, Map<String, String> attributes) throws ParsingFailedException { String type = attributes.get("type"); Class<?> clazz = null; Object value = null; if (type.equals("string")) { clazz = String.class; value = attributes.get("value"); } else if (type.equals("real")) { clazz = Double.class; value = Double.parseDouble(attributes.get("value")); } else if (type.equals("integer")) { clazz = Integer.class; value = Integer.parseInt(attributes.get("value")); } String name = attributes.get("name").replaceAll(" ", "_"); AttributeName an = graph.getMetaData().getAttributeName(name); if (an == null) { an = graph.getMetaData().getFactory() .createAttributeName(name, clazz); } else if (!an.getDataType().equals(clazz)) { throw new ParsingFailedException( "inconsistent use of attribute names"); } if (entity instanceof ONDEXConcept) { ((ONDEXConcept) entity).createAttribute(an, value, false); } else if (entity instanceof ONDEXRelation) { ((ONDEXRelation) entity).createAttribute(an, value, false); } }
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 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."); } }
edge.createAttribute(an, Boolean.TRUE, false);
Attribute attribute = ortho_relation.getAttribute(an_goscore); if (attribute == null) ortho_relation.createAttribute(an_goscore, goScore, false); else attribute.setValue(goScore); attribute = ortho_relation.getAttribute(an_pfamhits); if (attribute == null) ortho_relation.createAttribute(an_pfamhits, pfamMatchScore, false); else attribute.setValue(pfamMatchScore);
private void processSpeciesReferences(ONDEXConcept reactionC, ListOf<? extends SimpleSpeciesReference> references, RelationType rt) { if (references == null) { return; } for (int j = 0; j < references.size(); j++) { SimpleSpeciesReference reactantRef = references.get(j); ONDEXConcept speciesC = speciesById.get(reactantRef.getSpecies()); if (speciesC != null) { ONDEXRelation reactantRel = graph.getFactory().createRelation(speciesC, reactionC, rt, etSBML); if (reactantRel != null) { if (reactantRef instanceof SpeciesReference) { reactantRel.createAttribute(anStoch, ((SpeciesReference) reactantRef).getStoichiometry(), false); // TODO: handle stoich math } } else { logFail("Failed to create relation!"); } } else { logFail("Unable to resolve species reference: " + reactantRef.getSpecies()); } } }
private void processSpeciesReferences(ONDEXConcept reactionC, ListOf<? extends SimpleSpeciesReference> references, RelationType rt) { if (references == null) { return; } for (int j = 0; j < references.size(); j++) { SimpleSpeciesReference reactantRef = references.get(j); ONDEXConcept speciesC = speciesById.get(reactantRef.getSpecies()); if (speciesC != null) { ONDEXRelation reactantRel = graph.getFactory().createRelation(speciesC, reactionC, rt, etSBML); if (reactantRel != null) { if (reactantRef instanceof SpeciesReference) { reactantRel.createAttribute(anStoch, ((SpeciesReference) reactantRef).getStoichiometry(), false); // TODO: handle stoich math } } else { logFail("Failed to create relation!"); } } else { logFail("Unable to resolve species reference: " + reactantRef.getSpecies()); } } }
/** * 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()); } } }
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); } }
target.createAttribute(an, source.getAttribute(anOriginal).getValue(), source.getAttribute(anOriginal).isDoIndex());