Skip to content

Commit 4e271f5

Browse files
committed
Some exception handling fixes (biojava#111)
1 parent f85cd21 commit 4e271f5

6 files changed

Lines changed: 38 additions & 36 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/StructureTools.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ public class StructureTools {
7676
*/
7777
public static final String CB_ATOM_NAME = "CB";
7878

79-
80-
public static final Character UNKNOWN_GROUP_LABEL = new Character('x');
79+
/**
80+
* The character to use for unknown compounds in sequence strings
81+
*/
82+
public static final char UNKNOWN_GROUP_LABEL = 'X';
8183

8284
/**
8385
* Below this ratio of aminoacid/nucleotide residues to the sequence total,
@@ -665,8 +667,9 @@ public static final Character convert_3code_1code(String code3)
665667
}
666668

667669
/**
668-
* Convert a three letter code into single character.
669-
* catches for unusual characters
670+
* Convert a three letter aminoacid code into a single character code.
671+
* If the code corresponds to a nucleotide null is returned, in all other cases
672+
* {@value #UNKNOWN_GROUP_LABEL} is returned
670673
*
671674
* @param groupCode3 three letter representation
672675
* @return null if group is a nucleotide code

biojava-structure/src/main/java/org/biojava/nbio/structure/align/BioJavaStructureAlignment.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ private void copyResults(AFPChain afpChain, AlternativeAlignment altAlig, Atom[]
199199
}
200200

201201
private static char getOneLetter(Group g){
202-
try {
203-
return StructureTools.get1LetterCode(g.getPDBName());
204-
} catch (Exception e) {
205-
return 'X';
206-
}
207-
}
202+
203+
if (g==null) return StructureTools.UNKNOWN_GROUP_LABEL;
204+
205+
return StructureTools.get1LetterCode(g.getPDBName());
206+
207+
}
208208

209209
}

biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CECalculator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,12 +1320,9 @@ private void checkPrintRmsdNew(int traceMaxSize, int winSize, Atom[] ca1, Atom[]
13201320

13211321
private static char getOneLetter(Group g){
13221322

1323-
try {
1324-
Character c = StructureTools.get1LetterCode(g.getPDBName());
1325-
return c;
1326-
} catch (Exception e){
1327-
return 'X';
1328-
}
1323+
if (g==null) return StructureTools.UNKNOWN_GROUP_LABEL;
1324+
1325+
return StructureTools.get1LetterCode(g.getPDBName());
13291326
}
13301327

13311328

biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeCalculatorEnhanced.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,12 +1324,9 @@ private void checkPrintRmsdNew(int traceMaxSize, int winSize, Atom[] ca1, Atom[]
13241324

13251325
private static char getOneLetter(Group g){
13261326

1327-
try {
1328-
Character c = StructureTools.get1LetterCode(g.getPDBName());
1329-
return c;
1330-
} catch (Exception e){
1331-
return 'X';
1332-
}
1327+
if (g==null) return StructureTools.UNKNOWN_GROUP_LABEL;
1328+
1329+
return StructureTools.get1LetterCode(g.getPDBName());
13331330
}
13341331

13351332

biojava-structure/src/main/java/org/biojava/nbio/structure/align/model/AfpChainWriter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,12 +1048,13 @@ private static CharSequence getPDBPos(Atom atom)
10481048

10491049
private static char getOneLetter(Group g){
10501050

1051-
try {
1052-
Character c = StructureTools.get1LetterCode(g.getPDBName());
1053-
return c;
1054-
} catch (Exception e){
1055-
return 'X';
1056-
}
1051+
1052+
if (g==null) return StructureTools.UNKNOWN_GROUP_LABEL;
1053+
1054+
1055+
return StructureTools.get1LetterCode(g.getPDBName());
1056+
1057+
10571058
}
10581059

10591060

biojava-structure/src/main/java/org/biojava/nbio/structure/align/seq/SmithWaterman3Daligner.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
4848
import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet;
4949
import org.biojava.nbio.core.sequence.template.Compound;
50+
import org.slf4j.Logger;
51+
import org.slf4j.LoggerFactory;
5052

5153

5254
/** provides a 3D superimposition based on the sequence alignment
@@ -57,6 +59,8 @@
5759
public class SmithWaterman3Daligner extends AbstractStructureAlignment implements StructureAlignment {
5860

5961
public static final String algorithmName = "Smith-Waterman superposition";
62+
63+
private static final Logger logger = LoggerFactory.getLogger(SmithWaterman3Daligner.class);
6064

6165
/**
6266
* version history:
@@ -117,10 +121,12 @@ public AFPChain align(Atom[] ca1, Atom[] ca2, Object parameters)
117121

118122
SequencePair<ProteinSequence, AminoAcidCompound> pair = smithWaterman.getPair();
119123

120-
// Print the alignment to the screen
121-
// System.out.println(aligner.getAlignmentString());
124+
logger.debug("Smith-Waterman alignment is: "+pair.toString(100));
125+
122126
// convert to a 3D alignment...
123127
afpChain = convert(ca1,ca2,pair, smithWaterman);
128+
129+
124130

125131
} catch (CompoundNotFoundException e){
126132

@@ -291,11 +297,10 @@ private AFPChain convert(Atom[] ca1, Atom[] ca2, SequencePair<ProteinSequence,
291297

292298
private static char getOneLetter(Group g){
293299

294-
try {
295-
return StructureTools.get1LetterCode(g.getPDBName());
296-
} catch (Exception e){
297-
return 'X';
298-
}
300+
if (g==null) return StructureTools.UNKNOWN_GROUP_LABEL;
301+
302+
return StructureTools.get1LetterCode(g.getPDBName());
303+
299304
}
300305

301306
@Override
@@ -305,7 +310,6 @@ public String getAlgorithmName() {
305310

306311
@Override
307312
public ConfigStrucAligParams getParameters() {
308-
// TODO Auto-generated method stub
309313
return params;
310314
}
311315

0 commit comments

Comments
 (0)