Skip to content

Commit

Permalink
Rarefy can generate multiple replicates
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Jul 6, 2017
1 parent 858208f commit 4c29185
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/rarefy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var rarefyNb int
var rarefySeed int64
var rarefyOutput string
var rarefyCounts string
var rarefyReplicates int

// rarefyCmd represents the rarefy command
var rarefyCmd = &cobra.Command{
Expand All @@ -37,6 +38,7 @@ Parameters are:
from the number of sequences in the output alignment)
* c: counts associated to each sequence (if the count of a sequence is missing, it
is considered as 0). Sum of counts of all sequences must be > n.
* r: the number of replicates to generate (if r>1, output format will be phylip anyway)
Output: An alignment (phylip or fasta).
`,
Expand All @@ -45,10 +47,15 @@ Output: An alignment (phylip or fasta).
counts := parseCountFile(rarefyCounts)
f := openWriteFile(rarefyOutput)
for al := range rootaligns {
if sample, err := al.Rarefy(rarefyNb, counts); err != nil {
io.ExitWithMessage(err)
} else {
writeAlign(sample, f)
if rarefyReplicates > 1 {
rootphylip = true
}
for i := 0; i < rarefyReplicates; i++ {
if sample, err := al.Rarefy(rarefyNb, counts); err != nil {
io.ExitWithMessage(err)
} else {
writeAlign(sample, f)
}
}
}
f.Close()
Expand All @@ -61,6 +68,7 @@ func init() {
rarefyCmd.PersistentFlags().Int64VarP(&rarefySeed, "seed", "s", time.Now().UTC().UnixNano(), "Initial Random Seed")
rarefyCmd.PersistentFlags().StringVarP(&rarefyOutput, "output", "o", "stdout", "Rarefied alignment output file")
rarefyCmd.PersistentFlags().StringVarP(&rarefyCounts, "counts", "c", "stdin", "Count file (tab separated), one line per sequence: seqname\\tcount")
rarefyCmd.PersistentFlags().IntVarP(&rarefyReplicates, "replicates", "r", 1, "Number of replicates to generate")
}

func parseCountFile(file string) map[string]int {
Expand Down

0 comments on commit 4c29185

Please sign in to comment.