Commit 5d5d422a authored by BELCOUR Arnaud's avatar BELCOUR Arnaud

Add gene assoc in intersect and unique reaction files.

parent 3a4d1894
......@@ -39,10 +39,13 @@ from scipy.spatial.distance import squareform, pdist
def reaction_figure_creation(reaction_file, output_folder):
# Check if output_folder exists, if not create it.
output_folder_data = output_folder + '/data'
output_folder_data_intersect = output_folder + '/data/intersect'
output_folder_data_unique = output_folder + '/data/unique'
output_folder_upset = output_folder + '/upset_graph'
temp_data_folder = output_folder + '/upset_graph/temp_data/'
folders = [output_folder, output_folder_data, output_folder_upset, temp_data_folder]
folders = [output_folder, output_folder_data, output_folder_data_intersect,
output_folder_data_unique, output_folder_upset, temp_data_folder]
for folder in folders:
if not os.path.isdir("{0}".format(folder)):
......@@ -57,7 +60,7 @@ def reaction_figure_creation(reaction_file, output_folder):
# (columns with _formula contain the reaction formula)
columns = [column for column in all_reactions_dataframe.columns if '(sep=;)' not in column]
columns = [column for column in columns if '_formula' not in column]
reactions_dataframe = all_reactions_dataframe[columns]
reactions_dataframe = all_reactions_dataframe[columns].copy()
reactions_dataframe.set_index('reaction', inplace=True)
......@@ -123,9 +126,15 @@ def reaction_figure_creation(reaction_file, output_folder):
cluster_subintersection[set_list] = intersection_temp
cluster_species_name = '&'.join(['_'.join(cluster_classes[cluster]) for cluster in set_list])
cluster_subintersection_name[cluster_species_name] = list(intersection_temp)
# Create a file containing intersection between each cluster.
df = pa.DataFrame(dict([ (k,pa.Series(v)) for k,v in cluster_subintersection_name.items() ]))
df.to_csv(output_folder_data+'/intersect.tsv', sep='\t', index=None)
# Create a file containing intersection between each cluster.
df = pa.DataFrame({'reaction': list(intersection_temp)})
df.set_index('reaction', inplace=True)
gene_assoc_columns = [column for column in all_reactions_dataframe.columns if '(sep=;)' in column]
column_species = [ species for cluster in set_list for species in cluster_classes[cluster]]
temp_gene_assoc_columns = [gene_assoc for gene_assoc in gene_assoc_columns if gene_assoc.split('_genes_assoc')[0] in column_species]
gene_assoc_reactions = all_reactions_dataframe[temp_gene_assoc_columns]
df = df.join(gene_assoc_reactions)
df.to_csv(output_folder_data_intersect+'/'+cluster_species_name+'_intersect.tsv', sep='\t', index=True)
# Create reactions which intersect for each cluster.
cluster_subsubintersection = {}
......@@ -140,9 +149,15 @@ def reaction_figure_creation(reaction_file, output_folder):
cluster_unique = {}
for cluster in cluster_classes:
cluster_unique[cluster] = cluster_reactions[cluster]-cluster_intersections-cluster_subsubintersection[cluster]
# Create a file containing reactions unique for each cluster.
df = pa.DataFrame(dict([ ('&'.join(cluster_classes[k]),pa.Series(list(v))) for k,v in cluster_unique.items() ]))
df.to_csv(output_folder_data+'/unique.tsv', sep='\t', index=None)
# Create a file containing reactions unique for each cluster.
df = pa.DataFrame({'reaction': list(cluster_unique[cluster])})
df.set_index('reaction', inplace=True)
gene_assoc_columns = [column for column in all_reactions_dataframe.columns if '(sep=;)' in column]
column_species = [ species for species in cluster_classes[cluster]]
temp_gene_assoc_columns = [gene_assoc for gene_assoc in gene_assoc_columns if gene_assoc.split('_genes_assoc')[0] in column_species]
gene_assoc_reactions = all_reactions_dataframe[temp_gene_assoc_columns]
df = df.join(gene_assoc_reactions)
df.to_csv(output_folder_data_unique+'/'+'_'.join(cluster_classes[cluster])+'_unique.tsv', sep='\t', index=True)
# Create data for creating upset graph using intervene.
for cluster in cluster_classes:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment