| 443 | } |
| 444 | |
| 445 | func ExampleFilterData() { |
| 446 | // Create channels for input and output |
| 447 | inputChan := make(chan sam.Alignment, 2) // Buffered channel to prevent blocking |
| 448 | outputChan := make(chan sam.Alignment) |
| 449 | |
| 450 | var results []sam.Alignment |
| 451 | ctx := context.Background() |
| 452 | errorGroup, ctx := errgroup.WithContext(ctx) |
| 453 | errorGroup.Go(func() error { |
| 454 | return bio.RunWorkers(ctx, 1, outputChan, func(ctx context.Context) error { |
| 455 | return bio.FilterData(ctx, inputChan, outputChan, func(data sam.Alignment) bool { return (data.FLAG & 0x900) == 0 }) |
| 456 | }) |
| 457 | }) |
| 458 | |
| 459 | // Send some example Alignments to the input channel |
| 460 | inputChan <- sam.Alignment{FLAG: 0x900} // Not primary, should not be outputted |
| 461 | inputChan <- sam.Alignment{SEQ: "FAKE", FLAG: 0x000} // Primary, should be outputted |
| 462 | close(inputChan) // Close the input channel to signal no more data |
| 463 | |
| 464 | // Collect results from the output channel |
| 465 | for alignment := range outputChan { |
| 466 | results = append(results, alignment) |
| 467 | } |
| 468 | |
| 469 | fmt.Println(results) |
| 470 | // Output: [{ 0 0 0 0 0 FAKE []}] |
| 471 | } |
| 472 | |
| 473 | func Example_runWorkflow() { |
| 474 | // Workflows are a way of running bioinformatics programs replacing stdin/stdout |