Skip to content

Commit 67bc453

Browse files
committed
added FASTA IO example tests.
1 parent a54050d commit 67bc453

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

io_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package poly
22

33
import (
4+
"bytes"
5+
"fmt"
46
"io/ioutil"
57
"os"
68
"testing"
@@ -237,6 +239,41 @@ FASTA related tests begin here.
237239
238240
******************************************************************************/
239241

242+
// ExampleReadFASTA shows basic usage for ReadFASTA
243+
func ExampleReadFASTA() {
244+
sequence := ReadFASTA("data/base.fasta")
245+
fmt.Println(sequence.Features[0].Description)
246+
// Output: gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]
247+
}
248+
249+
func ExampleParseFASTA() {
250+
file, _ := ioutil.ReadFile("data/base.fasta")
251+
sequence := ParseFASTA(string(file))
252+
253+
fmt.Println(sequence.Features[0].Description)
254+
// Output: gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]
255+
}
256+
257+
func ExampleBuildFASTA() {
258+
sequence := ReadFASTA("data/base.fasta") // get example data
259+
fasta := BuildFASTA(sequence) // build a fasta byte array
260+
firstLine := string(bytes.Split(fasta, []byte("\n"))[0])
261+
262+
fmt.Println(firstLine)
263+
// Output: >gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]
264+
}
265+
266+
func ExampleWriteFASTA() {
267+
sequence := ReadFASTA("data/base.fasta") // get example data
268+
WriteFASTA(sequence, "data/test.fasta") // write it out again
269+
testSequence := ReadFASTA("data/test.fasta") // read it in again
270+
271+
os.Remove("data/test.fasta") // getting rid of test file
272+
273+
fmt.Println(testSequence.Features[0].Description)
274+
// Output: gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]
275+
}
276+
240277
func TestFASTAIO(t *testing.T) {
241278
inputFilename := "data/base.fasta"
242279
testOutputFilename := "data/test.fasta"

0 commit comments

Comments
 (0)