| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
package jalview.ws.dbsources; |
| 23 |
|
|
| 24 |
|
import jalview.api.FeatureSettingsModelI; |
| 25 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 26 |
|
import jalview.datamodel.AlignmentI; |
| 27 |
|
import jalview.datamodel.DBRefEntry; |
| 28 |
|
import jalview.datamodel.DBRefSource; |
| 29 |
|
import jalview.datamodel.PDBEntry; |
| 30 |
|
import jalview.datamodel.PDBEntry.Type; |
| 31 |
|
import jalview.datamodel.SequenceI; |
| 32 |
|
import jalview.io.DataSourceType; |
| 33 |
|
import jalview.io.FileFormat; |
| 34 |
|
import jalview.io.FileFormatI; |
| 35 |
|
import jalview.io.FormatAdapter; |
| 36 |
|
import jalview.io.PDBFeatureSettings; |
| 37 |
|
import jalview.structure.StructureImportSettings; |
| 38 |
|
import jalview.util.MessageManager; |
| 39 |
|
import jalview.util.Platform; |
| 40 |
|
import jalview.ws.ebi.EBIFetchClient; |
| 41 |
|
|
| 42 |
|
import java.io.File; |
| 43 |
|
import java.util.ArrayList; |
| 44 |
|
import java.util.List; |
| 45 |
|
|
| 46 |
|
import com.stevesoft.pat.Regex; |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
@author |
| 50 |
|
|
| 51 |
|
|
| |
|
| 0% |
Uncovered Elements: 98 (98) |
Complexity: 32 |
Complexity Density: 0.52 |
|
| 52 |
|
public class Pdb extends EbiFileRetrievedProxy |
| 53 |
|
{ |
| 54 |
|
private static final String SEPARATOR = "|"; |
| 55 |
|
|
| 56 |
|
private static final String COLON = ":"; |
| 57 |
|
|
| 58 |
|
private static final int PDB_ID_LENGTH = 4; |
| 59 |
|
|
| 60 |
|
private static Regex ACCESSION_REGEX; |
| 61 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 62 |
0 |
public Pdb()... |
| 63 |
|
{ |
| 64 |
0 |
super(); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
@see |
| 71 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 72 |
0 |
@Override... |
| 73 |
|
public String getAccessionSeparator() |
| 74 |
|
{ |
| 75 |
0 |
return null; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@see |
| 82 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 83 |
0 |
@Override... |
| 84 |
|
public Regex getAccessionValidator() |
| 85 |
|
{ |
| 86 |
0 |
if (ACCESSION_REGEX == null) |
| 87 |
|
{ |
| 88 |
0 |
ACCESSION_REGEX = Platform |
| 89 |
|
.newRegex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)"); |
| 90 |
|
} |
| 91 |
0 |
return ACCESSION_REGEX; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
@see |
| 98 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
0 |
@Override... |
| 100 |
|
public String getDbSource() |
| 101 |
|
{ |
| 102 |
0 |
return DBRefSource.PDB; |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
@see |
| 109 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
0 |
@Override... |
| 111 |
|
public String getDbVersion() |
| 112 |
|
{ |
| 113 |
0 |
return "0"; |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
@see |
| 120 |
|
|
| |
|
| 0% |
Uncovered Elements: 72 (72) |
Complexity: 21 |
Complexity Density: 0.44 |
|
| 121 |
0 |
@Override... |
| 122 |
|
public AlignmentI getSequenceRecords(String queries) throws Exception |
| 123 |
|
{ |
| 124 |
0 |
AlignmentI pdbAlignment = null; |
| 125 |
0 |
String chain = null; |
| 126 |
0 |
String id = null; |
| 127 |
0 |
if (queries.indexOf(COLON) > -1) |
| 128 |
|
{ |
| 129 |
0 |
chain = queries.substring(queries.indexOf(COLON) + 1); |
| 130 |
0 |
id = queries.substring(0, queries.indexOf(COLON)); |
| 131 |
|
} |
| 132 |
|
else |
| 133 |
|
{ |
| 134 |
0 |
id = queries; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
0 |
if (queries.length() > PDB_ID_LENGTH && chain == null) |
| 142 |
|
{ |
| 143 |
0 |
chain = queries.substring(PDB_ID_LENGTH, PDB_ID_LENGTH + 1); |
| 144 |
0 |
id = queries.substring(0, PDB_ID_LENGTH); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
0 |
if (!isValidReference(id)) |
| 148 |
|
{ |
| 149 |
0 |
jalview.bin.Console |
| 150 |
|
.errPrintln("Ignoring invalid pdb query: '" + id + "'"); |
| 151 |
0 |
stopQuery(); |
| 152 |
0 |
return null; |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
0 |
Type pdbFileFormat = StructureImportSettings |
| 160 |
|
.getDefaultStructureFileFormat(); |
| 161 |
0 |
String ext = pdbFileFormat.getExtension(); |
| 162 |
0 |
String fetchFormat = pdbFileFormat.getFormat(); |
| 163 |
|
|
| 164 |
0 |
EBIFetchClient ebi = new EBIFetchClient(); |
| 165 |
0 |
File tmpFile = ebi.fetchDataAsFile("pdb:" + id, fetchFormat, ext); |
| 166 |
0 |
file = tmpFile.getAbsolutePath(); |
| 167 |
0 |
stopQuery(); |
| 168 |
0 |
if (file == null) |
| 169 |
|
{ |
| 170 |
0 |
return null; |
| 171 |
|
} |
| 172 |
0 |
try |
| 173 |
|
{ |
| 174 |
|
|
| 175 |
0 |
FileFormatI fileFormat = (pdbFileFormat == Type.PDB) ? FileFormat.PDB |
| 176 |
|
: FileFormat.MMCif; |
| 177 |
0 |
pdbAlignment = new FormatAdapter().readFile(tmpFile, |
| 178 |
|
DataSourceType.FILE, fileFormat); |
| 179 |
0 |
if (pdbAlignment != null) |
| 180 |
|
{ |
| 181 |
0 |
List<SequenceI> toremove = new ArrayList<SequenceI>(); |
| 182 |
0 |
for (SequenceI pdbcs : pdbAlignment.getSequences()) |
| 183 |
|
{ |
| 184 |
0 |
String chid = null; |
| 185 |
|
|
| 186 |
0 |
for (PDBEntry pid : pdbcs.getAllPDBEntries()) |
| 187 |
|
{ |
| 188 |
0 |
if (pid.getFile() == file) |
| 189 |
|
{ |
| 190 |
0 |
chid = pid.getChainCode(); |
| 191 |
|
|
| 192 |
|
} |
| 193 |
|
} |
| 194 |
0 |
if (chain == null || (chid != null && (chid.equals(chain) |
| 195 |
|
|| chid.trim().equals(chain.trim()) |
| 196 |
|
|| (chain.trim().length() == 0 && chid.equals("_"))))) |
| 197 |
|
{ |
| 198 |
|
|
| 199 |
|
|
| 200 |
0 |
pdbcs.setName(jalview.datamodel.DBRefSource.PDB + SEPARATOR + id |
| 201 |
|
+ SEPARATOR + pdbcs.getName()); |
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
|
| 209 |
|
|
| 210 |
|
|
| 211 |
|
|
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
0 |
DBRefEntry dbentry = new DBRefEntry(getDbSource(), |
| 219 |
0 |
getDbVersion(), (chid == null ? id : id + chid)); |
| 220 |
|
|
| 221 |
0 |
pdbcs.addDBRef(dbentry); |
| 222 |
|
} |
| 223 |
|
else |
| 224 |
|
{ |
| 225 |
|
|
| 226 |
|
|
| 227 |
0 |
toremove.add(pdbcs); |
| 228 |
|
} |
| 229 |
|
} |
| 230 |
|
|
| 231 |
0 |
for (SequenceI pdbcs : toremove) |
| 232 |
|
{ |
| 233 |
0 |
pdbAlignment.deleteSequence(pdbcs); |
| 234 |
0 |
if (pdbcs.getAnnotation() != null) |
| 235 |
|
{ |
| 236 |
0 |
for (AlignmentAnnotation aa : pdbcs.getAnnotation()) |
| 237 |
|
{ |
| 238 |
0 |
pdbAlignment.deleteAnnotation(aa); |
| 239 |
|
} |
| 240 |
|
} |
| 241 |
|
} |
| 242 |
|
} |
| 243 |
|
|
| 244 |
0 |
if (pdbAlignment == null || pdbAlignment.getHeight() < 1) |
| 245 |
|
{ |
| 246 |
0 |
throw new Exception(MessageManager.formatMessage( |
| 247 |
|
"exception.no_pdb_records_for_chain", new String[] |
| 248 |
0 |
{ id, ((chain == null) ? "' '" : chain) })); |
| 249 |
|
} |
| 250 |
|
|
| 251 |
|
} catch (Exception ex) |
| 252 |
|
{ |
| 253 |
0 |
stopQuery(); |
| 254 |
0 |
throw (ex); |
| 255 |
|
} |
| 256 |
0 |
return pdbAlignment; |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
|
| 260 |
|
|
| 261 |
|
|
| 262 |
|
@see |
| 263 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 264 |
0 |
@Override... |
| 265 |
|
public boolean isValidReference(String accession) |
| 266 |
|
{ |
| 267 |
0 |
Regex r = getAccessionValidator(); |
| 268 |
0 |
return r.search(accession.trim()); |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
|
| 272 |
|
|
| 273 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 274 |
0 |
@Override... |
| 275 |
|
public String getTestQuery() |
| 276 |
|
{ |
| 277 |
0 |
return "1QIP"; |
| 278 |
|
} |
| 279 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 280 |
0 |
@Override... |
| 281 |
|
public String getDbName() |
| 282 |
|
{ |
| 283 |
0 |
return "PDB"; |
| 284 |
|
} |
| 285 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 286 |
0 |
@Override... |
| 287 |
|
public int getTier() |
| 288 |
|
{ |
| 289 |
0 |
return 0; |
| 290 |
|
} |
| 291 |
|
|
| 292 |
|
|
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| 296 |
|
|
| 297 |
|
|
| 298 |
|
|
| 299 |
|
|
| 300 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 301 |
0 |
@Override... |
| 302 |
|
public FeatureSettingsModelI getFeatureColourScheme() |
| 303 |
|
{ |
| 304 |
0 |
return new PDBFeatureSettings(); |
| 305 |
|
} |
| 306 |
|
} |