-
Notifications
You must be signed in to change notification settings - Fork 0
/
names.go
58 lines (48 loc) · 1.25 KB
/
names.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
57
58
package main
import (
"fmt"
"io"
"github.com/bjeight/fastats/fasta"
)
// names() is fastats names in the cli. It writes the ids / descriptions of the records
func names(w io.Writer, filepaths []string, pattern string, file bool, counts bool, description bool, lenFormat string) error {
var err error
if description {
_, err = w.Write([]byte("file\tdescription\n"))
if err != nil {
return err
}
} else {
_, err = w.Write([]byte("file\tid\n"))
if err != nil {
return err
}
}
err = collectCommandLine(w, namesRecords, filepaths, pattern, file, counts, description, lenFormat)
if err != nil {
return err
}
return nil
}
func namesRecords(r *fasta.Reader, args arguments, w io.Writer) error {
// get the file name in case we need to print it to stdout
filename := filenameFromFullPath(args.filepath)
// iterate over every record in the fasta file
for {
record, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
return (err)
}
// if the statistic is to be calculated per file, add this record's length
// to the total, else just write it.
s := fmt.Sprintf("%s\t%s\n", filename, return_record_name(record, args.description))
_, err = w.Write([]byte(s))
if err != nil {
return err
}
}
return nil
}