// Medusa is a graph viewer which allows interactive editing of networks
// (edges and nodes) and also connects to databases.
//
// Copyright (C) 2006 Sean Hooper
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330,
// Boston, MA 02111-1307 USA
package medusa.stringconnection;
import java.io.IOException;
import java.net.Socket;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import medusa.graph.Edge;
import medusa.graph.Graph;
public class GetGraph implements Runnable {
private Thread me;
private boolean done;
private String url;
private int port;
private ArrayList selection;
private Graph g;
private float cutoff;
public GetGraph(String url, int port, ArrayList selection, float cutoff){
this.url=url;
this.port=port;
this.selection=selection;
this.cutoff=cutoff;
}
public Graph getGraph(){
return g;
}
public void start(){
if (me==null) {
me = new Thread(this);
}
me.start();
}
public void stop(){
if (me!=null) {
me=null;
}
}
public void run(){
Thread myThread=Thread.currentThread();
done=false;
if (me==myThread){
//System.out.println("thread running");
try {
getGraphFromString();
//System.out.println("should be done getting graph");
}
catch (IOException ie){
g=new Graph();
}
done=true;
}
//System.out.println("thread is d"+done);
}
int progress=0;
public int getProgress(){
return progress;
}
public boolean isDone(){
return done;
}
public void getGraphFromString() throws IOException{
// for each selection in the selectionPanel, go to string and
// retrieve the network
progress = 0;
g= new Graph();
Socket stringSocket = new Socket(url,port);
PrintWriter out = new PrintWriter(stringSocket.getOutputStream(),true);
BufferedReader in = new BufferedReader
(new InputStreamReader
(stringSocket.getInputStream() ));
String inLine;
StringBuffer temp = new StringBuffer();
String send;
for (Iterator select = selection.iterator(); select.hasNext();){
// add edge to graph
temp.append("GI:");
send=(String)select.next();
temp.append(send);
temp.append("\n");
//System.out.println(send+": edge sent");
}
temp.append("bye");
out.println(temp.toString());
// ---------------------------------------------------------++++++++++++++++++++++++++++++++++++++++++++++++++
// debugging!
//System.out.println("wait for stream");
while (!in.ready()) {}
//System.out.println(" stream ready");
while( (inLine=in.readLine())!=null){
//System.out.println("line: "+inLine);
if (inLine.length()>10){
progress++;
parseEdge(g,inLine);
//System.out.println(inLine);
}
//System.out.println(progress);
}
//System.out.println("closing everything");
out.close();
in.close();
stringSocket.close();
//System.out.println(progress);
}
//-----------------------------------------------------------------------------
/* this is where a line from the socketListener is
* converted into edges
Table "public.precomputed_gene_links"
Column | Type | Modifiers
--------------------------------+-----------------------+-----------
gene_id_a | character varying(40) | not null
gene_id_b | character varying(40) | not null
equiv_nscore | integer |
equiv_nscore_transferred | integer |
equiv_fscore | integer |
equiv_pscore | integer |
equiv_hscore | integer |
array_score | integer |
array_score_transferred | integer |
experimental_score | integer |
experimental_score_transferred | integer |
database_score | integer |
database_score_transferred | integer |
textmining_score | integer |
textmining_score_transferred | integer |
combined_score | integer |
final String linkQuery1="SELECT gene_id_a, gene_id_b, equiv_nscore, equiv_fscore, "
+"equiv_pscore, equiv_hscore, array_score, experimental_score,"
+" database_score, textmining_score, combined_score "
+"FROM precomputed_gene_links WHERE gene_id_a = '";
*/
private void parseEdge(Graph g, String inLine){
String[] result = inLine.split("\\t+");
// check if combined score allows edge
float combined=Float.parseFloat(result[result.length-1])/1000f;
//System.out.println(combined);
if (combined0.){
Edge e = new Edge(n1,n2,confidence,i-1);
//System.out.println(e);
g.addEdge(e);
//System.out.println(g.report());
}
}
}
}
Ads help maintain this website.