Skip to content

Latest commit

 

History

History
173 lines (109 loc) · 3.33 KB

programmingPrimer.md

File metadata and controls

173 lines (109 loc) · 3.33 KB

Programming Primer

As mentioned before, this course is not aimed towards being a thorough course on programming languages. We will be using the three languages for some examples, however. As such, a basic knowledge of the commands will come in handy to be able to follow the exercises.


Setup & Prerequisites

Mathematica

To have the version 10 or above installed and running is enough.

Python and R

Installing Python version 3.7 with anaconda, and R 3.5.1 (with RStudio). Additionally, most of the examples and exercises will be shown running in atom (follow this guide to setup the Hydrogen kernels to run the packages from within the IDE).


Installing Libraries

Mathematica

(* Moving the library.m file to the folder: /Users/User/Library/Mathematica/Applications/ *)

Python

Note: to install the anaconda image, follow the instructions on this README file.

# Using anaconda on terminal
source activate dataViz
pip install packageName
conda install packageName

R

install.packages(libraryName)

Loading Libraries

Mathematica

<<LibraryName`

Python

import LibraryName
import LibraryName as Shorthand

R

library("LibraryName")

Loading Data

Mathematica

SetDirectory[NotebookDirectory[]]
rawData=Import["filename.csv"]

Python

import numpy as np
# Through numpy
path = "/DIRECTORY/"
rawData = np.genfromtxt(path + 'filename.csv', delimiter=',')

R

path = "/DIRECTORY/"
setwd(path)
readData = read.csv2(paste0(path,"deterministicData.csv"), sep=",", header=FALSE, dec=".")

Extracting Rows and Columns from a Data Structure

Mathematica

This quick reference shows the ways to access elements in a matrix form.

Python

Please follow this guide for a quick rundown on the most common ways to access elements in arrays.

R

For dataframe manipulation please refer to this guide. In the case of vectors, please follow this rundown.


Saving Data

Mathematica

Export["filename.csv",data]

Python

# Through Numpy
np.savetxt("foo.csv", a, delimiter=",")

R

write.csv(data, file = "filename.csv",row.names=FALSE)

Saving Media

Mathematica

Export["filename.extension", plotVariableName, ImageResolution->resolution, ImageSize->size]

Python

import plotly
import plotly.io as pio

# Static Media
pio.write_image(figure, 'filename.png')


# HTML
plotly.offline.plot(figure, filename='alleleFrequencyPython.html')

R

library(htmlwidgets)

# Static Media
pdf("filename.extension", width = 4, height = 4)
plotRoutine()
dev.off()

# HTML
htmlwidgets::saveWidget(media, "filename.html")