private void Generate_fisher_excat_intances(params string[] experimental_background_genes) { if (Options.Report) { Report_class.WriteLine("{0}: Generate fisher exact instances", typeof(Ontology_process_analysis_class).Name); } experimental_background_genes = experimental_background_genes.Distinct().OrderBy(l => l).ToArray(); Ontology_type_enum[] ontologies = this.Options.Ontologies; int ontologies_length = ontologies.Length; Ontology_type_enum ontology; this.Ontology_fishers = new Ontology_fisher_exact_class[ontologies_length]; for (int indexO = 0; indexO < ontologies_length; indexO++) { ontology = ontologies[indexO]; this.Ontology_fishers[indexO] = new Ontology_fisher_exact_class(ontology, experimental_background_genes); this.Ontology_fishers[indexO].Generate_new_instance(); } if (Options.Report) { Report_class.WriteLine(); } }
public static void WriteData <T>(List <T> Data, ReadWriteOptions_base Options) where T : class { Report_class.WriteLine("{0}: Write file {1}", typeof(T).Name, Options.File); StreamWriter writer = new StreamWriter(Options.File, false); WriteData(Data, Options, writer); }
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"); } } }
public double Get_leftTailed_p_value(int a, int b, int c, int d) { if (Report) { Report_class.WriteLine("{0}: Get left tailed p-value", typeof(Fisher_exact_test_class).Name); } double p; if (Check_if_n_not_larger_than_max_size(a, b, c, d)) { p = Get_specific_p_value(a, b, c, d); int min = (a < d) ? a : d; for (int i = 0; i < min; i++) { p += Get_specific_p_value(--a, ++b, ++c, --d); } } else { p = -1; }; if (Report) { for (int i = 0; i < typeof(Fisher_exact_test_class).Name.Length + 2; i++) { Report_class.Write(" "); } Report_class.WriteLine("p_value: {0}", p); } if (p > 1) { p = 1; } return(p); }
public double Get_rightTailed_p_value(int a, int b, int c, int d) { if (Report) { Report_class.WriteLine("{0}: Get right tailed p-value", typeof(Fisher_exact_test_class).Name); } double p; if (Check_if_n_not_larger_than_max_size(a, b, c, d)) { p = Get_specific_p_value(a, b, c, d); int min = (c < b) ? c : b; for (int i = 0; i < min; i++) { p += Get_specific_p_value(++a, --b, --c, ++d); } } else { p = -1; }; if (Report) { for (int i = 0; i < typeof(Fisher_exact_test_class).Name.Length + 2; i++) { Report_class.Write(" "); } Report_class.WriteLine("p_value: {0}", p); } return(p); }
private void Generate_parent_child_network() { if (Options.Report) { Report_class.WriteLine("{0}: Generate hierarchical parent child MBCO network", typeof(Mbc_enrichment_pipeline_class).Name); } Mbco_parentChild_nw.Generate_by_reading_safed_obo_file(); }
public static void Create_subdirectory_if_it_does_not_exist(string actDirectory, string sub_directory_name) { if (!Directory.Exists(actDirectory + sub_directory_name)) { Report_class.WriteLine("{0}: Create subdirectory {1} in directory {2}", typeof(ReadWriteClass).Name, sub_directory_name, actDirectory); DirectoryInfo dir = new DirectoryInfo(actDirectory); dir.CreateSubdirectory(sub_directory_name); } }
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 static void WriteData <T>(T[] Data, ReadWriteOptions_base Options) where T : class { if (Options.Report != ReadWrite_report_enum.Report_nothing) { Report_class.WriteLine("{0}: Write file {1}", typeof(T).Name, Options.File); } StreamWriter writer = new StreamWriter(Options.File, false); WriteData(Data, Options, writer); }
public static void WriteData <T>(List <T> Data, ReadWriteOptions_base Options, StreamWriter writer) where T : class { WriteData_headline <T>(Data, Options, writer); WriteData_body <T>(Data, Options, writer); writer.Close(); if (Options.Report != ReadWrite_report_enum.Report_nothing) { Report_class.WriteLine(); } }
public void Generate_new_instance() { if (Options.Report) { Report_class.WriteLine("-------------------------------------------------------------------------------"); Report_class.WriteLine("{0}: Generate new instance based on {1}", typeof(Ontology_fisher_exact_class).Name, this.Ontology_association.Ontology); } this.Ontology_association.Keep_only_input_genes_in_process_gene_association(this.Background_genes); this.Fisher = new Fisher_exact_test_class(this.Background_genes.Length, false); }
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 static void Delete_file_if_it_exists(string complete_file_name) { if (File.Exists(complete_file_name)) { Report_class.Write("Delete file: {0}?", complete_file_name); Console.ReadLine(); FileInfo delete_file = new FileInfo(complete_file_name); delete_file.Delete(); Report_class.WriteLine(" deleted"); } }
public static void WriteData <T>(List <T> Data, ReadWriteOptions_base Options, StreamWriter writer) where T : class { PropertyInfo[] propInfo = typeof(T).GetProperties(); PropertyInfo prop; int[] propertyIndexes = Get_propertyIndexes <T>(propInfo, Options.Key_propertyNames); //Generate and write Headline int propertyIndexes_length = propertyIndexes.Length; if (Options.File_has_headline == true) { char headline_delimiter = Options.HeadlineDelimiters[0]; StringBuilder headline = new StringBuilder(); for (int index = 0; index < propertyIndexes_length; index++) { if (index < propertyIndexes_length - 1) { headline.AppendFormat("{0}{1}", Options.Key_columnNames[index], headline_delimiter); } else { headline.AppendFormat("{0}", Options.Key_columnNames[index]); } } writer.WriteLine(headline); } //Generate and write lines char line_delimiter = Options.LineDelimiters[0]; StringBuilder line = new StringBuilder(); int data_count = Data.Count; for (int lineIndex = 0; lineIndex < data_count; lineIndex++) { line.Clear(); for (int index = 0; index < propertyIndexes_length; index++) { prop = propInfo[propertyIndexes[index]]; if (index < propertyIndexes_length - 1) { line.AppendFormat("{0}{1}", prop.GetValue(Data[lineIndex], null), line_delimiter); } else { line.AppendFormat("{0}", prop.GetValue(Data[lineIndex], null)); } } writer.WriteLine(line); } writer.Close(); Report_class.WriteLine(); }
private void Print_options() { Report_class.WriteLine("{0}: Print options", typeof(Ontology_process_analysis_options_class).Name); for (int i = 0; i < typeof(Ontology_process_analysis_options_class).Name.Length + 2; i++) { Report_class.Write(" "); } Report_class.Write("Used Ontologies:"); for (int i = 0; i < Ontologies.Length; i++) { Report_class.Write(" {0}", Ontologies[i]); } Report_class.WriteLine(); }
private Data_class Generate_data_instance_with_separated_or_combined_entries(Data_class data) { if (Options.Report) { Report_class.WriteLine("{0}: Prepare data for enrichment analysis", typeof(Mbc_enrichment_pipeline_class).Name); } bool positive_entries_exist = false; bool negative_entries_exist = false; int data_length = data.Data_length; Data_line_class data_line; int col_length = data.ColChar.Columns_length; for (int indexData = 0; indexData < data_length; indexData++) { data_line = data.Data[indexData]; for (int indexCol = 0; indexCol < col_length; indexCol++) { if (data_line.Columns[indexCol] > 0) { positive_entries_exist = true; } else if (data_line.Columns[indexCol] < 0) { negative_entries_exist = true; } } } if ((positive_entries_exist) && (negative_entries_exist)) { Data_class data_sep = new Data_class(); if (Options.Data_value_signs_of_interest.Contains(Data_value_signs_of_interest_enum.Combined)) { data_sep.Add_other_data_instance(data); } if (Options.Data_value_signs_of_interest.Contains(Data_value_signs_of_interest_enum.Upregulated)) { data_sep.Add_other_data_instance(data.Get_data_instance_with_only_upregulated_entries()); } if (Options.Data_value_signs_of_interest.Contains(Data_value_signs_of_interest_enum.Downregulated)) { data_sep.Add_other_data_instance(data.Get_data_instance_with_only_downregulated_entries()); } return(data_sep); } else { return(data); } }
public static void Delete_file_if_it_exists(string complete_file_name) { Report_class.Write("Delete file {0}:", complete_file_name); if (File.Exists(complete_file_name)) { FileInfo delete_file = new FileInfo(complete_file_name); delete_file.Delete(); Report_class.WriteLine(" deleted"); } else { Report_class.WriteLine(" File does not exist"); } }
// a b // c d public Fisher_exact_test_class(int input_max_size, bool report) { max_size = input_max_size; Report = report; if (Report) { Report_class.WriteLine("{0}: Initialize array of factorials with max_size = {1}", typeof(Fisher_exact_test_class).Name, max_size); } log_factorials = new double[max_size + 1]; log_factorials[0] = 0; for (int i = 1; i < max_size + 1; i++) { log_factorials[i] = log_factorials[i - 1] + Math.Log(i); } }
public static void Write_one_type_array_as_single_column <T>(T[] Array, ReadWriteOptions_base Options) { Report_class.WriteLine("{0}: Write file {1}", typeof(T).Name, Options.File); StreamWriter writer = new StreamWriter(Options.File, false); //Generate and write lines char line_delimiter = Options.LineDelimiters[0]; StringBuilder line = new StringBuilder(); int array_length = Array.Length; for (int index = 0; index < array_length; index++) { writer.WriteLine(Array[index]); } writer.Close(); Report_class.WriteLine(); }
public static void WriteArray <T>(T[] array, string file_name) { Report_class.WriteLine("{0}: Write array {1}", typeof(T).Name, file_name); StreamWriter writer = new StreamWriter(file_name, false); PropertyInfo[] propInfo = typeof(T).GetProperties(); //Generate and write lines StringBuilder line = new StringBuilder(); int array_length = array.Length; for (int indexA = 0; indexA < array_length; indexA++) { writer.WriteLine(array[indexA]); } writer.Close(); Report_class.WriteLine(); }
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); }
private void Generate_leave_out_scp_network() { if (Options.Report) { Report_class.WriteLine("{0}: Generate SCP networks", typeof(Mbc_enrichment_pipeline_class).Name); } Dictionary <string, int> processName_processLevel_dict = Mbco_parentChild_nw.Get_processName_level_dictionary_after_setting_process_level(); Leave_out_class leave_out = new Leave_out_class(); leave_out.Generate_by_reading_safed_file(); Leave_out_scp_network_for_dynamicEnrichment_analysis.Options.Consider_scp_interactions_between_signaling_processes = this.Options.Consider_interactions_between_signalingSCPs_for_dyanmicEnrichment; Leave_out_scp_network_for_dynamicEnrichment_analysis.Options.Top_quantile_of_considered_SCP_interactions_per_level = this.Options.Top_quantile_of_scp_interactions_for_dynamicEnrichment_per_level; Leave_out_scp_network_for_dynamicEnrichment_analysis.Generate_scp_scp_network_from_leave_out(leave_out); Leave_out_scp_network_for_dynamicEnrichment_analysis.Scp_nw.Nodes.Set_processLevel_for_all_nodes_based_on_dictionary(processName_processLevel_dict); Leave_out_scp_network_for_dynamicEnrichment_visualization.Options.Consider_scp_interactions_between_signaling_processes = this.Options.Consider_interactions_between_signalingSCPs_for_dyanmicEnrichment; Leave_out_scp_network_for_dynamicEnrichment_visualization.Options.Top_quantile_of_considered_SCP_interactions_per_level = this.Options.Top_quantile_of_scp_interactions_for_visualization_of_dynamicEnrichment_per_level; Leave_out_scp_network_for_dynamicEnrichment_visualization.Generate_scp_scp_network_from_leave_out(leave_out); Leave_out_scp_network_for_dynamicEnrichment_visualization.Scp_nw.Transform_into_undirected_single_network_and_set_all_widths_to_one(); Leave_out_scp_network_for_dynamicEnrichment_visualization.Scp_nw.Nodes.Set_processLevel_for_all_nodes_based_on_dictionary(processName_processLevel_dict); }
private void Generate_mbco_association(string[] bg_genes) { if (Options.Report) { Report_class.WriteLine("{0}: Generate MBCO gene-SCP association networks", typeof(Mbc_enrichment_pipeline_class).Name); } MBCO_association = new MBCO_association_class(); MBCO_association.Generate_by_reading_safed_file(); string[] all_mbco_genes = MBCO_association.Get_all_distinct_ordered_symbols(); if (bg_genes.Length > 0) { this.Exp_bg_genes = Array_class.Deep_copy_string_array(bg_genes); this.Final_bg_genes = Overlap_class.Get_intersection(this.Exp_bg_genes, all_mbco_genes); } else { this.Exp_bg_genes = new string[0]; this.Final_bg_genes = Array_class.Deep_copy_string_array(all_mbco_genes); } this.MBCO_association.Keep_only_bg_symbols(this.Final_bg_genes); this.MBCO_association.Remove_background_genes_scp(); this.MBCO_fisher_standard = new Ontology_fisher_class(); this.MBCO_fisher_standard.Generate(this.MBCO_association, Ontology_type_enum.Molecular_biology_cell, this.Final_bg_genes); }
public void Print_options() { Report_class.WriteLine("{0}: Print options", typeof(Mbc_enrichment_pipeline_options_class).Name); int right_shift = 4; #region Write general options for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.WriteLine("General:"); for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.WriteLine("Report: {0}", Report); Report_class.WriteLine(); #endregion #region Write parameter for both standard and dynamic enrichment analysis for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.WriteLine("Parameter for both standard and dynamic enrichment analysis:"); for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.Write("Data value signs of interest:"); int signs_of_interest_length = Data_value_signs_of_interest.Length; for (int indexS = 0; indexS < signs_of_interest_length; indexS++) { if (indexS != 0) { Report_class.Write(","); } Report_class.Write(" {0}", Data_value_signs_of_interest[indexS]); } Report_class.WriteLine(); for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.WriteLine("Maximum pvalue: {0}", Maximum_pvalue_for_standardDynamicEnrichment); Report_class.WriteLine(); #endregion #region Write parameter for standard enrichment analysis for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.WriteLine("Parameter for standard enrichment analysis only:"); for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.Write("Keep top predictions:"); int keep_top_length = Kept_top_predictions_standardEnrichment_per_level.Length; for (int level = 1; level < keep_top_length; level++) { if (level != 1) { Report_class.Write(", "); } Report_class.Write(" Level {0}: {1}", level, Kept_top_predictions_standardEnrichment_per_level[level]); } Report_class.WriteLine(); Report_class.WriteLine(); #endregion #region Write parameter for dyanmic enrichment analysis for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.WriteLine("Parameter for dynamic enrichment analysis only:"); for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.Write("Do dynamic enrichment for: "); int scp_levels_for_dynamicEnrichment_length = Scp_levels_for_dynamicEnrichment.Length; for (int indexLevel = 0; indexLevel < scp_levels_for_dynamicEnrichment_length; indexLevel++) { if ((indexLevel != 0) && (indexLevel == scp_levels_for_dynamicEnrichment_length - 1)) { Report_class.Write(" and "); } else if (indexLevel != 0) { Report_class.Write(", "); } Report_class.Write(" Level {0}", Scp_levels_for_dynamicEnrichment[indexLevel]); } Report_class.WriteLine(); for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.WriteLine("Number of neighboring SCPs that are merged to SCP unions:"); for (int indexLevel = 0; indexLevel < scp_levels_for_dynamicEnrichment_length; indexLevel++) { int level = Scp_levels_for_dynamicEnrichment[indexLevel]; int[] merge_scps_current_level = Numbers_of_merged_scps_for_dynamicEnrichment_per_level[level]; for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.Write("To generate level-{0} SCP unions merge ", level); int merge_length = merge_scps_current_level.Length; for (int indexM = 0; indexM < merge_length; indexM++) { if ((indexM != 0) && (indexM == merge_length - 1)) { Report_class.Write(" or "); } else if (indexM != 0) { Report_class.Write(", "); } Report_class.Write("{0}", merge_scps_current_level[indexM]); } Report_class.WriteLine(" SCPs"); } for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.Write("Top quantile of scp interactions that are considered to identify neighboring SCPs: "); int top_quantile_length = Top_quantile_of_scp_interactions_for_dynamicEnrichment_per_level.Length; for (int indexLevel = 0; indexLevel < scp_levels_for_dynamicEnrichment_length; indexLevel++) { int level = Scp_levels_for_dynamicEnrichment[indexLevel]; if (indexLevel != 0) { Report_class.Write(", "); } Report_class.WriteLine("Level {0}: {1}", level, Top_quantile_of_scp_interactions_for_dynamicEnrichment_per_level[level]); } for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.Write("Top quantile of scp interactions that are considered to visualize SCP network:"); top_quantile_length = Top_quantile_of_scp_interactions_for_visualization_of_dynamicEnrichment_per_level.Length; for (int indexLevel = 0; indexLevel < scp_levels_for_dynamicEnrichment_length; indexLevel++) { int level = Scp_levels_for_dynamicEnrichment[indexLevel]; if (indexLevel != 1) { Report_class.Write(", "); } Report_class.Write("Level {0}: {1}", level, Top_quantile_of_scp_interactions_for_visualization_of_dynamicEnrichment_per_level[level]); } Report_class.WriteLine(); for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.Write("Keep top predicted SCP unions or single SCPs: "); top_quantile_length = Top_quantile_of_scp_interactions_for_visualization_of_dynamicEnrichment_per_level.Length; for (int indexLevel = 0; indexLevel < scp_levels_for_dynamicEnrichment_length; indexLevel++) { int level = Scp_levels_for_dynamicEnrichment[indexLevel]; if (indexLevel != 0) { Report_class.Write(", "); } Report_class.Write("Level {0}: {1}", level, Kept_top_predictions_dynamicEnrichment_per_level[level]); } Report_class.WriteLine(); for (int i = 0; i < right_shift; i++) { Report_class.Write(" "); } Report_class.Write("Keep not more than x SCPs as part of a single SCP prediction or a predicted SCP-union: "); top_quantile_length = Top_quantile_of_scp_interactions_for_visualization_of_dynamicEnrichment_per_level.Length; for (int indexLevel = 0; indexLevel < scp_levels_for_dynamicEnrichment_length; indexLevel++) { int level = Scp_levels_for_dynamicEnrichment[indexLevel]; if (indexLevel != 0) { Report_class.Write(", "); } Report_class.WriteLine("Level {0}: {1}", level, Kept_singleSCPs_dynamicEnrichment_per_level[level]); } Report_class.WriteLine(); #endregion }
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); }
public void Generate(params string[] background_genes) { Report_class.WriteLine("{0}: Generate", typeof(Ontology_process_analysis_class).Name); Generate_fisher_excat_intances(background_genes); }
public static Dictionary <TD, T_line> ReadRawData_and_fillDictionary <TD, T_line>(StreamReader stream, DictionaryReadWriteOptions_base options, string file_name) where T_line : class { if ((options.Report == ReadWrite_report_enum.Report_main) || (options.Report == ReadWrite_report_enum.Report_everything)) { Report_class.WriteLine("{0}:\nRead file for dictionary: {1}", typeof(T_line).Name, file_name); } Stopwatch timer = new Stopwatch(); timer.Start(); //Read headline, if it exists, determine indexes of columns to be safed in list //Begin FileInfo file = new FileInfo(options.File); PropertyInfo[] propInfo = typeof(T_line).GetProperties(); PropertyInfo dict_key_propInfo = typeof(TD).GetProperties()[0]; string[] columnNames = { Global_class.Empty_entry }; int dictionaryKey_index; int[] columnIndexes; int[] invalidLine_defining_columnIndexes = new int[0]; int[] invalidLine_defining_popertyIndexes = new int[0]; int[] propertyIndexes; if (options.File_has_headline) { string headline = stream.ReadLine(); columnNames = Get_and_modify_columnNames(headline, options); columnIndexes = Get_columnIndexes_of_given_columnNames <T_line>(columnNames, options.Key_columnNames); dictionaryKey_index = Get_columnIndexes_of_given_columnNames <T_line>(columnNames, options.DictionaryKey_columnName)[0]; if (options.Invalid_line_defining_columnNames.Length > 0) { invalidLine_defining_columnIndexes = Get_columnIndexes_of_given_columnNames <T_line>(columnNames, options.Invalid_line_defining_columnNames); invalidLine_defining_popertyIndexes = Get_propertyIndexes_of_corresponding_given_columnNames <T_line>(propInfo, options.Key_propertyNames, options.Key_columnNames, options.Invalid_line_defining_columnNames); } } else { columnIndexes = options.Key_columnIndexes; dictionaryKey_index = options.DictionaryKey_columnIndex; } propertyIndexes = Get_propertyIndexes <T_line>(propInfo, options.Key_propertyNames); if (columnIndexes.Length != propertyIndexes.Length) { Report_class.Write_error_line("{0}: Length columnIndexes (Key_columnNames/columnIndexes) != propertyIndexes (Key_propertyNames)", typeof(T_line).Name); } //End //Skip lines for (int indexSkip = 0; indexSkip < options.Skip_lines; indexSkip++) { stream.ReadLine(); } //Determine indexes of columns which contain a safecondition, if safeconditions exist //Begin bool safeConditions_exist = options.SafeCondition_entries != null; int[] safeConditions_columnIndexes = new int[0]; string[] safeConditions_entries = options.SafeCondition_entries; int safeConditions_length = -1; if (safeConditions_exist == true) { safeConditions_length = options.SafeCondition_entries.Length; if (options.File_has_headline) { safeConditions_columnIndexes = Get_columnIndexes_of_given_columnNames <T_line>(columnNames, options.SafeCondition_columnNames); } else { safeConditions_columnIndexes = options.SafeCondition_columnIndexes; } if (safeConditions_columnIndexes.Length != safeConditions_entries.Length) { Report_class.WriteLine("{0}: length safeConditions_columnIndexes (_columnNames/columnIndexes) != length safeConditions_columnEntries", typeof(T_line).Name); } } //End //Generate and fill list //Begin Dictionary <TD, T_line> dictionary = new Dictionary <TD, T_line>(); var TD_Type = typeof(TD); var T_line_Type = typeof(T_line); int invalidLine_defining_columnIndexes_length = invalidLine_defining_columnIndexes.Length; string inputLine; int readLines = 0; int safedLines = 0; int colIndex; int propIndex; bool safeLine; bool report_check_lineDelimiters = false; bool valid; string invalidLineDefiningColumnEntry; int line_count = 0; while ((inputLine = stream.ReadLine()) != null) { if ((inputLine.Length > 0) && (!inputLine.Substring(0, 5).Equals("-----"))) { line_count++; string[] columnEntries = inputLine.Split(options.LineDelimiters); if (columnEntries.Length == 1) { report_check_lineDelimiters = true; } safeLine = true; if (safeConditions_exist) { for (int indexSC = 0; indexSC < safeConditions_length; indexSC++) { columnEntries[safeConditions_columnIndexes[indexSC]] = char.ToUpper(columnEntries[safeConditions_columnIndexes[indexSC]][0]) + columnEntries[safeConditions_columnIndexes[indexSC]].ToLower().Substring(1); ///transient solution!!!!!! if (safeConditions_entries[indexSC] != columnEntries[safeConditions_columnIndexes[indexSC]]) { safeLine = false; } } } valid = true; for (int indexIndex = 0; indexIndex < invalidLine_defining_columnIndexes_length; indexIndex++) { invalidLineDefiningColumnEntry = columnEntries[invalidLine_defining_columnIndexes[indexIndex]]; try { var obj = Convert.ChangeType(invalidLineDefiningColumnEntry, propInfo[invalidLine_defining_popertyIndexes[indexIndex]].PropertyType); valid = true; } catch (InvalidCastException) { valid = false; } catch (FormatException) { valid = false; } catch (OverflowException) { valid = false; } catch (ArgumentNullException) { valid = false; } } if ((safeLine) && (valid)) { //TD new_dictionary_key = new TD();//)Activator.CreateInstance(TD_Type); TD new_dictionary_key = (TD)Convert.ChangeType(columnEntries[dictionaryKey_index], TD_Type); T_line newLine = (T_line)Activator.CreateInstance(T_line_Type); for (int i = 0; i < columnIndexes.Length; i++) { colIndex = columnIndexes[i]; propIndex = propertyIndexes[i]; if (columnEntries[colIndex] == "#DIV/0!") { columnEntries[colIndex] = "NaN"; } if (propInfo[propIndex].PropertyType.IsEnum) { columnEntries[colIndex] = char.ToUpper(columnEntries[colIndex][0]) + columnEntries[colIndex].ToLower().Substring(1); propInfo[propIndex].SetValue(newLine, Enum.Parse(propInfo[propIndex].PropertyType, columnEntries[colIndex]), null); } else if (string.IsNullOrEmpty(columnEntries[colIndex])) { if (propInfo[propIndex].PropertyType == typeof(int)) { propInfo[propIndex].SetValue(newLine, options.Empty_integer_value, null); } else if (propInfo[propIndex].PropertyType == typeof(string)) { propInfo[propIndex].SetValue(newLine, options.Empty_string_value, null); } else { Report_class.Write_error_line("{0}: ReadRawData_and_FillList: {1} unhandled null entry", typeof(ReadWriteClass).Name, options.File); } } else { if ((columnEntries[colIndex] != "") && ((columnEntries[colIndex] != "NA") || (propInfo[propIndex].PropertyType == typeof(string)))) { propInfo[propIndex].SetValue(newLine, Convert.ChangeType(columnEntries[colIndex], propInfo[propIndex].PropertyType), null); } } } dictionary.Add(new_dictionary_key, newLine); safedLines = safedLines + 1; } readLines = readLines + 1; if ((options.Report == ReadWrite_report_enum.Report_everything) && (readLines % 2000000 == 0)) { Report_class.WriteLine("{0}: Read lines: {1} Mio, \tSafed lines: {2} Mio", typeof(T_line).Name, (double)readLines / 1000000, (double)safedLines / 1000000); } } } if (report_check_lineDelimiters) { Report_class.Write_error_line("{0}: only one column entry: Check lineDelimiters", typeof(ReadWriteClass).Name); } timer.Stop(); if (options.Report == ReadWrite_report_enum.Report_everything) { Report_class.WriteLine("{0}: Read lines: {1} Mio, Safed lines: {2} Mio", typeof(T_line).Name, (double)readLines / 1000000, (double)safedLines / 1000000); Report_class.WriteLine("{0}: Time: {1}", typeof(T_line).Name, timer.Elapsed); } if (options.Report >= ReadWrite_report_enum.Report_main) { Report_class.WriteLine(); } stream.Close(); if (dictionary.Count == 0) { Report_class.Write_error_line("{0}: ReadFile {1} data.count == 0, no lines filled!", typeof(ReadWriteClass).Name, options.File); } return(dictionary); }