Skip to content

Commit

Permalink
Added option --pos to goalign shuffle swap
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Dec 19, 2023
1 parent bdfb55a commit 3eda576
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions cmd/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

var swapRate float64
var swapPos float64

// swapCmd represents the swap command
var swapCmd = &cobra.Command{
Expand All @@ -18,7 +19,13 @@ It may take Fasta or Phylip input alignment.
If the input alignment contains several alignments, will process all of them
The only option is to specify the rate of swap.
It will exchange sequences from one seq to another of the alignment.
if rate>=0 and rate<=1 then it takes rate/2 sequences and exchanges sequences
with rate/2 other sequences, from a random position.
If given pos >=0 and <=1 then take this position (relative to align length)
instead of a random one.
A rate of 0.5 will swap 25% of the sequences with
other 25% of the sequences at a random position.
Expand Down Expand Up @@ -50,7 +57,10 @@ goalign shuffle swap -i align.fasta -r 0.5
defer utils.CloseWriteFile(f, shuffleOutput)

for al := range aligns.Achan {
al.Swap(swapRate)
if err = al.Swap(swapRate, swapPos); err != nil {
io.LogError(err)
return
}
writeAlign(al, f)
}

Expand All @@ -66,4 +76,5 @@ func init() {
shuffleCmd.AddCommand(swapCmd)

swapCmd.PersistentFlags().Float64VarP(&swapRate, "rate", "r", 0.5, "Rate of Swap sequences (>=0 and <=1)")
swapCmd.PersistentFlags().Float64Var(&swapPos, "pos", -1, "Position of the break point (0<pos<1, relative to alignment length), default: -1 (means random)")
}
3 changes: 2 additions & 1 deletion docs/commands/shuffle.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This command adds different type of noises in an input alignment, with these sub
```
* `goalign shuffle seqs` : Shuffles sequence order in alignment. It does not add any noise in the alignment.
* `goalign shuffle sites`: Shuffles vertically a given proportion of the alignment sites. Optionnaly, it is possible to shuffle vertically an additional (same) proportion of the remaining intact sites for a given proportion of the sequences (~rogues)
* `goalign shuffle swap` : Swaps a given portion of the sequences in the input alignment. The only option to specify is the swap rate. A rate of 0.5 will swap 25% of the sequences with other 25% of the sequences from a random position to the end. Example swaping 50% of sequences:
* `goalign shuffle swap` : Swaps a given portion of the sequences in the input alignment. The option `-r` specifies the swap rate. A rate of 0.5 will swap 25% of the sequences with other 25% of the sequences from a random position to the end. The option `--pos` specifies the position from which to swap the sequences. If pos <0 or >1, the, the position is random. Example swaping 50% of sequences at a random position:
```
s1 CCCCCCCCCCCCCC s1 CCCCCCCCCCCCCC
s2 AAAAAAAAAAAAAA => s2 AAAAAATTTTTTTT
Expand Down Expand Up @@ -137,6 +137,7 @@ Usage:
goalign shuffle swap [flags]
Flags:
--pos float Position of the break point (0<pos<1, relative to alignment length), default: -1 (means random) (default -1)
-r, --rate float Rate of Swap sequences (>=0 and <=1) (default 0.5)
Global Flags:
Expand Down

0 comments on commit 3eda576

Please sign in to comment.