Spaces:
Sleeping
Sleeping
File size: 3,811 Bytes
436f829 aefe3f5 436f829 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | # Install required packages
#install.packages("reshape2")
#if (!requireNamespace("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
#BiocManager::install("BSgenome")
#BiocManager::install("BSgenome.Hsapiens.UCSC.hg19")
#BiocManager::install("GenomeInfoDb")
#BiocManager::install("deconstructSigs")
# Install required Bioconductor packages if not already installed
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
# Check and install `deconstructSigs` if not already installed
if (!requireNamespace("deconstructSigs", quietly = TRUE))
BiocManager::install("deconstructSigs")
# Load the package
library(deconstructSigs)
# Set the data source variable
data_source <- "GENIE" # Change this to either "DFCI" or "GENIE" based on your data source
# Read mutation data based on data source
if (data_source == "DFCI") {
setwd("~/Documents/github/onconpc/data/seq_panel_data/dfci/")
mutationData <- read.csv('profile_mutation_dfci', header = TRUE, sep="\t")
} else if (data_source == "GENIE") {
mutationData <- read.csv('data_mutations_extended_5.0-public.txt', sep="\t",
comment.char="#", header=TRUE, fill=TRUE)
mutationData <- subset(mutationData, Center %in% c('DFCI', 'MSK', 'VICC'))
}
# Add "chr" prefix to each chromosome name
if (data_source == "GENIE") {
mutationData[,"CHROMOSOME"] <- paste0("chr", mutationData[,"Chromosome"])
}
# Filter out specific chromosomes
mutationData <- mutationData[!grepl("GL|chrMT", mutationData[,"CHROMOSOME"]), ]
unique(mutationData[,"CHROMOSOME"])
# Convert to deconstructSigs input format based on data source
head(mutationData)
if (data_source == "DFCI") {
sigs.input <- mut.to.sigs.input(mut.ref = mutationData,
sample.id = "UNIQUE_SAMPLE_ID", # type: str
chr = "CHROMOSOME",
pos = "POSITION",
ref = "REF_ALLELE",
alt = "ALT_ALLELE")
} else if (data_source == "GENIE") {
sigs.input <- mut.to.sigs.input(mut.ref = mutationData,
sample.id = "Tumor_Sample_Barcode", # type: str
chr = "CHROMOSOME",
pos = "Start_Position",
ref = "Reference_Allele",
alt = "Tumor_Seq_Allele2")
}
# Filter samples with low mutations
sigs.input <- sigs.input[rowSums(sigs.input) >= 1,]
# Set filename variable for saving output
if (data_source == "DFCI") {
filename <- "trinucs_dfci_profile.csv" # Modify this as needed
} else if (data_source == "GENIE") {
filename <- "trinucs_genie.csv"
}
# Save the output
write.csv(sigs.input, file = filename)
# ===================== [OPTIONAL] =====================
# Visualization of trinucs
trinucs_selected <- sigs.input
results <- vector("list", nrow(trinucs_selected))
names(results) <- row.names(trinucs_selected)
# Select the first 10 samples
subset_data <- head(trinucs_selected, 10)
# run the estimation of exposures for each sample and save the results in the list
for( sID in row.names(subset_data) ){
results[[sID]] <- whichSignatures(subset_data, # the matrix generated with mut.to.sigs.input
sample.id=sID, # the current sample ID
signatures.ref=signatures.cosmic, # the data.frame with the signatures that comes with deconstructSigs
tri.counts.method="exome2genome", # which normalization method to use
contexts.needed=TRUE) # set to TRUE if your input matrix contains counts instead of frequencies
}
plotSignatures(results[[1]])
|