001package org.biopax.paxtools.pattern.miner;
002
003import org.biopax.paxtools.model.BioPAXElement;
004import org.biopax.paxtools.model.level3.ProteinReference;
005import org.biopax.paxtools.pattern.Match;
006import org.biopax.paxtools.pattern.Pattern;
007import org.biopax.paxtools.pattern.PatternBox;
008import org.biopax.paxtools.pattern.constraint.Type;
009
010import java.io.IOException;
011import java.io.OutputStream;
012import java.util.List;
013import java.util.Map;
014
015/**
016 * Miner for the controls-state-change-detailed pattern. Different from the controls-state-change
017 * pattern, this miner also records the modifications of the controller, and gained and lost
018 * modifications of the changed gene.
019 * @author Ozgun Babur
020 */
021public class ControlsStateChangeDetailedMiner extends MinerAdapter
022{
023        /**
024         * Constructor that sets name and description.
025         */
026        public ControlsStateChangeDetailedMiner()
027        {
028                super("controls-state-change-detailed", "Captures exactly the same pattern as " +
029                        "\"Controls-state-change\", but the result file is more detailed. Together with " +
030                        "upstream and downstream genes, it also contains modifications of the upstream " +
031                        "entity, as well as the gained and lost modifications of the downstream entity.");
032        }
033
034        /**
035         * Constructs the pattern.
036         * @return pattern
037         */
038        @Override
039        public Pattern constructPattern()
040        {
041                return PatternBox.controlsStateChange();
042        }
043
044        /**
045         * Writes the result as "A modifications-of-A B gains-of-B loss-of-B", where A and B are gene
046         * symbols, and whitespace is tab. Modifications are comma separated.
047         * @param matches pattern search result
048         * @param out output stream
049         */
050        @Override
051        public void writeResult(Map<BioPAXElement, List<Match>> matches, OutputStream out)
052                throws IOException
053        {
054                writeResultDetailed(matches, out, 5);
055        }
056
057        /**
058         * Gets the header of the result file.
059         * @return header
060         */
061        @Override
062        public String getHeader()
063        {
064                return "Upstream\tModifications-of-upstream\tDownstream\tGain-of-downstream\tLoss-of-downstream";
065        }
066
067        /**
068         * Creates values for the result file columns.
069         * @param m current match
070         * @param col current column
071         * @return value of the given match at the given column
072         */
073        @Override
074        public String getValue(Match m, int col)
075        {
076                switch(col)
077                {
078                        case 0:
079                        {
080                                return getGeneSymbol(m, "controller ER");
081                        }
082                        case 1:
083                        {
084                                return concat(getModifications(m, "controller simple PE", "controller PE"), " ");
085                        }
086                        case 2:
087                        {
088                                return getGeneSymbol(m, "changed ER");
089                        }
090                        case 3:
091                        {
092                                return concat(getDeltaModifications(m,
093                                        "input simple PE", "input PE", "output simple PE", "output PE")[0], " ");
094                        }
095                        case 4:
096                        {
097                                return concat(getDeltaModifications(m,
098                                        "input simple PE", "input PE", "output simple PE", "output PE")[1], " ");
099                        }
100                        default: throw new RuntimeException("Invalid col number: " + col);
101                }
102        }
103}