Skip to content

Commit

Permalink
Added option -l to goalign concat to keep information of the coordina…
Browse files Browse the repository at this point in the history
…tes of all input alignments in the concatenated alignment
  • Loading branch information
fredericlemoine committed Nov 6, 2023
1 parent ea985a7 commit 5284c05
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/concat.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package cmd

import (
"fmt"

"github.com/evolbioinfo/goalign/align"
"github.com/evolbioinfo/goalign/io"
"github.com/evolbioinfo/goalign/io/utils"
"github.com/spf13/cobra"
)

var concatout string
var concatlog string

// concatCmd represents the concat command
var concatCmd = &cobra.Command{
Expand All @@ -33,13 +36,22 @@ or goalign concat -i none -p align*.phy
var alchan *align.AlignChannel
var align align.Alignment = nil
var f utils.StringWriterCloser
var l utils.StringWriterCloser
var start int
if l, err = utils.OpenWriteFile(concatlog); err != nil {
io.LogError(err)
return
}

start = 0
if infile != "none" {
if aligns, err = readalign(infile); err != nil {
io.LogError(err)
return
}
for al := range aligns.Achan {
fmt.Fprintf(l, "%d\t%d\t%s\n", start, start+al.Length(), infile)
start += al.Length()
if align == nil {
align = al
} else {
Expand All @@ -61,6 +73,8 @@ or goalign concat -i none -p align*.phy
return
}
for al := range alchan.Achan {
fmt.Fprintf(l, "%d\t%d\t%s\n", start, start+al.Length(), otherfile)
start += al.Length()
if align == nil {
align = al
} else {
Expand All @@ -76,6 +90,7 @@ or goalign concat -i none -p align*.phy
return
}
}
utils.CloseWriteFile(l, concatlog)

if f, err = utils.OpenWriteFile(concatout); err != nil {
io.LogError(err)
Expand All @@ -91,4 +106,5 @@ or goalign concat -i none -p align*.phy
func init() {
RootCmd.AddCommand(concatCmd)
concatCmd.PersistentFlags().StringVarP(&concatout, "output", "o", "stdout", "Alignment output file")
concatCmd.PersistentFlags().StringVarP(&concatlog, "log", "l", "none", "Log output file (coordinates of all input alignments in the concatenated alignment)")
}

0 comments on commit 5284c05

Please sign in to comment.