Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package mc_view

File PDBfile.java

 

Coverage histogram

../img/srcFileCovDistChart8.png
21% of files have more coverage

Code metrics

38
86
9
1
259
204
34
0.4
9.56
9
3.78

Classes

Class Line # Actions
PDBfile 37 86 34
0.744360974.4%
 

Contributing tests

This file is covered by 37 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package mc_view;
22   
23    import java.io.IOException;
24    import java.util.ArrayList;
25    import java.util.Hashtable;
26    import java.util.List;
27    import java.util.Vector;
28   
29    import jalview.datamodel.AlignmentAnnotation;
30    import jalview.datamodel.DBRefSource;
31    import jalview.datamodel.SequenceI;
32    import jalview.io.DataSourceType;
33    import jalview.io.FileParse;
34    import jalview.io.StructureFile;
35    import jalview.util.MessageManager;
36   
 
37    public class PDBfile extends StructureFile
38    {
39    private static String CALC_ID_PREFIX = "JalviewPDB";
40   
 
41  0 toggle public PDBfile(boolean addAlignmentAnnotations,
42    boolean predictSecondaryStructure, boolean externalSecStr)
43    {
44  0 super();
45  0 addSettings(addAlignmentAnnotations, predictSecondaryStructure,
46    externalSecStr);
47    }
48   
 
49  16 toggle public PDBfile(boolean addAlignmentAnnotations, boolean predictSecStr,
50    boolean externalSecStr, String dataObject,
51    DataSourceType sourceType) throws IOException
52    {
53  16 super(false, dataObject, sourceType);
54  16 addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr);
55  16 doParse();
56    }
57   
 
58  0 toggle public PDBfile(boolean addAlignmentAnnotations, boolean predictSecStr,
59    boolean externalSecStr, FileParse source) throws IOException
60    {
61  0 super(false, source);
62  0 addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr);
63  0 doParse();
64    }
65   
 
66  0 toggle @Override
67    public String print(SequenceI[] seqs, boolean jvSuffix)
68    {
69  0 return null;
70    }
71   
 
