-package main
+// Copyright (C) The Lightning Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package lightning
import (
"bufio"
"net/http"
_ "net/http/pprof"
"os"
+ "regexp"
"strings"
"git.arvados.org/arvados.git/sdk/go/arvados"
MaxVariants int
MinCoverage float64
MaxTag int
+ MatchGenome string
}
func (f *filter) Flags(flags *flag.FlagSet) {
flags.IntVar(&f.MaxVariants, "max-variants", -1, "drop tiles with more than `N` variants")
flags.Float64Var(&f.MinCoverage, "min-coverage", 0, "drop tiles with coverage less than `P` across all haplotypes (0 < P ≤ 1)")
flags.IntVar(&f.MaxTag, "max-tag", -1, "drop tiles with tag ID > `N`")
+ flags.StringVar(&f.MatchGenome, "match-genome", "", "keep genomes whose names contain `regexp`, drop the rest")
+}
+
+func (f *filter) Args() []string {
+ return []string{
+ fmt.Sprintf("-max-variants=%d", f.MaxVariants),
+ fmt.Sprintf("-min-coverage=%f", f.MinCoverage),
+ fmt.Sprintf("-max-tag=%d", f.MaxTag),
+ fmt.Sprintf("-match-genome=%s", f.MatchGenome),
+ }
}
func (f *filter) Apply(tilelib *tileLibrary) {
// f.MinCoverage.
mincov := int(2*f.MinCoverage*float64(len(tilelib.compactGenomes)) + 1)
TAG:
- for tag := 0; tag < len(tilelib.variant) && tag < f.MaxTag; tag++ {
+ for tag := 0; tag < len(tilelib.variant) && (tag < f.MaxTag || f.MaxTag < 0); tag++ {
tagcov := 0
for _, cg := range tilelib.compactGenomes {
+ if len(cg) < tag*2+2 {
+ continue
+ }
if cg[tag*2] > 0 {
tagcov++
}
}
}
for _, cg := range tilelib.compactGenomes {
- cg[tag*2] = 0
- cg[tag*2+1] = 0
+ if len(cg) > tag*2 {
+ cg[tag*2] = 0
+ cg[tag*2+1] = 0
+ }
}
}
}
}
}
+
+ re, err := regexp.Compile(f.MatchGenome)
+ if err != nil {
+ log.Errorf("invalid regexp %q does not match anything, dropping all genomes", f.MatchGenome)
+ }
+ for name := range tilelib.compactGenomes {
+ if !re.MatchString(name) {
+ delete(tilelib.compactGenomes, name)
+ }
+ }
}
type filtercmd struct {