-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e450844
commit 76128fc
Showing
3 changed files
with
54 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters