Exemplo n.º 1
0
        /// <summary>
        /// Gets the design matrix used for obtaining a single abundance value per run.
        /// The contrast matrix ends up having the same number of rows as the number of runs.
        /// </summary>
        public static DesignMatrix GetRunQuantificationDesignMatrix(FoldChangeDataSet dataSet)
        {
            var columnNames = new List<string>();
            var matrixColumns = new List<double[]>();
            var contrastValues = new List<double[]>();
            var featuresByRun = Enumerable.Range(0, dataSet.RunCount)
                .Select(dataSet.GetFeaturesForRun).ToArray();
            columnNames.Add("Intercept");
            matrixColumns.Add(Enumerable.Repeat(1.0, dataSet.RowCount).ToArray());
            contrastValues.Add(Enumerable.Repeat(1.0, dataSet.RunCount).ToArray());

            for (int iFeature = 1; iFeature < dataSet.FeatureCount; iFeature++)
            {
                columnNames.Add("Feature" + iFeature);
                matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow => iFeature == dataSet.Features[iRow] ? 1.0 : 0.0).ToArray());
                contrastValues.Add(Enumerable.Range(0, dataSet.RunCount).Select(run =>
                {
                    var features = featuresByRun[run];
                    if (features.Contains(iFeature))
                    {
                        return 1.0/features.Count;
                    }
                    return 0;
                }).ToArray());
            }

            for (int iRun = 1; iRun < dataSet.RunCount; iRun++)
            {
                columnNames.Add("Run" + iRun);
                matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow=>iRun == dataSet.Runs[iRow] ? 1.0 : 0.0).ToArray());
                contrastValues.Add(Enumerable.Range(0, dataSet.RunCount).Select(run=>run == iRun ? 1.0 : 0).ToArray());
            }
            return new DesignMatrix(dataSet, matrixColumns.ToArray(), contrastValues.ToArray(), columnNames.ToArray());
        }
Exemplo n.º 2
0
 private DesignMatrix(FoldChangeDataSet dataSet, double[][] matrixColumns, double[][] contrastValues, string[] columnNames)
 {
     DataSet = dataSet;
     _matrixColumns = matrixColumns;
     _contrastValues = contrastValues;
     _columnNames = columnNames;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the design matrix used for obtaining a single abundance value per run.
        /// The contrast matrix ends up having the same number of rows as the number of runs.
        /// </summary>
        public static DesignMatrix GetRunQuantificationDesignMatrix(FoldChangeDataSet dataSet)
        {
            var columnNames    = new List <string>();
            var matrixColumns  = new List <double[]>();
            var contrastValues = new List <double[]>();
            var featuresByRun  = Enumerable.Range(0, dataSet.RunCount)
                                 .Select(dataSet.GetFeaturesForRun).ToArray();

            columnNames.Add("Intercept");
            matrixColumns.Add(Enumerable.Repeat(1.0, dataSet.RowCount).ToArray());
            contrastValues.Add(Enumerable.Repeat(1.0, dataSet.RunCount).ToArray());

            for (int iFeature = 1; iFeature < dataSet.FeatureCount; iFeature++)
            {
                columnNames.Add("Feature" + iFeature);
                matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow => iFeature == dataSet.Features[iRow] ? 1.0 : 0.0).ToArray());
                contrastValues.Add(Enumerable.Range(0, dataSet.RunCount).Select(run =>
                {
                    var features = featuresByRun[run];
                    if (features.Contains(iFeature))
                    {
                        return(1.0 / features.Count);
                    }
                    return(0);
                }).ToArray());
            }

            for (int iRun = 1; iRun < dataSet.RunCount; iRun++)
            {
                columnNames.Add("Run" + iRun);
                matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow => iRun == dataSet.Runs[iRow] ? 1.0 : 0.0).ToArray());
                contrastValues.Add(Enumerable.Range(0, dataSet.RunCount).Select(run => run == iRun ? 1.0 : 0).ToArray());
            }
            return(new DesignMatrix(dataSet, matrixColumns.ToArray(), contrastValues.ToArray(), columnNames.ToArray()));
        }
