ماهي ملفات MAF؟



ملف MAF هو اختصار لـ Mutation Annotation Format، وهو صيغة ملفات قياسية تُستخدم بشكل واسع في المعلوماتية الحيوية (Bioinformatics) لتخزين وتمثيل بيانات الطفرات الجينية المكتشفة في الدراسات الجينومية، خصوصًا في مجال أبحاث السرطان.

يُعتبر ملف الـ MAF تنسيقًا جدوليًا (جدول نصي مفصول بفواصل أو تبويبات) يضم معلومات وصفية عن كل طفرة جينية، بحيث يتيح للباحثين تبادل البيانات وتحليلها بطريقة موحّدة ومنظمة.

🟠 المحتويات الأساسية لملف MAF:

▪️ Gene Symbol (رمز الجين): اسم الجين الذي حدثت فيه الطفرة.

▪️ Chromosome (الكروموسوم): موقع الطفرة على الكروموسوم.

▪️ Start/End Position (موضع البداية والنهاية): الموقع الجينومي للطفرات.

▪️ Variant Classification (تصنيف الطفرة): يحدد نوع الطفرة (مثل: Silent، Missense، Nonsense، Frame-shift…).

▪️ Variant Type (نوع التغير): مثل SNP (تعدد أشكال النوكليوتيدات المفردة) أو Insertion أو Deletion.

▪️ Reference & Tumor Allele (الأليل المرجعي وأليل الورم): مقارنة بين التسلسل المرجعي والتغير المرصود.

▪️ Sample Information (معلومات العينة): مثل المريض، نوع النسيج (ورمي أو طبيعي).

ننطلق الآن للعمل على هذا الملف!




1. سنقوم بتهيئة بيئة العمل، ثم نحمّل الحزم البرمجية التي سنحتاج إليها أثناء هذه الورشة.

library(maftools)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(skimr)
## Warning: package 'skimr' was built under R version 4.5.1
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ ggplot2   3.5.2     ✔ stringr   1.5.1
## ✔ lubridate 1.9.4     ✔ tibble    3.2.1
## ✔ purrr     1.0.4     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(data.table)
## 
## Attaching package: 'data.table'
## 
## The following objects are masked from 'package:lubridate':
## 
##     hour, isoweek, mday, minute, month, quarter, second, wday, week,
##     yday, year
## 
## The following object is masked from 'package:purrr':
## 
##     transpose
## 
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
library(ggrepel)



2. نقوم بقراءة ملف البيانات الوصفية الذي تم حفظه في اليوم الأول

url <- "https://raw.githubusercontent.com/Dalah-Info/health-info-bioinformatics-r/refs/heads/main/Day1/Breast_tumor_metadata_cleaned.csv"
Breast_tumor_metadata = read.csv(url,  row.names = NULL)



3. نقوم بقراءة ملف الطفرات الجينية: MFA

url2 <- "https://github.com/Dalah-Info/health-info-bioinformatics-r/raw/refs/heads/main/maf_file/filtered_maf_breast_only_maftools.maf.gz"
maf_file = read.maf(maf = url2)
## -Reading
## -Validating
## -Silent variants: 44872 
## -Summarizing
## --Possible FLAGS among top ten genes:
##   TTN
##   MUC16
##   FLG
## -Processing clinical data
## --Missing clinical data
## -Finished in 11.9s elapsed (9.390s cpu)



4. نستكشف شكل ملف MAF والبيانات المسجلة فيه

head(maf_file@data) #البيانات الوصفية للحينات نجدها في هذه الخانة

نقوم باستخدام أداة skimr لتقرأ لنا الملف الوصفي كاملا

