Skip to content

Commit 5b44b56

Browse files
authored
Merge pull request #36 from hilbertglm/20240130-streaming
Added an example for FastaStreamer
2 parents 39a6e97 + 4ad8eb6 commit 5b44b56

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/readwrite.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ BioJava can also be used to parse large FASTA files. The example below can parse
7979
}
8080
```
8181

82+
BioJava can also process large FASTA files using the Java streams API.
83+
84+
```java
85+
FastaStreamer
86+
.from(path)
87+
.stream()
88+
.forEach(sequence -> System.out.printf("%s -> %ss\n", sequence.getOriginalHeader(), sequence.getSequenceAsString()));
89+
```
90+
91+
If you need to specify a header parser other that `GenericFastaHeaderParser` or a sequence creater other than a
92+
`ProteinSequenceCreator`, these can be specified before streaming the contents as follows:
93+
94+
```java
95+
FastaStreamer
96+
.from(path)
97+
.withHeaderParser(new PlainFastaHeaderParser<>())
98+
.withSequenceCreator(new CasePreservingProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet()))
99+
.stream()
100+
.forEach(sequence -> System.out.printf("%s -> %ss\n", sequence.getOriginalHeader(), sequence.getSequenceAsString()));
101+
```
102+
82103

83104

84105
<!--automatically generated footer-->

0 commit comments

Comments
 (0)