import pandas as pd 
import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt

import os
# Setting the working directory
os.chdir('workingDirectory') 

# Bicluster.py file. Have all implementations of the used metrics
from Bicluster import *

method  = "ISA" # For example
folder = "folderWithBiclusterFiles"
outputFolder = "outputFolder" #Folder were the csv with the metrics calculated will be stored

Metrics = ["Bic_ID",
           "method",
           "NumberTemporalPoints",
           "NumberRegionPoints",
           "Area",
           "Variance",
           "MSR",
           "SMSR",
           "VirtualError"
           ]

dataset = pd.DataFrame(columns = Metrics) 

Id_num = 0
for bicluster in os.listdir(folder): #Reading every bicluster
  # We are assuming that all csv files in the folder are biclusters. If not, change the conditions.
  if ".csv" in bic: #check if the file is a csv
    Id_num = Id_num + 1
    bic = ImportSingleBicluster(folder + "/", bicluster)
    x = bic.to_numpy()
    Id = method + str(Id_num)
    #adding the line to the pandas dataframe
    dataset.loc[Id] = np.nan
    dataset.loc[Id,"Bic_ID"] = Id
    dataset.loc[Id,"method"] = method
    dataset.loc[Id,"NumberTemporalPoints"] = ComputeNumberColumns(x)
    dataset.loc[Id,"NumberRegionPoints"] = ComputeNumberRows(x)
    dataset.loc[Id,"Area"] = ComputeArea(x)
    dataset.loc[Id,"Variance"] = ComputeVariance(x)
    dataset.loc[Id,"MSR"] = ComputeMSR(x)
    dataset.loc[Id,"SMSR"] = ComputeSMSR(x)
    dataset.loc[Id,"VirtualError"] = ComputeVirtualError(x)

dataset.to_csv(outputFolder + "/" + method + ".csv")