skim(maf_file@data) 
Data summary
Name
Number of rows 85864
Number of columns 114
Key NULL
_______________________
Column type frequency:
character 100
factor 3
numeric 11
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
Hugo_Symbol 0 1 1 18 0 16686 0
Center 0 1 1 1 0 1 0
NCBI_Build 0 1 6 6 0 1 0
Chromosome 0 1 1 2 0 24 0
Strand 0 1 1 1 0 1 0
Reference_Allele 0 1 1 61745 0 1184 0
Tumor_Seq_Allele1 0 1 1 61745 0 1184 0
Tumor_Seq_Allele2 0 1 1 66 0 186 0
dbSNP_RS 0 1 1 35 0 21513 0
dbSNP_Val_Status 0 1 1 1 0 1 0
Matched_Norm_Sample_Barcode 0 1 28 28 0 1040 0
Match_Norm_Seq_Allele1 0 1 1 61745 0 1184 0
Match_Norm_Seq_Allele2 0 1 1 61745 0 1184 0
Tumor_Validation_Allele1 0 1 1 1 0 1 0
Tumor_Validation_Allele2 0 1 1 1 0 1 0
Match_Norm_Validation_Allele1 0 1 1 1 0 1 0
Match_Norm_Validation_Allele2 0 1 1 1 0 1 0
Verification_Status 0 1 1 1 0 1 0
Validation_Status 0 1 1 1 0 1 0
Mutation_Status 0 1 1 1 0 1 0
Sequencing_Phase 0 1 1 1 0 1 0
Sequence_Source 0 1 1 1 0 1 0
Validation_Method 0 1 1 1 0 1 0
Score 0 1 1 1 0 1 0
BAM_File 0 1 1 1 0 1 0
Sequencer 0 1 1 1 0 1 0
Tumor_Sample_UUID 0 1 1 1 0 1 0
Matched_Norm_Sample_UUID 0 1 1 1 0 1 0
HGVSc 0 1 1 22890 0 39030 0
HGVSp 0 1 1 90 0 59584 0
HGVSp_Short 0 1 1 40 0 60497 0
Transcript_ID 0 1 15 15 0 16784 0
Exon_Number 0 1 1 8 0 3640 0
all_effects 0 1 41 3818 0 84508 0
Allele 0 1 1 66 0 186 0
Gene 0 1 15 15 0 16695 0
Feature 0 1 15 15 0 16784 0
Feature_type 0 1 10 10 0 1 0
Consequence 0 1 9 24 0 12 0
cDNA_position 0 1 1 13 0 11610 0
CDS_position 0 1 1 13 0 11024 0
Protein_position 0 1 1 11 0 5784 0
Amino_acids 0 1 1 2920 0 1568 0
Codons 0 1 1 8758 0 2419 0
Existing_variation 0 1 1 334 0 60584 0
ALLELE_NUM 0 1 1 1 0 1 0
DISTANCE 0 1 1 1 0 1 0
SYMBOL 0 1 1 18 0 16686 0
SYMBOL_SOURCE 0 1 4 24 0 4 0
HGNC_ID 0 1 1 5 0 16563 0
BIOTYPE 0 1 7 34 0 13 0
CANONICAL 0 1 1 3 0 2 0
CCDS 0 1 1 11 0 16120 0
ENSP 0 1 1 15 0 16765 0
SWISSPROT 0 1 1 65 0 15940 0
TREMBL 0 1 1 3288 0 8780 0
UNIPARC 0 1 1 13 0 16716 0
RefSeq 0 1 1 1 0 1 0
SIFT 0 1 1 32 0 205 0
PolyPhen 0 1 1 24 0 1003 0
EXON 0 1 1 8 0 3640 0
INTRON 0 1 1 8 0 729 0
DOMAINS 0 1 1 1667 0 44012 0
GMAF 0 1 1 17 0 149 0
AFR_MAF 0 1 1 17 0 108 0
AMR_MAF 0 1 1 17 0 43 0
ASN_MAF 0 1 1 1 0 1 0
EAS_MAF 0 1 1 17 0 72 0
EUR_MAF 0 1 1 15 0 36 0
SAS_MAF 0 1 1 17 0 64 0
AA_MAF 0 1 1 17 0 270 0
EA_MAF 0 1 1 17 0 137 0
CLIN_SIG 0 1 1 54 0 26 0
SOMATIC 0 1 1 55 0 109 0
PUBMED 0 1 1 92 0 61 0
MOTIF_NAME 0 1 1 1 0 1 0
MOTIF_POS 0 1 1 1 0 1 0
HIGH_INF_POS 0 1 1 1 0 1 0
MOTIF_SCORE_CHANGE 0 1 1 1 0 1 0
IMPACT 0 1 4 8 0 3 0
PICK 0 1 1 1 0 1 0
VARIANT_CLASS 0 1 3 12 0 4 0
TSL 0 1 1 1 0 1 0
HGVS_OFFSET 0 1 1 2 0 22 0
PHENO 0 1 1 55 0 152 0
MINIMISED 0 1 1 1 0 1 0
ExAC_AF 0 1 1 1 0 1 0
ExAC_AF_AFR 0 1 1 1 0 1 0
ExAC_AF_AMR 0 1 1 1 0 1 0
ExAC_AF_EAS 0 1 1 1 0 1 0
ExAC_AF_FIN 0 1 1 1 0 1 0
ExAC_AF_NFE 0 1 1 1 0 1 0
ExAC_AF_OTH 0 1 1 1 0 1 0
ExAC_AF_SAS 0 1 1 1 0 1 0
GENE_PHENO 0 1 1 1 0 2 0
FILTER 0 1 3 31 0 18 0
COSMIC 0 1 4 5629 0 3835 0
CENTERS 0 1 10 68 0 75 0
CONTEXT 0 1 11 61756 0 80417 0
DBVS 0 1 1 38 0 24 0

