Skip to content

Commit 76cf580

Browse files
committed
Updated Keywords parsing in mmCIF files
1 parent 86cb468 commit 76cf580

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ private void testHeader(Structure sPdb, Structure sCif) {
287287
// description is set in CIF parser to same as classification (_struct_keywords.pdbx_keywords field)
288288
// while in PDB parser it is simply not set
289289
//assertNotNull("pdb description null",hPdb.getDescription());
290-
assertNotNull("cif description null",hCif.getDescription());
290+
//assertNotNull("cif description null",hCif.getDescription()); //If we will enable this test again, we may use assertNull instead
291291
//assertEquals("failed getDescription:",hPdb.getDescription().toLowerCase(), hCif.getDescription().toLowerCase());
292292

293293
assertEquals("failed getDepDate:",hPdb.getDepDate(), hCif.getDepDate());

biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected CifFile getInternal(Structure structure, List<WrappedAtom> wrappedAtom
4646
.enterBlock(structure.getPDBCode());
4747

4848
blockBuilder.enterStructKeywords().enterText()
49-
.add(structure.getKeywords().toArray(new String[structure.getKeywords().size()]))
49+
.add(String.join(", ", structure.getKeywords()))
5050
.leaveColumn().leaveCategory();
5151

5252
if (atomSite.isDefined() && atomSite.getRowCount() > 0) {

biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConsumerImpl.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.ArrayList;
88
import java.util.Date;
99
import java.util.HashMap;
10-
import java.util.Iterator;
1110
import java.util.LinkedHashMap;
1211
import java.util.List;
1312
import java.util.Locale;
@@ -896,27 +895,24 @@ public void consumeStructConnType(StructConnType structConnType) {
896895

897896
@Override
898897
public void consumeStructKeywords(StructKeywords structKeywords) {
899-
//There may be a simpler implementation or a better implementation using
900-
// Java streams. However, I am not sure about the returned value from
901-
// getText().values()
902-
ArrayList<String> keywordsList = new ArrayList<String>();
903-
Iterator<String> iterator = structKeywords.getText().values().iterator();
904-
while (iterator.hasNext()) {
905-
String longString = (String) iterator.next();
906-
String[] strings = longString.split(" *, *");
907-
for (String string : strings) {
908-
keywordsList.add(string.trim());
909-
}
910-
}
911-
structure.setKeywords(keywordsList);
898+
ArrayList<String> keywordsList = new ArrayList<String>();
899+
900+
StrColumn text = structKeywords.getText();
901+
if (text.isDefined()) {
902+
String keywords = text.get(0);
903+
String[] strings = keywords.split(" *, *");
904+
for (String string : strings) {
905+
keywordsList.add(string.trim());
906+
}
907+
}
908+
structure.setKeywords(keywordsList);
912909

913910
StrColumn pdbxKeywords = structKeywords.getPdbxKeywords();
914911
if (pdbxKeywords.isDefined()) {
915-
//TODO I think no need for the Collectors.joining(", ") part.
916-
String keywords = pdbxKeywords.values().collect(Collectors.joining(", "));
917-
//TODO What is the right place to fill this field from?
918-
// pdbHeader.setDescription(keywords);
912+
String keywords = pdbxKeywords.get(0);
919913
pdbHeader.setClassification(keywords);
914+
//This field should be left empty
915+
// pdbHeader.setDescription(keywords);
920916
}
921917
}
922918

0 commit comments

Comments
 (0)