Option to treat tiles with no-calls as regular tiles.
[lightning.git] / import.go
index d50843d079fcc608ff882d2b15607d067ab61793..e24b25dfac3ecc26a8aac0346835fb9b527b27f0 100644 (file)
--- a/import.go
+++ b/import.go
@@ -32,6 +32,8 @@ type importer struct {
        projectUUID    string
        runLocal       bool
        skipOOO        bool
+       outputTiles    bool
+       includeNoCalls bool
        encoder        *gob.Encoder
 }
 
@@ -50,8 +52,11 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
        flags.StringVar(&cmd.projectUUID, "project", "", "project `UUID` for output data")
        flags.BoolVar(&cmd.runLocal, "local", false, "run on local host (default: run in an arvados container)")
        flags.BoolVar(&cmd.skipOOO, "skip-ooo", false, "skip out-of-order tags")
+       flags.BoolVar(&cmd.outputTiles, "output-tiles", false, "include tile variant sequences in output file")
+       flags.BoolVar(&cmd.includeNoCalls, "include-no-calls", false, "treat tiles with no-calls as regular tiles")
        priority := flags.Int("priority", 500, "container request priority")
        pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
+       loglevel := flags.String("loglevel", "info", "logging threshold (trace, debug, info, warn, error, fatal, or panic)")
        err = flags.Parse(args)
        if err == flag.ErrHelp {
                err = nil
@@ -72,6 +77,12 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
                }()
        }
 
+       lvl, err := log.ParseLevel(*loglevel)
+       if err != nil {
+               return 2
+       }
+       log.SetLevel(lvl)
+
        if !cmd.runLocal {
                runner := arvadosContainerRunner{
                        Name:        "lightning import",
@@ -101,7 +112,16 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
                        err = errors.New("cannot specify output file in container mode: not implemented")
                        return 1
                }
-               runner.Args = append([]string{"import", "-local=true", fmt.Sprintf("-skip-ooo=%v", cmd.skipOOO), "-tag-library", cmd.tagLibraryFile, "-ref", cmd.refFile, "-o", cmd.outputFile}, inputs...)
+               runner.Args = append([]string{"import",
+                       "-local=true",
+                       "-loglevel=" + *loglevel,
+                       fmt.Sprintf("-skip-ooo=%v", cmd.skipOOO),
+                       fmt.Sprintf("-output-tiles=%v", cmd.outputTiles),
+                       fmt.Sprintf("-include-no-calls=%v", cmd.includeNoCalls),
+                       "-tag-library", cmd.tagLibraryFile,
+                       "-ref", cmd.refFile,
+                       "-o", cmd.outputFile,
+               }, inputs...)
                var output string
                output, err = runner.Run()
                if err != nil {
@@ -116,15 +136,10 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
                return 1
        }
 
-       tilelib, err := cmd.loadTileLibrary()
+       taglib, err := cmd.loadTagLibrary()
        if err != nil {
                return 1
        }
-       go func() {
-               for range time.Tick(10 * time.Minute) {
-                       log.Printf("tilelib.Len() == %d", tilelib.Len())
-               }
-       }()
 
        var output io.WriteCloser
        if cmd.outputFile == "-" {
@@ -139,6 +154,16 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
        bufw := bufio.NewWriter(output)
        cmd.encoder = gob.NewEncoder(bufw)
 
+       tilelib := &tileLibrary{taglib: taglib, includeNoCalls: cmd.includeNoCalls, skipOOO: cmd.skipOOO}
+       if cmd.outputTiles {
+               tilelib.encoder = cmd.encoder
+       }
+       go func() {
+               for range time.Tick(10 * time.Minute) {
+                       log.Printf("tilelib.Len() == %d", tilelib.Len())
+               }
+       }()
+
        err = cmd.tileInputs(tilelib, infiles)
        if err != nil {
                return 1
@@ -171,7 +196,7 @@ func (cmd *importer) tileFasta(tilelib *tileLibrary, infile string) (tileSeq, er
        return tilelib.TileFasta(infile, input)
 }
 
-func (cmd *importer) loadTileLibrary() (*tileLibrary, error) {
+func (cmd *importer) loadTagLibrary() (*tagLibrary, error) {
        log.Printf("tag library %s load starting", cmd.tagLibraryFile)
        f, err := os.Open(cmd.tagLibraryFile)
        if err != nil {
@@ -195,7 +220,7 @@ func (cmd *importer) loadTileLibrary() (*tileLibrary, error) {
                return nil, fmt.Errorf("cannot tile: tag library is empty")
        }
        log.Printf("tag library %s load done", cmd.tagLibraryFile)
-       return &tileLibrary{taglib: &taglib, skipOOO: cmd.skipOOO}, nil
+       return &taglib, nil
 }
 
 func listInputFiles(paths []string) (files []string, err error) {
@@ -257,7 +282,9 @@ func (cmd *importer) tileInputs(tilelib *tileLibrary, infiles []string) error {
                                log.Printf("%s starting", infile)
                                defer log.Printf("%s done", infile)
                                tseqs, err := cmd.tileFasta(tilelib, infile)
-                               variants[0] = tseqs.Variants()
+                               var kept, dropped int
+                               variants[0], kept, dropped = tseqs.Variants()
+                               log.Printf("%s found %d unique tags plus %d repeats", infile, kept, dropped)
                                return err
                        }
                        infile2 := regexp.MustCompile(`\.1\.fasta(\.gz)?$`).ReplaceAllString(infile, `.2.fasta$1`)
@@ -266,7 +293,9 @@ func (cmd *importer) tileInputs(tilelib *tileLibrary, infiles []string) error {
                                log.Printf("%s starting", infile2)
                                defer log.Printf("%s done", infile2)
                                tseqs, err := cmd.tileFasta(tilelib, infile2)
-                               variants[1] = tseqs.Variants()
+                               var kept, dropped int
+                               variants[1], kept, dropped = tseqs.Variants()
+                               log.Printf("%s found %d unique tags plus %d repeats", infile, kept, dropped)
                                return err
                        }
                } else {
@@ -277,7 +306,9 @@ func (cmd *importer) tileInputs(tilelib *tileLibrary, infiles []string) error {
                                        log.Printf("%s phase %d starting", infile, phase+1)
                                        defer log.Printf("%s phase %d done", infile, phase+1)
                                        tseqs, err := cmd.tileGVCF(tilelib, infile, phase)
-                                       variants[phase] = tseqs.Variants()
+                                       var kept, dropped int
+                                       variants[phase], kept, dropped = tseqs.Variants()
+                                       log.Printf("%s phase %d found %d unique tags plus %d repeats", infile, phase+1, kept, dropped)
                                        return err
                                }
                        }