Skip to content

Instantly share code, notes, and snippets.

@JackKell
Created April 1, 2017 20:20
Show Gist options
  • Save JackKell/9c6c7b9b08995aa16bc2444a736d03ef to your computer and use it in GitHub Desktop.
Save JackKell/9c6c7b9b08995aa16bc2444a736d03ef to your computer and use it in GitHub Desktop.
main = function() {
# Import the data as a dataframe
drugData = read.delim(file="gene_expression.txt");
# Name the rows using the names from the first column of the drugData dataframe
dimnames(drugData)[[1]] = drugData[,1];
# Drop the first column of the drugData dataframe because we no longer need it because we have named our rows
drugData = drugData[,-1]
# Print some of the drugData for a sanity check
print(drugData[1:5, 1:4]);
# Check the class of the drugData to confirm that it is a dataframe
print(class(drugData));
# Make the drugData numeric
drugDataAsVector = as.vector(unlist(drugData), mode="numeric");
# Create a historgram of all the drugData
png("histogram.png")
hist(drugDataAsVector, xlab="gene expression");
# Create a histogram of the atf1Data
atf1Data = drugData$ATF1;
print(atf1Data);
png("histogramatf1.png")
hist(atf1Data, xlab="ATF1");
# Calculate the max, min, and mean of the drugData
print(max(drugDataAsVector));
print(min(drugDataAsVector));
print(mean(drugDataAsVector));
# Create a boxplot of the first 3 columns and all the rows in drugData
png("boxplot.png");
boxplot(drugData[,1:3]);
# Find the correlation between 2 columns
cor(drugData[,1], drugData[,2]);
png("scatterplot.png");
plot(drugData[,1], drugData[,2]);
coreraltionMatrix = cor(drugData);
print(class(coreraltionMatrix));
# Find the max and min correlation
maxCor = -1;
minCor = 1;
for (geneA in 1:ncol(coreraltionMatrix)) {
for (geneB in 1:ncol(coreraltionMatrix)) {
if (geneA != geneB) {
currentCor = cor(drugData[,geneA], drugData[,geneB])
if (currentCor > maxCor) {
maxCor = currentCor;
print(maxCor)
}
if (currentCor < minCor) {
minCor = currentCor;
print(minCor)
}
}
}
}
print(paste("The max cor is: ", maxCor));
print(paste("The min cor is: ", minCor));
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment