public Colchar_column_line_class Deep_copy() { Colchar_column_line_class copy = (Colchar_column_line_class)this.MemberwiseClone(); copy.SampleName = (string)this.SampleName.Clone(); return(copy); }
private Colchar_column_line_class[] Deep_copy_columns() { int columns_length = Columns.Length; Colchar_column_line_class[] copy_columns = new Colchar_column_line_class[columns_length]; for (int indexC = 0; indexC < columns_length; indexC++) { copy_columns[indexC] = this.Columns[indexC].Deep_copy(); } return(copy_columns); }
public void Keep_only_input_columns(params int[] inputColumns) { Correctness_check(); int inputColumns_length = inputColumns.Length; Colchar_column_line_class[] new_columns = new Colchar_column_line_class[inputColumns_length]; for (int indexInput = 0; indexInput < inputColumns_length; indexInput++) { new_columns[indexInput] = this.Columns[inputColumns[indexInput]].Deep_copy(); } Columns = new_columns; Column_rearrangements_adopted = false; }
public void Correctness_check() { int col_length = Columns_length; Colchar_column_line_class[] columns_copy = Deep_copy_columns(); columns_copy = Colchar_column_line_class.Order_in_standard_way(columns_copy); for (int indexC = 1; indexC < col_length; indexC++) { if (columns_copy[indexC].Equal_in_standard_way(columns_copy[indexC - 1])) { throw new Exception("duplicated column charactarization"); } } if (!Column_rearrangements_adopted) { throw new Exception("column rearrangements are not adopted"); } }
public int[] Order_columns_in_standard_way_and_get_old_new_index_array() { Correctness_check(); Column_rearrangements_adopted = false; Colchar_column_line_class[] old_columns = Deep_copy_columns(); Columns = Colchar_column_line_class.Order_in_standard_way(Columns); int columns_length = Columns.Length; #region Initialize index old new (and fill with -1 entries) int[] old_new_index_array = new int[columns_length]; for (int indexOld = 0; indexOld < columns_length; indexOld++) { old_new_index_array[indexOld] = -1; } #endregion #region Fill index old new Colchar_column_line_class old_column; Colchar_column_line_class new_column; for (int indexOld = 0; indexOld < columns_length; indexOld++) { old_column = old_columns[indexOld]; for (int indexNew = 0; indexNew < columns_length; indexNew++) { new_column = Columns[indexNew]; if (old_column.Equal_in_standard_way(new_column)) { old_new_index_array[indexOld] = indexNew; break; } } } #endregion return(old_new_index_array); }
public void Merge_all_columns() { int columns_count = this.Columns_length; Colchar_column_line_class column_line; StringBuilder sb_new_name = new StringBuilder(); sb_new_name.AppendFormat("Merged"); Entry_type_enum entryType = this.Columns[0].EntryType; for (int indexC = 0; indexC < columns_count; indexC++) { column_line = this.Columns[indexC]; if (!column_line.EntryType.Equals(entryType)) { throw new Exception(); } sb_new_name.AppendFormat("-"); sb_new_name.AppendFormat("{0}", column_line.Timepoint); } Colchar_column_line_class new_column_line = new Colchar_column_line_class(entryType, 0, sb_new_name.ToString()); this.Columns = new Colchar_column_line_class[] { new_column_line }; }
public void Add_to_data_instance(IAdd_to_data[] add_data) { int old_columns_length = ColChar.Columns_length; int add_data_length = add_data.Length; IAdd_to_data add_data_interface_line; #region Analyze, if new columns needed and add to colChar add_data = add_data.OrderBy(l => l.EntryType_for_data).ThenBy(l => l.Timepoint_for_data).ThenBy(l => l.SampleName_for_data).ToArray(); List <Colchar_column_line_class> colChar_column_list = new List <Colchar_column_line_class>(); Colchar_column_line_class colChar_column_line; for (int indexAdd = 0; indexAdd < add_data_length; indexAdd++) { add_data_interface_line = add_data[indexAdd]; if ((indexAdd == 0) || (!add_data_interface_line.EntryType_for_data.Equals(add_data[indexAdd - 1].EntryType_for_data)) || (!add_data_interface_line.Timepoint_for_data.Equals(add_data[indexAdd - 1].Timepoint_for_data)) || (!add_data_interface_line.SampleName_for_data.Equals(add_data[indexAdd - 1].SampleName_for_data))) { colChar_column_line = new Colchar_column_line_class(); colChar_column_line.EntryType = add_data_interface_line.EntryType_for_data; colChar_column_line.Timepoint = add_data_interface_line.Timepoint_for_data; colChar_column_line.SampleName = (string)add_data_interface_line.SampleName_for_data.Clone(); colChar_column_list.Add(colChar_column_line); } } ColChar.Identify_new_columns_and_add_at_right_site(colChar_column_list.ToArray()); int new_columns_length = ColChar.Columns.Length; #endregion int data_length = this.Data_length; Data_line_class data_line; #region Extend data lines by adding zero values at right site float[] new_columns; for (int indexD = 0; indexD < data_length; indexD++) { data_line = this.Data[indexD]; new_columns = new float[new_columns_length]; for (int indexOld = 0; indexOld < old_columns_length; indexOld++) { new_columns[indexOld] = data_line.Columns[indexOld]; } data_line.Columns = new_columns.ToArray(); } #endregion #region Add to data and generate ordered data add lines to data add_data = add_data.OrderBy(l => l.NCBI_official_symbol_for_data).ThenBy(l => l.EntryType_for_data).ThenBy(l => l.SampleName_for_data).ToArray(); int indexColumn; int indexData = 0; int stringCompare; Data_line_class new_data_line; List <Data_line_class> add_lines_to_data_list = new List <Data_line_class>(); int indexCol = -1; for (int indexAdd = 0; indexAdd < add_data_length; indexAdd++) { add_data_interface_line = add_data[indexAdd]; indexColumn = ColChar.Get_columnIndex(add_data_interface_line); stringCompare = -2; while ((indexData < data_length) && (stringCompare < 0)) { data_line = Data[indexData]; stringCompare = data_line.NCBI_official_symbol.CompareTo(add_data_interface_line.NCBI_official_symbol_for_data); if (stringCompare < 0) { indexData++; } else if (stringCompare == 0) { indexCol = ColChar.Get_columnIndex(add_data_interface_line); data_line.Add_to_this_line_after_checking_if_this_line_has_empty_entry(add_data_interface_line, indexCol); } } if (stringCompare != 0) { new_data_line = new Data_line_class(add_data_interface_line.NCBI_official_symbol_for_data, new_columns_length); new_data_line.Columns[indexColumn] = add_data_interface_line.Value_for_data; add_lines_to_data_list.Add(new_data_line); } } Data_line_class[] add_lines_to_data = add_lines_to_data_list.OrderBy(l => l.NCBI_official_symbol).ToArray(); #endregion #region Combine add_lines_to_data to generate final add_data_lines int add_lines_length = add_lines_to_data.Length; int firstIndex_same_rowName = -1; Data_line_class add_data_line; Data_line_class inner_add_data_line; List <Data_line_class> final_add_data_list = new List <Data_line_class>(); for (int indexAL = 0; indexAL < add_lines_length; indexAL++) { add_data_line = add_lines_to_data[indexAL]; if ((indexAL == 0) || (!add_data_line.NCBI_official_symbol.Equals(add_lines_to_data[indexAL - 1].NCBI_official_symbol))) { firstIndex_same_rowName = indexAL; } if ((indexAL == add_lines_length - 1) || (!add_data_line.NCBI_official_symbol.Equals(add_lines_to_data[indexAL + 1].NCBI_official_symbol))) { for (int indexInner = firstIndex_same_rowName; indexInner < indexAL; indexInner++) { inner_add_data_line = add_lines_to_data[indexInner]; add_data_line.Sum_values_to_this_in_consideration_of_empty_entry(inner_add_data_line); } final_add_data_list.Add(add_data_line); } } #endregion #region Add final data line to data int final_data_length = final_add_data_list.Count; int new_data_length = final_data_length + data_length; Data_line_class[] new_data = new Data_line_class[new_data_length]; int indexNew = -1; for (int indexOld = 0; indexOld < data_length; indexOld++) { indexNew++; new_data[indexNew] = Data[indexOld]; } for (int indexFinal = 0; indexFinal < final_data_length; indexFinal++) { indexNew++; new_data[indexNew] = final_add_data_list[indexFinal]; } Data = new_data; #endregion Keep_only_lines_that_contain_at_least_one_non_zero_value(); }
public void Identify_new_columns_and_add_at_right_site(Colchar_column_line_class[] add_data) { Correctness_check(); int old_columns_length = Columns_length; Colchar_column_line_class[] add_columns; #region Identify add columns List <Colchar_column_line_class> add_columns_list = new List <Colchar_column_line_class>(); add_data = Colchar_column_line_class.Order_in_standard_way(add_data); int add_data_length = add_data.Length; Colchar_column_line_class add_line; bool old_columns_contain_new_combination = false; Colchar_column_line_class old_column_line; Colchar_column_line_class add_column_line; for (int indexAdd = 0; indexAdd < add_data_length; indexAdd++) { add_line = add_data[indexAdd]; if ((indexAdd == 0) || (!Colchar_column_line_class.Equal_in_standard_way(add_line, add_data[indexAdd - 1]))) { old_columns_contain_new_combination = false; for (int indexOld = 0; indexOld < old_columns_length; indexOld++) { old_column_line = Columns[indexOld]; if (old_column_line.Equal_in_standard_way(add_line)) { old_columns_contain_new_combination = true; break; } } if (!old_columns_contain_new_combination) { add_column_line = new Colchar_column_line_class(add_line.EntryType, add_line.Timepoint, add_line.SampleName); add_columns_list.Add(add_column_line); } } } add_columns = add_columns_list.ToArray(); #endregion #region Add add columns at right site int add_columns_length = add_columns.Length; int new_columns_length = add_columns_length + old_columns_length; Colchar_column_line_class[] new_columns = new Colchar_column_line_class[new_columns_length]; int indexNew = -1; for (int indexOld = 0; indexOld < old_columns_length; indexOld++) { indexNew++; new_columns[indexNew] = this.Columns[indexOld].Deep_copy(); } for (int indexAdd = 0; indexAdd < add_columns_length; indexAdd++) { indexNew++; new_columns[indexNew] = add_columns[indexAdd].Deep_copy(); } Columns = new_columns; #endregion Correctness_check(); }
public Colchar_class() { Column_rearrangements_adopted = true; Columns = new Colchar_column_line_class[0]; }
public static bool Equal_in_standard_way(Colchar_column_line_class line1, Colchar_column_line_class line2) { return((line1.EntryType.Equals(line2.EntryType)) && (line1.Timepoint.Equals(line2.Timepoint)) && (line1.SampleName.Equals(line2.SampleName))); }
public bool Equal_in_standard_way(Colchar_column_line_class other) { return((this.EntryType.Equals(other.EntryType)) && (this.Timepoint.Equals(other.Timepoint)) && (this.SampleName.Equals(other.SampleName))); }