Skip to content

Commit

Permalink
Changed sample commands
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Apr 14, 2017
1 parent e450844 commit 76128fc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
34 changes: 6 additions & 28 deletions cmd/sample.go
Original file line number Diff line number Diff line change
@@ -1,46 +1,24 @@
package cmd

import (
"github.com/fredericlemoine/goalign/io"
"github.com/spf13/cobra"
"math/rand"
"time"
)

var sampleSeed int64
var sampleOutput string
var sampleNb int

// sampleCmd represents the sample command
var sampleCmd = &cobra.Command{
Use: "sample",
Short: "Samples a subset of sequences from the input alignment",
Long: `Samples a subset of sequences from the input alignment.
May take a Fasta or Phylip alignment in input.
Short: "Samples sequences or sites from an input alignment",
Long: `Samples sequences or sites from an input alignment. For example:
If the input alignment contains several alignments, will process all of them
Randomly sampling 10 sequences from the alignment:
goalign sample seqs -i align.fa -n 10 > sample.fa
As output, writes an alignment containing a sample of the sequences
Randomly sampling 10 subsequences with length 20 from the input alignment:
goalign sample seqs -n 10 -i align.fa -l 20 -o subalign_
`,
Run: func(cmd *cobra.Command, args []string) {
rand.Seed(sampleSeed)
f := openWriteFile(sampleOutput)
for al := range rootaligns {
if sample, err := al.Sample(sampleNb); err != nil {
io.ExitWithMessage(err)
} else {
writeAlign(sample, f)
}
}
f.Close()
},
}

func init() {
RootCmd.AddCommand(sampleCmd)
sampleCmd.PersistentFlags().IntVarP(&sampleNb, "nb-seq", "n", 1, "Number of sequences to sample from the alignment")
sampleCmd.PersistentFlags().Int64VarP(&sampleSeed, "seed", "s", time.Now().UTC().UnixNano(), "Initial Random Seed")
sampleCmd.PersistentFlags().StringVarP(&sampleOutput, "output", "o", "stdout", "Sampled alignment output file")
}
46 changes: 46 additions & 0 deletions cmd/sampleseq.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"github.com/fredericlemoine/goalign/io"
"github.com/spf13/cobra"
"math/rand"
"time"
)

var sampleseqSeed int64
var sampleseqOutput string
var sampleseqNb int

// sampleCmd represents the sample command
var sampleseqCmd = &cobra.Command{
Use: "seqs",
Short: "Samples a subset of sequences from the input alignment",
Long: `Samples a subset of sequences from the input alignment.
May take a Fasta or Phylip alignment in input.
If the input alignment contains several alignments, will process all of them
As output, writes an alignment containing a sample of the sequences
`,
Run: func(cmd *cobra.Command, args []string) {
rand.Seed(sampleseqSeed)
f := openWriteFile(sampleseqOutput)
for al := range rootaligns {
if sample, err := al.Sample(sampleseqNb); err != nil {
io.ExitWithMessage(err)
} else {
writeAlign(sample, f)
}
}
f.Close()
},
}

func init() {
sampleCmd.AddCommand(sampleseqCmd)
sampleseqCmd.PersistentFlags().IntVarP(&sampleseqNb, "nb-seq", "n", 1, "Number of sequences to sample from the alignment")
sampleseqCmd.PersistentFlags().Int64VarP(&sampleseqSeed, "seed", "s", time.Now().UTC().UnixNano(), "Initial Random Seed")
sampleseqCmd.PersistentFlags().StringVarP(&sampleseqOutput, "output", "o", "stdout", "Sampled alignment output file")
}
4 changes: 2 additions & 2 deletions cmd/samplesites.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var sitenb int

// samplesitesCmd represents the samplesites command
var samplesitesCmd = &cobra.Command{
Use: "samplesites",
Use: "sites",
Short: "Take a random subalignment",
Long: `Take a random subalignment.
Expand Down Expand Up @@ -48,7 +48,7 @@ and with a given length.
}

func init() {
RootCmd.AddCommand(samplesitesCmd)
sampleCmd.AddCommand(samplesitesCmd)
samplesitesCmd.PersistentFlags().Int64VarP(&siteseed, "seed", "s", time.Now().UTC().UnixNano(), "Initial Random Seed")
samplesitesCmd.PersistentFlags().StringVarP(&siteout, "output", "o", "stdout", "Alignment output file")
samplesitesCmd.PersistentFlags().IntVarP(&sitelength, "length", "l", 10, "Length of the random sub alignment")
Expand Down

0 comments on commit 76128fc

Please sign in to comment.