72  16 toggle @Override
73    public void parse() throws IOException
74    {
75  16 setDbRefType(DBRefSource.PDB);
76    // TODO set the filename sensibly - try using data source name.
77  16 setId(safeName(getDataName()));
78   
79  16 setChains(new Vector<PDBChain>());
80  16 List<SequenceI> rna = new ArrayList<SequenceI>();
81  16 List<SequenceI> prot = new ArrayList<SequenceI>();
82  16 PDBChain tmpchain;
83  16 String line = null;
84  16 boolean modelFlag = false;
85  16 boolean terFlag = false;
86  16 String lastID = "";
87   
88  16 int indexx = 0;
89  16 String atomnam = null;
90  16 try
91    {
92  ? while ((line = nextLine()) != null)
93    {
94  55440 if (line.indexOf("HEADER") == 0)
95    {
96  16 if (line.length() > 62)
97    {
98  16 String tid;
99  16 if (line.length() > 67)
100    {
101  12 tid = line.substring(62, 67).trim();
102    }
103    else
104    {
105  4 tid = line.substring(62).trim();
106    }
107  16 if (tid.length() > 0)
108    {
109  16 setId(tid);
110    }
111  16 continue;
112    }
113    }
114    // Were we to do anything with SEQRES - we start it here
115  55424 if (line.indexOf("SEQRES") == 0)
116    {
117    }
118   
119  55424 if (line.indexOf("MODEL") == 0)
120    {
121  0 modelFlag = true;
122    }
123   
124  55424 if (line.indexOf("TER") == 0)
125    {
126  26 terFlag = true;
127    }
128   
129  55424 if (modelFlag && line.indexOf("ENDMDL") == 0)
130    {
131  0 break;
132    }
133  55424 if (line.indexOf("ATOM") == 0
134    || (line.indexOf("HETATM") == 0 && !terFlag))
135    {
136  46602 terFlag = false;
137   
138    // Jalview is only interested in CA bonds????
139  46602 atomnam = line.substring(12, 15).trim();
140  46602 if (!atomnam.equals("CA") && !atomnam.equals("P"))
141    {
142  39498 continue;
143    }
144   
145  7104 Atom tmpatom = new Atom(line);
146  7104 if (tmpatom.resNumIns.trim().equals(lastID))
147    {
148    // phosphorylated protein - seen both CA and P..
149  3 continue;
150    }
151  7101 tmpchain = findChain(tmpatom.chain);
152  7101 if (tmpchain != null)
153    {
154  7066 tmpchain.atoms.addElement(tmpatom);
155    }
156    else
157    {
158    // PDBfile never handles alphafold models
159  35 tmpchain = new PDBChain(getId(), tmpatom.chain);
160  35 getChains().add(tmpchain);
161  35 tmpchain.atoms.addElement(tmpatom);
162    }
163  7101 lastID = tmpatom.resNumIns.trim();
164    }
165  15923 index++;
166    }
167   
168  16 makeResidueList();
169  16 makeCaBondList();
170   
171  16 if (getId() == null)
172    {
173  0 setId(inFile.getName());
174    }
175  16 for (PDBChain chain : getChains())
176    {
177  35 SequenceI chainseq = postProcessChain(chain);
178  35 if (isRNA(chainseq))
179    {
180  0 rna.add(chainseq);
181    }
182    else
183    {
184  35 prot.add(chainseq);
185    }
186    }
187  16 if (predictSecondaryStructure)
188    {
189  5 addSecondaryStructure(rna, prot);
190    }
191    } catch (OutOfMemoryError er)
192    {
193  0 System.out.println("OUT OF MEMORY LOADING PDB FILE");
194  0 throw new IOException(MessageManager
195    .getString("exception.outofmemory_loading_pdb_file"));
196    } catch (NumberFormatException ex)
197    {
198  0 if (line != null)
199    {
200  0 System.err.println("Couldn't read number from line:");
201  0 System.err.println(line);
202    }
203    }
204  16 markCalcIds();
205    }
206   
207    /**
208    * Process a parsed chain to construct and return a Sequence, and add it to
209    * the list of sequences parsed.
210    *
211    * @param chain
212    * @return
213    */
214   
 
215  6 toggle public static boolean isCalcIdHandled(String calcId)
216    {
217  6 return calcId != null && (CALC_ID_PREFIX.equals(calcId));
218    }
219   
 
220  254 toggle public static boolean isCalcIdForFile(AlignmentAnnotation alan,
221    String pdbFile)
222    {
223  254 return alan.getCalcId() != null
224    && CALC_ID_PREFIX.equals(alan.getCalcId())
225    && pdbFile.equals(alan.getProperty("PDBID"));
226    }
227   
 
228  0 toggle public static String relocateCalcId(String calcId,
229    Hashtable<String, String> alreadyLoadedPDB) throws Exception
230    {
231  0 int s = CALC_ID_PREFIX.length(),
232    end = calcId.indexOf(CALC_ID_PREFIX, s);
233  0 String between = calcId.substring(s, end - 1);
234  0 return CALC_ID_PREFIX + alreadyLoadedPDB.get(between) + ":"
235    + calcId.substring(end);
236    }
237   
 
238  16 toggle private void markCalcIds()
239    {
240  16 for (SequenceI sq : seqs)
241    {
242  35 if (sq.getAnnotation() != null)
243    {
244  18 for (AlignmentAnnotation aa : sq.getAnnotation())
245    {
246  22 String oldId = aa.getCalcId();
247  22 if (oldId == null)
248    {
249  0 oldId = "";
250    }
251  22 aa.setCalcId(CALC_ID_PREFIX);
252  22 aa.setProperty("PDBID", getId());
253  22 aa.setProperty("oldCalcId", oldId);
254    }
255    }
256    }
257    }
258   
259    }