Monday 17 September 2018

Using python with SVG - part 1

Trying to follow the instructions here:
https://jespermaag.github.io/blog/2018/gganatogram/
to help create some more tissues for gganatogram.

Unfortunately fail at first step:
Downloading SVG files using npm install --save anatomogram
This gave an error message...
Similar to this: https://github.com/npm/npm/issues/3190
I think I probably need to reinstall npm
Following this: https://stackoverflow.com/questions/11284634/upgrade-node-js-to-the-latest-version-on-mac-os

using Node -v gives a nice up todate version number v10.10.0

Try again with sudo npm install --save anatomogram
This has worked but gave warnings:
> styled-components@3.4.6 postinstall /Users/paulbrennan/Documents/anatomogram/node_modules/styled-components
> node ./scripts/postinstall.js || exit 0

Use styled-components at work? Consider supporting our development efforts at opencollective.com/styled-components
npm WARN saveError ENOENT: no such file or directory, open '/Users/paulbrennan/Documents/anatomogram/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/paulbrennan/Documents/anatomogram/package.json'
npm WARN anatomogram No description
npm WARN anatomogram No repository field.
npm WARN anatomogram No README data
npm WARN anatomogram No license field.

+ anatomogram@2.0.0
added 21 packages from 24 contributors, updated 1 package, moved 23 packages and audited 102 packages in 21.306s

found 0 vulnerabilities

Checked the file organisation and there are outline SVG files...

At the moment I can only find outlines not organs, etc...

Open PyCharm.
Cut and paste in code...

Hmm, check Python version and packages...
Pauls-MBP-2:anatomogram paulbrennan$ python --version

Python 2.7.10

Should probably update...
Maybe just do this:

Pauls-MBP-2:anatomogram paulbrennan$ python3


Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04) 

And gives:

>>> 

Test this:
>>> print("Hello world")
Hello world

Works.
Control D to exit (https://apple.stackexchange.com/questions/62164/how-do-i-exit-python-in-the-mountain-lion-terminal)

Wednesday 12 September 2018

ggplot object test framework....

Not generic but needs to be adapted to the object.
Useful though so here it is...

Adapted from here:
https://github.com/brennanpincardiff/drawProteins/blob/master/tests/testthat/test-geoms.R
with info from here:
https://stackoverflow.com/questions/13457562/how-to-determine-the-geom-type-of-each-layer-of-a-ggplot2-object/43982598#43982598

# testing framework for a ggplot object...

# these are the parts of the ggplot object:
## p$data
## p$layers
## p$scales
## p$mapping
## p$theme
## p$coordinates
## p$facet
## p$plot_env
## p$labels


# confirm its a ggplot
expect_is(ggseg(),c("gg","ggplot"))

p <- ggseg()

# should be a list of 9
# a ggplot object should be a list of 9
expect_equal(mode(p), "list")
expect_equal(length(p), 9)

## p$data
expect_equal(dim(p$data)[1], 10913)
expect_equal(dim(p$data)[2], 11)
expect_equal(colnames(p$data)[1], "long")

## p$layers
# should have a defined number of layers
expect_equal(length(p$layers), 1)
# https://stackoverflow.com/questions/13457562/how-to-determine-the-geom-type-of-each-layer-of-a-ggplot2-object/43982598#43982598
# layer should be a specific geom
expect_equal(class(p$layers[[1]]$geom)[1], "GeomPolygon")
# if there are multiple layers we can test more than one...

## p$labels
# should have x but not y labels
expect_equal(p$labels$x, "hemisphere")
expect_equal(p$labels$y, "")

Worked through adding tests to gganatogram...

Workflow


  1. Fork (online)
  2. Open in R-Studio - as a git repository
  3. Check the build before going forward (devtools::check())
  4. Write a test
  5. Run tests using R-Studio
  6. 19 different tests run today.
  7. Check the build again at the end - R-Studio tabs worked
  8. Commit in R-Studio
  9. Push to Github in R-Studio
  10. Create Pull Request online 
  11. Feel happy with some high quality coding done :-)


Used R-Studio for it all - advice from here (http://r-bio.github.io/intro-git-rstudio/) very useful.


Tuesday 11 September 2018

Drawing bodies, brains and protein structures...

Bodies

ggplot for bodies with expression data...
https://twitter.com/JesperMaag/status/1038914309957607424

https://github.com/jespermaag/gganatogram

https://github.com/ebi-gene-expression-group/anatomogram


Semantic Body Illustrations 
https://github.com/flekschas/sbi
https://academic.oup.com/bioinformatics/article/31/5/794/2748201
http://sbb.cellfinder.org/human-adult-female-body

Brains

https://github.com/LCBC-UiO/ggseg
https://github.com/LCBC-UiO/ggseg/wiki/Creating-and-contributing-atlases



https://rud.is/b/2016/02/11/plot-the-new-svg-r-logo-with-ggplot2/

Most importantly:
https://github.com/davidmcclure/svg-to-wkt
Convert SVG into text....


https://drmowinckels.io/blog/adding-external-images-to-plots/



And then proteins too...

http://thegrantlab.org/bio3d/index.php

Bio3D is an R package containing utilities for the analysis of protein structure, sequence and trajectory data.

https://www.rcsb.org/3d-view/1AYC




But still SVG to data.frame to plot...
I don't know the way!
https://github.com/davidmcclure/svg-to-wkt - maybe!

Info here: https://github.com/LCBC-UiO/ggseg/wiki/Creating-and-contributing-atlases