本文整理汇总了C#中IMatrixData.AddCategoryRow方法的典型用法代码示例。如果您正苦于以下问题:C# IMatrixData.AddCategoryRow方法的具体用法?C# IMatrixData.AddCategoryRow怎么用?C# IMatrixData.AddCategoryRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMatrixData
的用法示例。
在下文中一共展示了IMatrixData.AddCategoryRow方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FilterColumns
public static void FilterColumns(IMatrixData mdata, Parameters parameters, int[] cols)
{
bool reduceMatrix = GetReduceMatrix(parameters);
if (reduceMatrix){
mdata.ExtractExpressionColumns(cols);
} else{
Array.Sort(cols);
string[][] row = new string[mdata.ExpressionColumnCount][];
for (int i = 0; i < row.Length; i++){
bool contains = Array.BinarySearch(cols, i) >= 0;
row[i] = contains ? new[]{"Keep"} : new[]{"Discard"};
}
mdata.AddCategoryRow("Filter", "", row);
}
}
示例2: ProcessData
//.........这里部分代码省略.........
Dictionary<int, List<double>> factors = new Dictionary<int, List<double>>();
for (int i = 0; i < columns.Count; i++){
if (factors.ContainsKey(grouping[i])){
factors[grouping[i]].Add(normalizationFactors[i]);
} else{
factors.Add(grouping[i], new List<double>{normalizationFactors[i]});
}
}
double[] averagedNormalizationFactors = new double[columns.Count];
for (int i = 0; i < columns.Count; i++){
List<double> factor;
factors.TryGetValue(grouping[i], out factor);
averagedNormalizationFactors[i] = ArrayUtils.Mean(factor);
}
normalizationFactors = averagedNormalizationFactors;
}
// loop over all selected columns and calculate copy numbers
for (int col = 0; col < columns.Count; col++){
string sampleName = sampleNames[col];
double[] column = columns[col];
double factor = normalizationFactors[col];
double[] copyNumbers = new double[mdata.RowCount];
double[] concentrations = new double[mdata.RowCount]; // femtoliters
double[] massFraction = new double[mdata.RowCount];
double[] moleFraction = new double[mdata.RowCount];
double totalProtein = 0; // picograms
double histoneMass = 0; // picograms
double totalMolecules = 0;
for (int row = 0; row < mdata.RowCount; row++){
if (!double.IsNaN(column[row]) && !double.IsNaN(mw[row])){
copyNumbers[row] = (column[row]/detectabilityNormFactor[row])*factor;
totalMolecules += copyNumbers[row];
totalProtein += (copyNumbers[row]*mw[row]*1e12)/avogadro; // picograms
if (ArrayUtils.Contains(histoneRows, row)){
histoneMass += (copyNumbers[row]*mw[row]*1e12)/avogadro; // picograms
}
}
}
double totalVolume = (totalProtein/(param.GetDoubleParam("Total cellular protein concentration [g/l]").Value))*1000;
// femtoliters
for (int row = 0; row < mdata.RowCount; row++){
if (!double.IsNaN(column[row]) && !double.IsNaN(mw[row])){
concentrations[row] = ((copyNumbers[row]/(totalVolume*1e-15))/avogadro)*1e9; // nanomolar
massFraction[row] = (((copyNumbers[row]*mw[row]*1e12)/avogadro)/totalProtein)*1e6; // ppm
moleFraction[row] = (copyNumbers[row]/totalMolecules)*1e6; // ppm
}
}
string suffix = (sampleName == "") ? "" : " " + sampleName;
if (ArrayUtils.Contains(outputColumns, 0)){
mdata.AddNumericColumn("Copy number" + suffix, "", copyNumbers);
}
if (ArrayUtils.Contains(outputColumns, 1)){
mdata.AddNumericColumn("Concentration [nM]" + suffix, "", concentrations);
}
if (ArrayUtils.Contains(outputColumns, 2)){
mdata.AddNumericColumn("Abundance (mass/total mass) [*10^-6]" + suffix, "", massFraction);
}
if (ArrayUtils.Contains(outputColumns, 3)){
mdata.AddNumericColumn("Abundance (molecules/total molecules) [*10^-6]" + suffix, "", moleFraction);
}
double[] rank = ArrayUtils.Rank(copyNumbers);
double[] relativeRank = new double[mdata.RowCount];
double validRanks = mdata.RowCount;
for (int row = 0; row < mdata.RowCount; row++){
// remove rank for protein with no copy number information
if (double.IsNaN((copyNumbers[row])) || copyNumbers[row] == 0){
rank[row] = double.NaN;
validRanks--; // do not consider as valid
}
// invert ranking, so that rank 0 is the most abundant protein
rank[row] = mdata.RowCount - rank[row];
}
for (int row = 0; row < mdata.RowCount; row++){
relativeRank[row] = rank[row]/validRanks;
}
if (ArrayUtils.Contains(outputColumns, 4)){
mdata.AddNumericColumn("Copy number rank" + suffix, "", rank);
}
if (ArrayUtils.Contains(outputColumns, 5)){
mdata.AddNumericColumn("Relative copy number rank" + suffix, "", relativeRank);
}
if (intensityCols[col] < mdata.ExpressionColumnCount &&
param.GetSingleChoiceWithSubParams("Averaging mode").Value != 3){
totalProteinRow[intensityCols[col]] = Math.Round(totalProtein, 2);
totalMoleculesRow[intensityCols[col]] = Math.Round(totalMolecules, 0);
organismRow[intensityCols[col]] = new string[]{organism.name};
histoneMassRow[intensityCols[col]] = Math.Round(histoneMass, 4);
ploidyRow[intensityCols[col]] = Math.Round((histoneMass*1e-12)/cValue, 2);
cellVolumeRow[intensityCols[col]] = Math.Round(totalVolume, 2); // femtoliters
}
}
if (param.GetSingleChoiceWithSubParams("Averaging mode").Value != 3 && ArrayUtils.Contains(outputColumns, 6)){
mdata.AddNumericRow("Total protein [pg/cell]", "", totalProteinRow);
mdata.AddNumericRow("Total molecules per cell", "", totalMoleculesRow);
mdata.AddCategoryRow("Organism", "", organismRow);
mdata.AddNumericRow("Histone mass [pg/cell]", "", histoneMassRow);
mdata.AddNumericRow("Ploidy", "", ploidyRow);
mdata.AddNumericRow("Cell volume [fl]", "", cellVolumeRow);
}
}
示例3: LoadMatrixData
//.........这里部分代码省略.........
q = q.Substring(1, q.Length - 2);
}
if (q.Length >= 2 && q[0] == '\'' && q[q.Length - 1] == '\''){
q = q.Substring(1, q.Length - 2);
}
string[] ww = q.Length == 0 ? new string[0] : q.Split(';');
List<int> valids = new List<int>();
for (int j = 0; j < ww.Length; j++){
ww[j] = ww[j].Trim();
if (ww[j].Length > 0){
valids.Add(j);
}
}
ww = ArrayUtils.SubArray(ww, valids);
Array.Sort(ww);
if (categoryAnnotation[i].Length > count){
categoryAnnotation[i][count] = ww;
}
}
}
for (int i = 0; i < textColIndices.Count; i++){
if (textColIndices[i] >= w.Length){
stringAnnotation[i][count] = "";
} else{
string q = w[textColIndices[i]].Trim();
if (stringAnnotation[i].Length > count){
stringAnnotation[i][count] = RemoveSplitWhitespace(RemoveQuotes(q));
}
}
}
count++;
}
reader.Close();
string[] columnNames = ArrayUtils.SubArray(colNames, mainColIndices);
if (shortenExpressionNames){
columnNames = StringUtils.RemoveCommonSubstrings(columnNames, true);
}
string[] catColnames = ArrayUtils.SubArray(colNames, catColIndices);
string[] numColnames = ArrayUtils.SubArray(colNames, numColIndices);
string[] multiNumColnames = ArrayUtils.SubArray(colNames, multiNumColIndices);
string[] textColnames = ArrayUtils.SubArray(colNames, textColIndices);
matrixData.Name = origin;
matrixData.ColumnNames = RemoveQuotes(columnNames);
matrixData.Values.Set(mainValues);
if (hasAddtlMatrices){
matrixData.Quality.Set(qualityValues);
matrixData.IsImputed.Set(isImputedValues);
} else{
matrixData.Quality.Set(new float[mainValues.GetLength(0), mainValues.GetLength(1)]);
matrixData.IsImputed.Set(new bool[mainValues.GetLength(0), mainValues.GetLength(1)]);
}
matrixData.SetAnnotationColumns(RemoveQuotes(textColnames), stringAnnotation, RemoveQuotes(catColnames),
categoryAnnotation, RemoveQuotes(numColnames), numericAnnotation, RemoveQuotes(multiNumColnames),
multiNumericAnnotation);
if (colDescriptions != null){
string[] columnDesc = ArrayUtils.SubArray(colDescriptions, mainColIndices);
string[] catColDesc = ArrayUtils.SubArray(colDescriptions, catColIndices);
string[] numColDesc = ArrayUtils.SubArray(colDescriptions, numColIndices);
string[] multiNumColDesc = ArrayUtils.SubArray(colDescriptions, multiNumColIndices);
string[] textColDesc = ArrayUtils.SubArray(colDescriptions, textColIndices);
matrixData.ColumnDescriptions = new List<string>(columnDesc);
matrixData.NumericColumnDescriptions = new List<string>(numColDesc);
matrixData.CategoryColumnDescriptions = new List<string>(catColDesc);
matrixData.StringColumnDescriptions = new List<string>(textColDesc);
matrixData.MultiNumericColumnDescriptions = new List<string>(multiNumColDesc);
}
foreach (string key in catAnnotatRows.Keys){
string name = key;
string[] svals = ArrayUtils.SubArray(catAnnotatRows[key], mainColIndices);
string[][] cat = new string[svals.Length][];
for (int i = 0; i < cat.Length; i++){
string s = svals[i].Trim();
cat[i] = s.Length > 0 ? s.Split(';') : new string[0];
List<int> valids = new List<int>();
for (int j = 0; j < cat[i].Length; j++){
cat[i][j] = cat[i][j].Trim();
if (cat[i][j].Length > 0){
valids.Add(j);
}
}
cat[i] = ArrayUtils.SubArray(cat[i], valids);
Array.Sort(cat[i]);
}
matrixData.AddCategoryRow(name, name, cat);
}
foreach (string key in numAnnotatRows.Keys){
string name = key;
string[] svals = ArrayUtils.SubArray(numAnnotatRows[key], mainColIndices);
double[] num = new double[svals.Length];
for (int i = 0; i < num.Length; i++){
string s = svals[i].Trim();
num[i] = double.NaN;
double.TryParse(s, out num[i]);
}
matrixData.AddNumericRow(name, name, num);
}
matrixData.Origin = origin;
progress(0);
status("");
}
示例4: ProcessDataReadFromFile
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;
}
示例5: ProcessDataCreateFromGoupNames
private static void ProcessDataCreateFromGoupNames(IMatrixData mdata, Parameters param, ProcessInfo processInfo)
{
SingleChoiceWithSubParams scwsp = param.GetSingleChoiceWithSubParams("Pattern");
Parameters spar = scwsp.GetSubParameters();
string regexString = "";
string replacement = "";
switch (scwsp.Value) {
case 0:
case 1:
case 2:
regexString = GetSelectableRegexes()[scwsp.Value][1];
break;
case 3:
regexString = spar.GetStringParam("Regex").Value;
break;
case 4:
regexString = spar.GetStringParam("Regex").Value;
replacement = spar.GetStringParam("Replace with").Value;
break;
default:
break;
}
Regex regex;
try{
regex = new Regex(regexString);
}
catch (ArgumentException){
processInfo.ErrString = "The regular expression you provided has invalid syntax.";
return;
}
List<string[]> groupNames = new List<string[]>();
foreach (string sampleName in mdata.ExpressionColumnNames) {
string groupName = scwsp.Value < 4 ? regex.Match(sampleName).Groups[1].Value : regex.Replace(sampleName, replacement);
if (string.IsNullOrEmpty(groupName))
groupName = sampleName;
groupNames.Add(new[] { groupName });
}
mdata.AddCategoryRow("Grouping", "", groupNames.ToArray());
}
示例6: ProcessDataCreate
private static void ProcessDataCreate(IMatrixData mdata, Parameters param)
{
string name = param.GetStringParam("Row name").Value;
string[][] groupCol = new string[mdata.ExpressionColumnCount][];
for (int i = 0; i < mdata.ExpressionColumnCount; i++){
string ename = mdata.ExpressionColumnNames[i];
string value = param.GetStringParam(ename).Value;
groupCol[i] = value.Length > 0 ? value.Split(';') : new string[0];
}
mdata.AddCategoryRow(name, name, groupCol);
}
示例7: LoadData
//.........这里部分代码省略.........
for (int i = 0; i < multiNumColIndices.Count; i++){
if (multiNumColIndices[i] >= w.Length){
multiNumericAnnotation[i][count] = new double[0];
} else{
string q = w[multiNumColIndices[i]].Trim();
if (q.Length >= 2 && q[0] == '\"' && q[q.Length - 1] == '\"'){
q = q.Substring(1, q.Length - 2);
}
if (q.Length >= 2 && q[0] == '\'' && q[q.Length - 1] == '\''){
q = q.Substring(1, q.Length - 2);
}
string[] ww = q.Length == 0 ? new string[0] : q.Split(';');
multiNumericAnnotation[i][count] = new double[ww.Length];
for (int j = 0; j < ww.Length; j++){
double q1;
bool success = double.TryParse(ww[j], out q1);
multiNumericAnnotation[i][count][j] = success ? q1 : double.NaN;
}
}
}
for (int i = 0; i < catColIndices.Count; i++){
if (catColIndices[i] >= w.Length){
categoryAnnotation[i][count] = new string[0];
} else{
string q = w[catColIndices[i]].Trim();
if (q.Length >= 2 && q[0] == '\"' && q[q.Length - 1] == '\"'){
q = q.Substring(1, q.Length - 2);
}
if (q.Length >= 2 && q[0] == '\'' && q[q.Length - 1] == '\''){
q = q.Substring(1, q.Length - 2);
}
string[] ww = q.Length == 0 ? new string[0] : q.Split(';');
Array.Sort(ww);
categoryAnnotation[i][count] = ww;
}
}
for (int i = 0; i < numColIndices.Count; i++){
if (numColIndices[i] >= w.Length){
numericAnnotation[i][count] = double.NaN;
} else{
double q;
bool success = double.TryParse(w[numColIndices[i]].Trim(), out q);
numericAnnotation[i][count] = success ? q : double.NaN;
}
}
for (int i = 0; i < textColIndices.Count; i++){
if (textColIndices[i] >= w.Length){
stringAnnotation[i][count] = "";
} else{
string q = w[textColIndices[i]].Trim();
stringAnnotation[i][count] = RemoveSplitWhitespace(RemoveQuotes(q));
}
}
count++;
}
reader.Close();
string[] columnNames = ArrayUtils.SubArray(colNames, expressionColIndices);
string[] catColnames = ArrayUtils.SubArray(colNames, catColIndices);
string[] numColnames = ArrayUtils.SubArray(colNames, numColIndices);
string[] multiNumColnames = ArrayUtils.SubArray(colNames, multiNumColIndices);
string[] textColnames = ArrayUtils.SubArray(colNames, textColIndices);
matrixData.SetData(filename, RemoveQuotes(columnNames), expressionValues, RemoveQuotes(textColnames),
stringAnnotation, RemoveQuotes(catColnames), categoryAnnotation, RemoveQuotes(numColnames), numericAnnotation,
RemoveQuotes(multiNumColnames), multiNumericAnnotation);
if (colDescriptions != null){
string[] columnDesc = ArrayUtils.SubArray(colDescriptions, expressionColIndices);
string[] catColDesc = ArrayUtils.SubArray(colDescriptions, catColIndices);
string[] numColDesc = ArrayUtils.SubArray(colDescriptions, numColIndices);
string[] multiNumColDesc = ArrayUtils.SubArray(colDescriptions, multiNumColIndices);
string[] textColDesc = ArrayUtils.SubArray(colDescriptions, textColIndices);
matrixData.ExpressionColumnDescriptions = new List<string>(columnDesc);
matrixData.NumericColumnDescriptions = new List<string>(numColDesc);
matrixData.CategoryColumnDescriptions = new List<string>(catColDesc);
matrixData.StringColumnDescriptions = new List<string>(textColDesc);
matrixData.MultiNumericColumnDescriptions = new List<string>(multiNumColDesc);
}
foreach (string key in ArrayUtils.GetKeys(catAnnotatRows)){
string name = key;
string[] svals = ArrayUtils.SubArray(catAnnotatRows[key], expressionColIndices);
string[][] cat = new string[svals.Length][];
for (int i = 0; i < cat.Length; i++){
string s = svals[i].Trim();
cat[i] = s.Length > 0 ? s.Split(';') : new string[0];
}
matrixData.AddCategoryRow(name, name, cat);
}
foreach (string key in ArrayUtils.GetKeys(numAnnotatRows)){
string name = key;
string[] svals = ArrayUtils.SubArray(numAnnotatRows[key], expressionColIndices);
double[] num = new double[svals.Length];
for (int i = 0; i < num.Length; i++){
string s = svals[i].Trim();
num[i] = double.NaN;
double.TryParse(s, out num[i]);
}
matrixData.AddNumericRow(name, name, num);
}
matrixData.Origin = filename;
status("");
}
示例8: SetAnnotationRows
private static void SetAnnotationRows(IMatrixData result, IMatrixData mdata1, IMatrixData mdata2)
{
result.CategoryRowNames.Clear();
result.CategoryRowDescriptions.Clear();
result.ClearCategoryRows();
result.NumericRowNames.Clear();
result.NumericRowDescriptions.Clear();
result.NumericRows.Clear();
string[] allCatNames = ArrayUtils.Concat(mdata1.CategoryRowNames, mdata2.CategoryRowNames);
allCatNames = ArrayUtils.UniqueValues(allCatNames);
result.CategoryRowNames = new List<string>();
string[] allCatDescriptions = new string[allCatNames.Length];
for (int i = 0; i < allCatNames.Length; i++){
allCatDescriptions[i] = GetDescription(allCatNames[i], mdata1.CategoryRowNames, mdata2.CategoryRowNames,
mdata1.CategoryRowDescriptions, mdata2.CategoryRowDescriptions);
}
result.CategoryRowDescriptions = new List<string>();
for (int index = 0; index < allCatNames.Length; index++){
string t = allCatNames[index];
string[][] categoryRow = new string[mdata1.ExpressionColumnCount + mdata2.ExpressionColumnCount][];
for (int j = 0; j < categoryRow.Length; j++){
categoryRow[j] = new string[0];
}
int ind1 = mdata1.CategoryRowNames.IndexOf(t);
if (ind1 >= 0){
string[][] c1 = mdata1.GetCategoryRowAt(ind1);
for (int j = 0; j < c1.Length; j++){
categoryRow[j] = c1[j];
}
}
int ind2 = mdata2.CategoryRowNames.IndexOf(t);
if (ind2 >= 0){
string[][] c2 = mdata2.GetCategoryRowAt(ind2);
for (int j = 0; j < c2.Length; j++){
categoryRow[mdata1.ExpressionColumnCount + j] = c2[j];
}
}
result.AddCategoryRow(allCatNames[index], allCatDescriptions[index], categoryRow);
}
string[] allNumNames = ArrayUtils.Concat(mdata1.NumericRowNames, mdata2.NumericRowNames);
allNumNames = ArrayUtils.UniqueValues(allNumNames);
result.NumericRowNames = new List<string>(allNumNames);
string[] allNumDescriptions = new string[allNumNames.Length];
for (int i = 0; i < allNumNames.Length; i++){
allNumDescriptions[i] = GetDescription(allNumNames[i], mdata1.NumericRowNames, mdata2.NumericRowNames,
mdata1.NumericRowDescriptions, mdata2.NumericRowDescriptions);
}
result.NumericRowDescriptions = new List<string>(allNumDescriptions);
foreach (string t in allNumNames){
double[] numericRow = new double[mdata1.ExpressionColumnCount + mdata2.ExpressionColumnCount];
for (int j = 0; j < numericRow.Length; j++){
numericRow[j] = double.NaN;
}
int ind1 = mdata1.NumericRowNames.IndexOf(t);
if (ind1 >= 0){
double[] c1 = mdata1.NumericRows[ind1];
for (int j = 0; j < c1.Length; j++){
numericRow[j] = c1[j];
}
}
int ind2 = mdata2.NumericRowNames.IndexOf(t);
if (ind2 >= 0){
double[] c2 = mdata2.NumericRows[ind2];
for (int j = 0; j < c2.Length; j++){
numericRow[mdata1.ExpressionColumnCount + j] = c2[j];
}
}
result.NumericRows.Add(numericRow);
}
}