You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/files.md
+23-1Lines changed: 23 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ end
7
7
8
8
# FASTX formatted files
9
9
10
-
### Readers and writers
10
+
### Readers and writers - basics
11
11
A `Reader` and a `Writer` are structs that wrap an IO, and allows efficient reading/writing of FASTX `Record`s.
12
12
For FASTA, use `FASTAReader` and `FASTAWriter`, and for FASTQ - well I'm sure you've guessed it.
13
13
@@ -75,6 +75,8 @@ UInt8[]
75
75
```
76
76
77
77
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
78
80
It is recommended to use readers and writers to `do` syntax in the form:
79
81
```julia
80
82
FASTAWriter(open(my_path, "w")) do writer
@@ -97,6 +99,26 @@ end
97
99
98
100
However, this latter syntax does not easily extend to different types of IO, such as gzip compressed streams.
99
101
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.
Copy file name to clipboardExpand all lines: docs/src/index.md
+23-10Lines changed: 23 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,17 +23,21 @@ Press `]` to enter pkg mode again, and enter the following:
23
23
```
24
24
25
25
## 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.
28
27
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:
31
31
```julia
32
32
FASTAReader(open("seqs.fna")) do reader
33
33
for record in reader
34
34
println(identifier(record))
35
35
end
36
-
end
36
+
end
37
+
38
+
FASTQWriter(open("reads.fq", "w")) do writer
39
+
write(writer, FASTQRecord("abc", "TAG", "ABC"))
40
+
end
37
41
```
38
42
39
43
Alternatively, you can open and close the reader manually:
@@ -46,18 +50,27 @@ end
46
50
close(reader)
47
51
```
48
52
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
+
50
56
```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
53
63
end
54
64
```
55
65
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
+
57
70
```julia
58
71
using CodecZlib
59
72
60
-
FASTAReader(GzipDecompressorStream(open("seqs.fna.gz"))) do reader
0 commit comments