Skip to content

Commit

Permalink
nexus parser replace match chars #3
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed May 6, 2019
1 parent ff15423 commit 9ceaedc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion align/align.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions io/nexus/nexus_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (p *Parser) Parse() (al align.Alignment, err error) {
return
}
}
al.ReplaceMatchChars()
}
return
}
Expand Down

0 comments on commit 9ceaedc

Please sign in to comment.