private static string ProcessDataReadFromFile(IMatrixData mdata, Parameters param) { FileParam fp = param.GetFileParam("Input file"); string filename = fp.Value; string[] colNames = TabSep.GetColumnNames(filename, '\t'); int nameIndex = GetNameIndex(colNames); if (nameIndex < 0){ return "Error: the file has to contain a column called 'Name'."; } if (colNames.Length < 2){ return "Error: the file does not contain a grouping column."; } string[] nameCol = TabSep.GetColumn(colNames[nameIndex], filename, '\t'); Dictionary<string, int> map = ArrayUtils.InverseMap(nameCol); for (int i = 0; i < colNames.Length; i++){ if (i == nameIndex){ continue; } string groupName = colNames[i]; string[] groupCol = TabSep.GetColumn(groupName, filename, '\t'); string[][] newCol = new string[mdata.ExpressionColumnCount][]; for (int j = 0; j < newCol.Length; j++){ string colName = mdata.ExpressionColumnNames[j]; if (!map.ContainsKey(colName)){ newCol[j] = new string[0]; continue; } int ind = map[colName]; string group = groupCol[ind]; newCol[j] = new[]{group}; } mdata.AddCategoryRow(groupName, groupName, newCol); } return null; }
private static void ProcessDataWriteTemplateFile(IMatrixData mdata, Parameters param) { FileParam fp = param.GetFileParam("Output file"); StreamWriter writer = new StreamWriter(fp.Value); writer.WriteLine("Name\tNew grouping"); for (int i = 0; i < mdata.ExpressionColumnCount; i++){ string colName = mdata.ExpressionColumnNames[i]; writer.WriteLine(colName + "\t" + colName); } writer.Close(); }
public void Export(Parameters parameters, IMatrixData data, ProcessInfo processInfo) { string filename = parameters.GetFileParam("File name").Value; StreamWriter writer; try{ writer = new StreamWriter(filename); } catch (Exception e){ processInfo.ErrString = e.Message; return; } List<string> words = new List<string>(); for (int i = 0; i < data.ExpressionColumnCount; i++){ words.Add(Trunc(data.ExpressionColumnNames[i])); } for (int i = 0; i < data.CategoryColumnCount; i++){ words.Add(Trunc(data.CategoryColumnNames[i])); } for (int i = 0; i < data.NumericColumnCount; i++){ words.Add(Trunc(data.NumericColumnNames[i])); } for (int i = 0; i < data.StringColumnCount; i++){ words.Add(Trunc(data.StringColumnNames[i])); } for (int i = 0; i < data.MultiNumericColumnCount; i++){ words.Add(Trunc(data.MultiNumericColumnNames[i])); } writer.WriteLine(StringUtils.Concat("\t", words)); if (HasAnyDescription(data)){ words = new List<string>(); for (int i = 0; i < data.ExpressionColumnCount; i++){ words.Add(Trunc(data.ExpressionColumnDescriptions[i] ?? "")); } for (int i = 0; i < data.CategoryColumnCount; i++){ words.Add(Trunc(data.CategoryColumnDescriptions[i] ?? "")); } for (int i = 0; i < data.NumericColumnCount; i++){ words.Add(Trunc(data.NumericColumnDescriptions[i] ?? "")); } for (int i = 0; i < data.StringColumnCount; i++){ words.Add(Trunc(data.StringColumnDescriptions[i] ?? "")); } for (int i = 0; i < data.MultiNumericColumnCount; i++){ words.Add(Trunc(data.MultiNumericColumnDescriptions[i] ?? "")); } writer.WriteLine("#!{Description}" + StringUtils.Concat("\t", words)); } words = new List<string>(); for (int i = 0; i < data.ExpressionColumnCount; i++){ words.Add("E"); } for (int i = 0; i < data.CategoryColumnCount; i++){ words.Add("C"); } for (int i = 0; i < data.NumericColumnCount; i++){ words.Add("N"); } for (int i = 0; i < data.StringColumnCount; i++){ words.Add("T"); } for (int i = 0; i < data.MultiNumericColumnCount; i++){ words.Add("M"); } writer.WriteLine("#!{Type}" + StringUtils.Concat("\t", words)); for (int i = 0; i < data.NumericRowCount; i++){ words = new List<string>(); for (int j = 0; j < data.ExpressionColumnCount; j++){ words.Add("" + data.NumericRows[i][j]); } for (int j = 0; j < data.CategoryColumnCount; j++){ words.Add(""); } for (int j = 0; j < data.NumericColumnCount; j++){ words.Add(""); } for (int j = 0; j < data.StringColumnCount; j++){ words.Add(""); } for (int j = 0; j < data.MultiNumericColumnCount; j++){ words.Add(""); } writer.WriteLine("#!{N:" + data.NumericRowNames[i] + "}" + StringUtils.Concat("\t", words)); } for (int i = 0; i < data.CategoryRowCount; i++){ words = new List<string>(); for (int j = 0; j < data.ExpressionColumnCount; j++){ string[] s = data.CategoryRows[i][j]; words.Add(s.Length == 0 ? "" : StringUtils.Concat(";", s)); } for (int j = 0; j < data.CategoryColumnCount; j++){ words.Add(""); } for (int j = 0; j < data.NumericColumnCount; j++){ words.Add(""); } for (int j = 0; j < data.StringColumnCount; j++){ words.Add(""); } for (int j = 0; j < data.MultiNumericColumnCount; j++){ words.Add(""); } writer.WriteLine("#!{C:" + data.CategoryRowNames[i] + "}" + StringUtils.Concat("\t", words)); } for (int j = 0; j < data.RowCount; j++){ words = new List<string>(); for (int i = 0; i < data.ExpressionColumnCount; i++){ words.Add(Trunc("" + data[j, i])); } for (int i = 0; i < data.CategoryColumnCount; i++){ string[] q = data.CategoryColumns[i][j] ?? new string[0]; words.Add(Trunc((q.Length > 0 ? StringUtils.Concat(";", q) : ""))); } for (int i = 0; i < data.NumericColumnCount; i++){ words.Add(Trunc("" + data.NumericColumns[i][j])); } for (int i = 0; i < data.StringColumnCount; i++){ words.Add(Trunc(data.StringColumns[i][j])); } for (int i = 0; i < data.MultiNumericColumnCount; i++){ double[] q = data.MultiNumericColumns[i][j]; words.Add(Trunc((q.Length > 0 ? StringUtils.Concat(";", q) : ""))); } string s = StringUtils.Concat("\t", words); s = s.Replace("\"", ""); writer.WriteLine(s); } writer.Close(); }