// writeFlankSeqs writes fasta files containing the sequence of unmapped flanks // identified in the primary hits provided. cutoff specifies the minimum sequence // length to consider. left and right specify the filenames for the left and right // flank fasta sequence files. func writeFlankSeqs(reads string, hits hitSet, cutoff int, left, right string) error { f, err := os.Open(reads) if err != nil { return err } defer f.Close() lf, err := os.Create(left) if err != nil { return err } rf, err := os.Create(right) if err != nil { return err } r := fasta.NewReader(f, linear.NewSeq("", nil, alphabet.DNA)) sc := seqio.NewScanner(r) for sc.Next() { seq := sc.Seq().(*linear.Seq) h, ok := hits[seq.Name()] if !ok { continue } all := seq.Seq if h.qStart >= cutoff { seq.Seq = all[:h.qStart] _, err := fmt.Fprintf(lf, "%60a\n", seq) if err != nil { return err } } if h.qLen-h.qEnd >= cutoff { seq.Seq = all[h.qEnd:] _, err := fmt.Fprintf(rf, "%60a\n", seq) if err != nil { return err } } } err = sc.Error() if err != nil { return err } err = lf.Close() if err != nil { return err } return rf.Close() }
func main() { flag.Parse() if *in == "" || *typ < 0 || 2 < *typ { flag.Usage() os.Exit(1) } cfn := []func(s seq.Sequence, start, end int) (float64, error){ 0: complexity.WF, 1: complexity.Entropic, 2: complexity.Z, }[*typ] f, err := os.Open(*in) if err != nil { log.Fatalf("failed to open %q: %v", *in, err) } defer f.Close() sc := seqio.NewScanner(fasta.NewReader(f, linear.NewSeq("", nil, alphabet.DNAgapped))) for sc.Next() { seq := sc.Seq().(*linear.Seq) // err is always nil for a linear.Seq Start() and End(). c, _ := cfn(seq, seq.Start(), seq.End()) if *dist { fmt.Printf("%s\t%v\t%d\n", seq.Name(), c, seq.Len()) continue } if c >= *thresh { fmt.Printf("%60a\n", seq) } } if err := sc.Error(); err != nil { log.Fatalf("error during fasta read: %v", err) } }