-
Notifications
You must be signed in to change notification settings - Fork 3
/
fastq_count.go
executable file
·81 lines (68 loc) · 1.5 KB
/
fastq_count.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"flag"
"fmt"
"log"
"os"
"sync"
"time"
"github.com/d2jvkpn/fastq_count/pkg/cmd"
)
const USAGE = `
Usage: fastq_count [-phred value] [-out tsv] <input1.fastq input2.fastq.gz>
output (tsv) header: Total reads Total bases N bases Q20 Q30 GC
note:
1. When input is -, read standard input;
2. "pigz -dc *.fastq.gz | fastq_count -" is recommended for gzipped file(s).
`
const LISENSE = `
author: d2jvkpn
version: 1.2.0
release: 2021-07-04
project: https://github.com/d2jvkpn/fastq_count
lisense: GPLv3 (https://www.gnu.org/licenses/gpl-3.0.en.html)
`
func init() {
cmd.SetLogRFC3339()
}
func main() {
var (
jsonFormat bool
output string
inputs []string
err error
start time.Time
ct *Counter
)
ct = NewCounter()
flag.StringVar(&output, "output", "", "save result to file, default: stdout")
flag.IntVar(&ct.Phred, "phred", 33, "set phred value")
flag.BoolVar(&jsonFormat, "json_format", false, "output json format")
flag.Usage = func() {
fmt.Println(USAGE)
flag.PrintDefaults()
fmt.Println(LISENSE)
}
flag.Parse()
inputs = flag.Args()
if len(os.Args) == 1 {
flag.Usage()
os.Exit(2)
}
/// run
start = time.Now()
wg := new(sync.WaitGroup)
go func() {
for i := range inputs {
wg.Add(1)
input := inputs[i]
go ReadBlocks(input, ct, wg)
}
wg.Wait()
}()
ct.Counting()
if err = ct.Output(output, jsonFormat); err != nil {
log.Fatalln(err)
}
log.Printf("fastq count elapsed: %v\n", time.Since(start))
}