Skip to content

7. Advanced Adding custom variables for plotting or analysis

kbseah edited this page Jun 28, 2018 · 3 revisions

gbtools offers facility for plotting by GC and coverage values. But what if you have some other variables that you want to plot?

They must meet the following criteria:

  • Numeric
  • Single value per scaffold

An example: You have done a PCA analysis of tetranucleotide frequencies per scaffold, and you want to plot coverage vs. 1st principal component (in place of GC%).

7a. Attach the user-custom data to your existing gbt object

You originally imported the basic data and annotations with the gbt() function. In the earlier sections of this manual, we used the example of an object called d.

Suppose the custom data is in a data frame called customFrame. It MUST have a column called scaffold and a second column with the variable to be plotted.

Attach the custom data to your original object with the userAdd function:

d.user <- userAdd(d,customFrame,"pca") # "pca" is the name you give to this variable

7b. Plot with custom variable as x- or y-axis

You can call the user-custom variable in the plot() function using the userAxis= parameter. You will need to specify what is the x- and y-axis you want. Suppose you want to plot custom variable "pca" in the x-axis, and coverage from sample 1 in the y-axis:

plot(d.user,userAxis=c("pca","cov"),slice=1)
plot(d.user,userAxis=c("pca","cov"),slice=1,marker=FALSE,gc=TRUE) # color by GC%

If you want GC as x-axis, and custom variable "pca" as y-axis:

plot(d.user,userAxis=c("gc","pca"))

You can reproduce the behavior of the GC-coverage plot with userAxis=:

plot(d.user,userAxis=c("gc","cov"),slice=1)
plot(d.user,slice=1) # Does the same thing

7c. Other uses for custom variables (for developers)

The custom variables that the user adds with userAdd() are stored in a list object called userTab. When plotting, only the first column (after the scaffold ID column) is used. Non-numeric values will throw an error.

However, the userTab feature is designed to be flexible, so that users (or me, in the future) can add their own custom functions. userAdd() will not complain if you add categorical variables instead of numeric (as long as you don't try to plot it). In the future, I could implement coloring plot overlays by custom user data, for example. But since this is unlikely to be a common usage scenario, it is unimplemented for now.

I recommend that any custom functions written within the gbtools framework make use of the userTab feature and avoid adding more custom attributes to the gbt object class.

Next step

Mapping and reassembly