-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added options --internal / --external to gotree brlen subcommands. ap…
…i has been modified: Tree functions have been updated
- Loading branch information
1 parent
a77e677
commit a61803b
Showing
9 changed files
with
185 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package cmd | ||
|
||
import ( | ||
goio "io" | ||
"os" | ||
|
||
"github.com/evolbioinfo/gotree/io" | ||
"github.com/evolbioinfo/gotree/tree" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var brlensetlen float64 | ||
|
||
// minbrlenCmd represents the minbrlen command | ||
var brlenSetCmd = &cobra.Command{ | ||
Use: "set", | ||
Short: "Set the given branch length to all branches", | ||
Long: `Set the given branch length to all branches | ||
Example of usage: | ||
gotree brlen set -i tree.nw -o out.nw -l 0.001 | ||
if --internal=false is given, it won't apply to internal branches (only external) | ||
if --external=false is given, it won't apply to external branches (only internal) | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
var f *os.File | ||
var treefile goio.Closer | ||
var treechan <-chan tree.Trees | ||
|
||
if f, err = openWriteFile(outtreefile); err != nil { | ||
io.LogError(err) | ||
return | ||
} | ||
defer closeWriteFile(f, outtreefile) | ||
|
||
if treefile, treechan, err = readTrees(intreefile); err != nil { | ||
io.LogError(err) | ||
return | ||
} | ||
defer treefile.Close() | ||
|
||
for t := range treechan { | ||
if t.Err != nil { | ||
io.LogError(t.Err) | ||
return t.Err | ||
} | ||
for _, e := range t.Tree.Edges() { | ||
if (e.Right().Tip() && brlenexternal) || (!e.Right().Tip() && brleninternal) { | ||
e.SetLength(brlensetlen) | ||
} | ||
} | ||
f.WriteString(t.Tree.Newick() + "\n") | ||
} | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
brlenCmd.AddCommand(brlenSetCmd) | ||
brlenSetCmd.Flags().Float64VarP(&brlensetlen, "length", "l", 0.0, "Desired branch length") | ||
brlenSetCmd.PersistentFlags().StringVarP(&intreefile, "input", "i", "stdin", "Input tree") | ||
brlenSetCmd.PersistentFlags().StringVarP(&outtreefile, "output", "o", "stdout", "Min length output tree file") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.