Skip to content

Commit ce53c60

Browse files
committed
Add docs
1 parent b224ffd commit ce53c60

3 files changed

Lines changed: 49 additions & 12 deletions

File tree

docs/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[deps]
2+
BioGenerics = "47718e42-2ac5-11e9-14af-e5595289c2ea"
23
BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"
34
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
5+
FASTX = "c2308a5c-f048-11e8-3e8a-31650f418d12"
46

57
[compat]
68
BioSequences = "3"
7-
Documenter = "0.27"
9+
Documenter = "0.27"

docs/src/files.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ end
77

88
# FASTX formatted files
99

10-
### Readers and writers
10+
### Readers and writers - basics
1111
A `Reader` and a `Writer` are structs that wrap an IO, and allows efficient reading/writing of FASTX `Record`s.
1212
For FASTA, use `FASTAReader` and `FASTAWriter`, and for FASTQ - well I'm sure you've guessed it.
1313

@@ -75,6 +75,8 @@ UInt8[]
7575
```
7676

7777
To use it correctly, either call `flush`, or close the writer first (which also closes the underlying stream).
78+
79+
### Readers and writers with do-syntax
7880
It is recommended to use readers and writers to `do` syntax in the form:
7981
```julia
8082
FASTAWriter(open(my_path, "w")) do writer
@@ -97,6 +99,26 @@ end
9799

98100
However, this latter syntax does not easily extend to different types of IO, such as gzip compressed streams.
99101

102+
### `rdr` and `wtr` macros
103+
The `rdr` and `wtr` macros use the passed file name to determine the FASTX reader or writer to use - including any compression file extensions.
104+
Since this both uses heuristics, and the macro is a little opaque to users, it is recommended to use these macros for ephemeral REPL work, and not in packages where the more explicit forms are preferred.
105+
106+
The macro call `rdr"seqs.fna.gz"` expands to
107+
```julia
108+
FASTAReader(GzipDecompressorStream(open("seqs.fna.gz"; lock=false)))
109+
```
110+
111+
To use rdr `rdr` and `wtr` macros with `do`-syntax, use the `defer` function.
112+
The only purpose of the defer function is to enable `do`-syntax:
113+
114+
```julia
115+
record = FASTARecord("my_header", "TAGAG")
116+
117+
defer(wtr"seqs.fna.gz") do writer
118+
write(writer, record)
119+
end
120+
```
121+
100122
### Validate files
101123
The functions `validate_fasta` and `validate_fastq` can be used to check if an `IO`
102124
contains data that can be read as FASTX.

docs/src/index.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,21 @@ Press `]` to enter pkg mode again, and enter the following:
2323
```
2424

2525
## Quickstart
26-
"FASTX" is a shorthand for the two related formats FASTA and FASTQ.
27-
See more documentation in the sections in the sidebar.
26+
See more detailed documentation in the sections in the sidebar.
2827

29-
### Read FASTA or FASTQ files
30-
It is preferred to use the `do` syntax to automatically close the file when it's done:
28+
### Read and writing FASTA or FASTQ files
29+
The idiomatic way uses a `do` block to automatically close the reader or writer
30+
when the block is exited:
3131
```julia
3232
FASTAReader(open("seqs.fna")) do reader
3333
for record in reader
3434
println(identifier(record))
3535
end
36-
end
36+
end
37+
38+
FASTQWriter(open("reads.fq", "w")) do writer
39+
write(writer, FASTQRecord("abc", "TAG", "ABC"))
40+
end
3741
```
3842

3943
Alternatively, you can open and close the reader manually:
@@ -46,18 +50,27 @@ end
4650
close(reader)
4751
```
4852

49-
### Write FASTA or FASTQ files
53+
### Read or write GZip compressed FASTA or FASTQ files
54+
For this you need to use a separate package to read GZip files, such as the `CodecZlib` package:
55+
5056
```julia
51-
FASTQWriter(open("reads.fq", "w")) do writer
52-
write(writer, FASTQRecord("abc", "TAG", "ABC"))
57+
using CodecZlib
58+
59+
FASTAReader(GzipDecompressorStream(open("seqs.fna.gz"))) do reader
60+
for record in reader
61+
println(identifier(record))
62+
end
5363
end
5464
```
5565

56-
### Read and write Gzip compressed FASTA files
66+
For added convenience, you can also use the reader and writer macros `rdr""` and `wtr""`.
67+
These macros use the file extensions to determine the biological sequence reader or writer type, and any file compresion.
68+
To use these macros with the `do`-syntax, you can use the `defer` function. Hence, the above code block can also be written in the following equivalent way:
69+
5770
```julia
5871
using CodecZlib
5972

60-
FASTAReader(GzipDecompressorStream(open("seqs.fna.gz"))) do reader
73+
defer(rdr"seqs.fna.gz") do reader
6174
for record in reader
6275
println(identifier(record))
6376
end

0 commit comments

Comments
 (0)