public Ontology_enrichment_class Analyse_data_instance(Data_class data_input) { Data_class data = data_input.Deep_copy(); data.Keep_only_input_rowNames(this.Bg_genes); int data_length = data.Data_length; int col_length = data.ColChar.Columns_length; string[] symbols; List <Ontology_enrichment_line_class> enrich_list = new List <Ontology_enrichment_line_class>(); Ontology_enrichment_line_class[] add_enrich; Entry_type_enum entryType; int timepoint; string sample_name; for (int indexCol = 0; indexCol < col_length; indexCol++) { entryType = data.ColChar.Columns[indexCol].EntryType; timepoint = data.ColChar.Columns[indexCol].Timepoint; sample_name = (string)data.ColChar.Columns[indexCol].SampleName.Clone(); symbols = data.Get_alphabetically_ordered_ncbi_official_symbols__with_non_empty_entries_in_indicated_column(indexCol); add_enrich = Generate_enrichment_lines_and_calculate_pvalues(symbols, entryType, timepoint, sample_name); add_enrich = Add_missing_process_information(add_enrich); add_enrich = Add_upregulated_downregulated_symbol_information(add_enrich, data, indexCol); enrich_list.AddRange(add_enrich); } Ontology_enrichment_line_class[] enrich_array = Add_missing_process_information(enrich_list.ToArray()); Ontology_enrichment_class enrich = new Ontology_enrichment_class(); enrich.Add_other_lines(enrich_array); return(enrich); }
private void Write_scp_network_for_results_of_dynamic_enrichment_analsyis(Ontology_enrichment_class dynamic_onto_enrichment_filtered, Ontology_enrichment_class standard_onto_enrichment_filtered) { if (Options.Report) { Report_class.WriteLine("{0}: Visualize SCP relationships of dynamic enrichment results", typeof(Mbc_enrichment_pipeline_class).Name); } string subdirectory = Get_results_subdirectory_for_indicated_ontology(Ontology_type_enum.Molecular_biology_cell); dynamic_onto_enrichment_filtered.Order_by_complete_sample_pvalue(); standard_onto_enrichment_filtered.Order_by_complete_sample_pvalue(); Leave_out_class leave_out = new Leave_out_class(); leave_out.Generate_by_reading_safed_file(); List <Ontology_enrichment_line_class> sameSample_ontology_enrichment = new List <Ontology_enrichment_line_class>(); int dynamic_onto_enrich_length = dynamic_onto_enrichment_filtered.Enrich.Length; Ontology_enrichment_line_class enrichment_line; Leave_out_scp_scp_network_class current_scp_network; List <string> current_scpNames = new List <string>(); string complete_sampleName; string[] standard_enriched_scps; Dictionary <string, Shape_enum> nodeLable_shape_dict = new Dictionary <string, Shape_enum>(); for (int indexE = 0; indexE < dynamic_onto_enrich_length; indexE++) { enrichment_line = dynamic_onto_enrichment_filtered.Enrich[indexE]; if ((indexE == 0) || (!enrichment_line.Equal_complete_sample(dynamic_onto_enrichment_filtered.Enrich[indexE - 1]))) { sameSample_ontology_enrichment.Clear(); } sameSample_ontology_enrichment.Add(enrichment_line); if ((indexE == dynamic_onto_enrich_length - 1) || (!enrichment_line.Equal_complete_sample(dynamic_onto_enrichment_filtered.Enrich[indexE + 1]))) { current_scpNames.Clear(); foreach (Ontology_enrichment_line_class sameSample_enrichment_line in sameSample_ontology_enrichment) { current_scpNames.AddRange(sameSample_enrichment_line.Scp_name.Split(Global_class.Scp_delimiter)); } complete_sampleName = enrichment_line.Complete_sample_name; current_scp_network = Leave_out_scp_network_for_dynamicEnrichment_visualization.Deep_copy_scp_network(); current_scp_network.Scp_nw.Keep_only_input_nodeNames(current_scpNames.ToArray()); current_scp_network.Add_ancestors_of_missing_levels(this.Mbco_parentChild_nw); standard_enriched_scps = standard_onto_enrichment_filtered.Get_all_scps_of_completeSample(complete_sampleName); nodeLable_shape_dict.Clear(); foreach (string standard_enriched_scp in standard_enriched_scps) { nodeLable_shape_dict.Add(standard_enriched_scp, Shape_enum.Rectangle); } current_scp_network.Scp_nw.Write_yED_nw_in_results_directory_with_nodes_colored_by_level_and_sameLevel_processes_grouped(subdirectory + complete_sampleName + "_dynamicEnrichment_nw", Shape_enum.Diamond, nodeLable_shape_dict); } } }
public Ontology_enrichment_class Calculate_p_values_and_do_multiple_hypothesis_correction(Deg_class deg_input) { if (Options.Report) { Report_class.Write_major_separation_line(); Report_class.WriteLine("{0}: Calculate p values and perform multiple hypothesis correction for {1}", typeof(Ontology_fisher_exact_class).Name, this.Ontology_association.Ontology); } Deg_class deg = deg_input.Deep_copy(); deg.Keep_only_input_genes(this.Background_genes); this.Ontology_association.Process_gene_associations = this.Ontology_association.Process_gene_associations.OrderBy(l => l.ProcessName).ThenBy(l => l.GeneSymbol).ToArray(); deg.Degs = deg.Degs.OrderBy(l => l.Sequencing_run).ThenBy(l => l.Cell).ThenBy(l => l.Condition1).ThenBy(l => l.Condition2).ToArray(); int degs_length = deg.Degs.Length; Deg_line_class deg_line; List <string> inputGenes = new List <string>(); Ontology_enrichment_line_class[] add_enrichment_results; List <Ontology_enrichment_line_class> enrichment_results = new List <Ontology_enrichment_line_class>(); for (int indexDeg = 0; indexDeg < degs_length; indexDeg++) { deg_line = deg.Degs[indexDeg]; if ((indexDeg == 0) || (!deg_line.Sequencing_run.Equals(deg.Degs[indexDeg - 1].Sequencing_run)) || (!deg_line.Cell.Equals(deg.Degs[indexDeg - 1].Cell)) || (!deg_line.Condition1.Equals(deg.Degs[indexDeg - 1].Condition1)) || (!deg_line.Condition2.Equals(deg.Degs[indexDeg - 1].Condition2))) { inputGenes.Clear(); } if ((indexDeg != 0) && (!deg_line.Sequencing_run.Equals(deg.Degs[indexDeg - 1].Sequencing_run)) && (!deg_line.Cell.Equals(deg.Degs[indexDeg - 1].Cell)) && (!deg_line.Condition1.Equals(deg.Degs[indexDeg - 1].Condition1)) && (!deg_line.Condition2.Equals(deg.Degs[indexDeg - 1].Condition2)) && (deg_line.Gene.Equals(deg_line.Gene))) { throw new Exception(); //duplicated gene in same condition } inputGenes.Add(deg_line.Gene); if ((indexDeg == degs_length - 1) || (!deg_line.Sequencing_run.Equals(deg.Degs[indexDeg + 1].Sequencing_run)) || (!deg_line.Cell.Equals(deg.Degs[indexDeg + 1].Cell)) || (!deg_line.Condition1.Equals(deg.Degs[indexDeg + 1].Condition1)) || (!deg_line.Condition2.Equals(deg.Degs[indexDeg + 1].Condition2))) { add_enrichment_results = Calculate_p_values_and_do_mutliple_hypothesis_correcion_for_input_genes(inputGenes.ToArray(), deg_line); enrichment_results.AddRange(add_enrichment_results); } } Ontology_enrichment_class onto_enrich = new Ontology_enrichment_class(); onto_enrich.Add_to_array(enrichment_results.ToArray()); return(onto_enrich); }
public Ontology_enrichment_class Deep_copy() { Ontology_enrichment_class copy = (Ontology_enrichment_class)this.MemberwiseClone(); Ontology_enrichment_line_class onto_enrich_line; int enrich_length = this.Enrich.Length; copy.Enrich = new Ontology_enrichment_line_class[enrich_length]; for (int indexE = 0; indexE < enrich_length; indexE++) { onto_enrich_line = this.Enrich[indexE]; copy.Enrich[indexE] = this.Enrich[indexE].Deep_copy(); } return(copy); }
public void Analyze_de_instance(Data_class data, string base_file_name) { this.Base_file_name = (string)base_file_name.Clone(); Data_class data_sep = Generate_data_instance_with_separated_or_combined_entries(data); data_sep.Set_all_ncbi_official_gene_symbols_to_upper_case(); Ontology_enrichment_class standard_onto_enrich_standard; Ontology_enrichment_class standard_onto_enrich_filtered = Do_standard_enrichment_analysis_and_write_results(data_sep, out standard_onto_enrich_standard); Ontology_enrichment_class dynamic_onto_enrich_filtered = Do_dynamic_enrichment_analysis_for_mbco_and_write(standard_onto_enrich_standard, data_sep); Write_parent_child_network_for_results_of_standard_enrichment_analysis(standard_onto_enrich_filtered); Write_scp_network_for_results_of_dynamic_enrichment_analsyis(dynamic_onto_enrich_filtered, standard_onto_enrich_filtered); Write_legend_for_networks(base_file_name); }
public Ontology_enrichment_class Do_fisher_exact_test_for_de_instance_filter_and_write_for_individual_ontology(Deg_class deg) { int ontologies_length = this.Ontology_fishers.Length; Ontology_fisher_exact_class fisher; Ontology_enrichment_class onto_enrich = new Ontology_enrichment_class(); Ontology_enrichment_class onto_enrich_add; for (int indexO = 0; indexO < ontologies_length; indexO++) { fisher = this.Ontology_fishers[indexO]; onto_enrich_add = fisher.Calculate_p_values_and_do_multiple_hypothesis_correction(deg); onto_enrich.Add_other(onto_enrich_add); } return(onto_enrich); }
private Ontology_enrichment_class Do_standard_enrichment_analysis_and_write_results(Data_class data, out Ontology_enrichment_class onto_enrich) { if (Options.Report) { Report_class.WriteLine("{0}: Do standard enrichment analysis and write results", typeof(Mbc_enrichment_pipeline_class).Name); } onto_enrich = this.MBCO_fisher_standard.Analyse_data_instance(data); Ontology_type_enum ontology = Ontology_type_enum.Molecular_biology_cell; string subdirectory = Get_results_subdirectory_for_indicated_ontology(ontology); onto_enrich.Write(subdirectory, "Standard_enrichment_results.txt"); Ontology_enrichment_class onto_enrich_filtered = onto_enrich.Deep_copy(); onto_enrich_filtered.Keep_enrichment_lines_below_pvalue_cutoff(Options.Maximum_pvalue_for_standardDynamicEnrichment); onto_enrich_filtered.Keep_top_x_predictions_per_level_for_each_sample(Options.Kept_top_predictions_standardEnrichment_per_level); onto_enrich_filtered.Write(subdirectory, "Standard_enrichment_results_filtered.txt"); return(onto_enrich_filtered); }
public void Add_other(Ontology_enrichment_class other_onto_enrich) { Add_to_array(other_onto_enrich.Onto_enrich); }
public void Add_other(Ontology_enrichment_class other) { Add_other_lines(other.Enrich); }
private Ontology_enrichment_class Do_dynamic_enrichment_analysis_for_mbco_and_write(Ontology_enrichment_class mbco_onto_enrich_standard, Data_class data) { if (Options.Report) { Report_class.WriteLine("{0}: Do dynamic enrichment analysis and write results", typeof(Mbc_enrichment_pipeline_class).Name); } string subdirectory = Get_results_subdirectory_for_indicated_ontology(Ontology_type_enum.Molecular_biology_cell); mbco_onto_enrich_standard.Order_by_complete_sample_pvalue(); int mbco_onto_enrich_length = mbco_onto_enrich_standard.Enrich.Length; Ontology_enrichment_line_class enrich_line; MBCO_association_line_class[] new_mbco_association_lines; MBCO_association_class new_mbco_association; List <Ontology_enrichment_line_class> current_onto_enrich = new List <Ontology_enrichment_line_class>(); Ontology_fisher_class mbco_fisher_dynamic; int col_length = data.ColChar.Columns.Length; Data_class current_data; Colchar_column_line_class current_column_line; Ontology_enrichment_class current_dynamic_onto_enrich; Ontology_enrichment_class complete_dynamic_onto_enrich = new Ontology_enrichment_class(); List <Ontology_enrichment_line_class> dynamic_onto_enrich_list = new List <Ontology_enrichment_line_class>(); int added_standard_results_count = 0; for (int indexCol = 0; indexCol < col_length; indexCol++) { current_data = data.Deep_copy(); current_data.Keep_only_input_columns_and_remove_all_rows_that_are_left_over_with_only_zero_values(indexCol); current_column_line = current_data.ColChar.Columns[0]; current_onto_enrich.Clear(); for (int indexMbco = 0; indexMbco < mbco_onto_enrich_length; indexMbco++) { enrich_line = mbco_onto_enrich_standard.Enrich[indexMbco]; if ((enrich_line.EntryType.Equals(current_column_line.EntryType)) && (enrich_line.Timepoint.Equals(current_column_line.Timepoint)) && (enrich_line.Sample_name.Equals(current_column_line.SampleName))) { current_onto_enrich.Add(enrich_line); added_standard_results_count++; } } if (current_onto_enrich.Count == 0) { throw new Exception(); } new_mbco_association_lines = Generate_new_mbco_association_lines_by_merging_neighboring_scps(current_onto_enrich.ToArray()); new_mbco_association = new MBCO_association_class(); new_mbco_association.Add_to_array(new_mbco_association_lines); mbco_fisher_dynamic = new Ontology_fisher_class(); mbco_fisher_dynamic.Generate(new_mbco_association, Ontology_type_enum.Molecular_biology_cell, this.Final_bg_genes); current_dynamic_onto_enrich = mbco_fisher_dynamic.Analyse_data_instance(current_data); complete_dynamic_onto_enrich.Add_other(current_dynamic_onto_enrich); } if (added_standard_results_count != mbco_onto_enrich_standard.Enrich.Length) { throw new Exception(); } complete_dynamic_onto_enrich.Add_other(mbco_onto_enrich_standard); complete_dynamic_onto_enrich.Keep_only_enrichment_lines_of_indicated_levels(Options.Scp_levels_for_dynamicEnrichment); complete_dynamic_onto_enrich.Write(subdirectory, "Dynamic_enrichment_results.txt"); Ontology_enrichment_class complete_dynamic_onto_enrich_filtered = complete_dynamic_onto_enrich.Deep_copy(); complete_dynamic_onto_enrich_filtered.Keep_enrichment_lines_below_pvalue_cutoff(Options.Maximum_pvalue_for_standardDynamicEnrichment); complete_dynamic_onto_enrich_filtered.Keep_top_x_predictions_per_level_for_each_sample(Options.Kept_top_predictions_dynamicEnrichment_per_level); complete_dynamic_onto_enrich_filtered.Keep_top_x_predictedSCPs_as_part_of_SCPunit_or_singleSCPs(Options.Kept_singleSCPs_dynamicEnrichment_per_level); complete_dynamic_onto_enrich_filtered.Write(subdirectory, "Dynamic_enrichment_results_filtered.txt"); return(complete_dynamic_onto_enrich_filtered); }
private void Write_parent_child_network_for_results_of_standard_enrichment_analysis(Ontology_enrichment_class onto_enrich_mbc_for_nw_visualization) { if (Options.Report) { Report_class.WriteLine("{0}: Visualize parent child relationships of standard enrichment results", typeof(Mbc_enrichment_pipeline_class).Name); } string mbc_results_subdirectory = Get_results_subdirectory_for_indicated_ontology(Ontology_type_enum.Molecular_biology_cell); int enrich_length = onto_enrich_mbc_for_nw_visualization.Enrich.Length; Ontology_enrichment_line_class enrich_line; List <Ontology_enrichment_line_class> sameLevel_enrich_list = new List <Ontology_enrichment_line_class>(); onto_enrich_mbc_for_nw_visualization.Order_by_complete_sample_pvalue(); MBCO_obo_network_class current_obo_mbc; string complete_sampleName; for (int indexE = 0; indexE < enrich_length; indexE++) { enrich_line = onto_enrich_mbc_for_nw_visualization.Enrich[indexE]; if ((indexE == 0) || (!enrich_line.Complete_sample_name.Equals(onto_enrich_mbc_for_nw_visualization.Enrich[indexE - 1].Complete_sample_name))) { sameLevel_enrich_list.Clear(); } sameLevel_enrich_list.Add(enrich_line); if ((indexE == enrich_length - 1) || (!enrich_line.Complete_sample_name.Equals(onto_enrich_mbc_for_nw_visualization.Enrich[indexE + 1].Complete_sample_name))) { complete_sampleName = enrich_line.Complete_sample_name; current_obo_mbc = this.Mbco_parentChild_nw.Deep_copy_mbco_obo_nw(); current_obo_mbc.Add_significance_and_remove_unsignificant_nodes_but_keep_all_ancestors(sameLevel_enrich_list.ToArray()); current_obo_mbc.Write_yED_nw_in_results_directory_with_nodes_colored_by_minusLog10Pvalue_without_sameLevel_processes_grouped(mbc_results_subdirectory + complete_sampleName + "_parentChild_nw"); } } }