/
keelhaul.go
56 lines (49 loc) · 1.23 KB
/
keelhaul.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright ©2016 Dan Kortschak. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// keelhaul drops fasta sequences from stdin containing IDs in
// the exclude parameter file.
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"github.com/biogo/biogo/alphabet"
"github.com/biogo/biogo/io/seqio"
"github.com/biogo/biogo/io/seqio/fasta"
"github.com/biogo/biogo/seq/linear"
)
var exclude = flag.String("exclude", "", "specify file containing excluded reads")
func main() {
flag.Parse()
if *exclude == "" {
flag.Usage()
os.Exit(1)
}
nameSet := make(map[string]struct{})
f, err := os.Open(*exclude)
if err != nil {
log.Fatalf("failed to open exclude file %q: %v", *exclude, err)
}
ls := bufio.NewScanner(f)
for ls.Scan() {
nameSet[ls.Text()] = struct{}{}
}
err = ls.Err()
if err != nil {
log.Fatalf("failed to read exclude file: %v", err)
}
sc := seqio.NewScanner(fasta.NewReader(os.Stdin, linear.NewSeq("", nil, alphabet.DNA)))
for sc.Next() {
s := sc.Seq().(*linear.Seq)
if _, ok := nameSet[s.ID]; ok {
continue
}
fmt.Printf("%60a\n", s)
}
if err := sc.Error(); err != nil {
log.Fatalf("error during gff read: %v", err)
}
}