retainNoCalls: true,
retainTileSequences: true,
}
- err = tilelib.LoadGob(context.Background(), input, nil)
+ err = tilelib.LoadGob(context.Background(), input, strings.HasSuffix(*inputFilename, ".gz"), nil)
if err != nil {
return 1
}
tilelib := tileLibrary{
retainNoCalls: true,
}
- err = tilelib.LoadGob(context.Background(), input, func(cg CompactGenome) {
+ err = tilelib.LoadGob(context.Background(), input, strings.HasSuffix(*inputFilename, ".gz"), func(cg CompactGenome) {
if *pick != "" && *pick != cg.Name {
return
}
bedbufw = bufio.NewWriter(bedout)
}
- err = cmd.export(bufw, bedout, input, tilelib.taglib.keylen, refseq, cgs)
+ err = cmd.export(bufw, bedout, input, strings.HasSuffix(*inputFilename, ".gz"), tilelib.taglib.keylen, refseq, cgs)
if err != nil {
return 1
}
return 0
}
-func (cmd *exporter) export(out, bedout io.Writer, librdr io.Reader, taglen int, refseq map[string][]tileLibRef, cgs []CompactGenome) error {
+func (cmd *exporter) export(out, bedout io.Writer, librdr io.Reader, gz bool, taglen int, refseq map[string][]tileLibRef, cgs []CompactGenome) error {
need := map[tileLibRef]bool{}
var seqnames []string
for seqname, librefs := range refseq {
log.Infof("export: loading %d tile variants", len(need))
tileVariant := map[tileLibRef]TileVariant{}
- err := DecodeLibrary(librdr, func(ent *LibraryEntry) error {
+ err := DecodeLibrary(librdr, gz, func(ent *LibraryEntry) error {
for _, tv := range ent.TileVariants {
libref := tileLibRef{Tag: tv.Tag, Variant: tv.Variant}
if need[libref] {
_ "net/http/pprof"
"os"
"sort"
+ "strings"
"git.arvados.org/arvados.git/sdk/go/arvados"
"github.com/kshedden/gonpy"
retainTileSequences: true,
compactGenomes: map[string][]tileVariantID{},
}
- err = tilelib.LoadGob(context.Background(), input, nil)
+ err = tilelib.LoadGob(context.Background(), input, strings.HasSuffix(*inputFilename, ".gz"), nil)
if err != nil {
return 1
}
"net/http"
_ "net/http/pprof"
"os"
+ "strings"
"git.arvados.org/arvados.git/sdk/go/arvados"
log "github.com/sirupsen/logrus"
defer infile.Close()
}
log.Print("reading")
- cgs, err := ReadCompactGenomes(infile)
+ cgs, err := ReadCompactGenomes(infile, strings.HasSuffix(*inputFilename, ".gz"))
if err != nil {
return 1
}
import (
"bufio"
+ "compress/gzip"
"encoding/gob"
"io"
+ "io/ioutil"
_ "net/http/pprof"
"golang.org/x/crypto/blake2b"
TileVariants []TileVariant
}
-func ReadCompactGenomes(rdr io.Reader) ([]CompactGenome, error) {
+func ReadCompactGenomes(rdr io.Reader, gz bool) ([]CompactGenome, error) {
var ret []CompactGenome
- err := DecodeLibrary(rdr, func(ent *LibraryEntry) error {
+ err := DecodeLibrary(rdr, gz, func(ent *LibraryEntry) error {
ret = append(ret, ent.CompactGenomes...)
return nil
})
return ret, err
}
-func DecodeLibrary(rdr io.Reader, cb func(*LibraryEntry) error) error {
- dec := gob.NewDecoder(bufio.NewReaderSize(rdr, 1<<26))
+func DecodeLibrary(rdr io.Reader, gz bool, cb func(*LibraryEntry) error) error {
+ zrdr := ioutil.NopCloser(rdr)
var err error
+ if gz {
+ zrdr, err = gzip.NewReader(bufio.NewReaderSize(rdr, 1<<26))
+ if err != nil {
+ return err
+ }
+ }
+ dec := gob.NewDecoder(zrdr)
for err == nil {
var ent LibraryEntry
err = dec.Decode(&ent)
err = cb(&ent)
}
}
- if err == io.EOF {
- return nil
- } else {
+ if err != io.EOF {
return err
}
+ return zrdr.Close()
}
}
}
if cmd.outputFile == "-" {
- cmd.outputFile = "/mnt/output/library.gob"
+ cmd.outputFile = "/mnt/output/library.gob.gz"
} else {
// Not yet implemented, but this should write
// the collection to an existing collection,
if err != nil {
return 1
}
- fmt.Fprintln(stdout, output+"/library.gob")
+ fmt.Fprintln(stdout, output+"/library.gob.gz")
return 0
}
return 1
}
- var output io.WriteCloser
+ var outw, outf io.WriteCloser
if cmd.outputFile == "-" {
- output = nopCloser{stdout}
+ outw = nopCloser{stdout}
} else {
- output, err = os.OpenFile(cmd.outputFile, os.O_CREATE|os.O_WRONLY, 0777)
+ outf, err = os.OpenFile(cmd.outputFile, os.O_CREATE|os.O_WRONLY, 0777)
if err != nil {
return 1
}
- defer output.Close()
+ defer outf.Close()
+ if strings.HasSuffix(cmd.outputFile, ".gz") {
+ outw = gzip.NewWriter(outf)
+ } else {
+ outw = outf
+ }
}
- bufw := bufio.NewWriter(output)
+ bufw := bufio.NewWriter(outw)
cmd.encoder = gob.NewEncoder(bufw)
tilelib := &tileLibrary{taglib: taglib, retainNoCalls: cmd.saveIncompleteTiles, skipOOO: cmd.skipOOO}
if err != nil {
return 1
}
- err = output.Close()
+ err = outw.Close()
if err != nil {
return 1
}
+ if outf != nil && outf != outw {
+ err = outf.Close()
+ if err != nil {
+ return 1
+ }
+ }
return 0
}
import (
"bufio"
+ "compress/gzip"
"context"
"encoding/gob"
"errors"
"net/http"
_ "net/http/pprof"
"os"
+ "strings"
"sync"
"git.arvados.org/arvados.git/sdk/go/arvados"
}
}
runner.Args = append([]string{"merge", "-local=true",
- "-o", "/mnt/output/library.gob",
+ "-o", "/mnt/output/library.gob.gz",
}, cmd.inputs...)
var output string
output, err = runner.Run()
if err != nil {
return 1
}
- fmt.Fprintln(stdout, output+"/library.gob")
+ fmt.Fprintln(stdout, output+"/library.gob.gz")
return 0
}
+ var outf, outw io.WriteCloser
if *outputFilename == "-" {
- cmd.output = nopCloser{stdout}
+ outw = nopCloser{stdout}
} else {
- cmd.output, err = os.OpenFile(*outputFilename, os.O_CREATE|os.O_WRONLY, 0777)
+ outf, err = os.OpenFile(*outputFilename, os.O_CREATE|os.O_WRONLY, 0777)
if err != nil {
return 1
}
- defer cmd.output.Close()
+ defer outf.Close()
+ if strings.HasSuffix(*outputFilename, ".gz") {
+ outw = gzip.NewWriter(outf)
+ } else {
+ outw = outf
+ }
}
-
+ cmd.output = outw
err = cmd.doMerge()
if err != nil {
return 1
}
- err = cmd.output.Close()
+ err = outw.Close()
if err != nil {
return 1
}
+ if outf != nil && outf != outw {
+ err = outf.Close()
+ if err != nil {
+ return 1
+ }
+ }
return 0
}
go func(input string) {
defer wg.Done()
log.Printf("%s: reading", input)
- err := cmd.tilelib.LoadGob(ctx, infile, nil)
+ err := cmd.tilelib.LoadGob(ctx, infile, strings.HasSuffix(input, ".gz"), nil)
if err != nil {
cmd.setError(fmt.Errorf("%s: load failed: %w", input, err))
cancel()
return
}
- err = infile.Close()
- if err != nil {
- cmd.setError(fmt.Errorf("%s: error closing input file: %w", input, err))
- cancel()
- return
- }
log.Printf("%s: done", input)
}(input)
}
"net/http"
_ "net/http/pprof"
"os"
+ "strings"
"git.arvados.org/arvados.git/sdk/go/arvados"
"github.com/james-bowman/nlp"
retainNoCalls: true,
compactGenomes: map[string][]tileVariantID{},
}
- err = tilelib.LoadGob(context.Background(), input, nil)
+ err = tilelib.LoadGob(context.Background(), input, strings.HasSuffix(*inputFilename, ".gz"), nil)
if err != nil {
return 1
}
import (
"bufio"
- "encoding/gob"
"encoding/json"
"errors"
"flag"
"net/http"
_ "net/http/pprof"
"os"
+ "strings"
"git.arvados.org/arvados.git/sdk/go/arvados"
log "github.com/sirupsen/logrus"
}
bufw := bufio.NewWriter(output)
- err = cmd.doStats(input, bufw)
+ err = cmd.doStats(input, strings.HasSuffix(*inputFilename, ".gz"), bufw)
if err != nil {
return 1
}
return 0
}
-func (cmd *statscmd) doStats(input io.Reader, output io.Writer) error {
+func (cmd *statscmd) doStats(input io.Reader, gz bool, output io.Writer) error {
var ret struct {
Genomes int
CalledBases []int64
var tagSet [][]byte
var tagPlacements []int
tileVariantCalls := map[tileLibRef]int{}
- dec := gob.NewDecoder(bufio.NewReaderSize(input, 1<<26))
- for {
- var ent LibraryEntry
- err := dec.Decode(&ent)
- if err == io.EOF {
- break
- } else if err != nil {
- return fmt.Errorf("gob decode: %w", err)
- }
+ err := DecodeLibrary(input, gz, func(ent *LibraryEntry) error {
ret.Genomes += len(ent.CompactGenomes)
ret.TileVariants += len(ent.TileVariants)
if len(ent.TagSet) > 0 {
}
ret.CalledBases = append(ret.CalledBases, calledBases)
}
+ return nil
+ })
+ if err != nil {
+ return err
}
for id, p := range tagPlacements {
for len(ret.TagsPlacedNTimes) <= p {
// match.
//
// If onLoadGenome is non-nil, call it on each CompactGenome entry.
-func (tilelib *tileLibrary) LoadGob(ctx context.Context, rdr io.Reader, onLoadGenome func(CompactGenome)) error {
+func (tilelib *tileLibrary) LoadGob(ctx context.Context, rdr io.Reader, gz bool, onLoadGenome func(CompactGenome)) error {
cgs := []CompactGenome{}
cseqs := []CompactSequence{}
variantmap := map[tileLibRef]tileVariantID{}
- err := DecodeLibrary(rdr, func(ent *LibraryEntry) error {
+ err := DecodeLibrary(rdr, gz, func(ent *LibraryEntry) error {
if ctx.Err() != nil {
return ctx.Err()
}