Skip to content
Permalink
c1a081ff8f
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
776 lines (660 sloc) 26.8 KB
package edu.uconn.tripoint.triangulation;
import edu.uconn.tripoint.graph.Edge;
import edu.uconn.tripoint.graph.Node;
import edu.uconn.tripoint.pathway.Gene;
import edu.uconn.tripoint.pathway.Pathway;
import edu.uconn.tripoint.pathway.PathwayEdge;
import edu.uconn.tripoint.pathway.PathwayHelper;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.REngineException;
import quin.network.Location;
public class Triangulation {
private Map<Gene, TriangulatedGene> _alltgenes;
private TriangulatedGene[] _tgenearray;
private Map<Gene, List<Pathway>> _genepathways;
public void runTriangulation(Pathway globalpathway, Pathway[] pathways, Collection<Gene> genes, double downthresh,
double upthresh, double w, double p, double r, Map<Gene,List<Location>> noncoding){
_alltgenes = new TreeMap<Gene,TriangulatedGene>();
//Set a map of genes for log(n) access
TriangulatedGene[] triangulatedgenes = new TriangulatedGene[genes.size()];
int index = 0;
for(Iterator<Gene> it = genes.iterator(); it.hasNext();){
Gene g = it.next();
TriangulatedGene newgene = new TriangulatedGene(g);
_alltgenes.put(g, newgene);
triangulatedgenes[index++] = newgene;
}
_tgenearray = triangulatedgenes;
_genepathways = getGenePathways(pathways);
setInconsistencyScores(triangulatedgenes, pathways, downthresh, upthresh, w, p);
setSupportScores(triangulatedgenes, pathways, downthresh, upthresh, w, p);
setConsistencyScores(triangulatedgenes, pathways);
setImpactScores(triangulatedgenes, pathways, downthresh, upthresh, p, r);
NormParameters connparams = getConsistencyNormParams(triangulatedgenes, pathways);
NormParameters impnparams = getImpactNormParams(triangulatedgenes, pathways);
setTriangulationScores(triangulatedgenes, pathways, connparams, impnparams, noncoding);
}
private NormParameters getPermutedConsistencyNormParams(TriangulatedGene[] genes, Pathway[] pathways){
double nmin = Double.POSITIVE_INFINITY;
double nmax = Double.NEGATIVE_INFINITY;
double pmin = Double.POSITIVE_INFINITY;
double pmax = Double.NEGATIVE_INFINITY;
for(int i = 0; i < genes.length; i++){
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
double score = genes[i].getConsistencyPermutation(curpath.getId());
if(score > 0){
pmin = Math.min(pmin, score);
pmax = Math.max(pmax, score);
}
else if (score < 0){
nmin = Math.min(nmin, score);
pmax = Math.max(pmax, score);
}
}
}
if(nmin == Double.POSITIVE_INFINITY){
nmin = 0;
}
if(pmin == Double.POSITIVE_INFINITY){
pmin = 0;
}
if(nmax == Double.NEGATIVE_INFINITY){
nmax = 1;
}
if(pmax == Double.NEGATIVE_INFINITY){
pmax = 1;
}
return new NormParameters(nmin,nmax,pmin,pmax);
}
private NormParameters getConsistencyNormParams(TriangulatedGene[] genes, Pathway[] pathways){
double nmin = Double.POSITIVE_INFINITY;
double nmax = Double.NEGATIVE_INFINITY;
double pmin = Double.POSITIVE_INFINITY;
double pmax = Double.NEGATIVE_INFINITY;
for(int i = 0; i < genes.length; i++){
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
double score = genes[i].getConsistencyScore(curpath.getId());
if(score > 0){
pmin = Math.min(pmin, score);
pmax = Math.max(pmax, score);
}
else if (score < 0){
nmin = Math.min(nmin, score);
pmax = Math.max(pmax, score);
}
}
}
if(nmin == Double.POSITIVE_INFINITY){
nmin = 0;
}
if(pmin == Double.POSITIVE_INFINITY){
pmin = 0;
}
if(nmax == Double.NEGATIVE_INFINITY){
nmax = 1;
}
if(pmax == Double.NEGATIVE_INFINITY){
pmax = 1;
}
return new NormParameters(nmin,nmax,pmin,pmax);
}
private NormParameters getImpactNormParams(TriangulatedGene[] genes, Pathway[] pathways){
double nmin = Double.POSITIVE_INFINITY;
double nmax = Double.NEGATIVE_INFINITY;
double pmin = Double.POSITIVE_INFINITY;
double pmax = Double.NEGATIVE_INFINITY;
for(int i = 0; i < genes.length; i++){
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
double score = genes[i].getImpactScore(curpath.getId());
if(score > 0){
pmin = Math.min(pmin, score);
pmax = Math.max(pmax, score);
}
else if (score < 0){
nmin = Math.min(nmin, score);
pmax = Math.max(pmax, score);
}
}
}
if(nmin == Double.POSITIVE_INFINITY){
nmin = 0;
}
if(pmin == Double.POSITIVE_INFINITY){
pmin = 0;
}
if(nmax == Double.NEGATIVE_INFINITY){
nmax = 1;
}
if(pmax == Double.NEGATIVE_INFINITY){
pmax = 1;
}
return new NormParameters(nmin,nmax,pmin,pmax);
}
private NormParameters getPermutedImpactNormParams(TriangulatedGene[] genes, Pathway[] pathways){
double nmin = Double.POSITIVE_INFINITY;
double nmax = Double.NEGATIVE_INFINITY;
double pmin = Double.POSITIVE_INFINITY;
double pmax = Double.NEGATIVE_INFINITY;
for(int i = 0; i < genes.length; i++){
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
double score = genes[i].getImpactPermutation(curpath.getId());
if(score > 0){
pmin = Math.min(pmin, score);
pmax = Math.max(pmax, score);
}
else if (score < 0){
nmin = Math.min(nmin, score);
pmax = Math.max(pmax, score);
}
}
}
if(nmin == Double.POSITIVE_INFINITY){
nmin = 0;
}
if(pmin == Double.POSITIVE_INFINITY){
pmin = 0;
}
if(nmax == Double.NEGATIVE_INFINITY){
nmax = 1;
}
if(pmax == Double.NEGATIVE_INFINITY){
pmax = 1;
}
return new NormParameters(nmin,nmax,pmin,pmax);
}
private Map<Gene, List<Pathway>> getGenePathways(Pathway[] pathways){
Map<Gene, List<Pathway>> rv = new TreeMap<Gene,List<Pathway>>();
for(int i = 0; i < pathways.length; i++){
for(Iterator<Node<Gene,PathwayEdge>> it = pathways[i].getNodes().iterator(); it.hasNext();){
Gene curg = it.next().getData();
if(!rv.containsKey(curg)){
rv.put(curg, new LinkedList<Pathway>());
}
rv.get(curg).add(pathways[i]);
}
}
return rv;
}
public Map<Gene, List<Pathway>> getGenePathways(){
return _genepathways;
}
public void runPermutations(Collection<Gene> genes, int numpermutatons, long seedstart, Pathway globalpathway, Pathway[] pathways, double downthresh, double upthresh, double w, double p, double r, Map<Gene,List<Location>> noncoding){
//Store the original gene values in order
List<Double> values = new LinkedList<Double>();
for(Iterator<Gene> it = genes.iterator(); it.hasNext();){
values.add(it.next().getValue());
}
for(int i = 0; i < _tgenearray.length; i++){
_tgenearray[i].resetPermutations();
}
for(int i = 0; i < numpermutatons; i++){
List<Gene> randomlist = new LinkedList<Gene>(genes);
Collections.shuffle(randomlist, new Random(seedstart+i));
Iterator<Double> it1 = values.iterator();
Iterator<Gene> it2 = randomlist.iterator();
while(it1.hasNext()){
it2.next().setValue(it1.next());
}
setPermutationScores(globalpathway, pathways, downthresh, upthresh, w, p, r, noncoding);
//System.out.println(i);
if((i+1)%500 == 0){
System.out.println("Finished "+(i+1)+" permutations.");
}
}
//Restore the values
Iterator<Double> it1 = values.iterator();
Iterator<Gene> it2 = genes.iterator();
while(it1.hasNext()){
it2.next().setValue(it1.next());
}
try {
setFDRAdjustedValues(_tgenearray, pathways);
} catch (Exception e) {
e.printStackTrace();
}
}
//Set the FDR value using the Benjamini Hochberg Procedure
//The global pathway is omitted from this calculation
private void setFDRAdjustedValues(TriangulatedGene[] genes, Pathway[] pathways) throws Exception{
List<TriangulatedGene> gl = new LinkedList<TriangulatedGene>();
List<Pathway> pl = new LinkedList<Pathway>();
List<Double> ipvals = new LinkedList<Double>();
List<Double> spvals = new LinkedList<Double>();
List<Double> cpvals = new LinkedList<Double>();
List<Double> impvals = new LinkedList<Double>();
List<Double> trivals = new LinkedList<Double>();
for(int i = 0; i < genes.length; i++){
TriangulatedGene tg = genes[i];
for(Iterator<Pathway> it = _genepathways.get(tg.getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
gl.add(tg);
pl.add(curpath);
ipvals.add(tg.getInconsistencyPValue(curpath.getId()));
spvals.add(tg.getSupportPValue(curpath.getId()));
cpvals.add(tg.getConsistencyPValue(curpath.getId()));
impvals.add(tg.getImpactPValue(curpath.getId()));
trivals.add(tg.getTriangulationPValue(curpath.getId()));
}
}
FDRCorrection fdrc = new FDRCorrection();
try {
double[] iqvals = fdrc.getCorrectedPValues(getArray(ipvals));
double[] sqvals = fdrc.getCorrectedPValues(getArray(spvals));
double[] cqvals = fdrc.getCorrectedPValues(getArray(cpvals));
double[] imqvals = fdrc.getCorrectedPValues(getArray(impvals));
double[] triqvals = fdrc.getCorrectedPValues(getArray(trivals));
Iterator<TriangulatedGene> it1 = gl.iterator();
Iterator<Pathway> it2 = pl.iterator();
int index = 0;
while(it1.hasNext() && it2.hasNext()){
TriangulatedGene tg = it1.next();
Pathway p = it2.next();
tg.setInconsistencyFDR(p.getId(), iqvals[index]);
tg.setSupportFDR(p.getId(), sqvals[index]);
tg.setConsistencyFDR(p.getId(), cqvals[index]);
tg.setImpactFDR(p.getId(), imqvals[index]);
tg.setTriangulationFDR(p.getId(), triqvals[index]);
index++;
}
if(it1.hasNext() || it2.hasNext()){
throw new Exception("List sizes do not match.");
}
} catch (REngineException e) {
e.printStackTrace();
} catch (REXPMismatchException e) {
e.printStackTrace();
}
}
private double[] getArray(List<Double> l){
double[] rv = new double[l.size()];
int index = 0;
for(Iterator<Double> it = l.iterator(); it.hasNext();){
rv[index++] = it.next();
}
return rv;
}
public Collection<TriangulatedGene> getTriangulatedGenes(){
return _alltgenes.values();
}
public Map<Gene, TriangulatedGene> getTrianguatedGeneMapping(){
return _alltgenes;
}
private void setPermutationScores(Pathway globalpathway, Pathway[] pathways, double downthresh, double upthresh, double w, double p, double r, Map<Gene,List<Location>> noncoding){
for(int i = 0; i < _tgenearray.length; i++){
_tgenearray[i].newPermutationRound();
}
setPermutationInconsistencyScores(_tgenearray, pathways, downthresh, upthresh, w, p);
setPermutationSupportScores(_tgenearray, pathways, downthresh, upthresh, w, p);
setPermutationConsistencyScores(_tgenearray, pathways);
setPermutationImpactScores(_tgenearray, pathways, downthresh, upthresh, p, r);
NormParameters connparams = getPermutedConsistencyNormParams(_tgenearray, pathways);
NormParameters impnparams = getPermutedImpactNormParams(_tgenearray, pathways);
setPermutationTriangulationScores(_tgenearray, pathways, connparams, impnparams, noncoding);
}
private void setPermutationInconsistencyScores(TriangulatedGene[] genes, Pathway[] pathways, double downthresh, double upthresh, double w, double p){
for(int i = 0; i < genes.length; i++){
//genes[i].updateInconsistencyPermutation(globalpathway.getId(), getInconsistencyScore(globalpathway, genes[i], downthresh, upthresh, w, p));
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
genes[i].updateInconsistencyPermutation(curpath.getId(), getInconsistencyScore(curpath, genes[i], downthresh, upthresh, w, p));
}
}
}
private void setPermutationSupportScores(TriangulatedGene[] genes, Pathway[] pathways, double downthresh, double upthresh, double w, double p){
for(int i = 0; i < genes.length; i++){
//genes[i].updateSupportPermutation(globalpathway.getId(), getSupportScore(globalpathway, genes[i], downthresh, upthresh, w, p));
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
genes[i].updateSupportPermutation(curpath.getId(), getSupportScore(curpath, genes[i], downthresh, upthresh, w, p));
}
}
}
private void setPermutationConsistencyScores(TriangulatedGene[] genes, Pathway[] pathways){
for(int i = 0; i < genes.length; i++){
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
String pathwayid = curpath.getId();
double support = genes[i].getSupportPermutation(pathwayid);
double inconsistency = genes[i].getInconsistencyPermutation(pathwayid);
genes[i].updateConsistencyPermutation(pathwayid, (support-inconsistency));
}
}
}
private void setPermutationImpactScores(TriangulatedGene[] genes, Pathway[] pathways, double downthresh, double upthresh, double p, double rate){
//String gpathwayid = globalpathway.getId();
for(int i = 0; i < genes.length; i++){
//ImpactFunction f = new PermutationImpactFunction();
//genes[i].updateImpactPermutation(gpathwayid, getImpactScore(genes[i], globalpathway, globalpathway, f, downthresh, upthresh, p1, p2, rate));
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
double impact = getImpactScore(genes[i], curpath, downthresh, upthresh, p, rate);
genes[i].updateImpactPermutation(curpath.getId(), impact);
}
}
}
private void setPermutationTriangulationScores(TriangulatedGene[] genes, Pathway[] pathways, NormParameters connparam, NormParameters impnparam, Map<Gene,List<Location>> noncoding){
double max = 0;
for(Iterator<List<Location>> it = noncoding.values().iterator(); it.hasNext();){
max = Math.max(max, it.next().size());
}
for(int i = 0; i < genes.length; i++){
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
String pathwayid = curpath.getId();
double consistencyscore = genes[i].getConsistencyScore(pathwayid);
double impactscore = genes[i].getImpactScore(pathwayid);
double tri = 0;
double factor = 1;
if(consistencyscore < 0){
factor = -1;
}
if(consistencyscore != 0 && impactscore != 0){
tri = getNormScore(consistencyscore, connparam)+getNormScore(impactscore, impnparam);
}
if(noncoding != null && noncoding.size() > 0){
int numnoncoding = noncoding.get(genes[i].getGene()).size();
if(numnoncoding == 0){
tri = 0;
}
else{
tri += (numnoncoding/max);
}
genes[i].updateTriangulationPermutation(pathwayid, factor*tri/3);
}
else{
genes[i].updateTriangulationPermutation(pathwayid, factor*tri/2);
}
}
}
}
private void setInconsistencyScores(TriangulatedGene[] genes, Pathway[] pathways, double downthresh, double upthresh, double w, double p){
for(int i = 0; i < genes.length; i++){
//genes[i].setInconsistencyScore(globalpathway.getId(), getInconsistencyScore(globalpathway, genes[i], downthresh, upthresh, w, p));
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
genes[i].setInconsistencyScore(curpath.getId(), getInconsistencyScore(curpath, genes[i], downthresh, upthresh, w, p));
}
}
}
private void setSupportScores(TriangulatedGene[] genes, Pathway[] pathways, double downthresh, double upthresh, double w, double p){
for(int i = 0; i < genes.length; i++){
//genes[i].setSupportScore(globalpathway.getId(), getSupportScore(globalpathway, genes[i], downthresh, upthresh, w, p));
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
genes[i].setSupportScore(curpath.getId(), getSupportScore(curpath, genes[i], downthresh, upthresh, w, p));
}
}
}
private void setConsistencyScores(TriangulatedGene[] genes, Pathway[] pathways){
for(int i = 0; i < genes.length; i++){
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
String pathwayid = curpath.getId();
double support = genes[i].getSupportScore(pathwayid);
double inconsistency = genes[i].getInconsistencyScore(pathwayid);
genes[i].setConsistencyScore(pathwayid, (support-inconsistency));
}
}
}
private void setImpactScores(TriangulatedGene[] genes, Pathway[] pathways, double downthresh, double upthresh, double p, double rate){
//String gpathwayid = globalpathway.getId();
for(int i = 0; i < genes.length; i++){
//ImpactFunction f = new ScoreImpactFunction();
//genes[i].setImpactScore(gpathwayid, getImpactScore(genes[i], globalpathway, f, downthresh, upthresh, p1, p2, rate));
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
double impact = getImpactScore(genes[i], curpath, downthresh, upthresh, p, rate);
genes[i].setImpactScore(curpath.getId(), impact);
}
}
}
private void setTriangulationScores(TriangulatedGene[] genes, Pathway[] pathways, NormParameters connparam, NormParameters impnparam, Map<Gene,List<Location>> noncoding){
double max = 0;
for(Iterator<List<Location>> it = noncoding.values().iterator(); it.hasNext();){
max = Math.max(max, it.next().size());
}
for(int i = 0; i < genes.length; i++){
for(Iterator<Pathway> it = _genepathways.get(genes[i].getGene()).iterator(); it.hasNext();){
Pathway curpath = it.next();
String pathwayid = curpath.getId();
double consistencyscore = genes[i].getConsistencyScore(pathwayid);
double impactscore = genes[i].getImpactScore(pathwayid);
double tri = 0;
double factor = 1;
if(consistencyscore < 0){
factor = -1;
}
if(consistencyscore != 0 && impactscore != 0){
tri = getNormScore(consistencyscore, connparam)+getNormScore(impactscore, impnparam);
}
if(noncoding != null && noncoding.size() > 0){
int numnoncoding = noncoding.get(genes[i].getGene()).size();
if(numnoncoding == 0){
tri = 0;
}
else{
tri += (numnoncoding/max);
}
genes[i].setTriangulationScore(pathwayid, factor*tri/3);
}
else{
genes[i].setTriangulationScore(pathwayid, factor*tri/2);
}
}
}
}
private double getInconsistencyScore(Pathway pathway, TriangulatedGene gene, double downthresh, double upthresh, double w, double p){
double score = 0;
Node<Gene,PathwayEdge> n = pathway.getNode(gene.getGene());
if(n != null){
List<Edge<Gene,PathwayEdge>> edges = n.getEdges();
for(Iterator<Edge<Gene,PathwayEdge>> it = edges.iterator(); it.hasNext();){
Edge<Gene,PathwayEdge> next = it.next();
if(next.isDirected()){
Node<Gene,PathwayEdge> src = next.getSource();
if(!src.equals(n)){
Node<Gene,PathwayEdge> dest = next.getDestination();
int type = next.getData().getType();
double sv = src.getData().getValue();
double dv = dest.getData().getValue();
if(type == PathwayEdge.ACTIVATION){
if(sv > upthresh && dv < downthresh){
score += Math.pow(Math.abs(sv), p);
}
else if(sv < downthresh && dv > upthresh){
score += w*Math.pow(Math.abs(sv), p);
}
}
else if(type == PathwayEdge.INHIBITION){
if(sv > upthresh && dv > upthresh){
score += Math.pow(Math.abs(sv), p);
}
else if(sv < downthresh && dv < downthresh){
score += w*Math.pow(Math.abs(sv), p);
}
}
}
}
}
}
return score;
}
private double getSupportScore(Pathway pathway, TriangulatedGene gene, double downthresh, double upthresh, double w, double p){
double score = 0;
Node<Gene,PathwayEdge> n = pathway.getNode(gene.getGene());
if(n != null){
List<Edge<Gene,PathwayEdge>> edges = n.getEdges();
for(Iterator<Edge<Gene,PathwayEdge>> it = edges.iterator(); it.hasNext();){
Edge<Gene,PathwayEdge> next = it.next();
if(next.isDirected()){
Node<Gene,PathwayEdge> src = next.getSource();
if(!src.equals(n)){
Node<Gene,PathwayEdge> dest = next.getDestination();
int type = next.getData().getType();
double sv = src.getData().getValue();
double dv = dest.getData().getValue();
if(type == PathwayEdge.ACTIVATION){
if(sv > upthresh && dv > upthresh){
score += Math.pow(Math.abs(sv), p);
}
else if(sv < downthresh && dv < downthresh){
score += w*Math.pow(Math.abs(sv), p);
}
}
else if(type == PathwayEdge.INHIBITION){
if(sv > upthresh && dv < downthresh){
score += Math.pow(Math.abs(sv), p);
}
else if(sv < downthresh && dv > upthresh){
score += w*Math.pow(Math.abs(sv), p);
}
}
}
}
}
}
return score;
}
private double getImpactScore(TriangulatedGene g, Pathway pathway, double downthresh, double upthresh, double p, double rate){
double score = 0;
Node<Gene,PathwayEdge> n = pathway.getNode(g.getGene());
if(n == null){
return 0;
}
LinkedList<Node<Gene,PathwayEdge>> todo = new LinkedList<Node<Gene,PathwayEdge>>();
LinkedList<Integer> todoi = new LinkedList<Integer>();
todo.addLast(n);
todoi.addLast(0);
Set<Gene> seen = new TreeSet<Gene>();
seen.add(n.getData());
PathwayHelper ph = new PathwayHelper();
while(!todo.isEmpty()){
Node<Gene,PathwayEdge> curnode = todo.removeFirst();
Integer curi = todoi.removeFirst();
List<Edge<Gene,PathwayEdge>> downstreamedges = ph.getDownstreamEdges(curnode);
for(Iterator<Edge<Gene,PathwayEdge>> it = downstreamedges.iterator(); it.hasNext();){
Edge<Gene,PathwayEdge> nextedge = it.next();
Node<Gene,PathwayEdge> dest = ph.getDestination(curnode,nextedge);
if(!seen.contains(dest.getData())){
if(ph.isConsistent(nextedge, curnode, dest, downthresh, upthresh)){
todo.add(dest);
todoi.add(curi+1);
seen.add(dest.getData());
//double support = f.getSupportNormalization(_alltgenes.get(dest.getData()), globalpathway, pathway);
//score += Math.exp(-rate*curi)*(Math.pow(Math.abs(dest.getData().getValue()),p1)
// /Math.pow(Math.max(1, support), p2));
score += Math.exp(-rate*curi)*(Math.pow(Math.abs(dest.getData().getValue()),p));
}
/*else if(nextedge.getData().getType() != PathwayEdge.ASSOCIATION){
//This allows for inconsistencies that have no further downstream impact
//Two inconsistencies identifies these nodes
List<Node<Gene,PathwayEdge>> iinodes = ph.getInconsistentInconsistencies(dest,seen,downthresh,upthresh);
for(Iterator<Node<Gene,PathwayEdge>> it2 = iinodes.iterator(); it2.hasNext();){
Node<Gene,PathwayEdge> next = it2.next();
if(!seen.contains(next.getData())){
todo.add(next);
todoi.add(curi+2); //This is looking ahead by one so we add 2.
seen.add(next.getData());
//double support = f.getSupportNormalization(_alltgenes.get(next.getData()), globalpathway, pathway);
//score += Math.exp(-rate*(curi+1))*(Math.pow(Math.abs(next.getData().getValue()),p1)
// /Math.pow(Math.max(1, support), p2));
score += Math.exp(-rate*curi)*(Math.pow(Math.abs(dest.getData().getValue()),p));
}
}
}*/
}
}
}
return score;
}
private double getNormScore(double score, NormParameters np){
if(score < 0){
return (score - np.nmin)/np.ndiv;
}
else if(score > 0){
return (score - np.pmin)/np.pdiv;
}
return 0;
}
private class NormParameters{
public double nmin;
public double nmax;
public double ndiv;
public double pmin;
public double pmax;
public double pdiv;
public NormParameters(double nminp, double nmaxp, double pminp, double pmaxp){
nmin = nminp;
nmax = nmaxp;
ndiv = nmax-nmin;
pmin = pminp;
pmax = pmaxp;
pdiv = pmax-pmin;
}
}
// private double getImpactScoreNormalizer(TriangulatedGene g, Pathway pathway, double downthresh, double upthresh, double p, double e, double rate){
// double score = 0;
//
// Node<Gene,PathwayEdge> n = pathway.getNode(g.getGene());
// if(n == null){
// return 0;
// }
// LinkedList<Node<Gene,PathwayEdge>> todo = new LinkedList<Node<Gene,PathwayEdge>>();
// LinkedList<Integer> todoi = new LinkedList<Integer>();
// todo.addLast(n);
// todoi.addLast(0);
//
// Set<Gene> seen = new TreeSet<Gene>();
// seen.add(n.getData());
//
// PathwayHelper ph = new PathwayHelper();
//
// while(!todo.isEmpty()){
// Node<Gene,PathwayEdge> curnode = todo.removeFirst();
// Integer curi = todoi.removeFirst();
// List<Edge<Gene,PathwayEdge>> downstreamedges = ph.getDownstreamEdges(curnode);
// for(Iterator<Edge<Gene,PathwayEdge>> it = downstreamedges.iterator(); it.hasNext();){
// Edge<Gene,PathwayEdge> nextedge = it.next();
// Node<Gene,PathwayEdge> dest = ph.getDestination(curnode,nextedge);
// if(!seen.contains(dest.getData()) && nextedge.getData().getType() != PathwayEdge.ASSOCIATION){
// todo.add(dest);
// todoi.add(curi+1);
// seen.add(dest.getData());
// score += Math.exp(-rate*curi)*(Math.pow(Math.abs(dest.getData().getValue()),p));
// }
// }
// }
// return score;
// }
//Interface to eliminate duplicate code when getting
//the support score normalization factor
/*private interface ImpactFunction {
public double getSupportNormalization(TriangulatedGene g, Pathway global, Pathway local);
}
private class ScoreImpactFunction implements ImpactFunction{
@Override
public double getSupportNormalization(TriangulatedGene g, Pathway global, Pathway local) {
return g.getSupportScore(global.getId())-g.getSupportScore(local.getId());
}
}
private class PermutationImpactFunction implements ImpactFunction{
@Override
public double getSupportNormalization(TriangulatedGene g, Pathway global, Pathway local) {
return g.getSupportPermutation(global.getId())-g.getSupportPermutation(local.getId());
}
}*/
}