MCPcopy Create free account
hub / github.com/Koeng101/dnadesign / Example_basic

Function Example_basic

lib/bio/fasta/example_test.go:16–36  ·  view source on GitHub ↗

This example shows how to open a file with the fasta parser. The sequences within that file can then be analyzed further with different software.

()

Source from the content-addressed store, hash-verified

14// This example shows how to open a file with the fasta parser. The sequences
15// within that file can then be analyzed further with different software.
16func Example_basic() {
17 fastaString := ">testing\nATGC\n"
18 file := strings.NewReader(fastaString) // this "file" can be replaced with os.Open
19 parser := fasta.NewParser(file, 32*1024) // Initialize a parser for this file
20 var records []fasta.Record
21 for {
22 record, err := parser.Next()
23 if err != nil {
24 if errors.Is(err, io.EOF) {
25 err = nil // EOF not treated as parsing error.
26 }
27 if err != nil {
28 fmt.Printf("Got error: %s\n", err) // check if there was a parse error
29 }
30 break
31 }
32 records = append(records, record)
33 }
34 fmt.Println(records[0].Sequence)
35 // Output: ATGC
36}
37
38// ExampleWrite shows basic usage of the writer.
39func ExampleRecord_WriteTo() {

Callers

nothing calls this directly

Calls 1

NextMethod · 0.95

Tested by

no test coverage detected