Skip to content

Commit

Permalink
various cleanups and fixes from past 3 years
Browse files Browse the repository at this point in the history
  • Loading branch information
pbnjay committed Jun 30, 2022
1 parent 532734b commit 14d6463
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion data/uniprot.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"strings"
)

const UniprotDataURL = "https://www.uniprot.org/uniprot/%s.txt"
const UniprotDataURL = "https://rest.uniprot.org/uniprotkb/%s.txt"

var defaultUniprotFeatures = map[string][]string{
"COILED": {"motif", "coiled_coil", "#9cff00"},
Expand Down
4 changes: 1 addition & 3 deletions drawing/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *Settings) prepare(changelist []string, g *data.GraphicResponse) *diagra
}

pops := TickSlice{}
col := s.SynonymousColor
var col string
s.GraphicHeight = s.DomainHeight + s.Padding*2
if len(changelist) > 0 {
popMatch := make(map[string]int)
Expand Down Expand Up @@ -133,8 +133,6 @@ func (s *Settings) prepare(changelist []string, g *data.GraphicResponse) *diagra

if len(pops) > 0 {
poptop := startY + s.LollipopRadius
popbot := poptop + s.LollipopHeight
startY = popbot - (s.DomainHeight-s.BackboneHeight)/2

// position lollipops
for pi, pop := range pops {
Expand Down
31 changes: 31 additions & 0 deletions drawing/fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ package drawing

import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"

"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
Expand All @@ -30,6 +33,8 @@ var (
theFont *truetype.Font
)

var defaultFontURL = "https://github.com/googlefonts/opensans/raw/main/fonts/ttf/OpenSans-Regular.ttf"

// we try to have sane defaults wrt font usage
//
// 1) auto-load Arial if found as the default font.
Expand All @@ -55,6 +60,32 @@ func LoadDefaultFont() error {
return nil
}
}
err := LoadFont("OpenSans", "OpenSans-Regular.ttf")
if err == nil {
return nil
}

resp, err := http.Get(defaultFontURL)
if err == nil {
fmt.Fprintln(os.Stderr, "Downloading Font: OpenSans-Regular.ttf (Apache Licensed)")
fmt.Fprintln(os.Stderr, "Learn more about usage at https://github.com/googlefonts/opensans")
fmt.Fprint(os.Stderr, "Or provide a different truetype font with -f fontname.ttf\n\n")

f, err := os.Create("OpenSans-Regular.ttf")
if err == nil {
n, err := io.Copy(f, resp.Body)
if n == 0 || err != nil {
return fmt.Errorf("failed to download a font to use")
}
}
f.Close()
resp.Body.Close()
err = LoadFont("OpenSans", "OpenSans-Regular.ttf")
if err == nil {
return nil
}
}

return fmt.Errorf("unable to find Arial.ttf")
}

Expand Down
6 changes: 3 additions & 3 deletions drawing/png.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,18 @@ func vline(img draw.Image, x, y0, y1 int, clr color.Color) {

func drawRectWH(img draw.Image, x0, y0, w, h float64, clr color.Color) {
draw.Draw(img, image.Rect(int(x0), int(y0), int(x0+w), int(y0+h)),
&image.Uniform{clr}, image.ZP, draw.Over)
&image.Uniform{clr}, image.Point{}, draw.Over)
}

func drawRectWHShadow(img draw.Image, x0, y0, w, h float64, clr color.Color, shadowOffs float64) {
// approx 10% opacity
src := &image.Uniform{color.RGBA{0, 0, 0, 1 + uint8(75/shadowOffs)}}
for i := shadowOffs; i > 0; i-- {
r := image.Rect(int(x0+i), int(y0+i), int(x0+i+w), int(y0+i+h))
draw.Draw(img, r, src, image.ZP, draw.Over)
draw.Draw(img, r, src, image.Point{}, draw.Over)
}
r := image.Rect(int(x0), int(y0), int(x0+w), int(y0+h))
draw.Draw(img, r, &image.Uniform{clr}, image.ZP, draw.Over)
draw.Draw(img, r, &image.Uniform{clr}, image.Point{}, draw.Over)
}

// http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/joiningdata/lollipops

go 1.18

require (
github.com/inconshreveable/mousetrap v1.0.0
golang.org/x/image v0.0.0-20220617043117-41969df76e82
)

require github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
golang.org/x/image v0.0.0-20220617043117-41969df76e82 h1:KpZB5pUSBvrHltNEdK/tw0xlPeD13M6M6aGP32gKqiw=
golang.org/x/image v0.0.0-20220617043117-41969df76e82/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var (
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, `
fmt.Fprint(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.
Expand Down Expand Up @@ -117,6 +117,7 @@ Alternative input sources:
fetching domain/motif information
-l=filename.json use local file instead of Pfam API for graphic data
see: http://pfam.xfam.org/help#tabview=tab9
`)
}

Expand Down

0 comments on commit 14d6463

Please sign in to comment.