diff --git a/main.go b/main.go index 21e0ce5..1fa7379 100644 --- a/main.go +++ b/main.go @@ -7,8 +7,9 @@ import ( ) var ( - output = flag.String("o", "", "output SVG file (default GENE_SYMBOL.svg)") - width = flag.Int("w", 0, "SVG output width (default automatic fit labels)") + uniprot = flag.String("U", "", "Uniprot accession instead of GENE_SYMBOL") + output = flag.String("o", "", "output SVG file (default GENE_SYMBOL.svg)") + width = flag.Int("w", 0, "SVG output width (default automatic fit labels)") ) func main() { @@ -18,36 +19,58 @@ func main() { flag.PrintDefaults() } flag.Parse() - if flag.NArg() == 0 { - flag.Usage() - os.Exit(1) - } - if *output == "" { - *output = flag.Arg(0) + ".svg" + + var err error + acc := "" + geneSymbol := "" + if *uniprot == "" && flag.NArg() > 0 { + geneSymbol = flag.Arg(0) + + fmt.Fprintln(os.Stderr, "HGNC Symbol: ", flag.Arg(0)) + + acc, err = GetProtID(flag.Arg(0)) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + fmt.Fprintln(os.Stderr, "Uniprot/SwissProt Accession: ", acc) } - 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) + if *uniprot != "" { + acc = *uniprot } - defer f.Close() - fmt.Fprintln(os.Stderr, "HGNC Symbol: ", flag.Arg(0)) + varStart := 1 + if flag.NArg() == 0 { + varStart = 0 + if *uniprot == "" { + flag.Usage() + os.Exit(1) + } + } - acc, err := GetProtID(flag.Arg(0)) + data, err := GetPfamGraphicData(acc) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } - fmt.Fprintln(os.Stderr, "Uniprot/SwissProt Accession: ", acc) + if geneSymbol == "" { + geneSymbol = data.Metadata.Identifier + fmt.Fprintln(os.Stderr, "Pfam Symbol: ", geneSymbol) + } - data, err := GetPfamGraphicData(acc) + 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) - DrawSVG(f, *width, flag.Args()[1:], data) + DrawSVG(f, *width, flag.Args()[varStart:], data) }