Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:56:54 GMT
  2. Package jalview.structure

File PDBEntryUtils.java

 

Coverage histogram

../../img/srcFileCovDistChart9.png
12% of files have more coverage

Code metrics

24
44
5
1
155
111
17
0.39
8.8
5
3.4

Classes

Class Line # Actions
PDBEntryUtils 35 44 17
0.904109690.4%
 

Contributing tests

This file is covered by 45 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 jalview.structure;
22   
23    import java.util.ArrayList;
24    import java.util.HashSet;
25    import java.util.List;
26    import java.util.Set;
27    import java.util.regex.Matcher;
28    import java.util.regex.Pattern;
29   
30    import jalview.datamodel.PDBEntry;
31    import jalview.datamodel.SequenceI;
32    import jalview.io.StructureFile;
33    import mc_view.PDBChain;
34   
 
35    public class PDBEntryUtils
36    {
37   
 
38  147 toggle public static String inferChainId(SequenceI seq)
39    {
40  147 String targetChainId;
41  147 if (seq.getName().indexOf("|") > -1)
42    {
43  55 targetChainId = seq.getName()
44    .substring(seq.getName().lastIndexOf("|") + 1);
45  55 if (targetChainId.length() > 1)
46    {
47  1 if (targetChainId.trim().length() == 0)
48    {
49  0 targetChainId = " ";
50    }
51    else
52    {
53    // not a valid chain identifier
54  1 targetChainId = "";
55    }
56    }
57    }
58    else
59    {
60  92 targetChainId = "";
61    }
62  147 return targetChainId;
63    }
64    protected static Pattern id_and_chain=Pattern.compile("(\\d[0-9A-Za-z]{3})[_:|]?([0-9A-Za-z]{1,2})?.*");
65   
 
66  385 toggle public static List<PDBEntry> inferPDBEntry(SequenceI seq)
67    {
68  385 Matcher matcher = id_and_chain.matcher(seq.getName());
69   
70  385 if (matcher.matches())
71    {
72  143 String id = matcher.group(1);
73  143 PDBEntry pdbe = new PDBEntry();
74  143 pdbe.setId(id);
75  143 if (matcher.groupCount() > 1)
76    {
77  143 pdbe.setChainCode(matcher.group(2));
78    }
79   
80  143 return List.of(pdbe);
81    }
82  242 return List.of();
83    }
84   
85   
86    /**
87    * generate likely PDB IDs & chain codes from seq and ds that fit pdb
88    * @param seq
89    * @param ds
90    * @param pdb
91    * @return empty list or one or more PDBEntry which match pdb.getId()
92    */
 
93  187 toggle public static List<PDBEntry> selectPutativePDBe(SequenceI seq,
94    SequenceI ds, StructureFile pdb)
95    {
96  187 List<PDBEntry> putativePDBe = new ArrayList<PDBEntry>();
97  187 Set<PDBEntry> possiblePDBe=PDBEntryUtils.gatherPDBEntries(seq,true);
98  187 for (PDBEntry infPDBe: possiblePDBe)
99    {
100  299 if (infPDBe.getId().equalsIgnoreCase(pdb.getId()))
101    {
102  250 putativePDBe.add(infPDBe);
103    }
104    }
105  187 return putativePDBe;
106    }
107   
108   
 
109  193 toggle public static Set<PDBEntry> gatherPDBEntries(SequenceI seq,boolean inferFromName)
110    {
111  193 Set<PDBEntry> possiblePDBe=new HashSet<PDBEntry>();
112  577 while (seq!=null)
113    {
114  384 if (seq.getAllPDBEntries()!=null) {
115  384 possiblePDBe.addAll(seq.getAllPDBEntries());
116    }
117  384 if (inferFromName)
118    {
119  384 possiblePDBe.addAll(PDBEntryUtils.inferPDBEntry(seq));
120    }
121  384 seq = seq.getDatasetSequence();
122    }
123  193 return possiblePDBe;
124    }
125   
126   
 
127  163 toggle public static PDBEntry selectPutativePDBEntry(List<PDBEntry> putativePDBe,
128    PDBChain chain)
129    {
130  163 if (putativePDBe.isEmpty())
131    {
132  0 return null;
133    }
134   
135    // check if there's a chaincode
136  163 PDBEntry putativeEntry = null;
137  163 boolean hasChainCodes;
138    // check for a chaincode mapping
139  163 for (PDBEntry pdbe : putativePDBe)
140    {
141  199 if (pdbe.getChainCode() != null)
142    {
143  154 hasChainCodes = true;
144  154 if (pdbe.getChainCode().equals(chain.id))
145    {
146  91 putativeEntry = pdbe;
147  91 return putativeEntry;
148    }
149    } else {
150  45 return pdbe;
151    }
152    }
153  27 return null;
154    }
155    }