ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/proteinstructure/CaspRRFileRIGraph.java
Revision: 497
Committed: Thu Jan 3 14:20:03 2008 UTC (16 years, 9 months ago) by duarte
File size: 2831 byte(s)
Log Message:
Extracted some constants: NO_PDB_CODE, NO_PDB_CHAIN_CODE, NO_CONTACT_TYPE, NO_CUTOFF
Line File contents
1 package proteinstructure;
2
3 import java.io.*;
4 import java.util.*;
5
6 import edu.uci.ics.jung.graph.util.EdgeType;
7
8 /**
9 * A RIG loaded from a Casp contact prediction file.
10 * @author stehr
11 * @data 2007-12-19
12 */
13 public class CaspRRFileRIGraph extends RIGraph {
14
15 private static final long serialVersionUID = 1L;
16
17 /**
18 * Constructs a RIGraph object based on a Casp contact prediction file.
19 * @param fileName the contact prediction file
20 * @throws IOException
21 * @throws GraphFileFormatError
22 */
23 public CaspRRFileRIGraph (String fileName) throws IOException, GraphFileFormatError{
24 super();
25 // we set the sequence to blank when we read from file as we don't have the full sequence
26 // if sequence is present in RR file then is read from there
27 this.sequence="";
28 this.contactType=ProtStructGraph.NO_CONTACT_TYPE;
29 this.distCutoff=ProtStructGraph.NO_CUTOFF;
30 // we initialise pdbCode, chainCode and pdbChainCode to corresponding constants (empty strings at the moment) since file doesn't specify then
31 this.pdbCode=Pdb.NO_PDB_CODE;
32 this.chainCode=Pdb.NO_CHAIN_CODE;
33 this.pdbChainCode=Pdb.NO_PDB_CHAIN_CODE;
34
35 readFromCaspRRFile(fileName);
36
37 }
38
39 private void readFromCaspRRFile(String fileName) throws FileNotFoundException, IOException, GraphFileFormatError {
40 CaspRRFileData rrData = new CaspRRFileData();
41 File inFile = new File(fileName);
42 if(!CaspRRFileData.isValidCaspRRFile(inFile)) throw new GraphFileFormatError(fileName + " is not a valid casp contact prediction file.");
43 rrData.readFromFile(new File(fileName));
44
45 // convert meta data
46 this.sequence = rrData.getSequence();
47 this.contactType = CaspRRFileData.DEFAULT_CONT_TYPE; // i.e. Cb
48 this.groupNum = rrData.groupNum;
49 this.targetNum = rrData.targetNum;
50 this.caspModelNum = rrData.modelNum;
51
52 // add vertices
53 serials2nodes = new TreeMap<Integer,RIGNode>();
54 if (sequence == null || sequence.equals("")) throw new GraphFileFormatError("No sequence found in " + fileName);
55 this.fullLength = sequence.length();
56 for (int i=0;i<sequence.length();i++){
57 String letter = String.valueOf(sequence.charAt(i));
58 RIGNode node = new RIGNode(i+1,AAinfo.oneletter2threeletter(letter));
59 serials2nodes.put(i+1, node);
60 this.addVertex(node);
61 }
62
63 // set distCutoff
64 CaspRRFileData.RRContact firstContact = rrData.getContacts().get(0);
65 this.distCutoff = firstContact.maxDist;
66
67 // add edges
68 for(CaspRRFileData.RRContact cont:rrData.getContacts()) {
69 if(cont.minDist != 0) throw new GraphFileFormatError("Non-zero minimum distance value in " + fileName + ".");
70 if(this.distCutoff != cont.maxDist) throw new GraphFileFormatError("Distance cutoffs in " + fileName + " are not equal.");
71 this.addEdge(new RIGEdge(cont.weight), serials2nodes.get(cont.i), serials2nodes.get(cont.j), EdgeType.UNDIRECTED);
72 }
73 }
74
75 }