Variable type: factor

skim_variable n_missing complete_rate ordered n_unique top_counts
Variant_Classification 0 1 FALSE 9 Mis: 67056, Fra: 9253, Non: 5699, Spl: 2022
Variant_Type 0 1 FALSE 4 SNP: 74579, DEL: 10251, INS: 1032, ONP: 2
Tumor_Sample_Barcode 0 1 FALSE 1026 TCG: 5366, TCG: 4161, TCG: 3899, TCG: 3078

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
Entrez_Gene_Id 0 1 0.00 0.00 0 0 0 0 0 ▁▁▇▁▁
Start_Position 0 1 80053074.65 58360981.52 59392 34148848 65352191 119609094 249212537 ▇▆▃▂▁
End_Position 0 1 80053080.87 58360977.01 59392 34148848 65352191 119609094 249212537 ▇▆▃▂▁
t_depth 0 1 130.00 134.09 7 50 91 165 3230 ▇▁▁▁▁
t_ref_count 0 1 103.56 115.29 0 37 69 132 3150 ▇▁▁▁▁
t_alt_count 0 1 26.15 34.67 2 9 16 30 3063 ▇▁▁▁▁
n_depth 0 1 114.58 114.02 8 45 79 143 4046 ▇▁▁▁▁
n_ref_count 0 1 114.53 113.98 7 45 79 143 4045 ▇▁▁▁▁
n_alt_count 0 1 0.03 0.18 0 0 0 0 9 ▇▁▁▁▁
STRAND 0 1 -0.01 1.00 -1 -1 -1 1 1 ▇▁▁▁▇
NCALLERS 0 1 3.88 1.23 2 3 4 5 7 ▆▃▇▁▁



5. دمج ملف البيانات الوصفية والاكلينيكية مع ملف MAF

لماذا؟ 🔴

عادة ما يأتي ملف MAF منفصلا عن الملف الوصفي، ونحتاج لدمجهما معًا حتى نتمكن من تحليل الطفرات وربطها بهذه البيانات.

كيف؟ 🔴

نحتاج إلى عمود واحد مشترك بين الملفين، عادة يكون رمز العينة

أين نجد رمز العينة؟ 🔴

في ملف MAF، هناك نمطان من ترميز العينات (Sample Barcoding) يجب الانتباه لهما:

  1. نمط TCGA

  2. نمط UUID

اختر النمط الموجود في ملف الـ MAF وأيضًا في البيانات الوصفية (Metadata)، حتى تتمكن من ربط الجدولين باستخدام هذا العمود.

head(unique(maf_file@data$Tumor_Sample_UUID), 5) #لايوجد مدخلات
## [1] "."
head(unique(maf_file@data$Tumor_Sample_Barcode),5)
## [1] TCGA-3C-AAAU-01A-11D-A41F-09 TCGA-3C-AALI-01A-11D-A41F-09
## [3] TCGA-3C-AALJ-01A-31D-A41F-09 TCGA-3C-AALK-01A-11D-A41F-09
## [5] TCGA-4H-AAAK-01A-12D-A41F-09
## 1026 Levels: TCGA-3C-AAAU-01A-11D-A41F-09 ... TCGA-Z7-A8R6-01A-11D-A41F-09

