Skip to content

Commit

Permalink
Addded --nb-samples option to sample seqs
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Sep 3, 2019
1 parent e1a0be8 commit bfa8636
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions cmd/sampleseq.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

var sampleseqOutput string
var sampleseqNb int
var sampleseqSize int
var sampleseqNbSamples int

// sampleCmd represents the sample command
var sampleseqCmd = &cobra.Command{
Expand All @@ -21,7 +22,15 @@ 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
As output, writes an alignment containing a sample of the sequences.
All alignments are written on the output in the following order:
For each input alignment
For each sample
write(sampled alignment)
It is advised to manipulate phylip alignments, in order to be able to
divide the output file with 'goalign divide' for example.
`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -40,24 +49,28 @@ As output, writes an alignment containing a sample of the sequences
defer closeWriteFile(f, sampleseqOutput)

for al := range aligns.Achan {
if sample, err = al.Sample(sampleseqNb); err != nil {
io.LogError(err)
return
} else {
writeAlign(sample, f)
for i := 0; i < sampleseqNbSamples; i++ {
if sample, err = al.Sample(sampleseqSize); err != nil {
io.LogError(err)
return
} else {
writeAlign(sample, f)
}
}
}

if aligns.Err != nil {
err = aligns.Err
io.LogError(err)
}

return
},
}

func init() {
sampleCmd.AddCommand(sampleseqCmd)
sampleseqCmd.PersistentFlags().IntVarP(&sampleseqNb, "nb-seq", "n", 1, "Number of sequences to sample from the alignment")
sampleseqCmd.PersistentFlags().IntVarP(&sampleseqSize, "nb-seq", "n", 1, "Number of sequences to sample from the alignment")
sampleseqCmd.PersistentFlags().IntVarP(&sampleseqNbSamples, "nb-samples", "s", 1, "Number of samples to generate")
sampleseqCmd.PersistentFlags().StringVarP(&sampleseqOutput, "output", "o", "stdout", "Sampled alignment output file")
}

0 comments on commit bfa8636

Please sign in to comment.