Section A — Arithmetic with Gene Expression Counts

Q1. Add Two Gene Counts

gene_a <- 120
gene_b <- 200
gene_a + gene_b
## [1] 320

Q2. Multiply Read Depths from Two Runs

500000 * 600000
## [1] 3e+11

Q3. Calculate Fold-Change in Expression

control <- 300
treated <- 150
treated / control
## [1] 0.5

Q4. Remainder of Reads per Lane

1001000 %% 250000
## [1] 1000

Q5. Store a Gene Count in a Variable

gene_x_count <- 350
gene_x_count
## [1] 350

Q6. Add Counts from Two Patients

patient_a <- 100
patient_b <- 120
patient_a + patient_b
## [1] 220

Q7. Update a Mistaken Value

patient_b <- 130
patient_a + patient_b
## [1] 230

Q8. Store the Name of a Marker Gene

marker_gene <- "CD274"
marker_gene
## [1] "CD274"

Section B — Working with Data Types

Q9. Check the Data Type of a Count

x <- 100
class(x)
## [1] "numeric"

Q10. Check the Type of a Gene Name

gene_name <- "TP53"
class(gene_name)
## [1] "character"

Q11. Logical Flag for Marker Gene

is_marker <- TRUE
class(is_marker)
## [1] "logical"

Section C — Vectors for Gene Expression Data

Q12. Create a Vector of Gene Counts

counts <- c(120, 150, 130)
counts
## [1] 120 150 130

Q13. Assign Gene Names to Counts

names(counts) <- c("TP53", "BRCA1", "EGFR")
counts
##  TP53 BRCA1  EGFR 
##   120   150   130

Q14. Print the Named Vector

counts
##  TP53 BRCA1  EGFR 
##   120   150   130
names(counts)
## [1] "TP53"  "BRCA1" "EGFR"

Q15. Extract One Gene’s Count

counts["EGFR"]
## EGFR 
##  130

Q16. Extract the First Two Genes

counts[1:2]
##  TP53 BRCA1 
##   120   150

Section D — Managing Sample and Gene Metadata

Q17. Create Sample Names

samples <- c("Sample1", "Sample2", "Sample3")
samples
## [1] "Sample1" "Sample2" "Sample3"

Q18. Combine Gene Names with Counts

genes <- c("TP53", "BRCA1", "EGFR")
counts <- c(120, 150, 130)
names(counts) <- genes
counts
##  TP53 BRCA1  EGFR 
##   120   150   130

Q19. Check the Class of the Count Vector

class(counts)
## [1] "numeric"

Section E — Data Conversion and Filtering

Q20. Create Patient IDs with Sequence

patient_ids <- paste("Patient", 1:5, sep = "_")
patient_ids
## [1] "Patient_1" "Patient_2" "Patient_3" "Patient_4" "Patient_5"

Q21. What Happens in a Mixed Vector?

mixed_vector <- c("TP53", 100, TRUE)
class(mixed_vector)
## [1] "character"
mixed_vector
## [1] "TP53" "100"  "TRUE"

Q22. Convert a Character to Numeric

as.numeric("150")
## [1] 150

Q23. Addition with Mixed Types (Fails)

x <- 5
y <- "6"
x + y
## Error in `x + y`:
## ! non-numeric argument to binary operator

it fail because we are adding number to string/character.

Q24. Fix the Error and Add

x <- 5
y <- "6"
x + as.numeric(y)
## [1] 11

Q25. Filter Genes with High Expression

counts <- c(TP53 = 120, BRCA1 = 90, EGFR = 310)
counts[counts > 100]
## TP53 EGFR 
##  120  310