Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handling nulls in descriptions
  • Loading branch information
josemduarte committed May 11, 2023
commit a8a96ec122133b10cf5b4faf0cd6d79d65b7dbbe
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ protected CifFile getInternal(Structure structure, List<WrappedAtom> wrappedAtom
EntityInfo e = entityInfos.get(i);
entityIds[i] = Integer.toString(e.getMolId());
entityTypes[i] = e.getType().getEntityType();
entityDescriptions[i] = e.getDescription();
entityDescriptions[i] = e.getDescription() == null? "?" : e.getDescription();
}

String[] polyEntityIds = entityInfos.stream().filter(e -> e.getType() == EntityType.POLYMER).map(e -> Integer.toString(e.getMolId())).collect(Collectors.toList()).toArray(new String[]{});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streams have a toArray method as well. .collect(Collectors.toList()).toArray(new String[]{}) can be simplified to .toArray(String[]::new), effectively skipping the creation of a List.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thanks. Added a commit.

And shame to IntelliJ for not suggesting this!

String[] entitySeqs = entityInfos.stream().filter(e -> e.getType() == EntityType.POLYMER).map(e -> e.getChains().get(0).getSeqResSequence()).collect(Collectors.toList()).toArray(new String[]{});
String[] polyEntitySeqs = entityInfos.stream().filter(e -> e.getType() == EntityType.POLYMER).map(e -> e.getChains().get(0).getSeqResSequence()).collect(Collectors.toList()).toArray(new String[]{});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.


blockBuilder.enterEntity()
.enterId()
Expand All @@ -127,7 +127,7 @@ protected CifFile getInternal(Structure structure, List<WrappedAtom> wrappedAtom
.leaveColumn()

.enterPdbxSeqOneLetterCodeCan()
.add(entitySeqs)
.add(polyEntitySeqs)
.leaveColumn()

.leaveCategory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import java.io.InputStream;
import java.util.zip.GZIPInputStream;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class CifFileSupplierImplTest {

Expand All @@ -29,6 +28,7 @@ public void shouldReadRawPdbOutputtingCifWithEntity() throws IOException {
String cifText = CifStructureConverter.toText(s);
assertTrue(cifText.contains("_entity.type"));
assertTrue(cifText.contains("_entity_poly.pdbx_seq_one_letter_code_can"));
assertFalse(cifText.contains("null"));

InputStream inputStream = new ByteArrayInputStream(cifText.getBytes());
Structure readStruct = CifStructureConverter.fromInputStream(inputStream);
Expand Down