From 67bc453e3db06ce93201176b5145c491633d0a18 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Fri, 30 Oct 2020 16:39:51 -0700 Subject: [PATCH] added FASTA IO example tests. --- io_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/io_test.go b/io_test.go index a5df1537..167f93fd 100644 --- a/io_test.go +++ b/io_test.go @@ -1,6 +1,8 @@ package poly import ( + "bytes" + "fmt" "io/ioutil" "os" "testing" @@ -237,6 +239,41 @@ FASTA related tests begin here. ******************************************************************************/ +// ExampleReadFASTA shows basic usage for ReadFASTA +func ExampleReadFASTA() { + sequence := ReadFASTA("data/base.fasta") + fmt.Println(sequence.Features[0].Description) + // Output: gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus] +} + +func ExampleParseFASTA() { + file, _ := ioutil.ReadFile("data/base.fasta") + sequence := ParseFASTA(string(file)) + + fmt.Println(sequence.Features[0].Description) + // Output: gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus] +} + +func ExampleBuildFASTA() { + sequence := ReadFASTA("data/base.fasta") // get example data + fasta := BuildFASTA(sequence) // build a fasta byte array + firstLine := string(bytes.Split(fasta, []byte("\n"))[0]) + + fmt.Println(firstLine) + // Output: >gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus] +} + +func ExampleWriteFASTA() { + sequence := ReadFASTA("data/base.fasta") // get example data + WriteFASTA(sequence, "data/test.fasta") // write it out again + testSequence := ReadFASTA("data/test.fasta") // read it in again + + os.Remove("data/test.fasta") // getting rid of test file + + fmt.Println(testSequence.Features[0].Description) + // Output: gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus] +} + func TestFASTAIO(t *testing.T) { inputFilename := "data/base.fasta" testOutputFilename := "data/test.fasta"