Graph Construction

SmCCNet:

Example of running SmCCNet Workflow
import pandas as pd
from bioneuralnet.graph_generation import SmCCNet

def main():
    try:
        print("Starting SmCCNet Workflow...")

        phenotype_df = pd.DataFrame({
            'SampleID': ['S1', 'S2', 'S3', 'S4'],
            'Phenotype': ['Control', 'Treatment', 'Control', 'Treatment']
        })

        omics_df1 = pd.DataFrame({
            'SampleID': ['S1', 'S2', 'S3', 'S4'],
            'GeneA': [1.2, 2.3, 3.1, 4.0],
            'GeneB': [2.1, 3.4, 1.2, 3.3],
            'GeneC': [3.3, 1.5, 2.2, 4.1]
        })

        omics_df2 = pd.DataFrame({
            'SampleID': ['S1', 'S2', 'S3', 'S4'],
            'GeneD': [4.2, 5.3, 6.1, 7.0],
            'GeneE': [5.1, 6.4, 4.2, 6.3],
            'GeneF': [6.3, 4.5, 5.2, 7.1]
        })

        omics_dfs = [omics_df1, omics_df2]
        data_types = ['Transcriptomics', 'Proteomics']

        smccnet = SmCCNet(
            phenotype_df=phenotype_df,
            omics_dfs=omics_dfs,
            data_types=data_types,
            kfold=5,
            summarization="PCA",
            seed=732
        )

        adjacency_matrix = smccnet.run()

        print("\nAdjacency Matrix:")
        print(adjacency_matrix)

    except Exception as e:
        print(f"An error occurred during execution: {e}")
        raise e

if __name__ == "__main__":
    main()

WGCNA:

Example of running WGCNA Workflow
import pandas as pd
from bioneuralnet.graph_generation.wgcna import WGCNA

def run_wgcna_workflow(omics_data: pd.DataFrame,
                       phenotype_data: pd.Series,
                       data_types: list = ['gene', 'miRNA'],
                       soft_power: int = 6,
                       min_module_size: int = 30,
                       merge_cut_height: float = 0.25) -> pd.DataFrame:
    try:
        wgcna_instance = WGCNA(
            phenotype_data=phenotype_data,
            omics_data=omics_data,
            data_types=data_types,
            soft_power=soft_power,
            min_module_size=min_module_size,
            merge_cut_height=merge_cut_height,
        )

        adjacency_matrix = wgcna_instance.run()
        print("Adjacency matrix generated using WGCNA.")

        return adjacency_matrix

    except Exception as e:
        print(f"An error occurred during the WGCNA workflow: {e}")
        raise e

def main():
    try:
        print("Starting WGCNA Workflow...")

        omics_data = pd.DataFrame({
            'gene_feature1': [0.1, 0.2, 0.3],
            'gene_feature2': [0.4, 0.5, 0.6],
            'miRNA_feature1': [0.7, 0.8, 0.9],
            'miRNA_feature2': [1.0, 1.1, 1.2]
        }, index=['GeneA', 'GeneB', 'GeneC'])


        phenotype_data = pd.Series([0, 1, 0], index=['GeneA', 'GeneB', 'GeneC'], name='Phenotype')
        adjacency_matrix = run_wgcna_workflow(
            omics_data=omics_data,
            phenotype_data=phenotype_data
        )

        print("\nGenerated Adjacency Matrix:")
        print(adjacency_matrix)

        output_file = 'output/adjacency_matrix.csv'
        adjacency_matrix.to_csv(output_file)

        print(f"Adjacency matrix saved to {output_file}")
        print("\nWGCNA Workflow completed successfully.")

    except Exception as e:
        print(f"An error occurred during execution: {e}")
        raise e

if __name__ == "__main__":
    main()