#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

Seq_1<-500000
Seq_2<-600000
Seq_1*Seq_2
## [1] 3e+11

#Q3. Calculate Fold-Change in Expression

Gene_X_control<-300
Gene_X_treated<-150

Gene_X_foldchange<-c(Gene_X_control/Gene_X_treated)
Gene_X_foldchange
## [1] 2

#Q4. Remainder of Reads per Lane

Sample_reads<-1001000
reads_per_lane<-250000
Remainder_per_lane<-Sample_reads%%reads_per_lane
Remainder_per_lane
## [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
Total_count<-Patient_A+Patient_b
Total_count
## [1] 220

#Q7. Update a Mistaken Value

Patient_A<-100
Patient_B_updated<-130
Updated_Total_count<-Patient_A+Patient_B_updated
Updated_Total_count
## [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

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

#Q11. Logical Flag for Marker Gene

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

#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")

#Q14.Print the Named Vector

counts
##  TP53 BRCA1  EGFR 
##   120   150   130

#Q15. Extract One Gene’s Count

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

#Q16. Extract the First Two Genes

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

#Q17. Create Sample Names

vector<-c("Sample1","Sample2","Sample3")
vector
## [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?

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

#Q22. Convert a Character to Numeric

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

#Q23. Addition with Mixed Types (Fails)

x <- 5
y <- "6"
#x + y

#Q24. Fix the Error and Add

Y<-as.numeric(y)
x+Y
## [1] 11

#Q25. Filter Genes with High Expression

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