---
title: "OmicsData Example Usage"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{OmicsData Example Usage}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

# Example Usage of OmicsData

This vignette demonstrates how to use the `OmicsData` class and associated functions in the `omicsTools` package.

```{r setup, include=FALSE}
library(omicsTools)
```

## Example 1: Using Generated Data

```{r}

# Create an instance of OmicsData with generated data
omics_data <- createOmicsData()

# Define custom thresholds
custom_thresholds <- define_thresholds(skewness = 3, kurtosis = 8)

# Update the OmicsData object with custom thresholds
omics_data@thresholds <- custom_thresholds

# Calculate measures for each feature
omics_data <- calculate_measures(omics_data)

# Flag anomalies
omics_data <- flag_anomalies(omics_data)

# Plotting distribution measures
plot_distribution_measures(omics_data)

# Plotting sample measures
plot_sample_measures(omics_data)

# Prepare data for UpSet plot
upset_data <- prepare_upset_data(omics_data)

# Convert to binary matrix for UpSetR
upset_matrix <- convert_to_binary_matrix(upset_data)

# Ensure there are at least two columns for the UpSet plot
ensure_enough_sets_for_upset(upset_matrix)

```


## Example 2: Using User-Provided Data

```{r}
# Generate user data (replace with actual data loading if available)
user_data <- generate_data_with_anomalies(n_samples = 100, n_features = 200)
user_data
```

```{r}
# Create an instance of OmicsData with user-provided data
omics_data_user <- createOmicsData(data = user_data)
omics_data_user
```

```{r}
# Define custom thresholds
custom_thresholds_user <- define_thresholds(skewness = 4, kurtosis = 6, shapiro_p = 1e-5, cooks_distance = 0.5, lof = 10)
```

```{r}
# Update the OmicsData object with custom thresholds
omics_data_user@thresholds <- custom_thresholds_user
```

```{r}
# Calculate measures for each feature
omics_data_user <- calculate_measures(omics_data_user)
```

```{r}
# Flag anomalies
omics_data_user <- flag_anomalies(omics_data_user)
```


```{r}
# Plotting distribution measures
plot_distribution_measures(omics_data_user)
```

```{r}
# Plotting sample measures
plot_sample_measures(omics_data_user)
```

```{r}
# Prepare data for UpSet plot
upset_data_user <- prepare_upset_data(omics_data_user)
```


```{r}
# Convert to binary matrix for UpSetR
upset_matrix_user <- convert_to_binary_matrix(upset_data_user)
```

```{r}
# Ensure there are at least two columns for the UpSet plot
ensure_enough_sets_for_upset(upset_matrix_user)
```

