ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/proteinstructure/FileGraph.java
Revision: 207
Committed: Wed Jun 27 11:06:34 2007 UTC (17 years, 3 months ago) by duarte
File size: 4216 byte(s)
Log Message:
Restructured construction of Pdb and Graph objects: now subclasses for each case
Cleaned up and made consistent database connections
Now can also pass a MySQLConnection in all cases (as well as having default values for a default connection)
PdbaseInfo and MsdsdInfo classes removed: now merged into PdbasePdb and MsdsdPdb respectively
Updated following this changes testPdb and compareCMs

Line User Rev File contents
1 duarte 207 package proteinstructure;
2    
3     import java.io.BufferedReader;
4     import java.io.File;
5     import java.io.FileNotFoundException;
6     import java.io.FileReader;
7     import java.io.IOException;
8     import java.util.TreeMap;
9     import java.util.regex.Matcher;
10     import java.util.regex.Pattern;
11    
12     /**
13     * A residue interaction graph derived from a single chain pdb protein structure loaded from a graph file in aglappe's format
14     *
15     * @author Jose Duarte
16     * Class: FileGraph
17     * Package: proteinstructure
18     */
19     public class FileGraph extends Graph {
20    
21    
22     /**
23     * Constructs Graph object by reading a file with contacts
24     * If the contacts file doesn't have the sequence then the graph object won't have sequence or nodes
25     * That means it won't be possible to get a ContactMap from it using getCM because CM needs both sequence and nodes
26     * @param contactsfile
27     * @throws IOException
28     * @throws FileNotFoundException
29     */
30     public FileGraph (String contactsfile) throws IOException, FileNotFoundException{
31     // we set the sequence to blank when we read from file as we don't have the full sequence
32     // if sequence is present in contactsfile then is read from there
33     this.sequence="";
34     this.ct="";
35     this.cutoff=0.0;
36     // we initialise pdbCode, chainCode and pdbChainCode to empty strings in case the file doesn't specify then
37     this.pdbCode="";
38     this.chainCode="";
39     this.pdbChainCode="";
40     if (ct.contains("/")){
41     directed=true;
42     }
43     read_graph_from_file(contactsfile); // initialises contacts, and nodes (only if sequence is given)
44     if (!sequence.equals("")){
45     this.fullLength=sequence.length();
46     this.obsLength=nodes.size();
47     } else {
48     // if contacts have correct residue numbering then this should get the right full length up to the maximum node that makes a contact,
49     // we will miss: nodes without contacts at the end of sequence and gaps (unobserved residues) at the end of the sequence.
50     // We don't know more without nodes and sequence
51     this.fullLength=contacts.getMaxNode();
52     // in this case nodes has not been initialised so we set obsLength=fullLength as we don't have the information
53     this.obsLength=fullLength;
54     }
55     this.numContacts=contacts.size();
56     this.modified=false;
57     }
58    
59     private void read_graph_from_file (String contactsfile) throws FileNotFoundException, IOException {
60     contacts = new ContactList();
61     //System.out.println("Reading contacts from file "+contactsfile);
62     BufferedReader fcont = new BufferedReader(new FileReader(new File(contactsfile)));
63     String line;
64     while ((line = fcont.readLine() ) != null ) {
65     Pattern p = Pattern.compile("^#");
66     Matcher m = p.matcher(line);
67     if (m.find()){
68     // Pattern ps = Pattern.compile("^#VER: (\\d\\.\\d)");
69     // Matcher ms = ps.matcher(line);
70     // if (ms.find()){
71     // if (!ms.group(1).equals(GRAPHFILEFORMATVERSION)){
72     // throw new GraphFileFormatError("The graph file "+contactsfile+" can't be read, wrong file format version");
73     // }
74     // }
75     Pattern ps = Pattern.compile("^#SEQUENCE:\\s*(\\w+)$");
76     Matcher ms = ps.matcher(line);
77     if (ms.find()){
78     sequence=ms.group(1);
79     }
80     ps = Pattern.compile("^#PDB:\\s*(\\w+)");
81     ms = ps.matcher(line);
82     if (ms.find()){
83     pdbCode=ms.group(1);
84     }
85     ps = Pattern.compile("^#PDB CHAIN CODE:\\s*(\\w)");
86     ms = ps.matcher(line);
87     if (ms.find()){
88     pdbChainCode=ms.group(1);
89     }
90     ps = Pattern.compile("^#CHAIN:\\s*(\\w)");
91     ms = ps.matcher(line);
92     if (ms.find()){
93     chainCode=ms.group(1);
94     }
95     ps = Pattern.compile("^#CT:\\s*([a-zA-Z/]+)");
96     ms = ps.matcher(line);
97     if (ms.find()){
98     ct=ms.group(1);
99     }
100     ps = Pattern.compile("^#CUTOFF:\\s*(\\d+\\.\\d+)");
101     ms = ps.matcher(line);
102     if (ms.find()){
103     cutoff=Double.parseDouble(ms.group(1));
104     }
105     }
106     else{
107     int i = Integer.parseInt(line.split("\\s+")[0]);
108     int j = Integer.parseInt(line.split("\\s+")[1]);
109     contacts.add(new Contact(i,j));
110     }
111     }
112     fcont.close();
113     // if sequence was given we take nodes from it
114     nodes = new TreeMap<Integer, String>();
115     for (int i=0;i<sequence.length();i++){
116     String letter = String.valueOf(sequence.charAt(i));
117     nodes.put(i+1, AA.oneletter2threeletter(letter));
118     }
119    
120     }
121    
122     }