github.com/vertgenlab/gonomics@v1.0.0/cmd/gsw/messages.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "log" 7 "os" 8 "strings" 9 10 "github.com/vertgenlab/gonomics/fileio" 11 "github.com/vertgenlab/gonomics/genomeGraph" 12 "github.com/vertgenlab/gonomics/giraf" 13 ) 14 15 // TODO: View feature needs some work. 16 type ViewExe struct { 17 Cmd *flag.FlagSet 18 GirafFile string 19 SamFile string 20 } 21 22 var extendHelpMsg *flag.FlagSet = flag.NewFlagSet("help", flag.ExitOnError) 23 24 func helpMessage() { 25 fmt.Printf( 26 " help\t\tDetailed help message for any command\n") 27 } 28 29 // TODO: finish implementing view function. 30 // it works, but we need to figure out an easy way to run the command. 31 func viewUsage() { 32 fmt.Printf( 33 " view\t\tVisualize graph generated alignment\n") 34 } 35 func flagsPrint() { 36 fmt.Print( 37 "\nFlags:\n" + 38 " -h, --help\t\tEnter gsw --help [align/ggtools/view] for detailed information\n" + 39 " -o, --out\t\tFilename[.gg/.vcf/.gz/.sam] (default: /dev/stdout)\n\n") 40 //" -t, --threads\t\tNumber of CPUs for goroutines (default: 4)\n\n") 41 } 42 43 func errorMessage() { 44 log.Fatalf("Error: Apologies, your command prompt was not recognized...\n\n-xoxo GG\n") 45 } 46 47 func moreHelp(cmdFlag string) { 48 if strings.Contains("align", cmdFlag) { 49 extendedAlignUsage() 50 } else if strings.Contains("ggtools", cmdFlag) { 51 ggtoolsExtend() 52 } else if strings.Contains("view", cmdFlag) { 53 viewExtend() 54 } else { 55 errorMessage() 56 } 57 } 58 59 func viewExtend() { 60 fmt.Print( 61 "Usage:\n" + 62 " gsw view [options] ref\n\n" + 63 "Options:\n" + 64 " -g, --giraf\t\tProvide a giraf alignment with its reference to visualize the alignment\n" + 65 " -s, --sam\t\tProvide a sam alignment with its reference to visualize the alignment\n\n") 66 } 67 68 func ViewArgs() *ViewExe { 69 view := &ViewExe{Cmd: flag.NewFlagSet("view", flag.ExitOnError)} 70 view.Cmd.StringVar(&view.GirafFile, "giraf", "", "Visualize sequences aligned to graphs in giraf format\n") 71 view.Cmd.StringVar(&view.SamFile, "sam", "", "Visualize sequences aligned to graphs in sam format\n\n") 72 return view 73 } 74 75 func RunViewExe() error { 76 view := ViewArgs() 77 view.Cmd.Parse(os.Args[2:]) 78 79 tail := view.Cmd.Args() 80 if len(tail) > 1 || !strings.HasSuffix(tail[0], ".gg") { 81 flag.PrintDefaults() 82 return fmt.Errorf("Error: Apologies, your command prompt was not recognized...\n\n-xoxo GG\n") 83 } 84 viewAlignmentStdOut(tail[0], view.GirafFile) 85 return nil 86 } 87 88 func viewAlignmentStdOut(ref string, g string) { 89 if !strings.HasSuffix(ref, ".gg") { 90 log.Fatalf("Error: Apologies, your command prompt was not recognized...\n\n-xoxo GG\n") 91 } 92 gg := genomeGraph.Read(ref) 93 if strings.HasSuffix(g, ".giraf") { 94 file := fileio.EasyOpen(g) 95 defer file.Close() 96 for curr, done := giraf.NextGiraf(file); !done; curr, done = giraf.NextGiraf(file) { 97 log.Printf("%s\n", genomeGraph.ViewGraphAlignment(curr, gg)) 98 } 99 } 100 }