import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStreamReader; import java.util.HashMap; import nct.graph.Edge; import nct.graph.WeightedNode; import nct.graph.basic.BasicGraph; import nct.graph.basic.BasicWeightedNode; import nct.networkblast.score.JointLogLikelihoodScoreModel; public class NCTEdgeSearch { /* * Asume we are dealing with a basic pvalue type file And also a file of * tabbed triples with gene one gene two and interaction score */ protected static BasicGraph, Double> createGraph(String nodeProbabilities) { /* * First create a map from node IDs to probability values */ BasicGraph, Double> result = new BasicGraph,Double>(); HashMap nodeMap = new HashMap(); double sum = 0; try{ BufferedReader reader = new BufferedReader(new FileReader(nodeProbabilities)); String line = reader.readLine(); while(line != null){ String[] splat = line.split("\t"); String nodeName = splat[0]; Double nodeProbability = Double.parseDouble(splat[1]); if(!nodeMap.containsKey(nodeName)){ nodeMap.put(nodeName,nodeProbability); } sum += nodeProbability; line = reader.readLine(); } reader.close(); }catch(Exception e){ e.printStackTrace(); System.exit(-1); } double averageProbability = sum/nodeMap.size(); HashMap> name2Node = new HashMap>(); try { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int UPDATE_INTERVAL = 100000; int idx = 0; String line = reader.readLine(); while (line != null) { if (idx % UPDATE_INTERVAL == 0) { System.err.println(idx + " interactions read"); } idx += 1; String[] splat = line.split("\t"); String source = splat[0]; String target = splat[1]; WeightedNode sourceNode = null; WeightedNode targetNode = null; if(name2Node.containsKey(source)){ sourceNode = name2Node.get(source); }else{ if(nodeMap.containsKey(source)){ sourceNode = new BasicWeightedNode(source,nodeMap.get(source)); }else{ sourceNode = new BasicWeightedNode(source,averageProbability); } name2Node.put(source,sourceNode); result.addNode(sourceNode); } if(name2Node.containsKey(target)){ targetNode = name2Node.get(target); }else{ if(nodeMap.containsKey(target)){ targetNode = new BasicWeightedNode(target,nodeMap.get(target)); }else{ targetNode = new BasicWeightedNode(target,averageProbability); } name2Node.put(target,targetNode); result.addNode(targetNode); } result.addEdge(sourceNode, targetNode, new Double(splat[2]), ""); line = reader.readLine(); } } catch (Exception e) { e.printStackTrace(); System.exit(-1); } return result; } public static void main(String[] args) { System.err.println("Building graph"); BasicGraph, Double> graph = createGraph(args[0]); System.err.println("Finished building graph"); //SimpleEdgeScoreModel model = new SimpleEdgeScoreModel(); //LogLikelihoodScoreModel model = new LogLikelihoodScoreModel(1,0.5,0.001);; JointLogLikelihoodScoreModel> model = new JointLogLikelihoodScoreModel>(1,0.5,0.5); /* * First, let's just iterate through the nodes and get their scores */ for(Edge,Double> edge : graph.getEdges()){ System.err.println(model.scoreEdge(edge.getSourceNode(),edge.getTargetNode(),graph)); } // NewComplexSearch search = new NewComplexSearch(0, 10); // // for (int iteration = 0; iteration < 20; iteration += 1) { // // System.err.println("Starting search " + iteration); // List> result = search.searchGraph(graph, // model); // System.err.println("Finished search " + iteration); // // // try { // FileWriter fw = new FileWriter("" + iteration + ".ea"); // double maxScore = Double.NEGATIVE_INFINITY; // Graph maxGraph = null; // System.err.println(result.size()); // for (Graph resultGraph : result) { // if (resultGraph.getScore() > maxScore) { // maxGraph = resultGraph; // } // } // System.err.println(maxGraph); // for (Edge edge : maxGraph.getEdges()) { // fw.write(edge.getSourceNode() + " (fn) " // + edge.getTargetNode() + " = " + edge.getWeight() // + "\n"); // graph // .removeEdge(edge.getSourceNode(), edge // .getTargetNode()); // } // fw.close(); // } catch (Exception e) { // e.printStackTrace(); // System.exit(-1); // } // } } }