Ejemplo n.º 1
0
// Call execute to use the args (os.Args[1:] by default)
// and run through the command tree finding appropriate matches
// for commands and then corresponding flags.
func (c *Command) Execute() (err error) {

	// Regardless of what command execute is called on, run on Root only
	if c.HasParent() {
		return c.Root().Execute()
	}

	if EnableWindowsMouseTrap && runtime.GOOS == "windows" {
		if mousetrap.StartedByExplorer() {
			c.Print(MousetrapHelpText)
			time.Sleep(5 * time.Second)
			os.Exit(1)
		}
	}

	// initialize help as the last point possible to allow for user
	// overriding
	c.initHelpCmd()

	var args []string

	if len(c.args) == 0 {
		args = os.Args[1:]
	} else {
		args = c.args
	}

	cmd, flags, err := c.Find(args)
	if err != nil {
		// If found parse to a subcommand and then failed, talk about the subcommand
		if cmd != nil {
			c = cmd
		}
		if !c.SilenceErrors {
			c.Println("Error:", err.Error())
			c.Printf("Run '%v --help' for usage.\n", c.CommandPath())
		}
		return err
	}

	err = cmd.execute(flags)
	if err != nil {
		// If root command has SilentUsage flagged,
		// all subcommands should respect it
		if !cmd.SilenceUsage && !c.SilenceUsage {
			c.Println(cmd.UsageString())
		}
		// If root command has SilentErrors flagged,
		// all subcommands should respect it
		if !cmd.SilenceErrors && !c.SilenceErrors {
			if err == flag.ErrHelp {
				cmd.HelpFunc()(cmd, args)
				return nil
			}
			c.Println("Error:", err.Error())
		}
		return err
	}
	return
}
Ejemplo n.º 2
0
func Mousetrap(app *cli.App) {
	oldBefore := app.Before
	app.Before = func(c *cli.Context) error {
		if mousetrap.StartedByExplorer() {
			cmd := exec.Command(os.Args[0], os.Args[1:]...)
			cmd.Env = append(os.Environ(), "MOUSETRAP=1")
			cmd.Stdin = os.Stdin
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			cmd.Run()
			cmd = exec.Command("cmd.exe", "/K")
			cmd.Env = os.Environ()
			cmd.Stdin = os.Stdin
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			err := cmd.Run()
			if err != nil {
				fmt.Println("Failed to execute sub-process. Error:", err)
				os.Exit(1)
			}
			os.Exit(0)
		}
		if oldBefore == nil {
			return nil
		}
		return oldBefore(c)
	}
}
Ejemplo n.º 3
0
func preExecHook(c *Command) {
	if mousetrap.StartedByExplorer() {
		c.Print(MousetrapHelpText)
		time.Sleep(5 * time.Second)
		os.Exit(1)
	}
}
Ejemplo n.º 4
0
func init() {
	if mousetrap.StartedByExplorer() {
		fmt.Println("Don't double-click ponydownloader")
		fmt.Println("You need to open cmd.exe and run it from the command line!")
		time.Sleep(5 * time.Second)
		os.Exit(1)
	}
}
Ejemplo n.º 5
0
Archivo: main.go Proyecto: 0x19/ngrok
func init() {
	if runtime.GOOS == "windows" {
		if mousetrap.StartedByExplorer() {
			fmt.Println("Don't double-click ngrok!")
			fmt.Println("You need to open cmd.exe and run it from the command line!")
			time.Sleep(5 * time.Second)
			os.Exit(1)
		}
	}
}
Ejemplo n.º 6
0
// Call execute to use the args (os.Args[1:] by default)
// and run through the command tree finding appropriate matches
// for commands and then corresponding flags.
func (c *Command) Execute() (err error) {

	// Regardless of what command execute is called on, run on Root only
	if c.HasParent() {
		return c.Root().Execute()
	}

	if EnableWindowsMouseTrap && runtime.GOOS == "windows" {
		if mousetrap.StartedByExplorer() {
			c.Print(MousetrapHelpText)
			time.Sleep(5 * time.Second)
			os.Exit(1)
		}
	}

	// initialize help as the last point possible to allow for user
	// overriding
	c.initHelp()

	var args []string

	if len(c.args) == 0 {
		args = os.Args[1:]
	} else {
		args = c.args
	}

	if len(args) == 0 {
		// Only the executable is called and the root is runnable, run it
		if c.Runnable() {
			err = c.execute([]string(nil))
		} else {
			c.Help()
		}
	} else {
		cmd, flags, e := c.Find(args)
		if e != nil {
			err = e
		} else {
			err = cmd.execute(flags)
		}
	}

	if err != nil {
		if err == flag.ErrHelp {
			c.Help()

		} else {
			c.Println("Error:", err.Error())
			c.Printf("Run '%v help' for usage.\n", c.Root().Name())
		}
	}

	return
}
Ejemplo n.º 7
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s [options] {-Q UNIPROT_DB IDENTIFER | -U UNIPROT_ID | GENE_SYMBOL} [PROTEIN CHANGES ...]\n", os.Args[0])
		fmt.Fprintln(os.Stderr, `
Protein ID input:
  GENE_SYMBOL is the official human HGNC gene symbol. This will use the
  UniprotKB API to lookup the UNIPROT_ID.

  You can provide a UniProt ID directly with -U (e.g. "-U P04637" for TP53)

  For more advanced usage, query UniprotKB's database mappings directly using
  a supported identifier with -Q DBNAME. Available DBNAMEs can be found here:
     http://www.uniprot.org/help/programmatic_access#id_mapping_examples

     RefSeq ID        e.g. -Q P_REFSEQ_AC NP_001265252.1
     Entrez GeneID    e.g. -Q P_ENTREZGENEID 4336
     Ensembl ID       e.g. -Q ENSEMBL_ID ENSG00000168314

Protein changes:
  Currently only point mutations are supported, and may be specified as:

    <AMINO><CODON><AMINO><#COLOR><@COUNT>

  Only CODON is required, and AMINO tags are not parsed.

  Synonymous mutations are denoted if the first AMINO tag matches the second
  AMINO tag, or if the second tag is not present. Otherwise the non-synonymous
  mutation color is used. The COLOR tag will override using the #RRGGBB style
  provided. The COUNT tag can be used to scale the lollipop marker size so that
  the area is exponentially proportional to the count indicated. Examples:

    R273C            -- non-synonymous mutation at codon 273
    T125@5           -- synonymous mutation at codon 125 with "5x" marker sizing
    R248Q#00ff00     -- green lollipop at codon 248
    R248Q#00ff00@131 -- green lollipop at codon 248 with "131x" marker sizing

  (N.B. color must come before count in tags)

Diagram generation options:
  -legend                 draw a legend for colored regions
  -syn-color="#0000ff"    color to use for synonymous mutation markers
  -mut-color="#ff0000"    color to use for non-synonymous mutation markers
  -hide-axis              do not draw the amino position x-axis
  -show-disordered        draw disordered regions on the backbone
  -show-motifs            draw simple motif regions
  -labels                 draw label text above lollipop markers
  -no-patterns            use solid fill instead of patterns (SVG only)
  -domain-labels=fit      hot to apply domain labels (default="truncated")
                            "fit" = only if fits in space available
                            "off" = do not draw text in the domains

Output options:
  -o=filename.png         set output filename (.png or .svg supported)
  -w=700                  set diagram pixel width (default = automatic fit)
  -dpi=300                set DPI (PNG output only)

Local file input:
  -l=filename.json        use local file instead of Pfam API for graphic data
                            see: http://pfam.xfam.org/help#tabview=tab9
`)
	}

	flag.Parse()
	drawing.DefaultSettings.ShowLegend = *showLegend
	drawing.DefaultSettings.ShowLabels = *showLabels
	drawing.DefaultSettings.HideDisordered = !*showDisordered
	drawing.DefaultSettings.HideMotifs = !*showMotifs
	drawing.DefaultSettings.HideAxis = *hideAxis
	drawing.DefaultSettings.SolidFillOnly = *noPatterns
	drawing.DefaultSettings.DomainLabelStyle = *domainLabels
	drawing.DefaultSettings.SynonymousColor = *synColor
	drawing.DefaultSettings.MutationColor = *mutColor
	drawing.DefaultSettings.GraphicWidth = float64(*width)

	if *fontPath == "" {
		err := drawing.LoadDefaultFont()
		if err != nil {
			fmt.Fprintln(os.Stderr, "ERROR: Unable to find Arial.ttf - Which is required for accurate font sizing.")
			fmt.Fprintln(os.Stderr, "       Please use -f=/path/to/arial.ttf or the TrueType (.ttf) font of your choice.")
			// continue in the hopes that SVG rendering will be ok...
			//os.Exit(1)
		}
	} else {
		fname := path.Base(*fontPath)
		fname = strings.TrimSuffix(fname, path.Ext(fname))
		err := drawing.LoadFont(fname, *fontPath)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
	}

	var err error
	varStart := 0
	acc := ""
	geneSymbol := ""
	if *uniprot == "" && flag.NArg() > 0 {
		geneSymbol = flag.Arg(0)
		varStart = 1

		if *queryDB == "GENENAME" {
			fmt.Fprintln(os.Stderr, "HGNC Symbol: ", flag.Arg(0))
			acc, err = data.GetProtID(flag.Arg(0))
		} else {
			fmt.Fprintln(os.Stderr, "Searching for ID: ", flag.Arg(0))
			acc, err = data.GetProtMapping(*queryDB, flag.Arg(0))
		}

		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}

		fmt.Fprintln(os.Stderr, "Uniprot/SwissProt Accession: ", acc)
	}

	if *uniprot != "" {
		acc = *uniprot
	}

	if flag.NArg() == 0 && *uniprot == "" {
		flag.Usage()

		if mousetrap.StartedByExplorer() {
			fmt.Fprintln(os.Stderr, `!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

This is a command-line utility for pipeline processing, you probably don't want
to double-click it! Open your command prompt with 'cmd.exe' and try again.

Press Enter/Ctrl-C to quit.`)
			fmt.Scanln(&acc)
		}
		os.Exit(1)
	}

	var d *data.PfamGraphicResponse
	if *localPath != "" {
		d, err = data.GetLocalPfamGraphicData(*localPath)
	} else {
		d, err = data.GetPfamGraphicData(acc)
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if geneSymbol == "" {
		geneSymbol = d.Metadata.Identifier
		fmt.Fprintln(os.Stderr, "Pfam Symbol: ", geneSymbol)
	}

	if *output == "" {
		*output = geneSymbol + ".svg"
	}

	f, err := os.OpenFile(*output, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer f.Close()

	fmt.Fprintln(os.Stderr, "Drawing diagram to", *output)
	if strings.HasSuffix(strings.ToLower(*output), ".png") {
		drawing.DrawPNG(f, *dpi, flag.Args()[varStart:], d)
	} else {
		drawing.DrawSVG(f, flag.Args()[varStart:], d)
	}
}