001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.survival.cox.comparators;
022
023import org.biojava.nbio.survival.cox.CoxInfo;
024import org.biojava.nbio.survival.cox.CoxVariables;
025
026/**
027 *
028 * @author Scooter Willis <willishf at gmail dot com>
029 */
030public class CoxVariablesVariableComparator implements CoxComparatorInterface {
031
032        String variables = "";
033        String variable = "";
034
035        /**
036         *
037         * @param variables
038         * @param variable
039         */
040        public CoxVariablesVariableComparator(String variables, String variable) {
041                this.variables = variables;
042                this.variable = variable;
043                description = "Signatures ranked by model " + variables + " and variable " + variable + " p-value";
044        }
045
046        @Override
047        public int compare(CoxVariables coxVariables1, CoxVariables coxVariables2) {
048                if(coxVariables1.equals(coxVariables2))
049                        return 0;
050                CoxInfo ci1 = coxVariables1.getCoxInfo(variables);
051                CoxInfo ci2 = coxVariables2.getCoxInfo(variables);
052                if(ci1 == null && ci2 == null)
053                        return 0;
054                if(ci1 == null && ci2 != null)
055                        return 1;
056                if(ci2 == null && ci1 != null)
057                        return -1;
058                if (ci1.getCoefficientsList().get(variable).getPvalue() < ci2.getCoefficientsList().get(variable).getPvalue()) {
059                        return -1;
060                } else if (ci1.getCoefficientsList().get(variable).getPvalue() > ci2.getCoefficientsList().get(variable).getPvalue()) {
061                        return 1;
062                } else {
063                        return 0;
064                }
065                //ascending order
066                // return coxVariables1.compareTo(coxVariables2);
067        }
068
069        @Override
070        public String getDescription() {
071           return description;
072        }
073        String description = "Signatures ranked by p-value ";
074
075        @Override
076        public void setDescription(String description) {
077           this.description = description;
078        }
079
080        @Override
081        public String getModelVariables() {
082                return variables;
083        }
084
085        @Override
086        public String getSortVariable() {
087                return variable;
088        }
089
090
091
092}