Methods
Gene Fusions identification and differential expression analysis
We employed two Gene Fusions(GFs) detection tools, including arriba, STAR-Fusion, to identify, parse, and annotate GFs junctions within each sample, using the human genome version hg38 as the reference. In our pursuit of biologically robust GFs identification within each cohort, we undertook an approach metafusion that amalgamated results from two GFs detection tools. Firstly, we exclusively retained Fusions located on chromosomes 1 to 22, as well as the X and Y chromosomes. Secondly, GFs were mandated to exhibit genomic overlap with gene regions as defined in the reference genome annotation file, specifically “gencode.v34.annotation.gtf.”. Thirdly to ensure the precision and recall in GFs prediction with different tools, one can either rely on consensus predictions or all predctions and choosing junction-crossing reads and reads mates which flank (span) the breakpoint. Fourthly, we offer FusionAnnotator to identify and prioritize GFs that have been previously reported in cancer or normal samples. Lastly, the detected data can be divided into Cis-SAGes and other categories to further explore the debate on what should be considered true fusion RNAs. This meticulous methodological approach was instrumental in ensuring the acquisition of biologically sound and reliable GFs datasets, thereby fortifying the integrity of our analysis within each cohort. This analysis facilitated comparisons between patient groups, such as those who responded to checkpoint immunotherapy versus non-responders, as well as between samples collected before and during ICB treatment.
Response and Response2
We gathered and processed patient ‘Response’ data from various cohorts. However, due to inconsistencies among these cohorts, such as the usage of different terms like CR, PR, SD, PD, R, NR, DCB, and NDB, we harmonized the response variable based on the timing of treatment and treatment response. As a result, we introduced a new variable called ‘Response2’ with four distinct categories: Pre-R, Pre-NR, On-R, and On-NR. In cases where response data was not available, we assigned the category NE.
Because raw Response labels are not uniform across cohorts, the app reports two analyses. The binary analysis uses the harmonised Response2 pre-treatment categories (Pre-R vs Pre-NR). The RECIST analysis retains only records explicitly coded as CR, PR, SD, or PD (CR/PR = response; SD/PD = no response) and excludes NE and non-RECIST labels such as R/NR, CB/NCB, and Responder/Non-responders. Cohorts with no evaluable RECIST contrast are reported as such rather than being classified by a fallback rule. For the binary analysis, the odds ratio compares the odds of response in Fusion+ versus Fusion- patients, so OR > 1 indicates higher response odds in Fusion+ patients.
Analysis units
The platform distinguishes four units that are not interchangeable:
- Fusion calls (records): one detected fusion in one sample. Home and Data Summary report 98,281 calls.
- Unique Fusion IDs: calls sharing the same head/tail gene combination and genomic loci are merged; there are 76,803 unique Fusion IDs.
- Samples: unique clinical samples (20,995). Composition/IOBR comparisons and frequency proportions use samples; frequency proportions use all analysed clinical samples in the cohort as the denominator, not only fusion-positive samples.
- Patients: one record per patient. Correlation, response, gene co-occurrence, KM, and Cox analyses use patients; a patient is Fusion+ when any of their samples carries the relevant fusion.
Comma-separated gene lists (e.g. A,B::C, common in Arriba output) are expanded before gene and pair counting, so such a call contributes to both A::C and B::C. Gene-level frequency counts distinct calls containing the gene, not occurrences (a SameGene call lists the gene on both sides).
For survival analyses, each patient contributes one clinical record. When multiple records exist, the record with an event for the endpoint being analysed is preferred, then longer follow-up for that endpoint; an OS event therefore cannot displace a PFS progression record in a PFS analysis. Survival-time units are inferred per cohort rather than assumed: a cohort is labelled in months only when both the median and maximum observed OS_Time are below 150; otherwise the day scale is used.
TME and IOBR feature comparisons can be run at the sample level or aggregated to the patient level. In patient mode, the selected feature is averaged across each patient’s samples and a patient is Fusion+ when any sample is Fusion+, which removes within-patient pseudoreplication. Both modes require at least two non-missing observations in each fusion group; a feature with a single observation in either group is reported as not testable rather than given a p-value.
In survival analyses, a group with zero observed events makes the hazard ratio non-estimable but does not invalidate the Kaplan-Meier curves or the log-rank test; the panel reports the HR as not estimable and continues to show both.
Filter semantics
Cohort groups and cohorts are linked with any-overlap semantics: a group is checked when at least one of its cohorts is selected, and narrowing groups narrows the cohort choices. Selecting nothing is equivalent to selecting everything, both in the global modal and in page-level cohort pickers. Treatment-status and pre-treatment filters apply within ICB cohorts only; non-ICB cohorts are unaffected. The global filters define the call set and therefore the Fusion+ vs Fusion− grouping; page-level selectors narrow the data further. A context bar on each filter-aware page lists the active selections, while effective post-filter counts are reported in the panel results.
Co-occurrence versus interaction
The Gene Co-occurrence panel performs Fisher exact tests on patient-level fusion presence for each gene pair, reporting odds ratios and FDR-adjusted p-values. A significant result indicates statistical co-occurrence or mutual exclusivity across patients; it does not establish physical, structural, or functional interaction between the genes.
Cancer Type Abbreviation
| Abbr. | Description |
|---|---|
| BLCA | Bladder urothelial carcinoma |
| SKCM | Skin cutaneous melanoma |
| KIRC & CCRCC | Kidney renal clear cell carcinoma |
| HNSC & HNSCC | Head and neck squamous cell carcinoma |
| NSCLC | Non-small cell lung cancer, including lung adenocarcinoma and lung squamous cell carcinoma |
| SCLC | Small cell lung cancer |
| SARC | Sarcoma |
| BRCA | Breast cancer |
| GBM | Glioblastoma Multiforme |
| STAD | Stomach Adenocarcinoma |
| SGC | Salivary gland cancer |
| LUSC | Lung Squamous Cell Carcinoma |
| MESO | Mesothelioma |
| PCPG | Pheochromocytoma and Paraganglioma |
| LIHC | Liver Hepatocellular Carcinoma |
| PRAD | Prostate Adenocarcinoma |
| ACC | Adrenocortical Carcinoma |
| TGCT | Testicular Germ Cell Tumors |
| PAAD | Pancreatic Adenocarcinoma |
| UCEC | Uterine Corpus Endometrial Carcinoma |
| THCA | Thyroid carcinoma |
| CESC | Cervical squamous cell carcinoma and endocervical adenocarcinoma |
| ESCA | Esophageal carcinoma |
| READ | Rectum adenocarcinoma |
| OV | Ovarian Serous Cystadenocarcinoma |
| CHOL | Cholangiocarcinoma |
| UCS | Uterine Carcinosarcoma |
| LUAD | Lung Adenocarcinoma |
| LGG | Brain Lower Grade Glioma |
| HGSC | High-Grade Serous Carcinoma |
| LSCC & LUSC | Lung Squamous Cell Carcinoma |
| PDAC | Pancreatic Ductal Adenocarcinoma |
| THYM | Thymoma |
| KICH | Kidney Chromophobe |
| KIRP | Kidney Renal Papillary Cell Carcinoma |
| COAD | Colon Adenocarcinoma |
| LAML & AML | Acute Myeloid Leukemia |
| NBL | Neuroblastoma |
| GNB | Ganglioneuroblastoma |
ImmunoFusion cohort naming maping
| Cancer | Sample_type | Project_id | Immunofusion-cohort |
|---|---|---|---|
| BRCA | Primary Tumor | CPTAC-2 | CPTAC-BRCA |
| COAD | Primary Tumor | CPTAC-2 | CPTAC-COAD |
| HGSC | Primary Tumor | CPTAC-2 | CPTAC-OV |
| LSCC | Primary Tumor | CPTAC-3 | CPTAC-LUSC |
| UCEC | Primary Tumor | CPTAC-3 | CPTAC-UCEC |
| LUAD | Primary Tumor | CPTAC-3 | CPTAC-LUAD |
| GBM | Primary Tumor | CPTAC-3 | CPTAC-GBM |
| HNSCC | Primary Tumor | CPTAC-3 | CPTAC-HNSC |
| CCRCC | Primary Tumor | CPTAC-3 | CPTAC-KIRC |
| PDAC | Primary Tumor | CPTAC-3 | CPTAC-PAAD |
| PDAC | Solid Tissue Normal | CPTAC-3 | CPTAC-NORMAL |
| LUAD | Solid Tissue Normal | CPTAC-3 | CPTAC-NORMAL |
| UCEC | Solid Tissue Normal | CPTAC-3 | CPTAC-NORMAL |
| CCRCC | Solid Tissue Normal | CPTAC-3 | CPTAC-NORMAL |
| HNSCC | Solid Tissue Normal | CPTAC-3 | CPTAC-NORMAL |
| LSCC | Solid Tissue Normal | CPTAC-3 | CPTAC-NORMAL |
| GTEX-Brain | Solid Tissue Normal | CPTAC-3 | CPTAC-NORMAL |
| – | Primary Blood Derived Cancer - Peripheral Blood/Recurrent Blood Derived Cancer - Peripheral Blood/Next Generation Cancer Model/Recurrent Blood Derived Cancer - Bone Marrow/Primary Blood Derived Cancer - Bone Marrow | TARGET-AML | TARGET-LAML |
| Acute myeloid leukemia, NOS | Primary Blood Derived Cancer - Bone Marrow/Recurrent Blood Derived Cancer - Bone Marrow/Primary Blood Derived Cancer - Peripheral Blood/ Blood Derived Cancer - Bone Marrow/Post-treatment/Recurrent Blood Derived Cancer - Peripheral Blood/ Blood Derived Cancer - Peripheral Blood | TARGET-AML | TARGET-LAML |
| Neuroblastoma, NOS | Primary Tumor/Recurrent Tumor/Recurrent Blood Derived Cancer - Bone Marrow | TARGET-NBL | TARGET-NBL |
| Ganglioneuroblastoma | Primary Tumor/Recurrent Tumor | TARGET-NBL | TARGET-GNB |
| – | Cell Lines / Next Generation Cancer Model | TARGET-AML | TARGET-CELL |
| – | Bone Marrow Normal | TARGET-AML | TARGET-NORMAL |
| Acute myeloid leukemia, NOS | Blood Derived Normal/Bone Marrow Normal | TARGET-AML | TARGET-NORMAL |
| ACC | Primary Tumor | TCGA-ACC | TCGA-ACC |
| BLCA | Primary Tumor | TCGA-BLCA | TCGA-BLCA |
| BRCA | Primary Tumor | TCGA-BRCA | TCGA-BRCA |
| BRCA | Metastatic | TCGA-BRCA | TCGA-BRCA |
| CESC | Primary Tumor | TCGA-CESC | TCGA-CESC |
| CESC | Metastatic | TCGA-CESC | TCGA-CESC |
| CHOL | Primary Tumor | TCGA-CHOL | TCGA-CHOL |
| COAD | Primary Tumor | TCGA-COAD | TCGA-COAD |
| COAD | Recurrent Tumor | TCGA-COAD | TCGA-COAD |
| COAD | Metastatic | TCGA-COAD | TCGA-COAD |
| DLBC | Primary Tumor | TCGA-DLBC | TCGA-DLBC |
| ESCA | Primary Tumor | TCGA-ESCA | TCGA-ESCA |
| ESCA | Metastatic | TCGA-ESCA | TCGA-ESCA |
| GBM | Primary Tumor | TCGA-GBM | TCGA-GBM |
| GBM | Recurrent Tumor | TCGA-GBM | TCGA-GBM |
| HNSC | Primary Tumor | TCGA-HNSC | TCGA-HNSC |
| HNSC | Metastatic | TCGA-HNSC | TCGA-HNSC |
| KICH | Primary Tumor | TCGA-KICH | TCGA-KICH |
| KIRC | Primary Tumor | TCGA-KIRC | TCGA-KIRC |
| KIRC | Additional - New Primary | TCGA-KIRC | TCGA-KIRC |
| KIRP | Primary Tumor | TCGA-KIRP | TCGA-KIRP |
| KIRP | Additional - New Primary | TCGA-KIRP | TCGA-KIRP |
| LAML | Primary Blood Derived Cancer - Peripheral Blood | TCGA-LAML | TCGA-LAML |
| LGG | Primary Tumor | TCGA-LGG | TCGA-LGG |
| LGG | Recurrent Tumor | TCGA-LGG | TCGA-LGG |
| LIHC | Primary Tumor | TCGA-LIHC | TCGA-LIHC |
| LIHC | Recurrent Tumor | TCGA-LIHC | TCGA-LIHC |
| LUAD | Primary Tumor | TCGA-LUAD | TCGA-LUAD |
| LUAD | Recurrent Tumor | TCGA-LUAD | TCGA-LUAD |
| LUSC | Primary Tumor | TCGA-LUSC | TCGA-LUSC |
| MESO | Primary Tumor | TCGA-MESO | TCGA-MESO |
| OV | Primary Tumor | TCGA-OV | TCGA-OV |
| OV | Recurrent Tumor | TCGA-OV | TCGA-OV |
| PAAD | Primary Tumor | TCGA-PAAD | TCGA-PAAD |
| PAAD | Metastatic | TCGA-PAAD | TCGA-PAAD |
| PCPG | Primary Tumor | TCGA-PCPG | TCGA-PCPG |
| PCPG | Additional - New Primary | TCGA-PCPG | TCGA-PCPG |
| PCPG | Metastatic | TCGA-PCPG | TCGA-PCPG |
| PRAD | Primary Tumor | TCGA-PRAD | TCGA-PRAD |
| PRAD | Metastatic | TCGA-PRAD | TCGA-PRAD |
| READ | Primary Tumor | TCGA-READ | TCGA-READ |
| READ | Recurrent Tumor | TCGA-READ | TCGA-READ |
| SARC | Primary Tumor | TCGA-SARC | TCGA-SARC |
| SARC | Recurrent Tumor | TCGA-SARC | TCGA-SARC |
| SARC | Metastatic | TCGA-SARC | TCGA-SARC |
| SKCM | Metastatic | TCGA-SKCM | TCGA-SKCM |
| SKCM | Primary Tumor | TCGA-SKCM | TCGA-SKCM |
| SKCM | Additional Metastatic | TCGA-SKCM | TCGA-SKCM |
| STAD | Primary Tumor | TCGA-STAD | TCGA-STAD |
| TGCT | Primary Tumor | TCGA-TGCT | TCGA-TGCT |
| TGCT | Additional - New Primary | TCGA-TGCT | TCGA-TGCT |
| THCA | Primary Tumor | TCGA-THCA | TCGA-THCA |
| THCA | Metastatic | TCGA-THCA | TCGA-THCA |
| THYM | Primary Tumor | TCGA-THYM | TCGA-THYM |
| UCEC | Primary Tumor | TCGA-UCEC | TCGA-UCEC |
| UCEC | Recurrent Tumor | TCGA-UCEC | TCGA-UCEC |
| UCS | Primary Tumor | TCGA-UCS | TCGA-UCS |
| UVM | Primary Tumor | TCGA-UVM | TCGA-UVM |
| BLCA | Solid Tissue Normal | TCGA-BLCA | TCGA-NORMAL |
| BRCA | Solid Tissue Normal | TCGA-BRCA | TCGA-NORMAL |
| CESC | Solid Tissue Normal | TCGA-CESC | TCGA-NORMAL |
| CHOL | Solid Tissue Normal | TCGA-CHOL | TCGA-NORMAL |
| COAD | Solid Tissue Normal | TCGA-COAD | TCGA-NORMAL |
| ESCA | Solid Tissue Normal | TCGA-ESCA | TCGA-NORMAL |
| HNSC | Solid Tissue Normal | TCGA-HNSC | TCGA-NORMAL |
| KICH | Solid Tissue Normal | TCGA-KICH | TCGA-NORMAL |
| KIRC | Solid Tissue Normal | TCGA-KIRC | TCGA-NORMAL |
| KIRP | Solid Tissue Normal | TCGA-KIRP | TCGA-NORMAL |
| LIHC | Solid Tissue Normal | TCGA-LIHC | TCGA-NORMAL |
| LUAD | Solid Tissue Normal | TCGA-LUAD | TCGA-NORMAL |
| LUSC | Solid Tissue Normal | TCGA-LUSC | TCGA-NORMAL |
| PAAD | Solid Tissue Normal | TCGA-PAAD | TCGA-NORMAL |
| PCPG | Solid Tissue Normal | TCGA-PCPG | TCGA-NORMAL |
| PRAD | Solid Tissue Normal | TCGA-PRAD | TCGA-NORMAL |
| READ | Solid Tissue Normal | TCGA-READ | TCGA-NORMAL |
| SARC | Solid Tissue Normal | TCGA-SARC | TCGA-NORMAL |
| SKCM | Solid Tissue Normal | TCGA-SKCM | TCGA-NORMAL |
| STAD | Solid Tissue Normal | TCGA-STAD | TCGA-NORMAL |
| THCA | Solid Tissue Normal | TCGA-THCA | TCGA-NORMAL |
| THYM | Solid Tissue Normal | TCGA-THYM | TCGA-NORMAL |
| UCEC | Solid Tissue Normal | TCGA-UCEC | TCGA-NORMAL |
Fusion calls label TARGET-CELL samples as Cell_Model. The group covers cell lines and next-generation cancer models, including endothelial, cord-blood, HEK293 and engineered fusion-cell models, which are not all tumor-derived. Earlier files used the legacy label Tumor_Cell; the app maps it to Cell_Model for display without modifying the database.
Clinical data preprocessing
TCGA
library(data.table)
library(dplyr)
# load("/home/data2/Projects/Fusion/unclean/TCGA_ALL_clinical.rdata")
#
# TCGA_ALL_clinical |>
# rename(Patient_ID = bcr_patient_barcode,
# Age = age_at_initial_pathologic_diagnosis,
# Sex = gender,
# Race = race,
# )
# [Discrepancy] [Not Applicable] [Not Available]
# [Discrepancy] [Not Available] [Unknown]
# # [Discrepancy] [Not Applicable]
# 29 105
# [Not Available] [Not Evaluated]
# 5140 4
# [Unknown]
library(UCSCXenaShiny)
table(tcga_clinical_fine$Stage_ajcc)
tcga_clinical
tcga_clinical_fine
tcga_genome_instability
tcga_purity
tcga_subtypes
tcga_surv
nrow(tcga_clinical_fine)
nrow(unique(tcga_clinical_fine))
tcga_clinical = unique(tcga_clinical_fine) |>
left_join(tcga_surv, by = c("Sample"="sample")) |>
left_join(tcga_purity, by = c("Sample"="sample"))
tcga_clinical[551, ]$Sample
sum(startsWith(tcga_genome_instability$sample, "TCGA"))
tcga_clinical = tcga_clinical |>
left_join(tcga_genome_instability[startsWith(tcga_genome_instability$sample, "TCGA") & !duplicated(tcga_genome_instability$sample), ], by = c("Sample"="sample")) |>
#left_join(tcga_genome_instability[duplicated(tcga_genome_instability$sample), ], by = c("Sample"="sample")) |>
left_join(tcga_subtypes, by = c("Sample"="sampleID"))
sum(is.na(tcga_clinical$Sample))
sum(duplicated(tcga_clinical$Sample))
tcga_clinical[duplicated(tcga_clinical$Sample), ]$Sample
tcga_clinical.final = tcga_clinical[!duplicated(tcga_clinical$Sample), ] |>
rename(Sample_ID = Sample, Sex = Gender, OS_Time = OS.time, OS_Status = OS, DSS_Time = DSS.time, DSS_Status = DSS, DFS_Time = DFI.time, DFS_Status = DFI, PFS_Time = PFI.time, PFS_Status = PFI) |>
select(-cancer_type) |>
mutate(Sex = ifelse(Sex == "FEMALE", "F", "M"),
Patient_ID = substr(Sample_ID, 1, 12))
sum(is.na(tcga_clinical.final$Sample_ID))
sum(is.na(tcga_clinical.final$Cancer))
sum(duplicated(tcga_clinical.final$Sample_ID))
tcga_clinical.final = tcga_clinical.final |>
select(Patient_ID, Sample_ID, everything()) |>
as.data.table()
tcga_clinical.final
fwrite(tcga_clinical.final, file = "/home/data2/Projects/Fusion/fusiondb/Clininfo/TCGA_info.tsv", sep = "\t")CPTAC
library(data.table)
# Clinical data from CPTAC paper ------------------------------------------
cli_list = fs::dir_ls("CPTAC_Clinical_meta_data_v1/")
cli = purrr::map(cli_list, fread) |> rbindlist(fill = TRUE, use.names = TRUE)
colnames(cli)
# Problem: Need to skip the second row
# This also includes samples from CPTAC-2/3, but the total number is fewer
cli2 = purrr::map(cli_list, function(x) {
# Since the column names are also different, read them twice—once for the column names and once for the data
data1 = fread(x)
data2 = fread(x, skip = 2, header = FALSE)
# Update the column names
colnames(data2) = colnames(data1)
data2$Cancer = stringr::str_remove(basename(x), "_meta.txt")
data2 |> as.data.table()
}) |> rbindlist(fill = TRUE, use.names = TRUE)
#colnames(cli2) = colnames(cli)
colnames(cli2)
cli2[Tumor == "Yes" & Normal == "Yes"] # This is to mark whether the patient has both tumor and normal samples
cli_list2 = fs::dir_ls("meta_data_BCM/")
cli3 = purrr::map(cli_list2, function(x) {
# Since the column names are also different, read them twice—once for the column names and once for the data
data1 = fread(x)
data2 = fread(x, skip = 2, header = FALSE)
# 更新列名
colnames(data2) = colnames(data1)
data2$Cancer = stringr::str_remove(basename(x), "_meta.txt")
data2 |> as.data.table()
}) |> rbindlist(fill = TRUE, use.names = TRUE)
colnames(cli3)
all.equal(cli2, cli3)
all.equal(sort(colnames(cli2)), sort(colnames(cli3)))
cli4 = cli3[, colnames(cli2), with = FALSE]
all.equal(cli2, cli4)
identical(cli2, cli4)
dplyr::setdiff(cli2, cli4) |> View()
dplyr::setdiff(cli4, cli2) |> nrow()
# rbind(cli2[idx == "01OV007"],
# cli4[idx == "01OV007"]) |> View()
# The files in the directories of the two data sources are basically identical
cli.final = cli2 |>
dplyr::rename(
Patient_ID = idx,
OS_Status = OS_event,
OS_Time = OS_days,
PFS_Status = PFS_event,
PFS_Time = PFS_days
) |>
dplyr::mutate(
Sample_ID = Patient_ID,
Sex = ifelse(Sex == "Female", "F", "M")
) |>
dplyr::select(
Patient_ID, Sample_ID, Cancer, Age, Sex, OS_Time, OS_Status, PFS_Time, PFS_Status, dplyr::everything()
)
# dplyr::select(
# - dplyr::starts_with("CIBERSORT"), - dplyr::starts_with("xCell")
# )
fwrite(cli.final, file = "CPTAC_cli_paper_combined.tsv", sep = "\t")
# Clinical data from GDC --------------------------------------------------
system("
cd /home/data2/Projects/Fusion/unclean/gdc_cli/CPTAC
mkdir CPTAC-3 CPTAC-2
tar zxvf clinical.project-cptac-2.2024-08-07.tar.gz -C CPTAC-2
tar zxvf clinical.project-cptac-3.2024-08-07.tar.gz -C CPTAC-3
")
cptac2 = fread("gdc_cli/CPTAC/CPTAC-2/clinical.tsv")
cptac3 = fread("gdc_cli/CPTAC/CPTAC-3/clinical.tsv")
which(colnames(cptac2) %in% "residual_disease")
which(colnames(cptac3) %in% "residual_disease")
all.equal(cptac2[[119]], cptac2[[192]])
all.equal(cptac3[[119]], cptac3[[192]])
cptac2[[192]] = NULL
cptac3[[192]] = NULL
setdiff(cptac2$case_submitter_id, cli.final$Sample_ID)
setdiff(cptac3$case_submitter_id, cli.final$Sample_ID)
# > setdiff(cptac2$case_submitter_id, cli.final$Sample_ID)
# [1] "01OV049" "26OV010" "100004028" "05BR058" "05BR055" "17OV019" "11BR069" "02OV042" "100004012" "05BR051" "03BR012" "02OV045" "04OV041"
# [14] "05BR052" "05BR031" "1488" "11OV009" "02OV040" "01OV002" "100002921" "22OV001" "13OV004" "100003304" "02OV035" "01OV046" "01OV045"
# [27] "17OV034"
# > setdiff(cptac3$case_submitter_id, cli.final$Sample_ID)
# [1] "C3N-02672" "C3L-01929" "C3N-02682" "C3N-02012" "C3N-02070"
# [6] "C3N-02696" "C3L-02354" "C3N-03026" "C3L-01739" "C3N-02088"
# [11] "C3L-04213" "C3N-03205" "C3L-04081" "C3N-03791" "C3L-03679"
# [16] "C3L-02643" "C3N-04686" "C3L-01558" "C3L-03268" "C3L-01633"
# [21] "C3L-02220" "C3N-02439" "C3N-02028" "C3N-03800" "C3L-04392"
# [26] "C3L-02556" "C3N-02721" "C3L-01672" "C3L-00938" "C3L-02201"
# [31] "C3N-02146" "C3N-02639" "C3N-03788" "C3L-03733" "C3L-04037"
# [36] "C3N-01091" "C3L-02747" "C3N-01879" "C3N-02996" "C3N-02296"
# [41] "C3L-02553" "C3L-03632" "C3N-03755" "GTEX-NPJ7-0011-R10A-SM-HAKXW" "C3L-02746"
length(setdiff(cptac3$case_submitter_id, cli.final$Sample_ID)) # 586
View(cptac2[case_submitter_id %in% setdiff(cptac2$case_submitter_id, cli.final$Sample_ID)])
View(cptac3[case_submitter_id %in% setdiff(cptac3$case_submitter_id, cli.final$Sample_ID)])
data.table::fwrite(
cptac3[case_submitter_id %in% setdiff(cptac3$case_submitter_id, cli.final$Sample_ID)],
file = "CPTAC3_non_included.tsv", sep = "\t"
)
cptac3
# Supplement the missing sample information in the paper based on the existing information in the GDC. ---------------------------------------------
# might be columns that have labeled cancer types.
# primary_diagnosis site_of_resection_or_biopsy tissue_or_organ_of_origin
cptac = rbind(cptac2, cptac3)[, .(case_submitter_id, primary_diagnosis, site_of_resection_or_biopsy, tissue_or_organ_of_origin)] |> unique()
cptac = dplyr::left_join(cptac, cli.final[, .(Sample_ID, Cancer)], by = c("case_submitter_id"="Sample_ID"))
setdiff(cli.final$Sample_ID, cptac$case_submitter_id)
# 29 cases are not in the GDC data.
table(cptac$Cancer, cptac$primary_diagnosis) |> pheatmap::pheatmap()
table(cptac$Cancer, cptac$site_of_resection_or_biopsy) |> pheatmap::pheatmap()
table(cptac$Cancer, cptac$tissue_or_organ_of_origin) |> pheatmap::pheatmap()
table(cptac$Cancer,
paste(
cptac$primary_diagnosis,
cptac$site_of_resection_or_biopsy,
cptac$tissue_or_organ_of_origin, sep = "_"
)) |> pheatmap::pheatmap(show_colnames = FALSE)
# Solve them one by one.
cat(sub("_meta.txt", "", basename(names(cli_list))))
typelist = sub("_meta.txt", "", basename(names(cli_list)))
# BRCA CCRCC COAD GBM HGSC HNSCC LSCC LUAD PDAC UCEC
for (i in typelist) {
message("check type ", i)
cptac_part = cptac |> dplyr::filter(Cancer == i)
message(" primary_diagnosis")
table(cptac_part$Cancer, cptac_part$primary_diagnosis) |> print()
message(" site_of_resection_or_biopsy")
table(cptac_part$Cancer, cptac_part$site_of_resection_or_biopsy) |> print()
message(" tissue_or_organ_of_origin")
table(cptac_part$Cancer, cptac_part$tissue_or_organ_of_origin) |> print()
}
# BRCA (122): tissue_or_organ_of_origin "Breast, NOS"
# CCRCC (103): primary_diagnosis "Renal cell carcinoma, NOS"
# tissue_or_organ_of_origin "Kidney, NOS"
# COAD (106): tissue_or_organ_of_origin "Colon, NOS", "Rectum, NOS"
# GBM (99): primary_diagnosis "Glioblastoma"
# HGSC (87): primary_diagnosis "Serous adenocarcinoma, NOS" AND
# tissue_or_organ_of_origin Fallopian tube Ovary Peritoneum, NOS
# HNSCC (108): Other situation: primary_diagnosis "Squamous cell carcinoma, NOS"
# Base of tongue, NOS Cheek mucosa Floor of mouth, NOS Gum, NOS
# HNSCC 1 2 18 3
#
# Head, face or neck, NOS Larynx, NOS Lip, NOS Oropharynx, NOS
# HNSCC 2 47 4 4
#
# Overlapping lesion of lip, oral cavity and pharynx Tongue, NOS Tonsil, NOS
# HNSCC
# LSCC (108): primary_diagnosis "Squamous cell carcinoma, NOS" AND
# tissue_or_organ_of_origin "lung" pattern
# LUAD (110): primary_diagnosis "Adenocarcinoma, NOS" AND
# tissue_or_organ_of_origin "lung" pattern
# PDAC (105): tissue_or_organ_of_origin "pancreas" pattern
# UCEC (95): primary_diagnosis "Endometrioid adenocarcinoma, NOS"
sum(!is.na(cptac$Cancer))
# rbind(cptac2, cptac3)[,192] # There are duplicate columns, need to go back and handle this earlier (fixed).
# Actual testing and updating
cptac_updated = rbind(cptac2, cptac3) |>
unique() |>
dplyr::mutate(
Cancer = dplyr::case_when(
tissue_or_organ_of_origin %in% "Breast, NOS" ~ "BRCA",
primary_diagnosis %in% "Renal cell carcinoma, NOS" ~ "CCRCC",
tissue_or_organ_of_origin %in% c("Colon, NOS", "Rectum, NOS") ~ "COAD",
grepl("Glioblastoma", primary_diagnosis, ignore.case = TRUE) | grepl("Oligodendroglioma", primary_diagnosis, ignore.case = TRUE) ~ "GBM",
grepl("GTEX", case_submitter_id, ignore.case = TRUE) ~ "GTEX-Brain",
case_submitter_id %in% c("C3L-06912", "C3L-07212") ~ "GBM",
#primary_diagnosis %in% "Glioblastoma" ~ "GBM",
primary_diagnosis %in% "Serous adenocarcinoma, NOS" & tissue_or_organ_of_origin %in% c("Fallopian tube", "Ovary", "Peritoneum, NOS") ~ "HGSC",
primary_diagnosis %in% "Squamous cell carcinoma, NOS" & grepl("lung", tissue_or_organ_of_origin, ignore.case = TRUE) ~ "LSCC",
primary_diagnosis %in% "Adenocarcinoma, NOS" & grepl("lung", tissue_or_organ_of_origin, ignore.case = TRUE) ~ "LUAD",
grepl("pancreas", tissue_or_organ_of_origin, ignore.case = TRUE) ~ "PDAC",
primary_diagnosis %in% "Endometrioid adenocarcinoma, NOS" ~ "UCEC",
TRUE ~ "HNSCC"
)
) |> as.data.table()
for (i in "HNSCC") { # typelist
message("check type ", i)
cptac_part = cptac_updated |> dplyr::filter(Cancer == i)
message(" primary_diagnosis")
table(cptac_part$Cancer, cptac_part$primary_diagnosis) |> print()
message(" site_of_resection_or_biopsy")
table(cptac_part$Cancer, cptac_part$site_of_resection_or_biopsy) |> print()
message(" tissue_or_organ_of_origin")
table(cptac_part$Cancer, cptac_part$tissue_or_organ_of_origin) |> print()
}
table(cptac$Cancer)
table(cptac_updated$Cancer)
cptac_updated |>
dplyr::filter(
primary_diagnosis == "'--" | site_of_resection_or_biopsy == "'--" |
tissue_or_organ_of_origin %in% c("'--", "Unknown")
)
# 1-9 from GTEX-Brain
# C3L-06912 C3L-07212 Gliomas # https://portal.gdc.cancer.gov/cases/e6027623-a5b2-4d82-a9ca-f37c948dd3ed
cptac_updated$case_submitter_id[grepl("GTEX", cptac_updated$case_submitter_id)]
nrow(cptac_updated)
fwrite(cptac_updated, file = "CPTAC_combined_with_cancer_annotated.tsv", sep = "\t")
cptac_unmatched = cptac_updated[! case_submitter_id %in% cli.final$Sample_ID]
colnames(cptac_unmatched)
colnames(cli.final)[1:20]
cptac_unmatched2 = cptac_unmatched |>
dplyr::select(
case_submitter_id, age_at_diagnosis, gender,
days_to_death, vital_status,
dplyr::starts_with("ajcc"),
dplyr::starts_with("days"),
last_known_disease_status, progression_or_recurrence, residual_disease,
tumor_grade, Cancer
)
sum(cptac_unmatched2$days_to_last_follow_up != "'--")
sum(cptac_unmatched2$days_to_death != "'--")
sum(cptac_unmatched2$days_to_recurrence != "'--")
sum(cptac_unmatched2$days_to_last_known_disease_status != "'--")
sum(cptac_unmatched2$progression_or_recurrence != "'--")
sum(!is.na(cli.final$OS_Time))
sum(!is.na(cli.final$PFS_Time))
sum(cli.final$OS_Time >= cli.final$PFS_Time, na.rm = TRUE)
cli.final[cli.final$OS_Time < cli.final$PFS_Time] |> View()
sum(as.integer(cptac_unmatched2$days_to_last_follow_up) >= as.integer(cptac_unmatched2$days_to_last_known_disease_status), na.rm = TRUE)
cptac_unmatched3 = cptac_unmatched2 |>
dplyr::rename(
Sample_ID = case_submitter_id,
Age = age_at_diagnosis,
Sex = gender,
OS_Time = days_to_last_follow_up,
OS_Status = vital_status,
PFS_Time = days_to_last_known_disease_status,
PFS_Status = progression_or_recurrence,
Histologic_Grade = tumor_grade,
Path_Stage_pT = ajcc_pathologic_t,
Path_Stage_pN = ajcc_pathologic_n,
Stage = ajcc_pathologic_stage
) |>
dplyr::select(
Sample_ID, Age, Sex, OS_Time, OS_Status, PFS_Time, PFS_Status,
Path_Stage_pN:Path_Stage_pT,
Histologic_Grade, Cancer
) |>
dplyr::mutate(
Patient_ID = Sample_ID,
Age = as.integer(round(as.integer(Age) / 365)),
Sex = fcase(Sex %in% "female", "F",
Sex %in% "male", "M", default = NA_character_),
OS_Time = as.integer(OS_Time),
OS_Status = fcase(OS_Status %in% "Alive", 0L,
OS_Status %in% "Dead", 1L, default = NA_integer_),
PFS_Time = as.integer(PFS_Time),
PFS_Status = fcase(PFS_Status %in% "no", 0L,
PFS_Status %in% "yes", 1L, default = NA_integer_),
OS_Time = ifelse(OS_Time < 0, NA_integer_, OS_Time),
Path_Stage_pN = fcase(
Path_Stage_pN %in% "N0", "pN0",
Path_Stage_pN %in% c("N1", "N1a"), "pN1",
Path_Stage_pN %in% c("N2", "N2a"), "pN2",
default = NA_character_
),
Path_Stage_pT = fcase(
Path_Stage_pT %in% "T0", "pT0",
Path_Stage_pT %in% c("T1", "T1a", "T1b", "T1c"), "pT1",
Path_Stage_pT %in% c("T2", "T2a", "T2b"), "pT2",
Path_Stage_pT %in% c("T3", "T3a", "T3b"), "pT3",
Path_Stage_pT %in% "T4", "pT4",
default = NA_character_
),
Stage = fcase(
Stage %in% c("Stage I", "Stage IA", "Stage IA1", "Stage IA2", "Stage IA3", "Stage IB"), "Stage I",
Stage %in% c("Stage II", "Stage IIA", "Stage IIB"), "Stage II",
Stage %in% c("Stage III", "Stage IIIA", "Stage IIIB", "Stage IIIC", "Stage IIIC1", "Stage IIIC2"), "Stage III",
Stage %in% c("Stage IV", "Stage IVB"), "Stage IV",
default = NA_character_
),
Histologic_Grade = fcase(
Histologic_Grade %in% "G1", "G1 Well differentiated",
Histologic_Grade %in% "G2", "G2 Moderately differentiated",
Histologic_Grade %in% "G3", "G3 Poorly differentiated",
Histologic_Grade %in% "G4", "G4 Undifferentiated",
default = NA_character_
)
)
cptac_unmatched3
# X: cannot be assessed
table(cptac_unmatched3$Path_Stage_pN)
table(cli.final$Path_Stage_pN)
table(cptac_unmatched3$Path_Stage_pT)
table(cli.final$Path_Stage_pT)
table(cptac_unmatched3$Stage)
table(cli.final$Stage)
table(cptac_unmatched3$Histologic_Grade)
table(cli.final$Histologic_Grade)
# Final output ------------------------------------------------------------
cli.final.2 = dplyr::bind_rows(
cli.final, cptac_unmatched3
) |> as.data.table()
table(cli.final.2$Cancer)
sum(table(cli.final.2$Cancer))
# Include all Race information?
cli.final.2 = dplyr::left_join(
cli.final.2, unique(rbind(cptac2, cptac3)[, .(case_submitter_id, race)]),
by = c("Sample_ID"="case_submitter_id")
) |>
dplyr::mutate(
race = ifelse(race %in% c("Unknown", "not reported"), NA_character_,
race)
) |>
as.data.table()
sum(is.na(cli.final.2$race))
fwrite(cli.final.2, file = "/home/data2/Projects/Fusion/fusiondb/Clininfo/CPTAC_info.tsv", sep = "\t")TARGET
library(data.table)
cli1 = fread("TARGET_donor_allprojects_transfer_to_sample.gz")
cli2 = fread("TARGET_phenotype.gz")
target_cli = cli2 |>
dplyr::select(-`_cohort`) |>
dplyr::rename(Patient_ID = `_PATIENT`,
Sample_ID = sample_id,
disease_code = primary_disease_code,
disease = `_primary_disease`,
sample_type = `_sample_type`) |>
dplyr::full_join(
cli1 |> dplyr::select(
-`_OS_UNIT`, -`_EVENT`, -`_TIME_TO_EVENT`
) |>
dplyr::rename(
Sample_ID = xena_sample,
Sex = `_gender`,
Age = `_age_at_diagnosis`,
OS_Status = `_OS_IND`,
OS_Time = `_OS`
), by = "Sample_ID"
) |>
dplyr::mutate(
Sex = ifelse(Sex == "Male", "M", "F"),
OS_Status = ifelse(OS_Status == "Alive", 0L, 1L)
) |>
dplyr::select(Patient_ID, Sample_ID, Age, Sex, OS_Time, OS_Status, dplyr::everything()) |>
as.data.table()
cli1
target_cli
fwrite(target_cli, file = "/home/data2/Projects/Fusion/fusiondb/Clininfo/TARGET_xena_info.tsv", sep = "\t")
# Using cli from GDC ------------------------------------------------------
system("
cd /home/data2/Projects/Fusion/unclean/gdc_cli/TARGET
mkdir ALL_P1 ALL_P2 ALL_P3 AML CCSK NBL OS RT WT
tar zxvf clinical.project-target-all-p1.2024-08-07.tar.gz -C ALL_P1
tar zxvf clinical.project-target-all-p2.2024-08-07.tar.gz -C ALL_P2
tar zxvf clinical.project-target-all-p3.2024-08-07.tar.gz -C ALL_P3
tar zxvf clinical.project-target-aml.2024-08-07.tar.gz -C AML
tar zxvf clinical.project-target-ccsk.2024-08-07.tar.gz -C CCSK
tar zxvf clinical.project-target-nbl.2024-08-07.tar.gz -C NBL
tar zxvf clinical.project-target-os.2024-08-07.tar.gz -C OS
tar zxvf clinical.project-target-rt.2024-08-07.tar.gz -C RT
tar zxvf clinical.project-target-wt.2024-08-07.tar.gz -C WT
")
gdc_target = rbindlist(
list(
fread("gdc_cli/TARGET/ALL_P1/clinical.tsv"),
fread("gdc_cli/TARGET/ALL_P2/clinical.tsv"),
fread("gdc_cli/TARGET/ALL_P3/clinical.tsv"),
fread("gdc_cli/TARGET/AML/clinical.tsv"),
fread("gdc_cli/TARGET/CCSK/clinical.tsv"),
fread("gdc_cli/TARGET/NBL/clinical.tsv"),
fread("gdc_cli/TARGET/OS/clinical.tsv"),
fread("gdc_cli/TARGET/RT/clinical.tsv"),
fread("gdc_cli/TARGET/WT/clinical.tsv")
),
use.names = TRUE, fill = TRUE
)
table(gdc_target$project_id)
any(duplicated(gdc_target))
gdc_target = gdc_target[!duplicated(gdc_target)]
all.equal(gdc_target[[119]], gdc_target[[192]])
gdc_target[[192]] = NULL
sum(gdc_target$days_to_last_follow_up != "'--")
sum(gdc_target$days_to_death != "'--")
gdc_target2 = gdc_target |>
dplyr::rename(
Sample_ID = case_submitter_id,
Age = age_at_diagnosis,
Sex = gender,
OS_Time = days_to_death,
OS_Status = vital_status
) |>
dplyr::select(
Sample_ID, Age, Sex, OS_Time, OS_Status,
project_id, race, primary_diagnosis
) |>
dplyr::mutate(
Patient_ID = Sample_ID,
Age = as.integer(round(as.integer(Age) / 365)),
Sex = fcase(Sex %in% "female", "F",
Sex %in% "male", "M", default = NA_character_),
OS_Time = as.integer(OS_Time),
OS_Status = fcase(OS_Status %in% "Alive", 0L,
OS_Status %in% "Dead", 1L, default = NA_integer_),
OS_Time = ifelse(OS_Time < 0, NA_integer_, OS_Time)
) |>
as.data.table()
#unique()
# exist a large number of case level replicate
gdc_target2[duplicated(gdc_target2), ]
duplicated(gdc_target[case_submitter_id == "TARGET-20-PANTIV"])
gdc_target[case_submitter_id == "TARGET-20-PANTIV"] |> View() # A few records that have been updated?
gdc_target2 = gdc_target2[!duplicated(gdc_target2)]
#table(gdc_target2$PFS_Time)
any(duplicated(gdc_target2))
any(duplicated(gdc_target2$Sample_ID))
gdc_target2[duplicated(gdc_target2$Sample_ID)]
# They may exist in different ALL projects.
gdc_dup = gdc_target2[Sample_ID %in% Sample_ID[duplicated(Sample_ID)]]
table(gdc_dup$project_id)
# TARGET-ALL-P1 TARGET-ALL-P2 TARGET-ALL-P3
# 10 57 47
#
# For now, we won't address this issue. If we conduct a combined analysis of ALL, we will consider removing duplicates.
colnames(gdc_target2)
gdc_target2 = gdc_target2[, c("Patient_ID", "Sample_ID", "Age", "Sex", "race", "primary_diagnosis", "OS_Time", "OS_Status", "project_id")]
fwrite(gdc_target2, file = "/home/data2/Projects/Fusion/fusiondb/Clininfo/TARGET_info.tsv", sep = "\t")
sum(!is.na(gdc_target2$OS_Time))
sum(!is.na(cli1$`_OS`))
nrow(na.omit(unique(target_cli[, .(Patient_ID, OS_Time, OS_Status)])))
nrow(na.omit(unique(gdc_target2[, .(Patient_ID, OS_Time, OS_Status)])))TCGA/TARGET/CPTAC Clinical/IOBR/TME/GENE data divide and anotate preprocessing
TARGET
library(data.table)
library(dplyr)
library(stringr)
library(tidyr)
file_meta <- "/home/data2/Projects/Fusion/fusiondb_v3/metafusion_calls_matched.cptac.tsv"
metafusion <- fread(file_meta, sep = "\t")
# TARGET
## info
### Because some projects are not included in the target_sheet, we should abandon them.
TARGET_sheet <- fread("/home/data2/Projects/Fusion/unclean/TARGET_gdc_sample_sheet.2023-11-15.tsv", sep = "\t")
project_choose <- substr(TARGET_sheet$`Sample ID`, 1, 9) |> unique()
project_choose
### "TARGET-20" "TARGET-00" "TARGET-21" "TARGET-30"
### TARGET_sheet pretreatment
### Composite Sample
###
### Composite Sample use comma to separate like TARGET-30-PAPEAV, TARGET-30-PAPTFZ
TARGET_Composite <- TARGET_sheet |>
filter(grepl(", ", `Sample ID`)) |>
select(`Sample ID`) |>
unique()
TARGET_Composite
### 1: TARGET-30-PAPEAV-01A, TARGET-30-PAPTFZ-01A
### 2: TARGET-30-PANUKV-01A, TARGET-30-PASUML-01A
### 3: TARGET-30-PANKFE-01A, TARGET-30-PAPUAR-01A
### 4: TARGET-30-PASYPX-01A, TARGET-30-PAIXIF-01A
### For the CPTAC databases, check whether there is any overlap between composite and normal Sample_ID in the info data.
check_TARGET_overlap <- TARGET_sheet |>
select(c(`Case ID`, `Sample ID`, `Sample Type`, `Project ID`)) |>
unique() |>
separate_rows(`Sample ID`, sep = ",\\s*")
check_TARGET_overlap <- check_TARGET_overlap |>
mutate(Sample_Type = ifelse(grepl(", ", `Sample ID`), "Composite", "Normal"))
overlap_samples <- check_TARGET_overlap |>
group_by(`Sample ID`) |>
summarise(Count = n(), .groups = 'drop') |>
filter(Count > 1)
overlap_samples
### A tibble: 4 × 2
### `Sample ID` Count
### <chr> <int>
### 1 TARGET-30-PANKFE-01A 2
### 2 TARGET-30-PAPTFZ-01A 2
### 3 TARGET-30-PASUML-01A 2
### 4 TARGET-30-PASYPX-01A 2
### So we choose abandon them.
TARGET_pretreatment <- TARGET_sheet |>
select(c(`Case ID`, `Sample ID`, `Sample Type`)) |>
rename("Patient_ID" = `Case ID`,
"Sample_ID" = `Sample ID`,
"Sample_type" = `Sample Type`) |>
filter(!grepl(",", Sample_ID)) |>
filter(grepl("^TARGET-(20|00|21|30)", Sample_ID)) |>
unique()
### TARGET_xena_info pretreatment
### This data use
TARGET_xena_info <- fread("/home/data2/Projects/Fusion/fusiondb/Clininfo/TARGET_xena_info.tsv", sep = "\t")
TARGET_xena_pretreatment <- TARGET_xena_info |>
mutate(Patient_ID = str_extract(Sample_ID, "^[^-]+-[^-]+-[^-]+")) |>
filter(grepl("^TARGET-(20|00|21|30)", Sample_ID)) |>
mutate(Age = round(Age, digits = 0),
across(c(Age, OS_Time, OS_Status), ~ as.integer(.))) |>
rename(Cancer = disease_code)
### TARGET_info pretreatment
### In the TARGET database, rows with the info column marked as '--' are annotated as NA.
filter_lose <- function(x) {
is.na(x) | x == "" | x == "--" | x == "Unknown" | x == "'--"
}
TARGET_info <- fread("/home/data2/Projects/Fusion/fusiondb/Clininfo/TARGET_info.tsv", sep = "\t")
replacement_table2 <- c(
"Acute lymphocytic leukemia" = "TARGET-ALL",
"'--" = "TARGET-Unkown",
"Precursor B-cell lymphoblastic leukemia" = "TARGET-B-ALL",
"Not Reported" = "TARGET-Unkown",
"Acute myeloid leukemia, NOS" = "TARGET-LAML",
"Clear cell sarcoma of kidney" = "TARGET-CCSK",
"Neuroblastoma, NOS" = "TARGET-NBL",
"Ganglioneuroblastoma" = "TARGET-GNB",
"Osteosarcoma, NOS" = "TARGET-OS",
"Malignant rhabdoid tumor" = "TARGET-MRT",
"Wilms tumor" = "TARGET-WT"
)
matched2 <- TARGET_info$primary_diagnosis %in% names(replacement_table2)
TARGET_info_pretreatment <- TARGET_info |>
mutate(cohort = case_when(
matched2 ~ replacement_table2[primary_diagnosis],
TRUE ~ as.character(NA)
)) |>
rename(Cancer = primary_diagnosis,
Project_id = project_id) |>
filter(grepl("^TARGET-(20|00|21|30)", Sample_ID)) |>
mutate(across(c("Age", "Sex", "OS_Time", "OS_Status", "race"), ~ ifelse(filter_lose(.x), NA, .x))) |>
mutate(Cancer = ifelse(Cancer == "'--", NA, Cancer))
### Check if the valid rows in TARGET_info match the valid rows in TARGET_xena_info.
### 1.Filter the valid rows.
filter_valid <- function(x) {
!is.na(x) & x != "" & x != "--" & x != "Unknown" & x == "'--"
}
### Filter the valid rows in TARGET_info.
TARGET_info_valid <- TARGET_info_pretreatment %>%
filter(filter_valid(Age) & filter_valid(OS_Time) & filter_valid(OS_Status) & filter_valid(Sex)) |>
select(c(Patient_ID, Age, OS_Time, OS_Status, Sex))
### Filter the valid rows in TARGET_xena_info.
TARGET_xena_info_valid <- TARGET_xena_pretreatment %>%
filter(filter_valid(Age) & filter_valid(OS_Time) & filter_valid(OS_Status) & filter_valid(Sex)) |>
select(c(Patient_ID, Age, OS_Time, OS_Status, Sex))
### 2. Merge the two data frames based on Patient_ID.
merged_data <- TARGET_info_valid %>%
inner_join(TARGET_xena_info_valid, by = "Patient_ID", suffix = c("_info", "_xena"))
### 3. Check whether the valid values in the merged data frame are consistent.
is_consistent <- merged_data %>%
rowwise() %>%
mutate(
Age_consistent = Age_info == Age_xena,
Sex_consistent = Sex_info == Sex_xena,
OS_Time_consistent = OS_Time_info == OS_Time_xena,
OS_Status_consistent = OS_Status_info == OS_Status_xena
) %>%
ungroup()
### 4. Age not onsistent
Age_not_consistent <- is_consistent |>
filter(Age_consistent == "FALSE")
### 5. Sex not onsistent
Sex_not_consistent <- is_consistent |>
filter(Sex_consistent == "FALSE")
### Sex_not_consistent
### A tibble: 0 × 13
### 6. OS_Time not onsistent
OS_Time_not_consistent <- is_consistent |>
filter(OS_Time_consistent == "FALSE") |>
mutate(
OS_Time_info_greater = OS_Time_info > OS_Time_xena,
OS_Time_xena_greater = OS_Time_xena > OS_Time_info,
OS_Time_equal = OS_Time_info == OS_Time_xena
)
nrow(OS_Time_not_consistent |> filter(OS_Time_info_greater == "FALSE"))
### [1]0
nrow(OS_Time_not_consistent |> filter(OS_Time_xena_greater == "TRUE"))
### [1]0
nrow(OS_Time_not_consistent |> filter(OS_Time_equal == "TRUE"))
### [1]0
### 7. OS_Status not onsistent
OS_Status_not_consistent <- is_consistent |>
filter(OS_Status_consistent == "FALSE")
unique(OS_Status_not_consistent$OS_Status_info)
### [1] 1
unique(OS_Status_not_consistent$OS_Status_xena)
### [1] 0
### All evidence shows that the GDC data has been updated more recently than the Xena data.
### Therefore, if there is a conflict between GDC data and Xena data, we should use the GDC data.
### Use the valid values from TARGET_xena_info to fill the missing values in TARGET_info.
### 1: Determine the matching Patient_ID.
matched_ids <- intersect(TARGET_xena_pretreatment$Patient_ID, TARGET_info_pretreatment$Patient_ID)
setDT(TARGET_xena_pretreatment)
setDT(TARGET_info_pretreatment)
### 2: Find the columns that require updates.
cols_to_update <- setdiff(names(TARGET_info_pretreatment), c("Sample_ID", "Patient_ID", "Cancer","project_id","cohort","race"))
### 3.Iterate through each matching Patient_ID and update TARGET_info_pretreatment using TARGET_xena_pretreatment.
### update Age
TARGET_xena_can <- TARGET_xena_pretreatment |>
filter(if_any("Age", ~ !filter_lose(.x)))
TARGET_info_match <- TARGET_info_pretreatment |>
mutate(Age = case_when(
filter_lose(Age) & Patient_ID %in% TARGET_xena_can$Patient_ID ~ TARGET_xena_can$Age[match(Patient_ID, TARGET_xena_can$Patient_ID)],
TRUE ~ Age))
### update Sex
TARGET_xena_can <- TARGET_xena_pretreatment |>
filter(if_any("Sex", ~ !filter_lose(.x)))
TARGET_info_match1 <- TARGET_info_match |>
mutate(Sex = case_when(
filter_lose(Sex) & Patient_ID %in% TARGET_xena_can$Patient_ID ~ TARGET_xena_can$Sex[match(Patient_ID, TARGET_xena_can$Patient_ID)],
TRUE ~ Sex))
### update OS_Time
TARGET_xena_can <- TARGET_xena_pretreatment |>
filter(if_any("OS_Time", ~ !filter_lose(.x)))
TARGET_info_match2 <- TARGET_info_match1 |>
mutate(OS_Time = case_when(
filter_lose(OS_Time) & Patient_ID %in% TARGET_xena_can$Patient_ID & OS_Status %in% TARGET_xena_can$OS_Status ~ TARGET_xena_can$OS_Time[match(Patient_ID, TARGET_xena_can$Patient_ID)],
TRUE ~ OS_Time))
### update OS_Status
TARGET_xena_can <- TARGET_xena_pretreatment |>
filter(if_any("OS_Status", ~ !filter_lose(.x)))
TARGET_info_after_match <- TARGET_info_match2 |>
mutate(OS_Status = case_when(
filter_lose(OS_Status) & Patient_ID %in% TARGET_xena_can$Patient_ID & OS_Time %in% TARGET_xena_can$OS_Time ~ TARGET_xena_can$OS_Status[match(Patient_ID, TARGET_xena_can$Patient_ID)],
TRUE ~ OS_Status))
### Use TARGET_sheet to perform a left join, ensuring that the Sample_ID is correct.
TARGET_info_after_match <- TARGET_info_after_match |> select(- Sample_ID)
TARGET_correct <- TARGET_pretreatment |>
left_join(TARGET_info_after_match, by = c("Patient_ID" = "Patient_ID")) |>
mutate(Run = Sample_ID)
### Replace the cohort column values with Project_ID where the row is TARGET-Unkown.
### TARGET_correct$project_id |> unique()
### [1] "TARGET-AML" "TARGET-NBL"
TARGET_correct_after_pro <- TARGET_correct %>%
mutate(
cohort = case_when(
cohort == "TARGET-Unkown" ~ Project_id,
TRUE ~ cohort),
cohort = case_when(
cohort == "TARGET-AML" ~ "TARGET-LAML",
TRUE ~ cohort)
)
### Divide a part of data into a group based on whether the Sample_type is cell
target_cell <- TARGET_correct_after_pro |> filter(`Sample_type` == "Cell Lines")
target_cell_sample <- target_cell$Sample_ID |> unique()
target_cell_patient <- target_cell$Patient_ID |> unique()
### target_cell_sample
### [1] "TARGET-20-MUTZ3-50A" "TARGET-20-ML1-50A" "TARGET-20-MV411D1-50A" "TARGET-20-KasumiD1-50A" "TARGET-20-HEK293-50A" "TARGET-20-MOLM14CBFGLIS-50A"
### [7] "TARGET-20-TF1-50A" "TARGET-20-IGROV1-50A" "TARGET-20-CMS-50A" "TARGET-20-WSUAML-50A" "TARGET-20-KasumiAZAD5-50A" "TARGET-20-KasumiAZAD11-50A"
### [13]"TARGET-20-REH-50A" "TARGET-20-MV411AZAD11-50A" "TARGET-20-MV411AZAD5-50A" "TARGET-20-THP1-50A" "TARGET-20-OCIAML2-50A" "TARGET-20-HL60-50A"
### target_cell_patient
### [1] "TARGET-20-MUTZ3" "TARGET-20-ML1" "TARGET-20-MV411D1" "TARGET-20-KasumiD1" "TARGET-20-HEK293" "TARGET-20-MOLM14CBFGLIS"
### [7] "TARGET-20-TF1" "TARGET-20-IGROV1" "TARGET-20-CMS" "TARGET-20-WSUAML" "TARGET-20-KasumiAZAD5" "TARGET-20-KasumiAZAD11"
### [13]"TARGET-20-REH" "TARGET-20-MV411AZAD11" "TARGET-20-MV411AZAD5" "TARGET-20-THP1" "TARGET-20-OCIAML2" "TARGET-20-HL60"
### reference : https://www.cellosaurus.org/
### MUTZ3:Acute myeloid leukemia
### ML1: Adult acute myeloid leukemia
### MV411D1:biphenotypic B-myelomonocytic leukemia
### KasumiD1:Acute myeloblastic leukemia
### TF1:Acute erythroid leukemia
### IGROV1: Ovarian endometrioid adenocarcinoma
### WSUAML:Acute myeloid leukemia。
### KasumiAZAD5:can't find, so KasumiD1:Acute myeloblastic leukemia
### KasumiAZAD11:can't find, so KasumiD1:Acute myeloblastic leukemia
### REH:Childhood B acute lymphoblastic leukemia
### MV411AZAD11:can't find, so MV411D1:biphenotypic B-myelomonocytic leukemia
### MV411AZAD5:can't find, so MV411D1:biphenotypic B-myelomonocytic leukemia
### THP1:Childhood acute monocytic leukemia
### OCIAML2:Adult acute myeloid leukemia
### HL60:Adult acute myeloid leukemia
### HEK293:Vaccine production cell line.
### CML:Childhood acute megakaryoblastic leukemia
### MOLM14CBFGLIS:can't find, so MOLM14:Adult acute myeloid leukemia
cell_data <- metafusion[metafusion$Sample_ID %in% target_cell_sample]
### > nrow(cell_data)
### [1] 1853
cell_info <- TARGET_info_pretreatment[TARGET_info_pretreatment$Patient_ID %in% target_cell_patient]
### nrow(cell_info)
### [1] 18
### no os.etc
cell_info2 <- TARGET_xena_pretreatment[TARGET_xena_pretreatment$Patient_ID %in% target_cell_patient]
### nrow(cell_info2)
### [1] 0
TARGET_info_after_cell <- TARGET_correct_after_pro |>
mutate(cohort = case_when(
`Sample_type` %in% "Cell Lines" ~ "TARGET-CELL",
TRUE ~ cohort
))
### The criteria for distinguishing normal samples based on Sample_type column in the TARGET databases are as follows:
TARGET_info_after_cell$Sample_type |> unique()
### [1] "Primary Blood Derived Cancer - Bone Marrow" "Recurrent Blood Derived Cancer - Bone Marrow"
### [3] "Blood Derived Normal" "Primary Blood Derived Cancer - Peripheral Blood"
### [5] "Bone Marrow Normal" "Cell Lines"
### [7] "Next Generation Cancer Model" "Blood Derived Cancer - Bone Marrow, Post-treatment"
### [9] "Primary Tumor" "Recurrent Tumor"
### [11] "Recurrent Blood Derived Cancer - Peripheral Blood" "Blood Derived Cancer - Peripheral Blood, Post-treatment"
###
### If the sample type is "Blood Derived Normal" or "Bone Marrow Normal", then it is a normal sample. Otherwise, it is a tumor sample.
TARGET_info_after_normal <- TARGET_info_after_cell |>
mutate(cohort = case_when(
`Sample_type` %in% c("Blood Derived Normal", "Bone Marrow Normal") ~ "TARGET-NORMAL",
TRUE ~ cohort
))
### Adjust the column order.
new_order <- c("Patient_ID", "Sample_ID", "Run", "Sample_type", "Age", "Sex", "race", "Cancer",
"OS_Time", "OS_Status", "Project_id", "cohort")
TARGET_info_after_processing <- TARGET_info_after_normal |>
select(all_of(new_order))
### make sure nrow is same between Before and After Processing.
TARGET_pretreatment |> nrow()
### [1] 3222
TARGET_info_after_processing |> nrow()
### [1] 3222
### make sure IOBR/TME data just contain sample which target_sheet gave.
detected_id_TARGET <- TARGET_info_after_processing$Run
### save info
cohorts <- unique(TARGET_info_after_processing$cohort)
for (cohort1 in cohorts) {
cohort_data <- subset(TARGET_info_after_processing, cohort == cohort1)
name <- gsub("-", "_", cohort1)
file_name <- paste0("/home/data2/Projects/Fusion/fusiondb_v3/Clininfo/", name ,"_info.tsv")
fwrite(cohort_data , file = file_name, sep = "\t")
}
##Gene
metafusion1 <- metafusion |>
mutate(
cohort = case_when(
Sample_ID %in% TARGET_info_after_processing$Run & grepl("TARGET", cohort) ~ TARGET_info_after_processing$cohort[match(Sample_ID, TARGET_info_after_processing$Run)],
TRUE ~ cohort
)
)
cp_file_name1 <- "/home/data2/Projects/Fusion/fusiondb_v3/metafusion_calls_matched.cptac.target.tsv"
fwrite(metafusion1, file = cp_file_name1, sep = "\t")
##TME
NBL_TME <- fread("/home/data2/Projects/Fusion/fusiondb/IOBR/TARGET-NBL_TME.tsv.gz", sep = "\t") |> mutate(Project_id = "TARGET-NBL")
AML_TME <- fread("/home/data2/Projects/Fusion/fusiondb/IOBR/TARGET-AML_TME.tsv.gz", sep = "\t") |> mutate(Project_id = "TARGET-AML")
TARGET_TME <- rbind(NBL_TME,AML_TME) |>
mutate(dash_count = str_count(ID, "-"))
### Manually check and delete composite samples from the info dataset.(TARGET-30-PAPTFZ-01A-01R-TARGET-30-PAPEAV-01A-01R)
TARGET_TME |>
filter(dash_count == 9) |>
select(ID) |>
unique()
### 1: TARGET-30-PASYPX-01A-01R-TARGET-30-PAIXIF-01A-01R
### 2: TARGET-30-PANKFE-01A-01R-TARGET-30-PAPUAR-01A-01R
### 3: TARGET-30-PANUKV-01A-01R-TARGET-30-PASUML-01A-01R
### 4: TARGET-30-PAPTFZ-01A-01R-TARGET-30-PAPEAV-01A-01R
TARGET_TME_pretreatment <- TARGET_TME |>
filter(dash_count != 9) |>
select(-dash_count)
### Filter TARGET Replicate Samples
### The filter rule following broad institute says:
###
### In many instances there is more than one aliquot for a given combination of individual, platform, and data type. However, only one aliquot may be ingested into Firehose. Therefore, a set of precedence rules are applied to select the most scientifically advantageous one among them. Two filters are applied to achieve this aim: an Analyte Replicate Filter and a Sort Replicate Filter.
###
### Analyte Replicate Filter
### The following precedence rules are applied when the aliquots have differing analytes. For RNA aliquots, T analytes are dropped in preference to H and R analytes, since T is the inferior extraction protocol. If H and R are encountered, H is the chosen analyte. This is somewhat arbitrary and subject to change, since it is not clear at present whether H or R is the better protocol. If there are multiple aliquots associated with the chosen RNA analyte, the aliquot with the later plate number is chosen. For DNA aliquots, D analytes (native DNA) are preferred over G, W, or X (whole-genome amplified) analytes, unless the G, W, or X analyte sample has a higher plate number.
###
### Sort Replicate Filter
### The following precedence rules are applied when the analyte filter still produces more than one sample. The sort filter chooses the aliquot with the highest lexicographical sort value, to ensure that the barcode with the highest portion and/or plate number is selected when all other barcode fields are identical.
###
### Ref Link: <https://confluence.broadinstitute.org/display/GDAC/FAQ#FAQ-sampleTypesQWhatTCGAsampletypesareFirehosepipelinesexecutedupon>
### <https://gist.github.com/ShixiangWang/33b2f9b49b77eaa8f773b428480f9101>
TARGET_TME_after_replicate <- TARGET_TME_pretreatment |>
mutate(
prefixes = str_remove(ID, "-[^-]+$"),
suffixes = str_extract(ID, "[^-]+$"),
second_chars = str_extract(suffixes, "[0-9]+"),
second_chars = as.integer(second_chars)) |>
group_by(prefixes) |>
slice(which.max(second_chars)) |>
ungroup() |>
mutate(ID = prefixes) |>
filter(ID %in% detected_id_TARGET) |> ### Ensure that all IDs in the TME data can be found in the TARGET info data.
select(-c(prefixes,suffixes,second_chars))
### Using TARGET info data cohort column to annotate TARGET TME data
cohort_data <- TARGET_info_after_processing |>
select(Run, cohort) |>
unique()
TARGET_TME_after_cohort <- TARGET_TME_after_replicate |>
mutate(Run = ID) |>
left_join(cohort_data, by = "Run") |>
select(-Run)
### save TME
cohorts_TME <- unique(TARGET_TME_after_cohort$cohort)
for (cohort1 in cohorts_TME) {
cohort_data <- subset(TARGET_TME_after_cohort, cohort == cohort1) |> select(-cohort)
file_name <- paste0("/home/data2/Projects/Fusion/fusiondb_v3/IOBR/", cohort1 ,"_TME.tsv.gz")
write.table(cohort_data,
file = gzfile(file_name),
sep = "\t",
row.names = FALSE,
quote = FALSE)
}
## IOBR
NBL_IOBR_signature <- fread("/home/data2/Projects/Fusion/fusiondb/IOBR/TARGET-NBL_IOBR_signature.tsv.gz", sep = "\t") |> mutate(Project_id = "TARGET-NBL")
AML_IOBR_signature <- fread("/home/data2/Projects/Fusion/fusiondb/IOBR/TARGET-AML_IOBR_signature.tsv.gz", sep = "\t") |> mutate(Project_id = "TARGET-AML")
TARGET_IOBR <- rbind(NBL_IOBR_signature,AML_IOBR_signature) |>
mutate(dash_count = str_count(ID, "-"))
### Manually check and delete composite samples from the info dataset.(TARGET-30-PAPTFZ-01A-01R-TARGET-30-PAPEAV-01A-01R)
TARGET_IOBR |>
filter(dash_count == 9) |>
select(ID) |>
unique()
### 1: TARGET-30-PASYPX-01A-01R-TARGET-30-PAIXIF-01A-01R
### 2: TARGET-30-PANKFE-01A-01R-TARGET-30-PAPUAR-01A-01R
### 3: TARGET-30-PANUKV-01A-01R-TARGET-30-PASUML-01A-01R
### 4: TARGET-30-PAPTFZ-01A-01R-TARGET-30-PAPEAV-01A-01R
TARGET_IOBR_pretreatment <- TARGET_IOBR |>
filter(dash_count != 9) |>
select(-dash_count)
TARGET_IOBR_after_replicate <- TARGET_IOBR_pretreatment |>
mutate(
prefixes = str_remove(ID, "-[^-]+$"),
suffixes = str_extract(ID, "[^-]+$"),
second_chars = str_extract(suffixes, "[0-9]+"),
second_chars = as.integer(second_chars)) |>
group_by(prefixes) |>
slice(which.max(second_chars)) |>
ungroup() |>
mutate(ID = prefixes) |>
filter(ID %in% detected_id_TARGET) |> ### Ensure that all IDs in the TME data can be found in the TARGET info data.
select(-c(prefixes,suffixes,second_chars))
### Using TARGET info data cohort column to annotate TARGET TME data
cohort_data <- TARGET_info_after_processing |>
select(Run, cohort) |>
unique()
TARGET_IOBR_after_cohort <- TARGET_IOBR_after_replicate |>
mutate(Run = ID) |>
left_join(cohort_data, by = "Run") |>
select(-Run)
### save IOBR
cohorts_IOBR <- unique(TARGET_IOBR_after_cohort$cohort)
for (cohort1 in cohorts_IOBR) {
cohort_data <- subset(TARGET_IOBR_after_cohort, cohort == cohort1) |> select(-cohort)
file_name <- paste0("/home/data2/Projects/Fusion/fusiondb_v3/IOBR/", cohort1 ,"_IOBR_signature.tsv.gz")
write.table(cohort_data,
file = gzfile(file_name),
sep = "\t",
row.names = FALSE,
quote = FALSE)
}
CPTAC
library(data.table)
library(dplyr)
library(stringr)
library(tidyr)
file_meta <- "/home/data2/Projects/Fusion/fusiondb_v3/metafusion_calls_matched.tsv"
metafusion <- fread(file_meta, sep = "\t")
# CPTAC
## info
CPTAC_sheet <- fread("/home/data2/Projects/Fusion/unclean/CPTAC_gdc_sample_sheet.2023-11-15.tsv", sep = "\t")
### Composite Sample
###
### Composite Sample use comma to separate like C3L-03400-05, C3L-03400-02
###
### It leads one question is whether these composite samples using comma to separate from identical patient?
rows_with_comma <- grepl(", ", CPTAC_sheet$`Sample ID`)
rows_with_comma_data <- CPTAC_sheet[rows_with_comma, ]
check_same_chars <- function(x) {
parts <- unlist(strsplit(x, ", "))
return(parts[1] == parts[2])
}
same_chars <- sapply(rows_with_comma_data$`Case ID`, check_same_chars)
if (all(same_chars)) {
cat("TRUE\n")
} else {
cat("FALSE\n")
}
### They are from identical patient.
### For the TARGET databases, check whether there is any overlap between composite and normal Sample_ID in the info data. If there is an overlap, retain only the normal Sample_ID.
check_cptac_overlap <- CPTAC_sheet |>
select(c(`Case ID`, `Sample ID`, `Sample Type`, `Project ID`)) |>
unique() |>
separate_rows(`Sample ID`, sep = ",\\s*")
check_cptac_overlap <- check_cptac_overlap |>
mutate(Sample_Type = ifelse(grepl(", ", `Sample ID`), "Composite", "Normal"))
overlap_samples <- check_cptac_overlap |>
group_by(`Sample ID`) |>
summarise(Count = n(), .groups = 'drop') |>
filter(Count > 1)
### > overlap_samples
### A tibble: 0 × 2
### ℹ 2 variables: Sample ID <chr>, Count <int>
### no this situation
### Due to the less rigorous patient naming conventions(like 604) in the CPTAC2 project, check for any overlapping patient names between CPTAC2 and CPTAC3.
CPTAC_sheet_rigorous <- CPTAC_sheet |>
select(c(`Case ID`, `Sample ID`, `Sample Type`, `Project ID`)) |>
unique()
duplicates <- CPTAC_sheet_rigorous |>
group_by(`Case ID`, `Sample ID`) |>
summarise(n_projects = n(), projects = paste(`Project ID`, collapse = ", ")) |>
filter(n_projects > 1)
### nrow(duplicates)
### [1] 0
### no same patient names between CPTAC2 and CPTAC3
### CPTAC_sheet pretreatment
matched_CPTAC_pretreatment <- CPTAC_sheet |>
select(c(`Case ID`, `Sample ID`, `Sample Type`, `Project ID`)) |>
rename("Patient_ID" = `Case ID`,
"Sample_ID" = `Sample ID`,
"Sample_type" = `Sample Type`,
"Project_id" = `Project ID`) |>
separate_rows(Patient_ID, sep = ",\\s*") |> #because they are from identical patient.
unique()
### CPTAC_info pretreatment
CPTAC_info <- fread("/home/data2/Projects/Fusion/fusiondb/Clininfo/CPTAC_info.tsv", sep = "\t")
# > CPTAC_info$Cancer |> unique()
# [1] "BRCA" "CCRCC" "COAD" "GBM" "HGSC" "HNSCC" "LSCC" "LUAD" "PDAC" "UCEC" "GTEX-Brain"
### We use our naming standard mutate a new column cohort.
cptac_replacement_table2 <- c(
"BRCA" = "CPTAC-BRCA",
"CCRCC" = "CPTAC-KIRC",
"COAD" = "CPTAC-COAD",
"GBM" = "CPTAC-GBM",
"HGSC" = "CPTAC-OV",
"HNSCC" = "CPTAC-HNSC",
"LSCC" = "CPTAC-LUSC" ,
"LUAD" = "CPTAC-LUAD",
"PDAC" = "CPTAC-PAAD",
"UCEC" = "CPTAC-UCEC",
"GTEX-Brain" = "CPTAC-GTEX-Brain"
)
matched_CPTAC_info <- CPTAC_info$Cancer %in% names(cptac_replacement_table2)
CPTAC_info_pretreatment <- CPTAC_info %>%
mutate(cohort = case_when(
matched_CPTAC_info ~ cptac_replacement_table2[Cancer],
TRUE ~ as.character(NA)
)) |>
select(-Sample_ID)
### CPTAC_info_pretreatment |> filter(is.na(cohort)) |> nrow()
### [1] 0
matched_CPTAC <- matched_CPTAC_pretreatment |>
left_join(CPTAC_info_pretreatment, by = c("Patient_ID" = "Patient_ID")) |>
mutate(Run = str_replace_all(Sample_ID, ", ", "-"))
### CPTAC Sample type
### matched_CPTAC_pretreatment$Sample_type |> unique()
### [1] "Primary Tumor" "Solid Tissue Normal"
### [3] "Primary Tumor, Primary Tumor" "Primary Tumor, Primary Tumor, Primary Tumor"
### [5] "Solid Tissue Normal, Solid Tissue Normal, Solid Tissue Normal" "Solid Tissue Normal, Solid Tissue Normal"
### [7] "Primary Tumor, Primary Tumor, Primary Tumor, Primary Tumor, Primary Tumor" "Primary Tumor, Primary Tumor, Primary Tumor, Primary Tumor"
###
### Just two sample type so if grepling "Solid Tissue Normal" is normal sample, grepling "Primary Tumor" is tumor sample
matched_CPTAC_after_processing <- matched_CPTAC |>
mutate(cohort = case_when(
grepl("Solid Tissue Normal", Sample_type) ~ "CPTAC-NORMAL",
TRUE ~ cohort
))
### make sure nrow is same between Before and After Processing.
matched_CPTAC_after_processing |> nrow()
### [1] 2558
matched_CPTAC_pretreatment |> nrow()
### [1] 2558
### make sure IOBR/TME data just contain sample which cptac_sheet gave.
detected_id_CPTAC <- matched_CPTAC_after_processing$Run |> unique()
### save info
cohorts <- unique(matched_CPTAC_after_processing$cohort)
for (cohort1 in cohorts) {
cohort_data <- subset(matched_CPTAC_after_processing, cohort == cohort1)
name <- gsub("-", "_", cohort1)
file_name <- paste0("/home/data2/Projects/Fusion/fusiondb_v3/Clininfo/", name ,"_info.tsv")
fwrite(cohort_data , file = file_name, sep = "\t")
}
## TME
CPTAC2_TME <- fread("/home/data2/Projects/Fusion/fusiondb/IOBR/CPTAC-2_TME.tsv.gz", sep = "\t") |> mutate(Project_id = "CPTAC2")
CPTAC3_TME <- fread("/home/data2/Projects/Fusion/fusiondb/IOBR/CPTAC-3_TME.tsv.gz", sep = "\t") |> mutate(Project_id = "CPTAC3")
CPTAC_TME <- rbind(CPTAC2_TME, CPTAC3_TME)
### Match matched_CPTAC_after_processing$Run to CPTAC_TME$ID
###
### CPTAC_TME can match
matched_can <- CPTAC_TME %>%
filter(ID %in% matched_CPTAC_after_processing$Run)
###
### CPTAC_TME can't match
matched_not <- CPTAC_TME %>%
filter(!(ID %in% matched_CPTAC_after_processing$Run))
###
### situtation 1: Due to the barcode naming convention and etc, some portion character are added to the endning of the IOBR/TME sample name.
### str_count(matched_last$ID, "_")
### [1] 1 2 0
### 1.1 "CPT000817-0008" and "CPT000817". If the value of str_count(matched_last$ID, "_") for a row is 0, then the value of the prefixes column for that row should be the characters before the last -, and the value of the suffixes column should be the characters after the last -.
### 1.2 "f6a7f764-2495-4a1d-89a2-e12f51_D7_1" and "f6a7f764-2495-4a1d-89a2-e12f51". If the value of str_count(matched_last$ID, "_") for a row is 1, then the value of the prefixes column for that row should be the characters before the first _, and the value of the suffixes column should be the characters after the first _.
### 1.3 "CPT008756_0001" and "CPT008756". f6a7f764-2495-4a1d-89a2-e12f51_D7_1, .If the value of str_count(matched_last$ID, "_") for a row is 2, then the value of the prefixes column for that row should be the characters before the first _, and the value of the suffixes column should be the characters after the first _.
matched_not <- matched_not %>%
rowwise() %>%
mutate(
prefixes = case_when(
str_count(ID, "_") == 0 ~ str_split(ID, "-")[[1]][1],
str_count(ID, "_") == 1 ~ str_split(ID, "_")[[1]][1],
str_count(ID, "_") == 2 ~ str_split(ID, "_")[[1]][1],
TRUE ~ NA_character_
),
suffixes = case_when(
str_count(ID, "_") == 0 ~ str_split(ID, "-")[[1]][length(str_split(ID, "-")[[1]])],
str_count(ID, "_") == 1 ~ str_split(ID, "_")[[1]][2],
str_count(ID, "_") == 2 ~ str_split(ID, "_")[[1]][2],
TRUE ~ NA_character_
),
name1 = prefixes
) %>%
ungroup()
### situtation 1 after processing can match
matched_in_situtation1 <- matched_not %>%
filter((name1 %in% matched_CPTAC_after_processing$Run))%>%
mutate(ID = name1) %>%
select(-c(suffixes,prefixes,name1) )
matched_can <- rbind(matched_can, matched_in_situtation1)
### not in situtation 1
matched_not_situtation1 <- matched_not %>%
filter(!(name1 %in% matched_CPTAC_after_processing$Run))
### situtation 2: Due to IOBR package analyze code, an additional "X" is added to the beginning of the IOBR/TME sample name.
### "X1104806" and "1104806", "X9f905736-f662-41d6-b3ac-16758d" and "9f905736-f662-41d6-b3ac-16758d".
matched_not_situtation1 <- matched_not_situtation1 %>%
mutate(name2 = str_remove(ID, "^X"))
### situtation 2 after processing can match
matched_in_situtation2 <- matched_not_situtation1 %>%
filter((name2 %in% matched_CPTAC_after_processing$Run)) %>%
mutate(ID = name2 ) %>%
select(-c(name1,prefixes,suffixes,name2))
matched_can <- rbind(matched_can, matched_in_situtation2)
### situtation 2 after processing can't match
matched_not_situtation2 <- matched_not_situtation1 %>%
filter(!(name2 %in% matched_CPTAC_after_processing$Run))
### situtation 3: Mixed situation1 and situation2.
### X161317f3-1a39-438e-af45-cd2502_D7 and 161317f3-1a39-438e-af45-cd2502
matched_not_situtation2 <- matched_not_situtation2 %>%
mutate(name3 = str_remove(prefixes, "^X"))
### situtation 3 after processing can match
matched_in_situtation3 <- matched_not_situtation2 %>%
filter((name3 %in% matched_CPTAC_after_processing$Run)) %>%
mutate(ID = name3) %>%
select(-c(name1,name2,prefixes,suffixes, name3))
matched_can <- rbind(matched_can, matched_in_situtation3)
### situtation 3 after processing can't match
matched_not_situtation3 <- matched_not_situtation2 %>%
filter(!(name3 %in% matched_CPTAC_after_processing$Run))
nrow(matched_not_situtation3 )
### [1] 81
### Check the reason why it still can't match after Type 3 processing
### After manual review, these Sample_ID are not included in either the info dataset or the gdc_sheet.
### Check if CPTAC TME data ID are any samples that have been divided into multiple portions.
matched_can |> select(ID) |> nrow()
### [1] 2558
matched_can |> select(ID) |> unique() |> nrow()
### [1] 2558
### No this situation.
### Check if CPTAC TME data has same norw with CPTAC info data.
matched_can |> select(ID) |> unique() |> nrow()
### [1] 2558
matched_CPTAC_after_processing |> select(Run) |> unique() |> nrow()
### [1] 2558
### Sure.
cohort_data <- matched_CPTAC_after_processing |>
select(Run, cohort) |>
unique()
matched_can <- matched_can |>
mutate(Run = ID) |>
left_join(cohort_data, by = "Run") |>
select(-Run)
cohorts_TME <- unique(matched_can$cohort)
for (cohort1 in cohorts_TME) {
cohort_data <- subset(matched_can, cohort == cohort1) |> select(-cohort)
file_name <- paste0("/home/data2/Projects/Fusion/fusiondb_v3/IOBR/", cohort1 ,"_TME.tsv.gz")
write.table(cohort_data,
file = gzfile(file_name),
sep = "\t",
row.names = FALSE,
quote = FALSE)
}
#IOBR
CPTAC2_Signature <- fread("/home/data2/Projects/Fusion/fusiondb/IOBR/CPTAC-2_IOBR_signature.tsv.gz", sep = "\t") |> mutate(Project_id = "CPTAC2")
CPTAC3_Signature <- fread("/home/data2/Projects/Fusion/fusiondb/IOBR/CPTAC-3_IOBR_signature.tsv.gz", sep = "\t") |> mutate(Project_id = "CPTAC3")
CPTAC_Signature <- rbind(CPTAC2_Signature, CPTAC3_Signature)
### Match matched_CPTAC_after_processing$Run to CPTAC_TME$ID
###
### CPTAC_TME can match
matched_can <- CPTAC_Signature %>%
filter(ID %in% matched_CPTAC_after_processing$Run)
###
### CPTAC_TME can't match
matched_not <- CPTAC_Signature %>%
filter(!(ID %in% matched_CPTAC_after_processing$Run))
###
### situtation 1:like TME
matched_not <- matched_not %>%
rowwise() %>%
mutate(
prefixes = case_when(
str_count(ID, "_") == 0 ~ str_split(ID, "-")[[1]][1],
str_count(ID, "_") == 1 ~ str_split(ID, "_")[[1]][1],
str_count(ID, "_") == 2 ~ str_split(ID, "_")[[1]][1],
TRUE ~ NA_character_
),
suffixes = case_when(
str_count(ID, "_") == 0 ~ str_split(ID, "-")[[1]][length(str_split(ID, "-")[[1]])],
str_count(ID, "_") == 1 ~ str_split(ID, "_")[[1]][2],
str_count(ID, "_") == 2 ~ str_split(ID, "_")[[1]][2],
TRUE ~ NA_character_
),
name1 = prefixes
) %>%
ungroup()
### situtation 1 after processing can match
matched_in_situtation1 <- matched_not %>%
filter((name1 %in% matched_CPTAC_after_processing$Run))%>%
mutate(ID = name1) %>%
select(-c(suffixes,prefixes,name1) )
matched_can <- rbind(matched_can, matched_in_situtation1)
### situtation 1 after processing can't match
matched_not_situtation1 <- matched_not %>%
filter(!(name1 %in% matched_CPTAC_after_processing$Run))
### situtation 2:like TME
matched_not_situtation1 <- matched_not_situtation1 %>%
mutate(name2 = str_remove(ID, "^X"))
### situtation 2 after processing can match
matched_in_situtation2 <- matched_not_situtation1 %>%
filter((name2 %in% matched_CPTAC_after_processing$Run)) %>%
mutate(ID = name2 ) %>%
select(-c(name1,prefixes,suffixes,name2))
matched_can <- rbind(matched_can, matched_in_situtation2)
### situtation 2 after processing can't match
matched_not_situtation2 <- matched_not_situtation1 %>%
filter(!(name2 %in% matched_CPTAC_after_processing$Run))
### situtation 3:like TME
matched_not_situtation2 <- matched_not_situtation2 %>%
mutate(name3 = str_remove(prefixes, "^X"))
### situtation 3 after processing can match
matched_in_situtation3 <- matched_not_situtation2 %>%
filter((name3 %in% matched_CPTAC_after_processing$Run)) %>%
mutate(ID = name3) %>%
select(-c(name1,name2,prefixes,suffixes, name3))
matched_can <- rbind(matched_can, matched_in_situtation3)
### situtation 3 after processing can't match
matched_not_situtation3 <- matched_not_situtation2 %>%
filter(!(name3 %in% matched_CPTAC_after_processing$Run))
nrow(matched_not_situtation3 )
### [1] 81
### Check the reason why it still can't match after Type 3 processing
### After manual review, these Sample_ID are not included in either the info dataset or the gdc_sheet.
### Check if CPTAC IOBR data ID are any samples that have been divided into multiple portions.
matched_can |> select(ID) |> nrow()
### [1] 2558
matched_can |> select(ID) |> unique() |> nrow()
### [1] 2558
### No this situation.
### Check if CPTAC IOBR data has same norw with CPTAC info data.
matched_can |> select(ID) |> unique() |> nrow()
### [1] 2558
matched_CPTAC_after_processing |> select(Run) |> unique() |> nrow()
### [1] 2558
### Sure.
cohort_data <- matched_CPTAC_after_processing |>
select(Run, cohort) |>
unique()
matched_can <- matched_can |>
mutate(Run = ID) |>
left_join(cohort_data, by = "Run") |>
select(-Run)
cohorts_IOBR <- unique(matched_can$cohort)
for (cohort1 in cohorts_IOBR) {
cohort_data <- subset(matched_can, cohort == cohort1) |> select(-cohort)
file_name <- paste0("/home/data2/Projects/Fusion/fusiondb_v3/IOBR/", cohort1 ,"_IOBR_signature.tsv.gz")
write.table(cohort_data,
file = gzfile(file_name),
sep = "\t",
row.names = FALSE,
quote = FALSE)
}
## Gene
metafusion1 <- metafusion |>
mutate(
cohort = case_when(
Sample_ID %in% matched_CPTAC_after_processing$Run & grepl("CPTAC", cohort) ~ matched_CPTAC_after_processing$cohort[match(Sample_ID, matched_CPTAC_after_processing$Run)],
TRUE ~ cohort
)
)
### In the past, the metafusion file had an issue with the sample_type being incorrectly labeled.
### After further investigation, it was found that only the composite Sample_ID in CPTAC had this issue, where samples labeled as 'Normal' were mistakenly identified as 'Tumor' in the sample_type column.
normal_id <- matched_CPTAC_after_processing |>
filter(cohort == "CPTAC-NORMAL") |>
select(Run) |>
unique() |>
pull(Run)
meta_normal <- metafusion1 |>
filter(Sample_ID %in% normal_id)
unique(meta_normal$sample_type)
#[1] "Normal" "Tumor"
meta_processing <- metafusion1 |>
mutate(
sample_type = ifelse(
sample_type != "Normal" & Sample_ID %in% normal_id,
"Normal",
sample_type
)
)
cp_file_name1 <- "/home/data2/Projects/Fusion/fusiondb_v3/metafusion_calls_matched.cptac.tsv"
fwrite(meta_processing, file = cp_file_name1, sep = "\t") TCGA
library(data.table)
library(dplyr)
library(stringr)
library(tidyr)
file_meta <- "/home/data2/Projects/Fusion/fusiondb_v3/metafusion_calls_matched.cptac.target.tsv"
metafusion <- fread(file_meta , sep = "\t")
# TCGA
## info
TCGA_info <- fread("/home/data2/Projects/Fusion/fusiondb/Clininfo/TCGA_info.tsv", sep = "\t")
### TCGA_sheet pretreatment
TCGA_sheet <- fread("/home/data2/Projects/Fusion/unclean/TCGA_sample_sheet.2024-05-14.tsv", sep = "\t") |>
select(c(`Sample ID`, `Sample Type`,`Project ID`))
colnames(TCGA_sheet) <- c("Sample_ID", "Sample_type","Project_id")
TCGA_sheet_pretreatment <- TCGA_sheet |>
mutate(Sample_ID = substr(Sample_ID, 1, 15)) |>
unique()
### We use our naming standard mutate a new column cohort.
TCGA_after_processing <- TCGA_sheet_pretreatment |>
left_join(TCGA_info, by = c("Sample_ID" = "Sample_ID")) |>
mutate(
cohort = Project_id,
Run = Sample_ID,
Patient_ID = substr(Sample_ID, 1, 12),
)
### TCGA Sample type
### TCGA_after_processing$Sample_type |> unique()
### [1] "Primary Tumor" "Solid Tissue Normal" "Metastatic"
### [4] "Additional - New Primary" "Primary Blood Derived Cancer - Peripheral Blood" "Additional Metastatic"
### [7] "Recurrent Tumor"
###
### "Solid Tissue Normal" is normal sample, others is tumor sample
TCGA_NORMAL <- TCGA_after_processing |>
filter(Sample_type == "Solid Tissue Normal")
NORMAL_id <- TCGA_NORMAL$Run |> unique()
TCGA_after_processing <- TCGA_after_processing |>
mutate(
Project_id = cohort,
cohort = case_when(
Run %in% NORMAL_id ~ "TCGA-NORMAL",
TRUE ~ cohort))
### make sure nrow is same between Before and After Processing.
TCGA_after_processing |> nrow()
### [1] 10545
TCGA_sheet_pretreatment |> nrow()
### [1] 10545
### make sure IOBR/TME data just contain sample which tcga_sheet gave.
detected_id_TCGA <- TCGA_after_processing$Run |> unique()
### save info
cohorts <- unique(TCGA_after_processing$cohort)
file_name1 <- paste0("/home/data2/Projects/Fusion/fusiondb_v3/Clininfo/")
for (cohort1 in cohorts) {
cohort_data <- subset(TCGA_after_processing, cohort == cohort1)
name <- gsub("-", "_", cohort1)
file_name <- paste0(file_name1, name ,"_info.tsv")
fwrite(cohort_data , file = file_name, sep = "\t")
}
## Gene
metafusion1 <- metafusion |>
mutate(
cohort = case_when(
Sample_ID %in% TCGA_after_processing$Run & grepl("TCGA", cohort) ~ TCGA_after_processing$cohort[match(Sample_ID, TCGA_after_processing$Run)],
TRUE ~ cohort
)
)
cp_file_name1 <- "/home/data2/Projects/Fusion/fusiondb_v3/metafusion_gdc_divide.tsv"
fwrite(metafusion1, file = cp_file_name1, sep = "\t")
## IOBR
folder_path <- "/home/data2/Projects/Fusion/fusiondb/IOBR"
file_pattern <- "^TCGA.*_IOBR_signature.tsv.gz$"
file_list <- list.files(path = folder_path, pattern = file_pattern, full.names = TRUE)
combined_data <- data.table()
for (file in file_list) {
file_data <- fread(file, sep = "\t")
file_name <- basename(file)
project_id <- sub("^(TCGA-[^_]+).*", "\\1", file_name)
file_data <- file_data %>%
mutate(Project_id = project_id)
combined_data <- rbind(combined_data, file_data)
}
### Filter TCGA Replicate Samples
### The filter rule following broad institute says:
###
### In many instances there is more than one aliquot for a given combination of individual, platform, and data type. However, only one aliquot may be ingested into Firehose. Therefore, a set of precedence rules are applied to select the most scientifically advantageous one among them. Two filters are applied to achieve this aim: an Analyte Replicate Filter and a Sort Replicate Filter.
###
### Analyte Replicate Filter
### The following precedence rules are applied when the aliquots have differing analytes. For RNA aliquots, T analytes are dropped in preference to H and R analytes, since T is the inferior extraction protocol. If H and R are encountered, H is the chosen analyte. This is somewhat arbitrary and subject to change, since it is not clear at present whether H or R is the better protocol. If there are multiple aliquots associated with the chosen RNA analyte, the aliquot with the later plate number is chosen. For DNA aliquots, D analytes (native DNA) are preferred over G, W, or X (whole-genome amplified) analytes, unless the G, W, or X analyte sample has a higher plate number.
###
### Sort Replicate Filter
### The following precedence rules are applied when the analyte filter still produces more than one sample. The sort filter chooses the aliquot with the highest lexicographical sort value, to ensure that the barcode with the highest portion and/or plate number is selected when all other barcode fields are identical.
###
### Ref Link: <https://confluence.broadinstitute.org/display/GDAC/FAQ#FAQ-sampleTypesQWhatTCGAsampletypesareFirehosepipelinesexecutedupon>
### <https://gist.github.com/ShixiangWang/33b2f9b49b77eaa8f773b428480f9101>
result_data <- combined_data |>
mutate(
prefixes = str_split(ID, "-", simplify = TRUE)[, 1:4] %>% apply(1, paste, collapse = "-"),
suffixes = str_split(ID, "-", simplify = TRUE)[, 5],
second_chars = str_extract(suffixes, "[0-9]+"),
second_chars = as.integer(second_chars))
result_IOBR <- result_data |>
group_by(prefixes) |>
slice(which.max(second_chars)) |>
ungroup() |>
mutate(cohort = Project_id,
ID = substr(prefixes, 1, 15),
cohort = case_when(ID %in% NORMAL_id ~ "TCGA-NORMAL",
TRUE ~ cohort)
) |>
filter(ID %in% detected_id_TCGA) |>
select(-c("suffixes", "second_chars","prefixes")) |>
unique()
cohorts_IOBR <- unique(result_IOBR$cohort)
for (cohort1 in cohorts_IOBR) {
cohort_data <- subset(result_IOBR, cohort == cohort1) |> select(-c(cohort,Project_id) )
file_name <- paste0("/home/data2/Projects/Fusion/fusiondb_v3/IOBR/", cohort1 ,"_IOBR_signature.tsv.gz")
write.table(cohort_data,
file = gzfile(file_name),
sep = "\t",
row.names = FALSE,
quote = FALSE)
}
## TME
folder_path <- "/home/data2/Projects/Fusion/fusiondb/IOBR"
file_pattern <- "^TCGA.*_TME.tsv.gz$"
file_list <- list.files(path = folder_path, pattern = file_pattern, full.names = TRUE)
combined_data1 <- data.table()
for (file in file_list) {
file_data <- fread(file, sep = "\t")
file_name <- basename(file)
project_id <- sub("^(TCGA-[^_]+).*", "\\1", file_name)
file_data <- file_data %>%
mutate(Project_id = project_id)
combined_data1 <- rbind(combined_data1, file_data)
}
result_data1 <- combined_data1 |>
mutate(
prefixes = str_split(ID, "-", simplify = TRUE)[, 1:4] %>% apply(1, paste, collapse = "-"),
suffixes = str_split(ID, "-", simplify = TRUE)[, 5],
second_chars = str_extract(suffixes, "[0-9]+"),
second_chars = as.integer(second_chars))
result_TME <- result_data1 |>
group_by(prefixes) |>
slice(which.max(second_chars)) |>
ungroup() |>
mutate(cohort = Project_id,
ID = substr(prefixes, 1, 15),
cohort = case_when(ID %in% NORMAL_id ~ "TCGA-NORMAL",
TRUE ~ cohort)
) |>
filter(ID %in% detected_id_TCGA) |>
select(-c("suffixes", "second_chars","prefixes")) |>
unique()
cohorts_TME <- unique(result_TME$cohort)
for (cohort1 in cohorts_TME) {
cohort_data <- subset(result_TME, cohort == cohort1) |> select(-c(cohort,Project_id) )
file_name <- paste0("/home/data2/Projects/Fusion/fusiondb_v3/IOBR/", cohort1 ,"_TME.tsv.gz")
write.table(cohort_data,
file = gzfile(file_name),
sep = "\t",
row.names = FALSE,
quote = FALSE)
} Fusion Event Scoring and Classification
library(data.table)
library(dplyr)
library(stringr)
library(tidyr)
library(tibble)
file_meta <- "/data/data2/Projects/Fusion/fusiondb_v4/metafusion_gdc_divide.tsv"
metafusion <- fread(file_meta , sep = "\t")
cohort1 <- fread("/data/data2/Projects/Fusion/fusiondb_v4/cohorts_meta.csv")
# Stratification Strategy
## 1. For tumor samples, if there are at least two samples within the total cohorts of a disease that have detected the same fusion value, +1 score.
## 2. If one fusion event's max_split_cnt and max_span_cnt are both greater than or equal to 1, +1 score;
## 3. If Arriba and STAR-Fusion detected identical fusion event, +1 score;
## 4. score >= 2 , high confident fusion, else low confident fusion
Tumor_data <- metafusion |>
filter(!(gene1 %in% c("IGH@-ext", "IGL@-ext", "IGL-@-ext", "IGH-@-ext") |
gene2 %in% c("IGH@-ext", "IGL@-ext", "IGL-@-ext", "IGH-@-ext"))) |>
mutate(
Score = 0,
fusion = paste0(gene1,"::",gene2),
disease = case_when(
grepl( "TCGA", cohort) ~ gsub("^TCGA-", "", cohort),
grepl( "TARGET", cohort) ~ gsub("^TARGET-", "", cohort),
grepl( "CPTAC", cohort) ~ gsub("^CPTAC-", "", cohort),
!cohort %in% c("TCGA", "TARGET", "CPTAC") ~ cohort1$cancer_type[match(cohort, cohort1$id)],
TRUE ~ NA
),
disease = case_when(
disease %in% c("LUSC", "LUAD") ~ "NSCLC",
TRUE ~ disease
)
)
### 1. frequence
Tumor_data1 <- Tumor_data %>%
group_by(disease, fusion) %>%
mutate(Score = case_when(
sample_type %in% c("Tumor", "Blood") & n_distinct(Sample_ID) >= 2 ~ Score + 1,
TRUE ~ Score)
) %>%
ungroup()
### 2. Reads counts
Tumor_data2 <- Tumor_data1 %>%
mutate(
Score = case_when(
max_split_cnt >= 1 & max_span_cnt >= 1 ~ Score + 1,
TRUE ~ Score
)
)
### 3. Tools detected
Tumor_data3 <- Tumor_data2 %>%
mutate(
Score = case_when(
tools == "arriba,starfusion" ~ Score + 1,
TRUE ~ Score)
)
# Annotate Strategy
## Annotate the gene types of the 5' gene and 3' gene based on the /gencode.v34.annotation.gtf file
gtf = fread("/data/data2/reference/hg38_ek12/gencode.v34.annotation.gtf")
extract_col <- function(x, name) {
library(magrittr)
stringr::str_extract(x, paste0(name, " ([^;]+);")) %>%
stringr::str_remove(paste0(name, " ")) %>%
stringr::str_remove_all("\"") %>%
stringr::str_remove(";")
}
gtf[, gene_type := extract_col(V9, "gene_type")]
table(gtf$gene_type)
table(gtf$V3)
gtf_gene = gtf[V3 == "gene"]
df <- gtf_gene %>%
mutate(
gene_id = str_replace(str_extract(V9, 'gene_id ".*?";'), 'gene_id "|";', ''),
gene_name = str_replace(str_extract(V9, 'gene_name ".*?";'), 'gene_name "|";', '')
) |>
mutate(
gene_id = str_replace(gene_id, '";$', ''),
gene_name = str_replace(gene_name, '";$', '')
)
## Annotate the gene types of the 5' gene and 3' gene based on the ucsc genome browser and genecards
match_type <- c(
"AL357556.3" = "lncRNA",
"Y_RNA" = "misc_RNA",
"PDCD6-AHRR"= "ncRNA",
"AHI1-DT"= "lncRNA",
"STX17-DT"= "lncRNA",
"ASMER1"= "lncRNA",
"B3GAT1-DT"= "lncRNA",
"C10orf95-AS1"= "lncRNA",
"C12orf75-AS1" = "lncRNA",
"CARINH"= "lncRNA",
"CCDST"= "lncRNA",
"CENATAC-DT"= "lncRNA",
"CFAP418-AS1"= "lncRNA",
"CHASERR"= "lncRNA",
"CHD1-DT"= "lncRNA",
"CMKLR2-AS"= "lncRNA",
"COX10-DT"= "lncRNA",
"CTD-2350J17.1"= "lncRNA",
"DIP2C-AS1"= "lncRNA",
"HSD52"= "lncRNA",
"EOLA2-DT"= "lncRNA",
"EPM2A-DT"= "lncRNA",
"ERCC6L2-AS1"= "lncRNA",
"ZNF8-ERVK3-1"= "lncRNA",
"FKBP14-AS1"= "lncRNA",
"HISLA"= "lncRNA",
"JUN-DT"= "lncRNA",
"KC6"= "lncRNA",
"KLRK1-AS1"= "lncRNA",
"KRT10-AS1"= "lncRNA",
"LINC00540"= "lncRNA",
"LINC01012"= "lncRNA",
"LINC01036"= "lncRNA",
"LINC01451"= "lncRNA",
"LINC02882"= "lncRNA",
"LINC02884"= "lncRNA",
"LINC02909"= "lncRNA",
"LINC02910"= "lncRNA",
"LINC03040"= "lncRNA",
"LITATS1"= "lncRNA",
"LNCBRM"= "lncRNA",
"LRP8-DT"= "lncRNA",
"LY6S-AS1"= "lncRNA",
"LYRM4-AS1"= "lncRNA",
"MAILR"= "lncRNA",
"MGC4859"= "lncRNA",
"MIR325HG"= "lncRNA",
"MIR3667HG"= "lncRNA",
"NCRNA00250"= "lncRNA",
"NIHCOLE"= "lncRNA",
"NOVA1-DT"= "lncRNA",
"OSMR-DT"= "lncRNA",
"PDXP-DT"= "lncRNA",
"PELATON"= "lncRNA",
"PITX1-AS1"= "lncRNA",
"PRDX6-AS1"= "lncRNA",
"PRKG2-AS1"= "lncRNA",
"RBM38-AS1"= "lncRNA",
"RFX3-DT"= "lncRNA",
"RNF32-AS1"= "lncRNA",
"RPL37A-DT"= "lncRNA",
"SEC61G-DT"= "lncRNA",
"SEZ6L-AS1"= "lncRNA",
"SLC12A2-DT"= "lncRNA",
"SLC2A1-DT"= "lncRNA",
"SMARCAL1-AS1"= "lncRNA",
"SMC5-DT"= "lncRNA",
"SNHG33"= "lncRNA",
"SRI-AS1"= "lncRNA",
"SRP14-DT"= "lncRNA",
"STAM-DT"= "lncRNA",
"SUCLG2-DT"= "lncRNA",
"TENM2-AS1"= "lncRNA",
"TMCC1-DT"= "lncRNA",
"TMEM132E-DT"= "lncRNA",
"TMEM161B-DT"= "lncRNA",
"TP73-AS3"= "lncRNA",
"UBA6-DT"= "lncRNA",
"UBL7-DT"= "lncRNA",
"YWHAH-AS1"= "lncRNA",
"ZNF567-DT"= "lncRNA",
"ZNRD2-DT"= "lncRNA",
"ZRANB2-DT"= "lncRNA",
"MIR4432HG"= "lncRNA",
"CTD-2194D22.4"= "lncRNA",
"SMASR"= "lncRNA",
"CFAP20DC-AS1"= "lncRNA",
"TMEM139-AS1"= "lncRNA",
"FLJ12825"= "lncRNA",
"RIPOR3-AS1"= "lncRNA",
"LL22NC03-63E9.3"= "lncRNA",
"HRAT17"= "lncRNA",
"LINC01377"= "lncRNA",
"FLJ46284"= "lncRNA",
"SMC2-DT"= "lncRNA",
"MIR9-1HG"= "lncRNA",
"LINC03042"= "lncRNA",
"EFCAB13-DT"= "lncRNA",
"UST-AS2"= "lncRNA",
"FLJ40194"= "lncRNA",
"LINC02898"= "lncRNA",
"LINC02899"= "lncRNA",
"IRAG1-AS1"= "lncRNA",
"KU-MEL-3"= "lncRNA",
"CRAT37"= "lncRNA",
"LINC03041"= "lncRNA",
"TNPO1-DT"= "lncRNA",
"SDK1-AS1"= "lncRNA",
"KCNK4-CATSPERZ"= "lncRNA",
"PIK3IP1-DT"= "lncRNA",
"USP12-DT"= "lncRNA",
"STK4-DT"= "lncRNA",
"UCA1-AS1"= "lncRNA",
"LOHAN2"= "lncRNA",
"NTRAS"= "lncRNA",
"LINC02903"= "lncRNA",
"D21S2088E"= "ncRNA",
"CIBAR1-DT"= "lncRNA",
"PAXIP1-DT"= "lncRNA",
"TPTE2-AS1"= "lncRNA",
"EPCIP-AS1"= "lncRNA",
"LINC02901"= "lncRNA",
"SCG5-AS1"= "lncRNA",
"TAF12-DT"= "lncRNA",
"TM4SF19-DYNLT2B"= "ncRNA",
"ARGLU1-DT"= "lncRNA",
"RNF32-DT"= "lncRNA",
"ST3GAL3-AS1"= "lncRNA",
"SLC6A12-AS1"= "lncRNA",
"IRF2-DT"= "lncRNA",
"RDUR"= "lncRNA",
"FLJ40288"= "lncRNA",
"SYN3-AS1"= "lncRNA",
"RFX5-AS1"= "lncRNA",
"SHROOM3-AS1"= "lncRNA",
"LINC03124"= "lncRNA",
"LINC02897"= "lncRNA",
"APRG1"= "lncRNA",
"TAX1BP1-AS1"= "lncRNA",
"PIRAT1"= "lncRNA",
"LINC03122"= "lncRNA",
"LINC00904"= "lncRNA",
"FLJ20021"= "lncRNA",
"PTPRD-DT"= "lncRNA",
"HSDL2-AS1"= "lncRNA",
"BTG2-DT"= "lncRNA",
"LINC02900"= "lncRNA",
"JAKMIP1-DT"= "lncRNA",
"LINC03043"= "lncRNA",
"NDUFV1-DT"= "lncRNA",
"GOLGA7B-DT"= "lncRNA",
"FAM247A"= "lncRNA",
"GS1-24F4.2"= "lncRNA",
"REPIN1-AS1"= "lncRNA",
"IRX2-DT"= "lncRNA",
"MGC27382"= "lncRNA",
"LINC02348"= "lncRNA",
"ACTE1P"= "pseudogene",
"KLHDC7B-DT"= "lncRNA",
"THBS3-AS1"= "lncRNA",
"LINC01882"= "lncRNA",
"PTPRK-AS1"= "lncRNA",
"ZNF232-AS1"= "lncRNA",
"ACE2-DT"= "lncRNA",
"BMAL2-AS1"= "lncRNA",
"CRMA"= "lncRNA",
"SLC1A2-AS1"= "lncRNA",
"NECTIN4-AS1"= "lncRNA",
"TMEM30A-DT"= "lncRNA",
"XPC-AS1"= "lncRNA",
"LINC02961"= "lncRNA",
"MGC32805"= "lncRNA",
"LETR1"= "lncRNA",
"WDR11-DT"= "lncRNA",
"GASK1B-AS1"= "lncRNA",
"RRS1-DT"= "lncRNA",
"LINC02911"= "lncRNA",
"PDGFA-DT"= "lncRNA",
"CDKN2A-AS1"= "lncRNA",
"CCDC13-AS2"= "lncRNA",
"SIM1-AS1"= "lncRNA",
"UBR5-DT"= "lncRNA",
"UBE2E2-DT"= "lncRNA",
"MIR9-2HG"= "lncRNA",
"SGSM3-AS1"= "lncRNA",
"RABGAP1L-AS1"= "lncRNA",
"UNQ6494" = "lncRNA",
"FLJ42969" = "lncRNA",
"FLJ31356" = "ncRNA",
"Metazoa_SRP" = "misc_RNA",
"AC000050.2" = "lncRNA",
"AC007461.1" = "lncRNA",
"AC020765.6" = "protein_coding",
"AC026748.7" = "lncRNA",
"AC069544.2" = "protein_coding",
"AC105001.2" = "protein_coding",
"AC114744.2" = "lncRNA",
"AC137894.4" = "lncRNA",
"AC183088.4" = "lncRNA",
"AC233280.36" = "unprocessed_pseudogene",
"AL136295.22" = "lncRNA",
"AP000356.5" = "protein_coding",
"AL391628.1" = "protein_coding",
"AC006486.3" = "protein_coding",
"AC093246.1" = "protein_coding",
"AL713999.2" = "protein_coding",
"AC018630.4" = "protein_coding",
"AC133555.6" = "lncRNA",
"AC106873.8" = "protein_coding",
"AC084756.2" = "protein_coding",
"AC008763.4" = "protein_coding",
"AC134684.11" = "unprocessed_pseudogene",
"AC067945.4" = "lncRNA",
"AP000721.2" = "lncRNA",
"AL096814.2" = "protein_coding",
"AC004510.2" = "lncRNA",
"AL096870.12" = "lncRNA",
"AC011455.8" = "lncRNA",
"AC084018.3" = "lncRNA",
"AC016912.2" = "lncRNA",
"AC096576.7" = "lncRNA",
"AC113189.12" = "lncRNA",
"AC009093.11"= "lncRNA",
"AC092032.2" = "transcribed_unprocessed_pseudogene",
"AC113143.3" = "lncRNA",
"AC020929.1" = "lncRNA",
"FAM86C1P" = "pseudogene",
"BMAL1" = "protein_coding",
"G6PC1" = "protein_coding",
"GBA1" = "protein_coding",
"GBA1LP" = "pseudogene",
"GGTA1" = "protein_coding",
"CMKLR2" = "protein_coding",
"IRAG2" = "protein_coding",
"MTX1LP" = "pseudogene",
"PHB1" = "protein_coding",
"SNORD3P1" = "pseudogene",
"SKIC2" = "protein_coding",
"TAFAZZIN" = "protein_coding",
"DYNLT2" = "protein_coding",
"GFUS" = "protein_coding",
"ZNF56P" = "pseudogene",
"PRP4K" = "protein_coding",
"NHERF2" = "protein_coding",
"NHERF1" = "protein_coding",
"ENTREP1" = "protein_coding",
"ATP5MJ" = "protein_coding",
"SKIC3" = "protein_coding",
"BLTP2" = "protein_coding",
"GARRE1" = "protein_coding",
"IRAG1" = "protein_coding",
"ENTREP3" = "protein_coding",
"POLR1G" = "protein_coding",
"GUSBP15" = "pseudogene",
"CEP43" = "protein_coding",
"BLTP3B" = "protein_coding",
"SSPOP" = "pseudogene",
"KATNIP" = "protein_coding",
"ENTREP2" = "protein_coding",
"MATCAP2" = "protein_coding",
"RIGI" = "protein_coding",
"DNAAF11" = "protein_coding",
"TMT1A" = "protein_coding",
"DNAAF9" = "protein_coding",
"ZZZ3" = "protein_coding",
"FBXL9P" = "pseudogene",
"HAPSTR1" = "protein_coding",
"CFAP263" = "protein_coding",
"MYL11" = "protein_coding",
"ZFTRAF1" = "protein_coding",
"METTL25B" = "protein_coding",
"DUSP13B" = "protein_coding",
"METTL13" = "protein_coding",
"IFT25" = "protein_coding",
"SMIM11" = "protein_coding",
"BLTP3A" = "protein_coding",
"BPNT2" = "protein_coding",
"ADISSP" = "protein_coding",
"MTNAP1" = "protein_coding",
"NTAQ1" = "protein_coding",
"DYNC2I1" = "protein_coding",
"ODAD2" = "protein_coding",
"DNAI7" = "protein_coding",
"VNN3P" = "pseudogene",
"FIRRM" = "protein_coding",
"ZNG1A" = "protein_coding",
"ATOSA" = "protein_coding",
"SLC19A4P" = "pseudogene",
"BMAL2" = "protein_coding",
"FERRY3" = "protein_coding",
"LDAF1" = "protein_coding",
"GFOD3P" = "pseudogene",
"CEP15" = "protein_coding",
"CFAP92" = "protein_coding",
"ELAPOR1" = "protein_coding",
"NHSL3" = "protein_coding",
"FHIP2A" = "protein_coding",
"MYG1" = "protein_coding",
"FAM200C" = "protein_coding",
"STEEP1" = "protein_coding",
"PALS1" = "protein_coding",
"RUSF1" = "protein_coding",
"FHIP2B" = "protein_coding",
"CFAP68" = "protein_coding",
"SLC26A10P" = "pseudogene",
"CENPBD2P" = "pseudogene",
"ZFTA" = "protein_coding",
"AFG2B" = "protein_coding",
"INTS15" = "protein_coding",
"BBLN" = "protein_coding",
"CSTPP1" = "protein_coding",
"BRME1" = "protein_coding",
"CLXN" = "protein_coding",
"TOP6BL" = "protein_coding",
"SPRING1" = "protein_coding",
"DNAI4" = "protein_coding",
"IFT56" = "protein_coding",
"TASL" = "protein_coding",
"ATOSB" = "protein_coding",
"PHAF1" = "protein_coding",
"SKIC8" = "protein_coding",
"POLR1HASP" = "pseudogene",
"YJU2B" = "protein_coding",
"ODAD4" = "protein_coding",
"ARB2A" = "protein_coding",
"FHIP1B" = "protein_coding",
"BLTP1" = "protein_coding",
"SPATA31H1" = "protein_coding",
"QNG1" = "protein_coding",
"MFSD14CP" = "pseudogene",
"CDIN1" = "protein_coding",
"SANBR" = "protein_coding",
"HYCC1" = "protein_coding",
"SPMIP6" = "protein_coding",
"GARIN1B" = "protein_coding",
"C19orf48P" = "pseudogene",
"VCF1" = "protein_coding",
"SLX9" = "protein_coding",
"CFAP91" = "protein_coding",
"DYNC2I2" = "protein_coding",
"VCF2" = "protein_coding",
"RLIG1" = "protein_coding",
"MTRFR" = "protein_coding",
"STYXL2" = "protein_coding",
"KGD4" = "protein_coding",
"ODAD1" = "protein_coding",
"GOLM2" = "protein_coding",
"ZBED10P" = "pseudogene",
"DNAAF10" = "protein_coding",
"NOPCHAP1" = "protein_coding",
"ABTB3" = "protein_coding",
"CEP20" = "protein_coding",
"KRBOX5" = "protein_coding",
"CHCT1" = "protein_coding",
"TEKTL1" = "protein_coding",
"DNAI3" = "protein_coding",
"CFAP276" = "protein_coding",
"OR14L1" = "protein_coding",
"CIMAP3" = "protein_coding",
"CIMIP1" = "protein_coding",
"CFAP210" = "protein_coding",
"RPLP1P5" = "pseudogene",
"MIX23" = "protein_coding",
"CFAP90" = "protein_coding",
"SPMIP4" = "protein_coding",
"CIBAR1" = "protein_coding",
"CFAP95" = "protein_coding",
"SPATA31G1" = "protein_coding",
"DNAAF6" = "protein_coding",
"MTCL2" = "protein_coding",
"CFAP251" = "protein_coding",
"KICS2" = "protein_coding",
"DNAAF8" = "protein_coding",
"ARK2N" = "protein_coding",
"ZNF285BP" = "pseudogene",
"KASH5" = "protein_coding",
"NTMT2" = "protein_coding",
"ZDHHC8BP" = "pseudogene",
"ZNG1B" = "protein_coding",
"SLC66A1LP" = "pseudogene",
"SPMIP2" = "protein_coding",
"GARIN3" = "protein_coding",
"CFAP418" = "protein_coding",
"BRD10" = "protein_coding",
"PABIR2" = "protein_coding",
"PABIR3" = "protein_coding",
"TAMALIN" = "protein_coding",
"GARIN2" = "protein_coding",
"CIMAP2" = "protein_coding",
"AFG2A" = "protein_coding",
"GARIN6" = "protein_coding",
"DYNLT5" = "protein_coding",
"SPMIP3" = "protein_coding",
"ALG1L1P" = "pseudogene",
"CFAP20DC" = "protein_coding",
"PRSS59P" = "pseudogene",
"SAXO4" = "protein_coding",
"ZNG1E" = "protein_coding",
"POLR1F" = "protein_coding",
"ELAPOR2" = "protein_coding",
"LHFPL7" = "protein_coding",
"SPMIP11" = "protein_coding",
"DYNLT2B" = "protein_coding",
"SPATA31F1" = "protein_coding",
"DRC12" = "protein_coding",
"REDIC1" = "protein_coding",
"GREP1" = "protein_coding",
"PDXDC2P-NPIPB14P" = "pseudogene",
"CCDC144BP" = "pseudogene",
"PTGR3" = "protein_coding",
"ACTMAP" = "protein_coding",
"CIMAP1D" = "protein_coding",
"EEIG2" = "protein_coding",
"HYCC2" = "protein_coding",
"RIMOC1" = "protein_coding",
"CSGALNACT2P1" = "pseudogene",
"FAM3C2P" = "pseudogene",
"GCATP1" = "pseudogene",
"SSX13P" = "pseudogene",
"DUSP29" = "protein_coding",
"CENATAC" = "protein_coding",
"CIMIP4" = "protein_coding",
"IHO1" = "protein_coding",
"AKR1C8" = "protein_coding",
"POU2AF2" = "protein_coding",
"CRACDL" = "protein_coding",
"GARIN1A" = "protein_coding",
"CASTOR3P" = "pseudogene",
"PKD1P4" = "pseudogene",
"USP41P" = "pseudogene",
"FBXW10B" = "protein_coding",
"SPMIP8" = "protein_coding",
"SAXO5" = "protein_coding",
"MTCL3" = "protein_coding",
"PEDS1" = "protein_coding",
"PEDS1-UBE2V1" = "protein_coding",
"GPR15LG" = "protein_coding",
"SPMAP1" = "protein_coding",
"MEIOSIN" = "protein_coding",
"SMIM34" = "protein_coding",
"EEIG1" = "protein_coding",
"LIAT1" = "protein_coding",
"SPACDR" = "protein_coding",
"TEX56P" = "pseudogene",
"CARD17P" = "pseudogene",
"TTLL13" = "protein_coding",
"CIMAP1B" = "protein_coding",
"UQCC5" = "protein_coding",
"CFAP96" = "protein_coding",
"ARK2C" = "protein_coding",
"TPRX2" = "protein_coding",
"TUBAP13" = "pseudogene",
"HNRNPA1L3" = "protein_coding",
"FAM25EP" = "pseudogene",
"PAFAH1B2P2" = "pseudogene",
"CASP4LP" = "pseudogene",
"CCDC121P1" = "pseudogene",
"ZNG1F" = "protein_coding",
"UQCR10P1" = "pseudogene",
"CBX3P2" = "pseudogene",
"FAM90A12" = "protein_coding",
"RHPN2P1" = "pseudogene",
"OSTCP3" = "pseudogene",
"ZNF285CP" = "pseudogene",
"ZKSCAN8P1" = "pseudogene",
"MATCAP1" = "protein_coding",
"CSPG4BP" = "pseudogene",
"NALF1" = "protein_coding",
"UQCC6" = "protein_coding",
"FHIP1A" = "protein_coding",
"RPL35AP20" = "pseudogene",
"SRSF6P1" = "pseudogene",
"CIROP" = "protein_coding",
"SPATA31F3" = "protein_coding",
"JPT1P1" = "pseudogene",
"SPMIP7" = "protein_coding",
"ZNF705EP" = "pseudogene",
"GOLGA6L3P" = "pseudogene",
"GUSBP13" = "pseudogene",
"NME2P3" = "pseudogene",
"B3GALT9" = "protein_coding",
"FMN2P1" = "pseudogene",
"ALOXE3P1" = "pseudogene",
"CDRT15P6" = "pseudogene",
"KPNA4P1" = "pseudogene",
"RBX1P2" = "pseudogene",
"LASP1NB" = "protein_coding",
"PPP5D1P" = "pseudogene",
"MISFA" = "protein_coding",
"SPMAP2L" = "protein_coding",
"TBC1D3JP" = "pseudogene",
"DNAJB6P3" = "pseudogene",
"NOTCH2NLR" = "protein_coding",
"C3orf86P" = "pseudogene",
"PKD1P6-NPIPP1" = "pseudogene",
"NFILZ" = "protein_coding",
"MALLP2" = "pseudogene",
"CSGALNACT2P2" = "pseudogene",
"MTND6P35" = "pseudogene",
"BMS1P4-AGAP5" = "pseudogene",
"ABCF2-H2BK1" = "protein_coding",
"MS4A19P" = "pseudogene",
"TBCEL-TECTA" = "protein_coding",
"FAM246C" = "protein_coding"
)
match_df <- data.frame(
gene_name = names(match_type),
gene_type = match_type,
stringsAsFactors = FALSE
)
match_all <- df |>
select(gene_name,gene_type) |>
bind_rows(match_df)
gene_type_map <- match_all %>%
distinct(gene_name, gene_type) %>%
deframe()
fusion_distribution <- Tumor_data3 %>%
filter(!(gene1 %in% c("IGH@-ext", "IGL@-ext", "IGL-@-ext", "IGH-@-ext") |
gene2 %in% c("IGH@-ext", "IGL@-ext", "IGL-@-ext", "IGH-@-ext"))) %>%
mutate(
gene1_type = sapply(str_split(gene1, ","), function(genes) {
types <- gene_type_map[genes]
paste(types[!is.na(types)], collapse = ",")
}),
gene2_type = sapply(str_split(gene2, ","), function(genes) {
types <- gene_type_map[genes]
paste(types[!is.na(types)], collapse = ",")
}
) )
gene2_nc <- fusion_distribution |> filter(is.na(gene2_type)) |> select(gene2) |> unique()
gene1_nc <- fusion_distribution |> filter(is.na(gene1_type)) |> select(gene1) |> unique()
nc <- c(gene1_nc$gene1, gene2_nc$gene2) |> unique()
nc
# New metafusion
metafusion_new <- fusion_distribution |>
select(-c(disease,fusion))
file_name <- "/data/data2/Projects/Fusion/fusiondb_v4/metafusion_calls.star.tsv"
write.table(metafusion_new,
file = file_name,
sep = "\t",
row.names = FALSE,
quote = FALSE)
Preprocessing code
The latest preprocessing and cohort-curation code used to build the ImmunoFusion database is maintained in the fusion_unclean repository. It includes fusion-call collection and filtering, clinical-data harmonization, sample-type and cohort annotation, and TME/IOBR preprocessing scripts.