<filename>TFAxSample_expectation.py
import pandas as pd

#import metadata rows and columns
TF_list = pd.read_csv("TF_list_26th_oct.csv", delimiter="\t", header=None)
Sample_info = pd.read_csv("meta_data_col_A549_shRNA.tsv", delimiter="\t")

#unique elements
TFs = TF_list.iloc[:,0].str.strip()
Knock_down = Sample_info["cmap_name"]

#Inefficient Iteration party
TFs_x_Genes_matrix = []
for i, gene in enumerate(TFs):
    gene_across_samples = []
    for experiment in Knock_down:
        if gene==experiment:
            gene_across_samples.append(0)
        else:
            gene_across_samples.append(1)
    TFs_x_Genes_matrix.append(gene_across_samples)
    print(round(i / len(TFs) * 100, 2), "%")


#Export
pd.DataFrame(Sample_info).to_csv("Sample_info.csv",header=False, index=False)
pd.DataFrame(TFs).to_csv("TF_list_expect.csv",header=False, index=False)
big_matrix = pd.DataFrame(TFs_x_Genes_matrix)
big_matrix.to_csv("TF_x_Sample_expect.csv", header=False,index=False)