Skip to content

Commit f5eae5c

Browse files
committed
Some fixes for biojava#111 and biojava#155
1 parent d9974e7 commit f5eae5c

4 files changed

Lines changed: 31 additions & 41 deletions

File tree

biojava3-structure/src/main/java/org/biojava/bio/structure/align/util/AtomCache.java

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import org.biojava.bio.structure.scop.ScopFactory;
5959
import org.biojava3.core.util.InputStreamProvider;
6060
import org.biojava3.structure.StructureIO;
61+
import org.slf4j.Logger;
62+
import org.slf4j.LoggerFactory;
6163

6264
/**
6365
* A utility class that provides easy access to Structure objects. If you are running a script that is frequently
@@ -71,6 +73,8 @@
7173
* @since 3.0
7274
*/
7375
public class AtomCache {
76+
77+
private static final Logger logger = LoggerFactory.getLogger(AtomCache.class);
7478

7579
public static final String BIOL_ASSEMBLY_IDENTIFIER = "BIO:";
7680
public static final String CHAIN_NR_SYMBOL = ":";
@@ -192,15 +196,7 @@ public Atom[] getAtoms(String name) throws IOException, StructureException {
192196
Atom[] atoms = null;
193197

194198
// System.out.println("loading " + name);
195-
Structure s = null;
196-
try {
197-
198-
s = getStructure(name);
199-
200-
} catch (StructureException ex) {
201-
System.err.println("error getting Structure for " + name);
202-
throw new StructureException(ex.getMessage(), ex);
203-
}
199+
Structure s = getStructure(name);
204200

205201
atoms = StructureTools.getAtomCAArray(s);
206202

@@ -459,7 +455,7 @@ public Structure getStructure(String name) throws IOException, StructureExceptio
459455
try {
460456
Thread.sleep(100);
461457
} catch (InterruptedException e) {
462-
System.err.println(e.getMessage());
458+
logger.error(e.getMessage());
463459
}
464460

465461
}
@@ -899,16 +895,7 @@ public Structure getStructureForCathDomain(StructureName structureName, CathData
899895

900896
String pdbId = structureName.getPdbId();
901897

902-
Structure s = null;
903-
904-
try {
905-
s = getStructure(pdbId);
906-
907-
} catch (StructureException ex) {
908-
System.err.println("error getting Structure for " + pdbId);
909-
910-
throw new StructureException(ex);
911-
}
898+
Structure s = getStructure(pdbId);
912899

913900
String rangeS = range.toString();
914901

@@ -1038,7 +1025,7 @@ private ScopDomain guessScopDomain(String name) throws IOException, StructureExc
10381025
}
10391026

10401027
// Didn't work. Guess it!
1041-
System.err.println("Warning, could not find SCOP domain: " + name);
1028+
logger.warn("Warning, could not find SCOP domain: " + name);
10421029

10431030
Matcher scopMatch = scopIDregex.matcher(name);
10441031
if (scopMatch.matches()) {
@@ -1063,14 +1050,16 @@ private ScopDomain guessScopDomain(String name) throws IOException, StructureExc
10631050
Iterator<ScopDomain> match = matches.iterator();
10641051
if (match.hasNext()) {
10651052
ScopDomain bestMatch = match.next();
1066-
System.err.print("Trying domain " + bestMatch.getScopId() + ".");
1053+
StringBuilder warnMsg = new StringBuilder();
1054+
warnMsg.append("Trying domain " + bestMatch.getScopId() + ".");
10671055
if (match.hasNext()) {
1068-
System.err.print(" Other possibilities: ");
1056+
warnMsg.append(" Other possibilities: ");
10691057
while (match.hasNext()) {
1070-
System.err.print(match.next().getScopId() + " ");
1058+
warnMsg.append(match.next().getScopId() + " ");
10711059
}
10721060
}
1073-
System.err.println();
1061+
warnMsg.append(System.getProperty("line.separator"));
1062+
logger.warn(warnMsg.toString());
10741063
return bestMatch;
10751064
} else {
10761065
return null;
@@ -1087,7 +1076,7 @@ protected void flagLoadingFinished(String name) {
10871076
currentlyLoading.remove(name);
10881077
}
10891078

1090-
protected Structure loadStructureFromCifByPdbId(String pdbId) throws StructureException {
1079+
protected Structure loadStructureFromCifByPdbId(String pdbId) throws IOException, StructureException {
10911080

10921081
Structure s;
10931082
flagLoading(pdbId);
@@ -1107,14 +1096,14 @@ protected Structure loadStructureFromCifByPdbId(String pdbId) throws StructureEx
11071096

11081097
} catch (IOException e) {
11091098
flagLoadingFinished(pdbId);
1110-
throw new StructureException(e.getMessage() + " while parsing " + pdbId, e);
1099+
throw e;//new StructureException(e.getMessage() + " while parsing " + pdbId, e);
11111100
}
11121101
flagLoadingFinished(pdbId);
11131102

11141103
return s;
11151104
}
11161105

1117-
protected Structure loadStructureFromPdbByPdbId(String pdbId) throws StructureException {
1106+
protected Structure loadStructureFromPdbByPdbId(String pdbId) throws IOException, StructureException {
11181107

11191108
Structure s;
11201109
flagLoading(pdbId);
@@ -1132,7 +1121,7 @@ protected Structure loadStructureFromPdbByPdbId(String pdbId) throws StructureEx
11321121

11331122
} catch (IOException e) {
11341123
flagLoadingFinished(pdbId);
1135-
throw new StructureException(e.getMessage() + " while parsing " + pdbId, e);
1124+
throw e;//new StructureException(e.getMessage() + " while parsing " + pdbId, e);
11361125
}
11371126
flagLoadingFinished(pdbId);
11381127

biojava3-structure/src/main/java/org/biojava/bio/structure/io/PDBFileParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import org.biojava.bio.structure.StructureException;
7070
import org.biojava.bio.structure.StructureImpl;
7171
import org.biojava.bio.structure.StructureTools;
72-
import org.biojava.bio.structure.contact.StructureInterface;
7372
import org.biojava.bio.structure.io.mmcif.ChemCompGroupFactory;
7473
import org.biojava.bio.structure.io.mmcif.ReducedChemCompProvider;
7574
import org.biojava.bio.structure.io.util.PDBTemporaryStorageUtils.LinkRecord;

biojava3-structure/src/main/java/org/biojava/bio/structure/io/mmcif/SimpleMMcifConsumer.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Locale;
3131
import java.util.Map;
3232
import java.util.Set;
33-
import java.util.logging.Logger;
3433

3534
import org.biojava.bio.structure.AminoAcid;
3635
import org.biojava.bio.structure.AminoAcidImpl;
@@ -90,6 +89,8 @@
9089
import org.biojava.bio.structure.xtal.CrystalCell;
9190
import org.biojava.bio.structure.xtal.SpaceGroup;
9291
import org.biojava.bio.structure.xtal.SymoplibParser;
92+
import org.slf4j.Logger;
93+
import org.slf4j.LoggerFactory;
9394

9495
/** A MMcifConsumer implementation that build a in-memory representation of the
9596
* content of a mmcif file as a BioJava Structure object.
@@ -127,7 +128,7 @@ public class SimpleMMcifConsumer implements MMcifConsumer {
127128

128129
FileParsingParameters params;
129130

130-
public static Logger logger = Logger.getLogger("org.biojava.bio.structure");
131+
private static final Logger logger = LoggerFactory.getLogger(SimpleMMcifConsumer.class);
131132

132133
public SimpleMMcifConsumer(){
133134
params = new FileParsingParameters();
@@ -1042,7 +1043,7 @@ public void newDatabasePDBremark(DatabasePDBremark remark) {
10421043
res = Float.parseFloat(resolution);
10431044

10441045
} catch (NumberFormatException e) {
1045-
logger.warning("could not parse resolution from line and ignoring it " + line);
1046+
logger.info("could not parse resolution from line and ignoring it " + line);
10461047
return ;
10471048

10481049

@@ -1064,14 +1065,14 @@ public void newRefine(Refine r){
10641065
// there are 2 resolution values, one for each method
10651066
// we take the first one found so that behaviour is like in PDB file parsing
10661067
if (pdbHeader.getResolution()!=PDBHeader.DEFAULT_RESOLUTION) {
1067-
logger.fine("more than 1 resolution value present (last encountered is "+r.getLs_d_res_high()+
1068+
logger.warn("more than 1 resolution value present (last encountered is "+r.getLs_d_res_high()+
10681069
"), will use only the first one ("+String.format("%4.2f",pdbHeader.getResolution())+")");
10691070
return;
10701071
}
10711072
try {
10721073
pdbHeader.setResolution(Float.parseFloat(r.getLs_d_res_high()));
10731074
} catch (NumberFormatException e){
1074-
logger.fine("could not parse resolution from " + r.getLs_d_res_high() + " " + e.getMessage());
1075+
logger.info("could not parse resolution from " + r.getLs_d_res_high() + " " + e.getMessage());
10751076
}
10761077
}
10771078

@@ -1150,20 +1151,20 @@ public void newCell(Cell cell) {
11501151

11511152
} catch (NumberFormatException e){
11521153
structure.getPDBHeader().getCrystallographicInfo().setCrystalCell(null);
1153-
logger.fine("could not parse some cell parameters ("+e.getMessage()+"), ignoring _cell ");
1154+
logger.info("could not parse some cell parameters ("+e.getMessage()+"), ignoring _cell ");
11541155
}
11551156
try {
11561157
// if Z parsing fails it is not so important
11571158
structure.getPDBHeader().getCrystallographicInfo().setZ(Integer.parseInt(cell.getZ_PDB()));
11581159
} catch (NumberFormatException e) {
1159-
logger.fine("could not parse some the Z parameter from _cell ");
1160+
logger.info("could not parse some the Z parameter from _cell ");
11601161
}
11611162
}
11621163

11631164
public void newSymmetry(Symmetry symmetry) {
11641165
String spaceGroup = symmetry.getSpace_group_name_H_M();
11651166
SpaceGroup sg = SymoplibParser.getSpaceGroup(spaceGroup);
1166-
if (sg==null) logger.fine("Space group '"+spaceGroup+"' not recognised as a standard space group");
1167+
if (sg==null) logger.warn("Space group '"+spaceGroup+"' not recognised as a standard space group");
11671168

11681169
structure.getPDBHeader().getCrystallographicInfo().setSpaceGroup(sg);
11691170
}
@@ -1223,7 +1224,7 @@ public void newStructRefSeq(StructRefSeq sref) {
12231224
r.setChainId(sref.getPdbx_strand_id());
12241225
StructRef structRef = getStructRef(sref.getRef_id());
12251226
if (structRef == null){
1226-
logger.warning("could not find StructRef " + sref.getRef_id() + " for StructRefSeq " + sref);
1227+
logger.warn("could not find StructRef " + sref.getRef_id() + " for StructRefSeq " + sref);
12271228
} else {
12281229
r.setDatabase(structRef.getDb_name());
12291230
r.setDbIdCode(structRef.getDb_code());

biojava3-structure/src/main/java/org/biojava/bio/structure/io/mmcif/SimpleMMcifParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.HashSet;
3232
import java.util.List;
3333
import java.util.Set;
34-
import java.util.logging.Logger;
3534

3635
import org.biojava.bio.structure.Structure;
3736
import org.biojava.bio.structure.io.MMCIFFileReader;
@@ -68,6 +67,8 @@
6867
import org.biojava.bio.structure.io.mmcif.model.StructRefSeq;
6968
import org.biojava.bio.structure.io.mmcif.model.Symmetry;
7069
import org.biojava.bio.structure.jama.Matrix;
70+
import org.slf4j.Logger;
71+
import org.slf4j.LoggerFactory;
7172

7273

7374
/** A simple mmCif file parser
@@ -104,7 +105,7 @@ public class SimpleMMcifParser implements MMcifParser {
104105

105106
Struct struct ;
106107

107-
public static Logger logger = Logger.getLogger("org.biojava.bio.structure");
108+
static final Logger logger = LoggerFactory.getLogger(SimpleMMcifParser.class);
108109

109110
public SimpleMMcifParser(){
110111
consumers = new ArrayList<MMcifConsumer>();

0 commit comments

Comments
 (0)