Exemplo n.º 4
0
 private DesignMatrix(FoldChangeDataSet dataSet, double[][] matrixColumns, double[][] contrastValues, string[] columnNames)
 {
     DataSet         = dataSet;
     _matrixColumns  = matrixColumns;
     _contrastValues = contrastValues;
     _columnNames    = columnNames;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Constructs a design matrix for a FoldChangeDataSet.
        /// If <paramref name="includeFeatureInteraction"/> is true, then the model is:
        /// ABUNDANCE ~ FEATURE +  SUBJECT + GROUP + FEATURE:GROUP
        /// if false, then the model is:
        /// ABUNDANCE ~ FEATURE +  SUBJECT + GROUP
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="includeFeatureInteraction"></param>
        /// <returns></returns>
        public static DesignMatrix GetDesignMatrix(FoldChangeDataSet dataSet, bool includeFeatureInteraction)
        {
            var columnNames    = new List <string>();
            var matrixColumns  = new List <double[]>();
            var contrastValues = new List <double>();

            columnNames.Add("Intercept");
            matrixColumns.Add(Enumerable.Repeat(1.0, dataSet.RowCount).ToArray());
            contrastValues.Add(0);

            for (int iFeature = 1; iFeature < dataSet.FeatureCount; iFeature++)
            {
                columnNames.Add("Feature" + iFeature);
                matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow => iFeature == dataSet.Features[iRow] ? 1.0 : 0.0).ToArray());
                contrastValues.Add(0.0);
            }

            if (dataSet.RowCount != dataSet.SubjectCount)
            {
                int controlGroupCount = dataSet.SubjectControls.Count(f => f);
                var subjectIndexes    = Enumerable.Range(1, dataSet.SubjectCount - 1);
                foreach (int iSubject in subjectIndexes)
                {
                    columnNames.Add("Subject" + iSubject);
                    matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow => iSubject == dataSet.Subjects[iRow] ? 1.0 : 0.0).ToArray());
                    if (dataSet.IsSubjectInControlGroup(iSubject))
                    {
                        contrastValues.Add(-1.0 / controlGroupCount);
                    }
                    else
                    {
                        contrastValues.Add(1.0 / (dataSet.SubjectCount - controlGroupCount));
                    }
                }
            }

            columnNames.Add("Control");
            matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow => dataSet.IsRowInControlGroup(iRow) ? 1.0 : 0.0).ToArray());
            contrastValues.Add(-1.0);

            if (includeFeatureInteraction)
            {
                for (int iFeature = 1; iFeature < dataSet.FeatureCount; iFeature++)
                {
                    columnNames.Add("Feature" + iFeature + "Interaction");
                    matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow =>
                                                                                   iFeature == dataSet.Features[iRow] && dataSet.IsRowInControlGroup(iRow) ? 1.0 : 0.0).ToArray());
                    contrastValues.Add(-1.0 / dataSet.FeatureCount);
                }
            }
            return(new DesignMatrix(dataSet, matrixColumns.ToArray(), contrastValues.Select(value => new[] { value }).ToArray(), columnNames.ToArray()));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructs a design matrix for a FoldChangeDataSet.
        /// If <paramref name="includeFeatureInteraction"/> is true, then the model is:
        /// ABUNDANCE ~ FEATURE +  SUBJECT + GROUP + FEATURE:GROUP
        /// if false, then the model is:
        /// ABUNDANCE ~ FEATURE +  SUBJECT + GROUP
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="includeFeatureInteraction"></param>
        /// <returns></returns>
        public static DesignMatrix GetDesignMatrix(FoldChangeDataSet dataSet, bool includeFeatureInteraction)
        {
            var columnNames = new List<string>();
            var matrixColumns = new List<double[]>();
            var contrastValues = new List<double>();
            columnNames.Add("Intercept");
            matrixColumns.Add(Enumerable.Repeat(1.0, dataSet.RowCount).ToArray());
            contrastValues.Add(0);

            for (int iFeature = 1; iFeature < dataSet.FeatureCount; iFeature++)
            {
                columnNames.Add("Feature" + iFeature);
                matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow=>iFeature == dataSet.Features[iRow] ? 1.0 : 0.0).ToArray());
                contrastValues.Add(0.0);
            }

            if (dataSet.RowCount != dataSet.SubjectCount)
            {
                int controlGroupCount = dataSet.SubjectControls.Count(f => f);
                var subjectIndexes = Enumerable.Range(1, dataSet.SubjectCount - 1);
                foreach (int iSubject in subjectIndexes)
                {
                    columnNames.Add("Subject" + iSubject);
                    matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow=>iSubject == dataSet.Subjects[iRow] ? 1.0 : 0.0).ToArray());
                    if (dataSet.IsSubjectInControlGroup(iSubject))
                    {
                        contrastValues.Add(-1.0/controlGroupCount);
                    }
                    else
                    {
                        contrastValues.Add(1.0 / (dataSet.SubjectCount - controlGroupCount));
                    }
                }
            }

            columnNames.Add("Control");
            matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow => dataSet.IsRowInControlGroup(iRow) ? 1.0 : 0.0).ToArray());
            contrastValues.Add(-1.0);

            if (includeFeatureInteraction)
            {
                for (int iFeature = 1; iFeature < dataSet.FeatureCount; iFeature++)
                {
                    columnNames.Add("Feature" + iFeature + "Interaction");
                    matrixColumns.Add(Enumerable.Range(0, dataSet.RowCount).Select(iRow =>
                        iFeature == dataSet.Features[iRow] && dataSet.IsRowInControlGroup(iRow) ? 1.0 : 0.0).ToArray());
                    contrastValues.Add(-1.0 / dataSet.FeatureCount);
                }
            }
            return new DesignMatrix(dataSet, matrixColumns.ToArray(), contrastValues.Select(value => new[]{value}).ToArray(), columnNames.ToArray());
        }