From 9ceaedcf0e56f41a79bedd1159b1b88e2167439e Mon Sep 17 00:00:00 2001 From: Frederic Lemoine Date: Mon, 6 May 2019 10:12:28 +0200 Subject: [PATCH] nexus parser replace match chars #3 --- align/align.go | 21 ++++++++++++++++++++- io/nexus/nexus_parser.go | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/align/align.go b/align/align.go index f02a381..46333d3 100644 --- a/align/align.go +++ b/align/align.go @@ -57,7 +57,9 @@ type Alignment interface { Recombine(rate float64, lenprop float64) RemoveGapSeqs(cutoff float64) // Removes sequences having >= cutoff gaps RemoveGapSites(cutoff float64, ends bool) // Removes sites having >= cutoff gaps - Sample(nb int) (Alignment, error) // generate a sub sample of the sequences + // Replaces match characters (.) by their corresponding characters on the first sequence + ReplaceMatchChars() + Sample(nb int) (Alignment, error) // generate a sub sample of the sequences ShuffleSites(rate float64, roguerate float64, randroguefirst bool) []string SimulateRogue(prop float64, proplen float64) ([]string, []string) // add "rogue" sequences SiteConservation(position int) (int, error) // If the site is conserved: @@ -322,6 +324,23 @@ func (a *align) Swap(rate float64) { } } +// Replaces match characters (.) by their corresponding characters on the first sequence +// +// If the correspongind character in the first sequence is also a ".", then leaves it unchanged. +func (a *align) ReplaceMatchChars() { + if a.NbSequences() <= 1 { + return + } + ref := a.seqs[0] + for seq := 1; seq < a.NbSequences(); seq++ { + for site := 0; site < a.Length(); site++ { + if ref.sequence[site] != POINT && a.seqs[seq].sequence[site] == POINT { + a.seqs[seq].sequence[site] = ref.sequence[site] + } + } + } +} + // Translates the alignment, and update the length of // the alignment func (a *align) Translate(phase int, geneticcode int) (err error) { diff --git a/io/nexus/nexus_parser.go b/io/nexus/nexus_parser.go index a07be10..5c96317 100644 --- a/io/nexus/nexus_parser.go +++ b/io/nexus/nexus_parser.go @@ -176,6 +176,7 @@ func (p *Parser) Parse() (al align.Alignment, err error) { return } } + al.ReplaceMatchChars() } return }