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.
()
| 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. |
| 16 | func 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. |
| 39 | func ExampleRecord_WriteTo() { |