From e4402603f14b5e10c54cd1ec38d6dce0710487c0 Mon Sep 17 00:00:00 2001 From: Frederic Lemoine Date: Sat, 14 Oct 2023 11:56:53 +0200 Subject: [PATCH] Updated docs for replace --- docs/api/replace.md | 45 ++++++++++++++++++++++++++++++++++++++++ docs/commands/replace.md | 8 +++++++ 2 files changed, 53 insertions(+) diff --git a/docs/api/replace.md b/docs/api/replace.md index 253f898..ac960cb 100644 --- a/docs/api/replace.md +++ b/docs/api/replace.md @@ -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)) +} +``` diff --git a/docs/commands/replace.md b/docs/commands/replace.md index b722d6e..230c191 100644 --- a/docs/commands/replace.md +++ b/docs/commands/replace.md @@ -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: @@ -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: