Skip to content

Commit 3f1f498

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 7437124 + fc6e86d commit 3f1f498

File tree

3 files changed

+141
-27
lines changed

3 files changed

+141
-27
lines changed

biojava-core/src/main/java/org/biojava/nbio/core/sequence/loader/UniprotProxySequenceReader.java

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@
2424
*/
2525
package org.biojava.nbio.core.sequence.loader;
2626

27+
import java.io.BufferedReader;
28+
import java.io.ByteArrayInputStream;
29+
import java.io.File;
30+
import java.io.FileNotFoundException;
31+
import java.io.FileReader;
32+
import java.io.FileWriter;
33+
import java.io.IOException;
34+
import java.io.InputStreamReader;
35+
import java.net.HttpURLConnection;
36+
import java.net.URL;
37+
import java.rmi.RemoteException;
38+
import java.util.ArrayList;
39+
import java.util.Iterator;
40+
import java.util.LinkedHashMap;
41+
import java.util.List;
42+
import java.util.regex.Pattern;
43+
44+
import javax.xml.parsers.ParserConfigurationException;
45+
import javax.xml.xpath.XPathExpressionException;
46+
2747
import org.biojava.nbio.core.exceptions.CompoundNotFoundException;
2848
import org.biojava.nbio.core.sequence.AccessionID;
2949
import org.biojava.nbio.core.sequence.DataSource;
@@ -35,26 +55,19 @@
3555
import org.biojava.nbio.core.sequence.features.DatabaseReferenceInterface;
3656
import org.biojava.nbio.core.sequence.features.FeaturesKeyWordInterface;
3757
import org.biojava.nbio.core.sequence.storage.SequenceAsStringHelper;
38-
import org.biojava.nbio.core.sequence.template.*;
58+
import org.biojava.nbio.core.sequence.template.Compound;
59+
import org.biojava.nbio.core.sequence.template.CompoundSet;
60+
import org.biojava.nbio.core.sequence.template.ProxySequenceReader;
61+
import org.biojava.nbio.core.sequence.template.SequenceMixin;
62+
import org.biojava.nbio.core.sequence.template.SequenceProxyView;
63+
import org.biojava.nbio.core.sequence.template.SequenceView;
3964
import org.biojava.nbio.core.util.XMLHelper;
4065
import org.slf4j.Logger;
4166
import org.slf4j.LoggerFactory;
4267
import org.w3c.dom.Document;
4368
import org.w3c.dom.Element;
4469
import org.xml.sax.SAXException;
4570

46-
import javax.xml.parsers.ParserConfigurationException;
47-
import javax.xml.xpath.XPathExpressionException;
48-
import java.io.*;
49-
import java.net.HttpURLConnection;
50-
import java.net.URL;
51-
import java.rmi.RemoteException;
52-
import java.util.ArrayList;
53-
import java.util.Iterator;
54-
import java.util.LinkedHashMap;
55-
import java.util.List;
56-
import java.util.regex.Pattern;
57-
5871
/**
5972
*
6073
* Pass in a Uniprot ID and this ProxySequenceReader when passed to a ProteinSequence will get the sequence data and other data elements
@@ -321,6 +334,28 @@ public ArrayList<AccessionID> getAccessions() throws XPathExpressionException {
321334

322335
return accessionList;
323336
}
337+
338+
/**
339+
* Pull uniprot protein aliases associated with this sequence
340+
* @return
341+
* @throws XPathExpressionException
342+
*/
343+
public ArrayList<String> getAliases() throws XPathExpressionException {
344+
ArrayList<String> aliasList = new ArrayList<String>();
345+
if (uniprotDoc == null) {
346+
return aliasList;
347+
}
348+
Element uniprotElement = uniprotDoc.getDocumentElement();
349+
Element entryElement = XMLHelper.selectSingleElement(uniprotElement, "entry");
350+
Element proteinElement = XMLHelper.selectSingleElement(entryElement, "protein");
351+
ArrayList<Element> keyWordElementList = XMLHelper.selectElements(proteinElement, "alternativeName");
352+
for (Element element : keyWordElementList) {
353+
Element fullNameElement = XMLHelper.selectSingleElement(element, "fullName");
354+
aliasList.add(fullNameElement.getTextContent());
355+
}
356+
357+
return aliasList;
358+
}
324359