سوف نختار رمز TCGA لأن UUID غير موجود في ملف الـ MAF.

🔴 رمز العينة في ملف MAF:

TCGA-OL-A66K-01A-11D-A29N-09 هو رمز كامل للعينة (sample/aliquot barcode). ويتكوّن من:

▪️ TCGA → المشروع (Project)

▪️ OL → موقع مصدر النسيج (Tissue Source Site - TSS)

▪️ A66K → معرّف المشارك (المريض) (Participant/Patient ID)

▪️ 01A → نوع العينة + القارورة (01 = ورم أولي “Primary tumor” ؛ A = قارورة)

▪️ 11D → الجزء + المحلل الحيوي (11 = جزء، D = DNA)

▪️ A29N → الصفيحة (Plate)

▪️ 09 → المركز (Center)

هل توجد هذه البيانات في ملف البيانات الوصفية؟ لنتحقق من ذلك

head(unique(Breast_tumor_metadata$bcr_patient_barcode),5)
## [1] "TCGA-3C-AAAU" "TCGA-3C-AALI" "TCGA-3C-AALJ" "TCGA-3C-AALK" "TCGA-4H-AAAK"

🔴رمز العينة في البيانات الوصفية (Metadata):

لدينا فقط رمز المريض (Patient Barcode) مثل: TCGA-EW-A6S9، وهو يتكون فقط من أول 12 حرفًا من رمز الـ TCGA الكامل الموجود في ملف MAF.

✅ إذن القاعدة هي: رمز المريض في الملف الوصفي = أول 12 حرف من رمز العينة في ملف MAF.

#ننشئ ملف بيانات يحتوي على الرمز الطويل والقصير للمريض، لنستخدمه لاحقا للدمج.

id_map <- data.frame(
  short_id = substr(maf_file@data$Tumor_Sample_Barcode, 1, 12),             # معرّف المريض (12 حرف)
  Tumor_Sample_Barcode = as.character(maf_file@data$Tumor_Sample_Barcode),  # المعرّف الكامل للعينة
  stringsAsFactors = FALSE
)

#إزالة التكرار على مستوى المريض 
id_map <- id_map[!duplicated(id_map$short_id), ]


matched_clinical_data <- merge(
  x = Breast_tumor_metadata,     # البيانات السريرية
  y = id_map,                    # خريطة المعرّفات من ملف الـ MAF
  by.x = "bcr_patient_barcode",  # اسم عمود المريض في البيانات السريرية
  by.y = "short_id",             # اسم عمود المريض (12 حرف) في الخريطة
  all.x = FALSE                  # احتفظ فقط بالمرضى الموجودين في الـ MAF
)


## الآن: matched_clinical_data يحوي فقط المرضى المطابقين، وبداخله عمود Tumor_Sample_Barcode المشترك.



✅ نستطيع الآن إنشاء ملف MAF مكتمل، يحتوي على البيانات الوصفية الإكلينيكية:



maf_file <- read.maf(maf = url2, clinicalData = matched_clinical_data, verbose = F)

5. ننطلق الآن لاستكشاف الطفرات الجينية المُسجلة في ملف MAF!



5.1 ملخص الطفرات المٌسجلة في ملف MAF لكل مريض.🩺

getSampleSummary(maf_file)



5.2 ملخص الطفرات المٌسجلة في ملف MAF لكل جين.🧬

getGeneSummary(maf_file)



5.3 رسم ملخص شامل لمعظم البيانات

# رسم ملخص شامل: عدد الطفرات، نسب الأنواع المختلفة، إحصائيات عامة

plotmafSummary(maf = maf_file, rmOutlier = TRUE, addStat = 'median', dashboard = TRUE, titvRaw = FALSE)



5.4 رسم Oncoplot لأكثر 10 جينات تعرضاً للطفرات

