11package cmd
22
33import (
4+ "fmt"
5+
46 "github.com/evolbioinfo/goalign/align"
57 "github.com/evolbioinfo/goalign/io"
68 "github.com/evolbioinfo/goalign/io/utils"
79 "github.com/spf13/cobra"
810)
911
1012var gapnbseqs float64
13+ var addgapslogfile string
1114
1215// rogueCmd represents the rogue command
1316var addgapsCmd = & cobra.Command {
@@ -21,6 +24,7 @@ goalign mutate gaps -i align.fa -n 0.5 -r 0.5
2124 RunE : func (cmd * cobra.Command , args []string ) (err error ) {
2225 var aligns * align.AlignChannel
2326 var f utils.StringWriterCloser
27+ var addgapslog utils.StringWriterCloser
2428
2529 if aligns , err = readalign (infile ); err != nil {
2630 io .LogError (err )
@@ -32,9 +36,25 @@ goalign mutate gaps -i align.fa -n 0.5 -r 0.5
3236 }
3337 defer utils .CloseWriteFile (f , mutateOutput )
3438
39+ if addgapslog , err = utils .OpenWriteFile (addgapslogfile ); err != nil {
40+ io .LogError (err )
41+ return
42+ }
43+ defer utils .CloseWriteFile (addgapslog , addgapslogfile )
44+
3545 for al := range aligns .Achan {
36- al .AddGaps (mutateRate , gapnbseqs , globalRand )
46+ affected := al .AddGaps (mutateRate , gapnbseqs , globalRand )
3747 writeAlign (al , f )
48+ for _ , s := range affected {
49+ if n , ok := al .GetSequenceNameById (s ); ! ok {
50+ err = fmt .Errorf ("affected sequence not found in the alignment: %d" , s )
51+ io .LogError (err )
52+ return
53+ } else {
54+ fmt .Fprintf (addgapslog , "%d\t %s\n " , s , n )
55+ }
56+ }
57+
3858 }
3959
4060 if aligns .Err != nil {
@@ -48,4 +68,5 @@ goalign mutate gaps -i align.fa -n 0.5 -r 0.5
4868func init () {
4969 mutateCmd .AddCommand (addgapsCmd )
5070 addgapsCmd .PersistentFlags ().Float64VarP (& gapnbseqs , "prop-seq" , "n" , 0.5 , "Proportion of the sequences in which to add gaps" )
71+ addgapsCmd .PersistentFlags ().StringVar (& addgapslogfile , "log" , "none" , "Log file with the names of affected sequences" )
5172}
0 commit comments