325360
/**
326361
*

biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,34 +145,45 @@ private void formIntraResidueBonds() {
145145
for (Chain chain : structure.getChains()) {
146146
List<Group> groups = chain.getAtomGroups();
147147

148-
for (Group group : groups) {
148+
for (Group mainGroup : groups) {
149149
// atoms with no residue number don't have atom information
150-
if (group.getResidueNumber() == null) {
150+
if (mainGroup.getResidueNumber() == null) {
151151
continue;
152152
}
153153

154-
ChemComp aminoChemComp = ChemCompGroupFactory.getChemComp(group
155-
.getPDBName());
154+
// Now add support for altLocGroup
155+
List<Group> totList = new ArrayList<Group>();
156+
totList.add(mainGroup);
157+
for(Group altLoc: mainGroup.getAltLocs()){
158+
totList.add(altLoc);
159+
}
160+
// Now iterate through this list
161+
for(Group group : totList){
162+
163+
ChemComp aminoChemComp = ChemCompGroupFactory.getChemComp(group
164+
.getPDBName());
156165

157-
for (ChemCompBond chemCompBond : aminoChemComp.getBonds()) {
166+
for (ChemCompBond chemCompBond : aminoChemComp.getBonds()) {
158167

159-
Atom a = group.getAtom(chemCompBond.getAtom_id_1());
160-
Atom b = group.getAtom(chemCompBond.getAtom_id_2());
161-
if ( a != null && b != null){
168+
Atom a = group.getAtom(chemCompBond.getAtom_id_1());
169+
Atom b = group.getAtom(chemCompBond.getAtom_id_2());
170+
if ( a != null && b != null){
162171

163-
int bondOrder = chemCompBond.getNumericalBondOrder();
172+
int bondOrder = chemCompBond.getNumericalBondOrder();
164173

165-
new BondImpl(a, b, bondOrder);
166-
} else {
174+
new BondImpl(a, b, bondOrder);
175+
} else {
167176

168-
// Some of the atoms were missing. That's fine, there's
169-
// nothing to do in this case.
177+
// Some of the atoms were missing. That's fine, there's
178+
// nothing to do in this case.
179+
}
170180
}
171181
}
172-
}
182+
}
173183
}
174184
}
175185

186+
176187
private void trimBondLists() {
177188
for (Chain chain : structure.getChains()) {
178189
for (Group group : chain.getAtomGroups()) {

biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,74 @@ public void test3PIUpdb() throws IOException, StructureException{
297297

298298

299299
}
300+
301+
302+
303+
@Test
304+
public void test4CUPBonds() throws IOException, StructureException{
305+
306+
AtomCache cache = new AtomCache();
307+
FileParsingParameters params = new FileParsingParameters();
308+
params.setAlignSeqRes(true);
309+
params.setCreateAtomBonds(true);
310+
cache.setFileParsingParams(params);
311+
312+
313+
StructureIO.setAtomCache(cache);
314+
315+
cache.setUseMmCif(false);
316+
317+
Structure structure = StructureIO.getStructure("4CUP");
318+
319+
assertNotNull(structure);
320+
321+
Atom[] ca = StructureTools.getAtomCAArray(structure);
322+
323+
//System.out.println(structure.getPdbId() + " has # CA atoms: " + ca.length);
324+
325+
List<Atom> caList = new ArrayList<Atom>();
326+
for ( Chain c: structure.getChains()){
327+
for (Group g: c.getAtomGroups()){
328+
329+
for (Group altLocGroup:g.getAltLocs()) {
330+
ensureAllAtomsSameAltCode(altLocGroup);
331+
List<Atom> theseAtoms = new ArrayList<Atom>();
332+
for (Atom a:altLocGroup.getAtoms()) {
333+
theseAtoms.add(a);
334+
}
335+
for (Atom a:altLocGroup.getAtoms()) {
336+
// Check the bonds are all part of this altLoc group
337+
assertNotEquals(0, a.getBonds().size());
338+
}
339+
}
340+
341+
List<Atom> atoms = g.getAtoms();
342+
boolean caInMain = false;
343+
for (Atom a: atoms){
344+
assertNotNull(a.getGroup());
345+
assertNotNull(a.getGroup().getChain());
346+
347+
if ( a.getName().equals(StructureTools.CA_ATOM_NAME)) {
348+
caList.add(a);
349+
caInMain = true;
350+
break;
351+
352+
}
353+
354+
355+
}
356+
if (! caInMain && g.hasAtom(StructureTools.CA_ATOM_NAME)){
357+
// g.hasAtom checks altLocs
358+
fail("CA is not in main group, but in altLoc");
359+
}
360+
361+
}
362+
}
363+
364+
assertTrue(ca.length == caList.size());
365+
366+
367+
}
300368

301369
@Test
302370
public void test3PIUmmcif() throws IOException, StructureException{

0 commit comments

Comments
 (0)