تعبر رسمة الـ oncoplot واحدة من أشهر الرسومات المرتبطة بدراسة الطفرات ساعد الباحث على رؤية الأنماط الجينية (mutation patterns) وتحديد الجينات الحرجة في تطور السرطان.

# oncoplot يعرض الجينات الأعلى تكراراً في عينات المرضى

oncoplot(maf = maf_file, top = 10)




7. ربط الطفرات الجينية بالبيانات السريرية

7.1 👩‍⚕️ هل توجد جينات تترافق طفراتها مع جنس المريض؟

7.1.1 📈 نتأكد من أن البيانات مناسبة لإجراء التحليل الإحصائي.

# توزيع العينات حسب الجنس

table_gender <- table(maf_file@clinical.data$gender) 

barplot(table_gender,
        main = "Gender distribution of breast tumor cases",
        ylab = "Count",
        col = c("pink", "lightblue"))

نستنتج أن المقارنة هنا لن تنجح إحصائيا بسبب الاختلاف الكبير بعدد العينات بين الذكور والإناث.



7.2 ☢️ هل توجد جينات تترافق طفراتها مع حالة العلاج الإشعاعي للمريض؟

7.2.1 نتأكد من أن البيانات مناسبة لإجراء التحليل الإحصائي.

# ملخص حالة العلاج الإشعاعي من البيانات السريرية

table_radiation <- table(maf_file@clinical.data$radiation_therapy)

#رسم توزيع الحالات

barplot(table_radiation,
        main = "Radiation therapy status",
        ylab = "Count",
        col = c("orange", "gray70", "gray90", "lightblue", "tomato"),
        las = 2)  # rotate labels for readability

7.2.2 نحتاج لإزالة البيانات الغير مُسجلة أو المفقودة.

# توحيد القيم إلى YES/NO فقط، وما عدا ذلك يحوّل إلى NA
maf_file@clinical.data$radiation_therapy <- ifelse(
  maf_file@clinical.data$radiation_therapy %in% c("NO", "YES"),
  maf_file@clinical.data$radiation_therapy,
  NA
)

# إعادة حساب الجدول بعد التنظيف
table_radiation <- table(maf_file@clinical.data$radiation_therapy)

# رسم التوزيع بعد التنظيف (YES/NO فقط)
barplot(table_radiation,
        main = "Radiation therapy status",
        ylab = "Count",
        col = c( "lightblue", "tomato"),
        las = 2)  # rotate labels for readability

7.2.3 📈 نقوم الآن بإجراء الاختبار الإحصائي.

#Clinical feature enrichment using maftools

