<- read.table(
expr_data file = "../exos_data/read-counts.csv", # replace the path with your own
header = TRUE, sep = ",", row.names = 1
)
Week 2 - Homework
week02
homework
Write your code directly in a Quarto document.
To create a Quarto document: go to File -> New File -> Quarto Document, then click Create.
Use the following code to import the file “read-counts.csv” (you have already downloaded it for the hand-on examples of week01). Name the imported data expr_data
.
- Is the imported data a matrix?
- Transform it to a matrix using
as.matrix()
.
- What are the dimensions of the matrix?
- What are the column names and row names?
- Extract all genes’ expression for the 10 WT samples (WT.1, WT.2, …, WT.10), and store it in a variable called
expr_wt
. Show the first few rows usinghead()
function.
- What is the average expression level across all WT samples for each gene? Store the results in a variable called
avg_wt
.
- Draw a histogram to check the distribution of the average gene expression level for WT samples.
- Repeat questions 5 to 7 for the SET1 samples (SET1.1, SET1.2, …, SET1.10).
- What is the absolute difference between the average expression of WT and SET1 samples for each gene? Which gene shows the biggest difference?
Hints:
- Use
abs()
to get the absolute value. (?abs
) - The
max()
function helps to find the maximum value from a vector. (?max
) - The
which.max()
function helps to find the index of the maximum value from a vector. (?which.max
)
- Compare the following matrix to the one we created during the course’ exercise (the matrix named
expression_levels
). What is the key difference in how the matrix is constructed? Provide a brief explanation.
matrix(
c(10, 12, 15, 20, 18, 22, 14, 16, 19, 8, 9, 7, 25, 30, 28),
ncol = 3
)
[,1] [,2] [,3]
[1,] 10 22 9
[2,] 12 14 7
[3,] 15 16 25
[4,] 20 19 30
[5,] 18 8 28
- Click “Render” to generate your Quarto report.
The homework correction is available here: link