|
1 | 1 | package poly |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
| 5 | + "fmt" |
4 | 6 | "io/ioutil" |
5 | 7 | "os" |
6 | 8 | "testing" |
@@ -237,6 +239,41 @@ FASTA related tests begin here. |
237 | 239 |
|
238 | 240 | ******************************************************************************/ |
239 | 241 |
|
| 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 | + |
240 | 277 | func TestFASTAIO(t *testing.T) { |
241 | 278 | inputFilename := "data/base.fasta" |
242 | 279 | testOutputFilename := "data/test.fasta" |
|
0 commit comments