mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-03-25 21:40:52 +00:00
This commit refactors the k-mer index management tools to use a unified subcommand structure with obik, adds support for per-set metadata and ID management, enhances the k-mer set group builder to support appending to existing groups, and improves command-line option handling with a new global options registration system. Key changes: - Introduce obik command with subcommands (index, ls, summary, cp, mv, rm, super, lowmask) - Add support for per-set metadata and ID management in kmer set groups - Implement ability to append to existing kmer index groups - Refactor option parsing to use a global options registration system - Add new commands for listing, copying, moving, and removing sets - Enhance low-complexity masking with new options and output formats - Improve kmer index summary with Jaccard distance matrix support - Remove deprecated obikindex and obisuperkmer commands - Update build process to use the new subcommand structure
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package obik
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obikmer"
|
|
"github.com/DavidGamba/go-getoptions"
|
|
)
|
|
|
|
func runCp(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("usage: obik cp [--set PATTERN]... [--force] <source_index> <dest_index>")
|
|
}
|
|
|
|
srcDir := args[0]
|
|
destDir := args[1]
|
|
|
|
ksg, err := obikmer.OpenKmerSetGroup(srcDir)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to open source kmer index: %w", err)
|
|
}
|
|
|
|
// Resolve set patterns
|
|
patterns := CLISetPatterns()
|
|
var ids []string
|
|
if len(patterns) > 0 {
|
|
indices, err := ksg.MatchSetIDs(patterns)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(indices) == 0 {
|
|
return fmt.Errorf("no sets match the given patterns")
|
|
}
|
|
ids = make([]string, len(indices))
|
|
for i, idx := range indices {
|
|
ids[i] = ksg.SetIDOf(idx)
|
|
}
|
|
} else {
|
|
// Copy all sets
|
|
ids = ksg.SetsIDs()
|
|
}
|
|
|
|
log.Infof("Copying %d set(s) from %s to %s", len(ids), srcDir, destDir)
|
|
|
|
dest, err := ksg.CopySetsByIDTo(ids, destDir, CLIForce())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Infof("Destination now has %d set(s)", dest.Size())
|
|
return nil
|
|
}
|