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 {
38 } else if len(flags.Args()) != 2 {
39 err = fmt.Errorf("usage: %s [options] a.fasta b.fasta", prog)
44 errs := make(chan error, 2)
45 for idx, fnm := range flags.Args() {
48 f, err := os.Open(fnm)
54 scanner := bufio.NewScanner(f)
55 scanner.Buffer(nil, 64*1024*1024)
57 buf := scanner.Bytes()
58 if len(buf) > 0 && buf[0] != '>' {
59 fasta[idx] = append(fasta[idx], bytes.ToUpper(buf)...)
65 for range flags.Args() {
66 if err = <-errs; err != nil {
71 variants, timedOut := hgvs.Diff(string(fasta[0]), string(fasta[1]), *timeout)
73 for i := range variants {
74 variants[i].Position += *offset
77 for _, v := range variants {
78 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)