radiation_therapy.ce = clinicalEnrichment(maf = maf_file, clinicalFeature = 'radiation_therapy')
## Sample size per factor in radiation_therapy:
## 
##  NO YES 
## 417 509
head(radiation_therapy.ce)
## $pairwise_comparision
##       Hugo_Symbol Feature_1 Feature_2 n_mutated_Feature1 n_mutated_Feature2
##            <char>    <char>    <char>             <char>             <char>
##    1:       GATA3       YES        NO          43 of 509          74 of 417
##    2:       CECR2       YES        NO           0 of 509          10 of 417
##    3:     LEPREL1       YES        NO           0 of 509          10 of 417
##    4:        TAF1       YES        NO           5 of 509          19 of 417
##    5:      SLC9C2       YES        NO           0 of 509           9 of 417
##   ---                                                                      
## 4707:      ZNF681       YES        NO           3 of 509           3 of 417
## 4708:        ZNF7       YES        NO           3 of 509           3 of 417
## 4709:      ZNF727       YES        NO           3 of 509           3 of 417
## 4710:      ZNF808       YES        NO           3 of 509           2 of 417
## 4711:      ZNF835       YES        NO           3 of 509           2 of 417
##                fdr
##              <num>
##    1: 2.638048e-05
##    2: 3.229996e-04
##    3: 3.229996e-04
##    4: 6.993148e-04
##    5: 7.259574e-04
##   ---             
## 4707: 1.000000e+00
## 4708: 1.000000e+00
## 4709: 1.000000e+00
## 4710: 1.000000e+00
## 4711: 1.000000e+00
## 
## $groupwise_comparision
##       Hugo_Symbol Group1 Group2 n_mutated_group1 n_mutated_group2      p_value
##            <char> <char> <char>           <char>           <char>        <num>
##    1:       GATA3     NO   Rest        74 of 417        54 of 603 4.707496e-05
##    2:       GATA3    YES   Rest        43 of 509        85 of 511 9.527331e-05
##    3:       CECR2    YES   Rest         0 of 509        14 of 511 1.115576e-04
##    4:        HEPH     NO   Rest        11 of 417         1 of 603 3.731997e-04
##    5:        TAF1     NO   Rest        19 of 417         6 of 603 6.136316e-04
##   ---                                                                         
## 9418:      ZNF808     NO   Rest         2 of 417         4 of 603 1.000000e+00
## 9419:      ZNF808    YES   Rest         3 of 509         3 of 511 1.000000e+00
## 9420:      ZNF835     NO   Rest         2 of 417         4 of 603 1.000000e+00
## 9421:      ZNF835    YES   Rest         3 of 509         3 of 511 1.000000e+00
## 9422:      ZSWIM2     NO   Rest         2 of 417         4 of 603 1.000000e+00
##               OR     OR_low     OR_high       fdr
##            <num>      <num>       <num>     <num>
##    1:  2.1916620 1.48158961   3.2586141 0.3503653
##    2:  0.4627994 0.30554509   0.6928226 0.3503653
##    3:  0.0000000 0.00000000   0.2966865 0.3503653
##    4: 16.2760993 2.34917271 700.8659343 0.8715152
##    5:  4.7429700 1.80112749  14.6414327 0.8715152
##   ---                                            
## 9418:  0.7219096 0.06499789   5.0635451 1.0000000
## 9419:  1.0039488 0.13381620   7.5321046 1.0000000
## 9420:  0.7219096 0.06499789   5.0635451 1.0000000
## 9421:  1.0039488 0.13381620   7.5321046 1.0000000
## 9422:  0.7219096 0.06499789   5.0635451 1.0000000
## 
## $cf_sizes
##        cf     N
##    <char> <int>
## 1:     NO   417
## 2:    YES   509
## 3:   <NA>    94
## 
## $clinicalFeature
## [1] "radiation_therapy"
# إبراز المقارنات ذات الدلالة الإحصائية (p < 0.05)
radiation_therapy.ce$pairwise_comparision[fdr < 0.05]

7.2.4 📈 استخراج الجينات المرتبط بالعلاج الاشعاعي بطريقة أكثر صحة إحصائيا

#Extract pairwise comparisons table
df <- radiation_therapy.ce$pairwise_comparision

# extract numerator/denominator and compute relative frequencies

df[, c("mut1", "total1") := tstrsplit(n_mutated_Feature1, " of ", fixed=TRUE)]
df[, c("mut2", "total2") := tstrsplit(n_mutated_Feature2, " of ", fixed=TRUE)]

# Convert to numeric
df[, `:=`(mut1 = as.numeric(mut1),
          total1 = as.numeric(total1),
          mut2 = as.numeric(mut2),
          total2 = as.numeric(total2))]

# Compute relative values
df[, rel1 := mut1 / total1]
df[, rel2 := mut2 / total2]

df <- df[order(-rel1, -rel2)]
df <- df[fdr < 0.01]

# Take top 10 significant genes
top10 <- df[order(fdr)][1:10]


# Reshape to long format for ggplot
plotdf <- melt(top10,
               id.vars = "Hugo_Symbol",
               measure.vars = c("rel1", "rel2"),
               variable.name = "Feature",
               value.name = "Relative")

# Make Feature labels clearer
plotdf[, Feature := fifelse(Feature == "rel1", "Feature_1 (YES)", "Feature_2 (NO)")]

