1 // Copyright (C) The Lightning Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "github.com/arvados/lightning/hgvs"
18 type diffFasta struct{}
20 func (cmd *diffFasta) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
24 fmt.Fprintf(stderr, "%s\n", err)
27 flags := flag.NewFlagSet("", flag.ContinueOnError)
28 flags.SetOutput(stderr)
29 offset := flags.Int("offset", 0, "coordinate offset")
30 sequence := flags.String("sequence", "chr1", "sequence label")
31 timeout := flags.Duration("timeout", 0, "timeout (examples: \"1s\", \"1ms\")")
32 err = flags.Parse(args)
33 if err == flag.ErrHelp {
36 } else if err != nil {
39 if len(flags.Args()) != 2 {
40 err = fmt.Errorf("usage: %s [options] a.fasta b.fasta", prog)
45 errs := make(chan error, 2)
46 for idx, fnm := range flags.Args() {
49 f, err := os.Open(fnm)
55 scanner := bufio.NewScanner(f)
56 scanner.Buffer(nil, 64*1024*1024)
58 buf := scanner.Bytes()
59 if len(buf) > 0 && buf[0] != '>' {
60 fasta[idx] = append(fasta[idx], bytes.ToUpper(buf)...)
66 for range flags.Args() {
67 if err = <-errs; err != nil {
72 variants, timedOut := hgvs.Diff(string(fasta[0]), string(fasta[1]), *timeout)
74 for i := range variants {
75 variants[i].Position += *offset
78 for _, v := range variants {
79 fmt.Fprintf(stdout, "%s:g.%s\t%s\t%d\t%s\t%s\t%v\n", *sequence, v.String(), *sequence, v.Position, v.Ref, v.New, timedOut)