Skip to content

Commit

Permalink
Updated docs for replace
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Oct 14, 2023
1 parent 18217b2 commit e440260
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/api/replace.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,48 @@ func main() {
fmt.Println(fasta.WriteAlignment(al))
}
```

Replace characters in sequences of input alignment using its position+sequence name.

```go
package main

import (
"bufio"
"fmt"
"io"

"github.com/evolbioinfo/goalign/align"
"github.com/evolbioinfo/goalign/io/fasta"
"github.com/evolbioinfo/goalign/io/utils"
)

func main() {
var fi io.Closer
var r *bufio.Reader
var err error
var al align.SeqBag
// or var al align.Alignment if aligned sequences

/* First Alignment*/

/* Get reader (plain text or gzip) */
if fi, r, err = utils.GetReader("align.fa"); err != nil {
panic(err)
}
defer fi.Close()

/* Parse Fasta */
if al, err = fasta.NewParser(r).Parse(); err != nil {
/* for aligned seqs: if al, err = fasta.NewParser(r).Parse(); err != nil {*/
panic(err)
}

// Will write a G at position 9 (0 based) of sequence "Seq001"
if err = al.ReplaceChar("Seq001", 9, "G"); err != nil {
panic(err)
}

fmt.Println(fasta.WriteAlignment(al))
}
```
8 changes: 8 additions & 0 deletions docs/commands/replace.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
This command replaces characters in sequences of an input alignment. The `--regexp (-e)` option considers the string to be replaced as a regular expression.
Unless `--unaligned`is specified, the replacement should not change sequence lengths, otherwise it returns an error.

If `--posfile` is given, then `--old` and `--new` are not considered. Instead, characters at sites+sequences specified in the input file
are replaced in the alignement. The format of the input posfile is tabulated with columns:

- 0: sequence name
- 1: site index
- 2: new character

#### Usage
```
Usage:
Expand All @@ -17,6 +24,7 @@ Flags:
-s, --old string String to replace in the sequences (default "none")
-o, --output string Output alignment file (default "stdout")
-e, --regexp Considers Replace alignment using regexp
-f, --posfile string File containing sites to replace by give characters in given sequences (deactivates --old & --new) (default "none")
--unaligned Considers input sequences as unaligned and fasta format (phylip, nexus,... options are ignored)
Global Flags:
Expand Down

0 comments on commit e440260

Please sign in to comment.