ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/proteinstructure/Graph.java
Revision: 129
Committed: Thu May 10 13:12:32 2007 UTC (17 years, 4 months ago) by duarte
File size: 2243 byte(s)
Log Message:
NEW FUNCTIONALITY: can retrieve now a ContactMap object from a Graph object
New method getCM in Graph. New member variables: sequence, accode, chain, nodes, directed
Passing more data from Pdb to Graph in get_graph
New constructor in ContactMap
Line User Rev File contents
1 duarte 123 package proteinstructure;
2     import java.io.FileOutputStream;
3     import java.io.PrintStream;
4     import java.io.IOException;
5     import java.util.ArrayList;
6 duarte 129 import java.util.TreeMap;
7 duarte 123
8    
9     public class Graph {
10    
11     ArrayList<Contact> contacts;
12 duarte 129 TreeMap<Integer,String> nodes;
13     String sequence;
14     String accode;
15     String chain;
16 duarte 123 double cutoff;
17     String ct;
18 duarte 129 boolean directed;
19 duarte 123
20 duarte 129 public Graph (ArrayList<Contact> contacts, TreeMap<Integer,String> nodes, String sequence, double cutoff,String ct, String accode, String chain) {
21 duarte 123 this.contacts=contacts;
22     this.cutoff=cutoff;
23 duarte 129 this.nodes=nodes;
24     this.sequence=sequence;
25     this.accode=accode;
26     this.chain=chain;
27 duarte 123 this.ct=ct;
28 duarte 129 directed=false;
29     if (ct.contains("/")){
30     directed=true;
31     }
32 duarte 123 }
33 duarte 129
34     //TODO implement (from python) constructors for reading from file and db
35     //TODO implement (from python) read_contacts_from_file
36     //TODO implement (from python) read_contacts_from_db
37     //TODO implement (from python) write_graph_to_db
38 duarte 123
39     public void write_contacts_to_file (String outfile) throws IOException {
40     PrintStream Out = new PrintStream(new FileOutputStream(outfile));
41     for (Contact pair:contacts){
42     int i_resser=pair.i;
43     int j_resser=pair.j;
44     Out.println(i_resser+"\t"+j_resser);
45     }
46     Out.close();
47     }
48 duarte 129
49     public ContactMap getCM() {
50     // residues is the map from residue nums to residue types used in ContactMap class, i.e. it is the same as Pdb.resser2restype or Graph.nodes
51     TreeMap<Integer,String> residues = new TreeMap<Integer,String>();
52     // we copy residues from nodes (deep copy)
53     for (int node:nodes.keySet()){
54     residues.put(node, nodes.get(node));
55     }
56     // check if we are in directed or undirected case. If undirected we fill the opposite contacts to pass a full list of contacts to ContactMap (which contains full matrix)
57     ArrayList<Contact> contacts2pass = new ArrayList<Contact>();
58     if (directed){
59     contacts2pass=contacts;
60     } else {
61     for (Contact cont:contacts){
62     int i_resser = cont.i;
63     int j_resser = cont.j;
64     contacts2pass.add(new Contact(i_resser,j_resser));
65     contacts2pass.add(new Contact(j_resser,i_resser));
66     }
67     }
68     // construct the ContactMap object and return it
69     ContactMap cm = new ContactMap(contacts2pass,residues,sequence);
70     return cm;
71    
72     }
73    
74 duarte 123 }