Skip to content

Commit f9d0480

Browse files
committed
fix for biojava#306 - now checks provided URL if it contains the string ".cif" and switches to mmCif parsing accordingly.
1 parent 66cfcdc commit f9d0480

1 file changed

Lines changed: 45 additions & 12 deletions

File tree

  • biojava-structure/src/main/java/org/biojava/nbio/structure/align/util

‎biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java‎

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@
3333
import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior;
3434
import org.biojava.nbio.structure.io.MMCIFFileReader;
3535
import org.biojava.nbio.structure.io.PDBFileReader;
36+
import org.biojava.nbio.structure.io.mmcif.MMcifParser;
37+
import org.biojava.nbio.structure.io.mmcif.SimpleMMcifConsumer;
38+
import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser;
3639
import org.biojava.nbio.structure.io.util.FileDownloadUtils;
3740
import org.biojava.nbio.structure.quaternary.io.BioUnitDataProviderFactory;
3841
import org.biojava.nbio.structure.scop.*;
3942
import org.biojava.nbio.core.util.InputStreamProvider;
4043
import org.slf4j.Logger;
4144
import org.slf4j.LoggerFactory;
4245

43-
import java.io.IOException;
44-
import java.io.StringWriter;
46+
import java.io.*;
4547
import java.net.URL;
4648
import java.util.*;
4749
import java.util.regex.Matcher;
@@ -1048,19 +1050,50 @@ private Structure getStructureFromURL(URL url) throws IOException, StructureExce
10481050
chainId = queryS.substring(8);
10491051
}
10501052

1051-
1052-
1053+
if ( fullu.contains(".cif")) {
1054+
1055+
// need to do mmcif parsing!
1056+
1057+
InputStreamProvider prov = new InputStreamProvider();
1058+
InputStream inStream = prov.getInputStream(url);
1059+
1060+
MMcifParser parser = new SimpleMMcifParser();
1061+
1062+
SimpleMMcifConsumer consumer = new SimpleMMcifConsumer();
1063+
consumer.setFileParsingParameters(params);
1064+
1065+
1066+
parser.addMMcifConsumer(consumer);
1067+
1068+
try {
1069+
parser.parse(new BufferedReader(new InputStreamReader(inStream)));
1070+
} catch (IOException e){
1071+
e.printStackTrace();
1072+
}
10531073

1054-
PDBFileReader reader = new PDBFileReader(path);
1055-
reader.setFetchBehavior(fetchBehavior);
1056-
reader.setObsoleteBehavior(obsoleteBehavior);
1074+
// now get the protein structure.
1075+
Structure cifStructure = consumer.getStructure();
1076+
if (chainId == null) {
1077+
return StructureTools.getReducedStructure(cifStructure, -1);
1078+
} else {
1079+
return StructureTools.getReducedStructure(cifStructure, chainId);
1080+
}
10571081

1058-
reader.setFileParsingParameters(params);
1059-
Structure s = reader.getStructure(url);
1060-
if (chainId == null) {
1061-
return StructureTools.getReducedStructure(s, -1);
10621082
} else {
1063-
return StructureTools.getReducedStructure(s, chainId);
1083+
1084+
// pdb file based parsing
1085+
1086+
PDBFileReader reader = new PDBFileReader(path);
1087+
reader.setFetchBehavior(fetchBehavior);
1088+
reader.setObsoleteBehavior(obsoleteBehavior);
1089+
1090+
reader.setFileParsingParameters(params);
1091+
Structure s = reader.getStructure(url);
1092+
if (chainId == null) {
1093+
return StructureTools.getReducedStructure(s, -1);
1094+
} else {
1095+
return StructureTools.getReducedStructure(s, chainId);
1096+
}
10641097
}
10651098
}
10661099

0 commit comments

Comments
 (0)