001package org.biopax.paxtools.pattern.miner;
002
003import org.biopax.paxtools.model.BioPAXElement;
004import org.biopax.paxtools.model.level3.Protein;
005import org.biopax.paxtools.model.level3.ProteinReference;
006import org.biopax.paxtools.model.level3.SequenceEntity;
007import org.biopax.paxtools.model.level3.SequenceEntityReference;
008import org.biopax.paxtools.pattern.Match;
009import org.biopax.paxtools.pattern.Pattern;
010import org.biopax.paxtools.pattern.constraint.*;
011
012import java.io.IOException;
013import java.io.OutputStream;
014import java.util.List;
015import java.util.Map;
016
017import static org.biopax.paxtools.pattern.constraint.ConBox.*;
018
019/**
020 * Miner for the directed relations between proteins.
021 * @author Ozgun Babur
022 */
023public class DirectedRelationMiner extends MinerAdapter
024{
025        /**
026         * Constructor that sets name and description.
027         */
028        public DirectedRelationMiner()
029        {
030                super("directed-relations", "Finds relations between proteins where " +
031                        "the first one is controlling an interaction where the second protein is participant.");
032        }
033
034        /**
035         * Constructs the pattern.
036         * @return pattern
037         */
038        @Override
039        public Pattern constructPattern()
040        {
041                Pattern p = new Pattern(SequenceEntityReference.class, "controller ER");
042                p.add(isHuman(), "controller ER");
043                p.add(linkedER(true), "controller ER", "controller generic ER");
044                p.add(erToPE(), "controller generic ER", "controller simple PE");
045                p.add(linkToComplex(), "controller simple PE", "controller PE");
046                p.add(peToControl(), "controller PE", "Control");
047                p.add(controlToInter(), "Control", "Interaction");
048                p.add(new NOT(participantER()), "Interaction", "controller ER");
049                p.add(participant(), "Interaction", "affected PE");
050                p.add(linkToSpecific(), "affected PE", "affected simple PE");
051                p.add(new Type(SequenceEntity.class), "affected simple PE");
052                p.add(peToER(), "affected simple PE", "affected generic ER");
053                p.add(peToER(), "affected generic ER", "affected ER");
054
055                return p;
056        }
057
058        /**
059         * Writes the result as "A B", where A and B are gene symbols, and whitespace is tab.
060         * @param matches pattern search result
061         * @param out output stream
062         */
063        @Override
064        public void writeResult(Map<BioPAXElement, List<Match>> matches, OutputStream out)
065                throws IOException
066        {
067                writeResultAsSIF(matches, out, true, getSourceLabel(), getTargetLabel());
068        }
069
070        /**
071         * Sets header of the output.
072         * @return header
073         */
074        @Override
075        public String getHeader()
076        {
077                return "Upstream\tDownstream";
078        }
079
080        public String getSourceLabel()
081        {
082                return "controller ER";
083        }
084
085        public String getTargetLabel()
086        {
087                return "affected ER";
088        }
089
090        @Override
091        public String[] getMediatorLabels()
092        {
093                return new String[]{"Control", "Interaction"};
094        }
095}