11 "github.com/arvados/lightning/hgvs"
14 type diffFasta struct{}
16 func (cmd *diffFasta) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
20 fmt.Fprintf(stderr, "%s\n", err)
23 flags := flag.NewFlagSet("", flag.ContinueOnError)
24 flags.SetOutput(stderr)
25 offset := flags.Int("offset", 0, "coordinate offset")
26 sequence := flags.String("sequence", "chr1", "sequence label")
27 timeout := flags.Duration("timeout", 0, "timeout (examples: \"1s\", \"1ms\")")
28 err = flags.Parse(args)
29 if err == flag.ErrHelp {
32 } else if err != nil {
35 if len(flags.Args()) != 2 {
36 err = fmt.Errorf("usage: %s [options] a.fasta b.fasta", prog)
41 errs := make(chan error, 2)
42 for idx, fnm := range flags.Args() {
45 f, err := os.Open(fnm)
51 scanner := bufio.NewScanner(f)
52 scanner.Buffer(nil, 64*1024*1024)
54 buf := scanner.Bytes()
55 if len(buf) > 0 && buf[0] != '>' {
56 fasta[idx] = append(fasta[idx], bytes.ToUpper(buf)...)
62 for range flags.Args() {
63 if err = <-errs; err != nil {
68 variants, timedOut := hgvs.Diff(string(fasta[0]), string(fasta[1]), *timeout)
70 for i := range variants {
71 variants[i].Position += *offset
74 for _, v := range variants {
75 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)