---
output:
  pdf_document: default
  html_document: default
---

```{r LIBRARIES, message=FALSE, warning=FALSE, paged.print=FALSE}
# Load required libraries
library(readxl)    # For reading data from Excel files
library(multiMiR)  # For querying validated miRNA-mRNA interactions
library(writexl)   # For writing data to Excel files
```

```{r LOAD DATA}
# Read data from an Excel file named "miRNAmRNA.xlsx" and store it in the "new_list" variable
new_list <- read_excel("C:/Users/Emre/Desktop/miRNAmRNA.xlsx")
mirnames <- new_list$miRNA
```

```{r MULTIMIR}
# Get validated miRNA-mRNA interactions using the "multiMiR" package.
# In this case, the interactions are queried for human (hsa) miRNAs (mirnames) from the "validated" table.
# The results will be summarized and stored in the "multimir_results" variable.
multimir_results <- get_multimir(org     = 'hsa',
                                 mirna   = mirnames,
                                 table   = 'validated',
                                 summary = TRUE)

# Display the first few rows of the "multimir_results" data to get an overview of the miRNA-mRNA interactions
head(multimir_results@data)
targets <- multimir_results@data

#excel_file <- "C:/Users/Emre/Desktop/Bioinformatik/Bioinformatik 2.Semester Master/Data Science in the Life Sciences/Project/multimir_results.xlsx"
#write_xlsx(targets, path = excel_file)
```

```{r MRNA FEATURE IMPORTANCE}
df <- read_excel("C:/Users/Emre/Desktop/multimir_results.xlsx")

#Read data from the "mRNAs.xlsx" file into the "mrna" variable.
mrna <- read_excel("C:/Users/Emre/Desktop/mRNAs.xlsx")
```

```{r}
# Extract the mrna names from the table
mrna_genes <-  mrna$mRNA
```

```{r }
# Filter the "df" data based on whether the "target_symbol" column contains gene names present in the "mrna_genes" variable.
filtered_df <- df[df$target_symbol %in% mrna_genes | duplicated(df$target_symbol) %in% mrna_genes, ]

# Print the filtered data.
print(filtered_df)
```