# Plot
ggplot(plotdf, aes(x = reorder(Hugo_Symbol, Relative), y = Relative, fill = Feature)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  coord_flip() +
  labs(x = "Gene", y = "Relative mutated fraction",
       title = "Top 10 significant genes by relative mutation frequency") +
  theme_minimal()




6. تحليل تأثير الطفرات على الحياة (هل تؤثر الطفرات في هذا الجين على مدة العيش؟)

لإجراء هذا التحليل نحتاج معلومتين رئيسيتين:

  1. حالة المريض: حي أو متوفى. ويجب كتابتها بطريقة 0 أو 1، حيث أن 0 ترمز للحياة و 1 ترمز للوفاة.

  2. يجب أن يكون لدينا عدد الأيام حتى آخر زيارة للمريض أو حتى وقت الوفاة.

6.1 نتأكد بأن البيانات تستوفي الشكل المطلوب لتطبيق التحليل

# 1) تحويل حالة الوفاة إلى 0/1
maf_file@clinical.data$vital_status <- ifelse(maf_file@clinical.data$vital_status %in% c("Dead", "1"), 1, 0)

# 2) تحويل الأيام إلى قيم رقمية
num <- function(x) suppressWarnings(as.numeric(as.character(x)))
dtd  <- num(maf_file@clinical.data$days_to_death)
dtlf <- num(maf_file@clinical.data$days_to_last_followup)

# 3) حساب زمن البقاء (OS.time): وقت الوفاة أو آخر متابعة

maf_file@clinical.data$OS.time <- ifelse(!is.na(dtd), dtd, dtlf)

# تأكيد أن القيم رقمية

maf_file@clinical.data[,vital_status :=  as.numeric(vital_status)]
maf_file@clinical.data[,OS.time :=  as.numeric(OS.time)]



6.2 🧬نقوم بتحليل تأثير الطفرات على الحياة في جين واحد فقط

# 4) تحليل البقاء لجين محدد (مثال: NEB)

mafSurvival(maf = maf_file, genes = 'NEB', time = 'OS.time', Status = 'vital_status', isTCGA = FALSE)
## Looking for clinical data in annoatation slot of MAF..
## Number of mutated samples for given genes:
## NEB 
##  54
## Median survival..
##     Group medianTime     N
##    <char>      <num> <int>
## 1: Mutant      984.5    54
## 2:     WT      823.5   966



6.3 🧬 تحليل تأثير الطفرات على الحياة باستخدام مجموعات من الجينات

ربما لا يكون لجين واحد تأثير كبير، ولكن في بعض الحالا وجود طفرتين في جينين مختلفين في وقت واحد يسبب إما وفاة أسرع أو يساعد على العيش لفترة أطول، ولاكتشاف ذلك نقوم بإجراء هذا التحليل.

# 5) تحليل البقاء لأكثر من جين

# البحث عن مجموعات جينات (مثلاً 2 جين) من بين أعلى 10 جين لتوقع البقاء

prog_geneset = survGroup(maf = maf_file, top = 10, geneSetSize = 2, time = "OS.time", Status = "vital_status", verbose = TRUE)
## ------------------
## genes: 10
## geneset size: 2
## 45 combinations
## Looking for clinical data in annoatation slot of MAF..
## Geneset:  PIK3CA,TP53 [N= 82 ]
## Geneset:  PIK3CA,TTN [N= 74 ]
## Geneset:  PIK3CA,CDH1 [N= 62 ]
## Geneset:  PIK3CA,GATA3 [N= 31 ]
## Geneset:  PIK3CA,MUC16 [N= 44 ]
## Geneset:  PIK3CA,KMT2C [N= 47 ]
## Geneset:  PIK3CA,MAP3K1 [N= 46 ]
## Geneset:  PIK3CA,FLG [N= 28 ]
## Geneset:  PIK3CA,RYR2 [N= 29 ]
## Geneset:  TP53,TTN [N= 84 ]
## Geneset:  TP53,CDH1 [N= 9 ]
## Geneset:  TP53,GATA3 [N= 11 ]
## Geneset:  TP53,MUC16 [N= 38 ]
## Geneset:  TP53,KMT2C [N= 27 ]
## Geneset:  TP53,MAP3K1 [N= 10 ]
## Warning in coxph.fit(X, Y, istrat, offset, init, control, weights = weights, :
## Loglik converged before variable 1 ; coefficient may be infinite.
## Geneset:  TP53,FLG [N= 28 ]
## Geneset:  TP53,RYR2 [N= 27 ]
## Geneset:  TTN,CDH1 [N= 32 ]
## Geneset:  TTN,GATA3 [N= 22 ]
## Geneset:  TTN,MUC16 [N= 44 ]
## Geneset:  TTN,KMT2C [N= 28 ]
## Geneset:  TTN,MAP3K1 [N= 10 ]
## Geneset:  TTN,FLG [N= 23 ]
## Geneset:  TTN,RYR2 [N= 25 ]
## Geneset:  CDH1,GATA3 [N= 10 ]
## Geneset:  CDH1,MUC16 [N= 20 ]
## Geneset:  CDH1,KMT2C [N= 13 ]
## Geneset:  CDH1,MAP3K1 [N= 9 ]
## Geneset:  CDH1,FLG [N= 9 ]
## Warning in coxph.fit(X, Y, istrat, offset, init, control, weights = weights, :
## Loglik converged before variable 1 ; coefficient may be infinite.
## Geneset:  CDH1,RYR2 [N= 12 ]
## Geneset:  GATA3,MUC16 [N= 12 ]
## Geneset:  GATA3,KMT2C [N= 13 ]
## Geneset:  GATA3,MAP3K1 [N= 9 ]
## Geneset:  GATA3,FLG [N= 8 ]
## Warning in coxph.fit(X, Y, istrat, offset, init, control, weights = weights, :
## Loglik converged before variable 1 ; coefficient may be infinite.
## Geneset:  GATA3,RYR2 [N= 9 ]
## Geneset:  MUC16,KMT2C [N= 17 ]
## Geneset:  MUC16,MAP3K1 [N= 8 ]
## Geneset:  MUC16,FLG [N= 18 ]
## Geneset:  MUC16,RYR2 [N= 21 ]
## Geneset:  KMT2C,MAP3K1 [N= 16 ]
## Geneset:  KMT2C,FLG [N= 9 ]
## Geneset:  KMT2C,RYR2 [N= 11 ]
## Geneset:  MAP3K1,RYR2 [N= 6 ]
## Geneset:  FLG,RYR2 [N= 8 ]
 #عرض أول 5 صفوف من النتيجة
head(prog_geneset, 5)



6.4 🪢 رسم نتائج التحليل لمجموعة من الجينات

# مثال: تحليل البقاء لجيني MUC17 و BRCA2

mafSurvGroup(maf = maf_file, geneSet = c("MUC17", "BRCA2"), time = "OS.time", Status = "vital_status")
## Looking for clinical data in annoatation slot of MAF..
## Median survival..
##     Group medianTime     N
##    <char>      <num> <int>
## 1: Mutant        170     5
## 2:     WT        847  1015




8. استخراج البيانات الجينية والدوائية

8.1 💊 البحث عن الأدوية المناسبة لكل جين في ملف MAF

# البحث عن تفاعلات دواء-جين للوحة الجينات المستخلصة من الـ MAF
dgi = drugInteractions(maf = maf_file, fontSize = 0.75)

8.2 ماذا عن الأدوية المُسجلة لجين واحد فقط؟

# استرجاع التفاعلات الدوائية لجين محدد
dnmt3a.dgi = drugInteractions(genes = "TP53", drugs = TRUE)
## Number of claimed drugs for given genes:
##      Gene     N
##    <char> <int>
## 1:   TP53   193
# عرض أعمدة مختارة مفيدة للتقارير
dnmt3a.dgi[,.(Gene, interaction_types, drug_name, drug_claim_name)]




9. استخراج مسارات أيضية مُتأثرة بالطفرات

pws = pathways(maf = maf_file, plotType = 'bar')
## Summarizing signalling pathways [Sanchez-Vega et al., https://doi.org/10.1016/j.cell.2018.03.035]

pws




✨ الخاتمة والملخص

في هذا الجزء من الورشة تعرفنا عمليًا على ملفات MAF المستخدمة في توصيف الطفرات الجينية، وكيفية استكشاف محتوياتها وربطها بالبيانات الإكلينيكية للمرضى.

✅ بهذا نكون قد وضعنا الأساس لفهم كيفية الانتقال من بيانات الطفرات الجينية الخام إلى تحليلات متقدمة تكشف أنماطًا بيولوجية وارتباطات إكلينيكية ذات أهمية بحثية وعلاجية.