/** * By default, a complex expansion can only expand interactions having at least one participant and where the provided interaction is * not null. * @param interaction : the interaction we want to expand * @return true if this complex expansion method can expand such an interaction, false otherwise. */ public boolean isInteractionExpandable(T interaction) { if (interaction == null || interaction.getParticipants().isEmpty()){ return false; } return true; }
public T getParticipantB() { if (!hasInitialisedB){ hasInitialisedB = true; if (wrappedInteraction.getParticipants().size() >= 2){ Iterator<T> participantIterator = wrappedInteraction.getParticipants().iterator(); participantIterator.next(); this.participantB = participantIterator.next(); } } return participantB; }
@Override protected Participant[] createParticipantsArray(Interaction interaction) { return (Participant[]) interaction.getParticipants().toArray(new DefaultParticipant[]{}); }
public T getParticipantA() { if (!hasInitialisedA){ hasInitialisedA = true; this.participantA = !wrappedInteraction.getParticipants().isEmpty() ? wrappedInteraction.getParticipants().iterator().next() : null; } return participantA; }
/** * Use DefaultInteractionInteractorComparator to know if two interactions are equals. * @param interaction1 * @param interaction2 * @return true if the two interactions are equal */ public static boolean areEquals(Interaction interaction1, Interaction interaction2){ if (interaction1 == interaction2){ return true; } else if (interaction1 == null || interaction2 == null){ return false; } else { // first compares participants of an interaction Collection<? extends Participant> participants1 = interaction1.getParticipants(); Collection<? extends Participant> participants2 = interaction2.getParticipants(); return compareParticipants(participants1, participants2); } }
/** * Use DefaultExactInteractionInteractorComparator to know if two interactions are equals. * @param interaction1 * @param interaction2 * @return true if the two interactions are equal */ public static boolean areEquals(Interaction interaction1, Interaction interaction2){ if (interaction1 == interaction2){ return true; } else if (interaction1 == null || interaction2 == null){ return false; } else { // first compares participants of an interaction Collection<? extends Participant> participants1 = interaction1.getParticipants(); Collection<? extends Participant> participants2 = interaction2.getParticipants(); return compareParticipants(participants1, participants2); } }
/** * This method can return all participants having causal relationships in an interaction * @param interaction * @return the collection of participants having causal relationships, empty collection if no participants with causal relationships */ public static Collection<Participant> extractParticipantWithCausalRelationships(Interaction interaction){ if (interaction != null && !interaction.getParticipants().isEmpty()){ Collection<Participant> participants = new ArrayList<Participant>(interaction.getParticipants().size()); for (Object o : interaction.getParticipants()){ Participant participant = (Participant) o; if (!participant.getCausalRelationships().isEmpty()){ participants.add(participant); } } return participants; } return Collections.EMPTY_LIST; } }
public void setParticipantA(T participantA) { getWrappedInteraction().getParticipants().remove(this.participantA); this.participantA = participantA; if (participantA != null){ getWrappedInteraction().getParticipants().add(this.participantA); } }
public void setParticipantB(T participantB) { getWrappedInteraction().getParticipants().remove(this.participantB); this.participantB = participantB; if (participantB != null){ getWrappedInteraction().getParticipants().add(this.participantB); } }
@Override protected Collection<B> collectBinaryInteractionsFromNary(T interaction){ Participant[] participants = createParticipantsArray(interaction); Collection<B> binaryInteractions = new ArrayList<B>((interaction.getParticipants().size() - 1)*(interaction.getParticipants().size() - 1)); for ( int i = 0; i < interaction.getParticipants().size(); i++ ) { Participant c1 = participants[i]; for ( int j = ( i + 1 ); j < participants.length; j++ ) { Participant c2 = participants[j]; // build a new interaction B binary = createBinaryInteraction(interaction, c1, c2); binaryInteractions.add(binary); } } return binaryInteractions; }
@Override protected Collection<B> collectBinaryInteractionsFromNary(T interaction) { Collection<B> binaryInteractions = new ArrayList<B>(interaction.getParticipants().size()-1); Participant bait = collectBestBaitForSpokeExpansion(interaction); for ( Object p : interaction.getParticipants() ) { if (p != bait){ // build a new interaction B binary = createBinaryInteraction(interaction, bait, (Participant)p); binaryInteractions.add(binary); } } return binaryInteractions; }
@Override protected Participant collectBestBaitForSpokeExpansion(Interaction interaction) { return ParticipantUtils.collectBestBaitParticipantForSpokeExpansion(interaction.getParticipants()); }
@Override protected Collection<B> collectBinaryInteractionsFromNary(T interaction){ Participant externalEntity = createParticipantForComplexEntity(createComplexEntity(interaction)); Collection<B> binaryInteractions = new ArrayList<B>(interaction.getParticipants().size()); for ( Object p : interaction.getParticipants() ) { // build a new interaction B binary = createBinaryInteraction(interaction, externalEntity, (Participant)p); binaryInteractions.add(binary); } return binaryInteractions; }
@Override public Collection<BinaryInteraction> expand(Interaction interaction) throws ComplexExpansionException { if (interaction instanceof InteractionEvidence){ Collection<BinaryInteraction> binaryInteractions = new ArrayList<BinaryInteraction>(interaction.getParticipants().size()); binaryInteractions.addAll(interactionEvidenceExpansion.expand((InteractionEvidence) interaction)); return binaryInteractions; } else if (interaction instanceof ModelledInteraction){ Collection<BinaryInteraction> binaryInteractions = new ArrayList<BinaryInteraction>(interaction.getParticipants().size()); binaryInteractions.addAll(modelledInteractionExpansion.expand((ModelledInteraction) interaction)); return binaryInteractions; } else { return super.expand(interaction); } }
@Override public Collection<BinaryInteraction> expand(Interaction interaction) throws ComplexExpansionException { if (interaction instanceof InteractionEvidence){ Collection<BinaryInteraction> binaryInteractions = new ArrayList<BinaryInteraction>(interaction.getParticipants().size()); binaryInteractions.addAll(interactionEvidenceExpansion.expand((InteractionEvidence) interaction)); return binaryInteractions; } else if (interaction instanceof ModelledInteraction){ Collection<BinaryInteraction> binaryInteractions = new ArrayList<BinaryInteraction>(interaction.getParticipants().size()); binaryInteractions.addAll(modelledInteractionExpansion.expand((ModelledInteraction) interaction)); return binaryInteractions; } else { return super.expand(interaction); } }
@Override public Collection<BinaryInteraction> expand(Interaction interaction) throws ComplexExpansionException { if (interaction instanceof InteractionEvidence){ Collection<BinaryInteraction> binaryInteractions = new ArrayList<BinaryInteraction>(interaction.getParticipants().size()); binaryInteractions.addAll(interactionEvidenceExpansion.expand((InteractionEvidence) interaction)); return binaryInteractions; } else if (interaction instanceof ModelledInteraction){ Collection<BinaryInteraction> binaryInteractions = new ArrayList<BinaryInteraction>(interaction.getParticipants().size()); binaryInteractions.addAll(modelledInteractionExpansion.expand((ModelledInteraction) interaction)); return binaryInteractions; } else { return super.expand(interaction); } }
public void write(I interaction) throws MIIOException { if (!isInitialised){ throw new IllegalStateException("The json writer has not been initialised. The options for the json writer should contain at least "+ InteractionWriterOptions.OUTPUT_OPTION_KEY + " to know where to write the interactions and "+ MIJsonWriterOptions.ONTOLOGY_FETCHER_OPTION_KEY+" to know which OntologyTermFetcher to use."); } try{ if (!interaction.getParticipants().isEmpty()){ // write interactors Iterator<Participant> pIterator = interaction.getParticipants().iterator(); while(pIterator.hasNext()){ registerAndWriteInteractor(pIterator.next()); } getInteractionWriter().write(interaction); } else { logger.log(Level.WARNING, "Ignore interaction as it does not contain any participants : "+interaction.toString()); } } catch (IOException e) { throw new MIIOException("Impossible to write " +interaction.toString(), e); } }
protected void buildInteractionkey(I interaction) { this.stringBuilder.setLength(0); this.interactorAcs.clear(); // read ordered set of interactor acs for (Object obj : interaction.getParticipants()) { Participant component = (Participant)obj; interactorAcs.add(component.getInteractor() instanceof IntactInteractor ? ((IntactInteractor) component.getInteractor()).getAc() : component.getInteractor().getShortName()); } for (String prL : interactorAcs) { stringBuilder.append(" "); stringBuilder.append(prL); } // interaction type stringBuilder.append(interaction.getInteractionType().getMIIdentifier()); // experiment CvTerm method = extractInteractionDetectionMethodFrom(interaction); if (method != null) { stringBuilder.append(" "); stringBuilder.append(method.getMIIdentifier()); } }
/** * * @param interaction : the interaction to wrap */ public AbstractBinaryInteractionWrapper(I interaction){ if (interaction == null){ throw new IllegalArgumentException("The wrappedInteraction of a AbstractBinaryInteractionWrapper cannot be null"); } if (interaction.getParticipants().size() > 2){ throw new IllegalArgumentException("The wrappedInteraction of a AbstractBinaryInteractionWrapper cannot have more than two participants"); } this.wrappedInteraction = interaction; Annotation annot = InteractionUtils.collectComplexExpansionMethodFromAnnotations(interaction.getAnnotations()); this.annotations = new AnnotationList(); ((AnnotationList)this.annotations).addAllOnly(interaction.getAnnotations()); if (annot != null){ this.complexExpansion = annot.getTopic(); ((AnnotationList)this.annotations).removeOnly(complexExpansion); } }
private void collectFeaturesAndAddToGraph(I interaction, Graph<F, BindingPair<F>> graph) { for (Object o : interaction.getParticipants()){ Participant participant = (Participant)o; for (Object o2 : participant.getFeatures()){ F feature = (F)o2; if (!feature.getLinkedFeatures().isEmpty()){ graph.addVertex(feature); for (Object o3 : feature.getLinkedFeatures()){ F feature2 = (F)o3; graph.addVertex(feature2); graph.addEdge(feature, feature2); } } } } } }