Пример #1
0
        private DataTable RProteinArray2DataTable(clsRarray rArray)
        {
            var matrix     = rArray.matrix;
            var rowNames   = rArray.rowNames;
            var colHeaders = rArray.colHeaders;
            var dataTable  = new DataTable();

            var dataColumn1 = new DataColumn
            {
                DataType   = Type.GetType("System.String"),
                ColumnName = clsRarray.rowNamesID
            };

            dataTable.Columns.Add(dataColumn1);

            foreach (var columnName in colHeaders)
            {
                var dataColumn = new DataColumn
                {
                    DataType   = Type.GetType("System.Double"),
                    ColumnName = columnName
                };
                dataTable.Columns.Add(dataColumn);
            }

            CopyMatrixDataToTable(matrix, dataTable, rowNames);

            // return clsDataTable.ClearZeros(mdatatable);

            return(dataTable);
        }
Пример #2
0
 public clsRconnect()
 {
     Message = null;
     _rcmd = "";
     _mRarray = new clsRarray();
     DataTable = new DataTable();
 }
Пример #3
0
 public clsRconnect()
 {
     Message   = null;
     _rcmd     = "";
     _mRarray  = new clsRarray();
     DataTable = new DataTable();
 }
Пример #4
0
        private DataTable RDoubleVector2DataTable(clsRarray mRary)
        {
            var        matrix     = mRary.matrix;
            var        rowNames   = mRary.rowNames;
            var        colHeaders = mRary.colHs;
            var        mdatatable = new DataTable();
            DataColumn mDataColumn;
            DataRow    mDataRow;

            mDataColumn            = new DataColumn();
            mDataColumn.DataType   = System.Type.GetType("System.String");
            mDataColumn.ColumnName = clsRarray.rowNamesID;
            //mDataColumn.ReadOnly = true ;
            mdatatable.Columns.Add(mDataColumn);

            mDataColumn            = new DataColumn();
            mDataColumn.DataType   = System.Type.GetType("System.Double");
            mDataColumn.ColumnName = colHeaders;
            //mDataColumn.ReadOnly = true ;
            mdatatable.Columns.Add(mDataColumn);

            for (var i = 0; i < matrix.GetLength(0); i++)
            {
                mDataRow    = mdatatable.NewRow();
                mDataRow[0] = rowNames[i];
                for (var j = 0; j < matrix.GetLength(1); j++)
                {
                    mDataRow[j + 1] = matrix[i, j];
                }
                mdatatable.Rows.Add(mDataRow);
            }
            //return clsDataTable.ClearZeros(mdatatable);
            return(clsDataTable.ReplaceMissing(mdatatable));
        }
Пример #5
0
        private DataTable RDoubleVector2DataTable(clsRarray rArray)
        {
            var matrix     = rArray.matrix;
            var rowNames   = rArray.rowNames;
            var colHeaders = rArray.colHs;
            var dataTable  = new DataTable();

            var dataColumn1 = new DataColumn
            {
                DataType   = Type.GetType("System.String"),
                ColumnName = clsRarray.rowNamesID
            };

            dataTable.Columns.Add(dataColumn1);

            var dataColumn2 = new DataColumn
            {
                DataType   = Type.GetType("System.Double"),
                ColumnName = colHeaders
            };

            dataTable.Columns.Add(dataColumn2);

            CopyMatrixDataToTable(matrix, dataTable, rowNames);

            // return clsDataTable.ClearZeros(dataTable);

            return(dataTable);
        }
Пример #6
0
        public bool GetTableFromRProtInfoMatrix(string varName)
        {
            try
            {
                _rcmd = "X<-sendmatrix(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);
                _rcmd = "Headers<-colnames(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);
                _rcmd = "Rows<-rownames(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);

                var matrix     = _rdn.GetSymbolAsStringMatrix("X");
                var colheaders = _rdn.GetSymbolAsStrings("Headers");
                var rownames   = _rdn.GetSymbolAsStrings("Rows");

                var rArray = new clsRarray(matrix, rownames, colheaders);

                DataTable = RproteinInfoArray2DataTable(rArray);

                return(true);
            }
            catch (Exception e)
            {
                var errmsg = _rcmd + " " + e.Message;
                Console.WriteLine(errmsg);
                Message = e.Message;
                return(false);
            }
        }
Пример #7
0
        public bool GetTableFromRvector(string varName)
        {
            try
            {
                _rcmd = "X<-sendmatrix(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);
                _rcmd = "Headers<-colnames(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);
                _rcmd = "Rows<-rownames(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);

                var matrix     = _rdn.GetSymbolAsNumberMatrix("X");
                var colheaders = _rdn.GetSymbolAsStrings("Headers");
                var rownames   = _rdn.GetSymbolAsStrings("Rows");

                var rowH   = rownames;
                var colH   = colheaders[0];
                var rArray = new clsRarray(matrix, rowH, colH);
                DataTable.Clear();
                DataTable = RDoubleVector2DataTable(rArray);

                return(true);
            }
            catch (Exception e)
            {
                var errmsg = _rcmd + " " + e.Message;
                Console.WriteLine(errmsg);
                Message = e.Message;
                return(false);
            }
        }
Пример #8
0
        private clsRarray DataTable2RstrArray(DataTable mTable)
        {
            var    matrix     = new string[mTable.Rows.Count, mTable.Columns.Count - 1];
            var    rowNames   = new string[mTable.Rows.Count];
            var    colHeaders = new string[mTable.Columns.Count - 1];
            string cellValue  = null;
            var    mRary      = new clsRarray();
            var    typerror   = false;

            //DataColumnCollection columnHeaders = mTable.Columns ;
            for (var col = 0; col < mTable.Columns.Count; col++)
            {
                if (typerror)
                {
                    break;
                }
                if (col > 0) //Start from 2nd column
                {
                    colHeaders[col - 1] = mTable.Columns[col].ToString();
                }
                for (var row = 0; row < mTable.Rows.Count; row++)
                {
                    if (typerror)
                    {
                        break;
                    }
                    if (col == 0) //Mass Tags
                    {
                        rowNames[row] = mTable.Rows[row].ItemArray[0].ToString();
                    }
                    else // string data
                    {
                        cellValue = mTable.Rows[row].ItemArray[col].ToString();
                        if (cellValue.Length > 0) //not an empty cell
                        {
                            matrix[row, col - 1] = cellValue;
                        }
                        else
                        {
                            matrix[row, col - 1] = "NA";
                        }
                    }
                }
            }
            if (!typerror)
            {
                mRary.rowNames   = rowNames;
                mRary.colHeaders = colHeaders;
                mRary.mstrMatrix = matrix;
            }
            else
            {
                _mRarray = null;
            }
            return(mRary);
        }
Пример #9
0
        private clsRarray DataTable2RstrArray(DataTable mTable)
        {
            var matrix     = new string[mTable.Rows.Count, mTable.Columns.Count - 1];
            var rowNames   = new string[mTable.Rows.Count];
            var colHeaders = new string[mTable.Columns.Count - 1];
            var rArray     = new clsRarray();

            //DataColumnCollection columnHeaders = mTable.Columns ;
            for (var col = 0; col < mTable.Columns.Count; col++)
            {
                if (col > 0) //Start from 2nd column
                {
                    colHeaders[col - 1] = mTable.Columns[col].ToString();
                }
                for (var row = 0; row < mTable.Rows.Count; row++)
                {
                    if (col == 0)
                    {
                        //Mass Tags
                        rowNames[row] = mTable.Rows[row].ItemArray[0].ToString();
                    }
                    else
                    {
                        // string data
                        var cellValue = mTable.Rows[row].ItemArray[col].ToString();
                        if (cellValue.Length > 0) //not an empty cell
                        {
                            matrix[row, col - 1] = cellValue;
                        }
                        else
                        {
                            matrix[row, col - 1] = "NA";
                        }
                    }
                }
            }

            rArray.rowNames   = rowNames;
            rArray.colHeaders = colHeaders;
            rArray.mstrMatrix = matrix;

            return(rArray);
        }
Пример #10
0
        private DataTable RproteinInfoArray2DataTable(clsRarray mRary)
        {
            string[,] matrix;
            matrix = mRary.mstrMatrix;
            var        rowNames   = mRary.rowNames;
            var        colHeaders = mRary.colHeaders;
            var        mdatatable = new DataTable();
            DataColumn mDataColumn;
            DataRow    mDataRow;

            mDataColumn            = new DataColumn();
            mDataColumn.DataType   = System.Type.GetType("System.String");
            mDataColumn.ColumnName = clsRarray.rowNamesID;
            //mDataColumn.ReadOnly = true ;
            mdatatable.Columns.Add(mDataColumn);

            for (var i = 0; i < colHeaders.Length; i++)
            {
                mDataColumn          = new DataColumn();
                mDataColumn.DataType = System.Type.GetType("System.String");
                //if (i == 0)
                //    mDataColumn.DataType = System.Type.GetType("System.Double");
                //else
                //    mDataColumn.DataType = System.Type.GetType("System.String");
                mDataColumn.ColumnName = colHeaders[i];
                //mDataColumn.ReadOnly = true ;
                mdatatable.Columns.Add(mDataColumn);
            }
            for (var i = 0; i < matrix.GetLength(0); i++)
            {
                mDataRow    = mdatatable.NewRow();
                mDataRow[0] = rowNames[i];
                for (var j = 0; j < matrix.GetLength(1); j++)
                {
                    mDataRow[j + 1] = matrix[i, j];
                }
                mdatatable.Rows.Add(mDataRow);
            }
            //return clsDataTable.ClearZeros(mdatatable);
            return(mdatatable);
        }
Пример #11
0
        private DataTable RproteinInfoArray2DataTable(clsRarray rArray)
        {
            var matrix     = rArray.mstrMatrix;
            var rowNames   = rArray.rowNames;
            var colHeaders = rArray.colHeaders;
            var dataTable  = new DataTable();

            var dataColumn1 = new DataColumn
            {
                DataType   = Type.GetType("System.String"),
                ColumnName = clsRarray.rowNamesID
            };

            dataTable.Columns.Add(dataColumn1);

            foreach (var columnName in colHeaders)
            {
                var dataColumn = new DataColumn
                {
                    DataType   = Type.GetType("System.String"),
                    ColumnName = columnName
                };

                dataTable.Columns.Add(dataColumn);
            }
            for (var i = 0; i < matrix.GetLength(0); i++)
            {
                var dataRow = dataTable.NewRow();
                dataRow[0] = rowNames[i];

                for (var j = 0; j < matrix.GetLength(1); j++)
                {
                    dataRow[j + 1] = matrix[i, j];
                }
                dataTable.Rows.Add(dataRow);
            }
            //return clsDataTable.ClearZeros(mdatatable);
            return(dataTable);
        }
Пример #12
0
        private DataTable RstrArray2DataTable(clsRarray mRary)
        {
            var matrix = mRary.mstrMatrix;
            var rowNames = mRary.rowNames;
            var colHeaders = mRary.colHeaders;
            var mdatatable = new DataTable();
            DataColumn mDataColumn;
            DataRow mDataRow;

            mDataColumn = new DataColumn();
            mDataColumn.DataType = System.Type.GetType("System.String");
            mDataColumn.ColumnName = clsRarray.rowNamesID;
            //mDataColumn.ReadOnly = true ;
            mdatatable.Columns.Add(mDataColumn);

            for (var i = 0; i < colHeaders.Length; i++)
            {
                mDataColumn = new DataColumn();
                mDataColumn.DataType = System.Type.GetType("System.String");
                mDataColumn.ColumnName = colHeaders[i];
                //mDataColumn.ReadOnly = true ;
                mdatatable.Columns.Add(mDataColumn);
            }
            for (var i = 0; i < matrix.GetLength(0); i++)
            {
                mDataRow = mdatatable.NewRow();
                mDataRow[0] = rowNames[i];
                for (var j = 0; j < matrix.GetLength(1); j++)
                {
                    mDataRow[j + 1] = matrix[i, j];
                }
                mdatatable.Rows.Add(mDataRow);
            }
            //return clsDataTable.ClearZeros(mdatatable);
            return mdatatable;
        }
Пример #13
0
        private clsRarray DataTable2RstrArray(DataTable mTable)
        {
            var matrix = new string[mTable.Rows.Count, mTable.Columns.Count - 1];
            var rowNames = new string[mTable.Rows.Count];
            var colHeaders = new string[mTable.Columns.Count - 1];
            string cellValue = null;
            var mRary = new clsRarray();
            var typerror = false;

            //DataColumnCollection columnHeaders = mTable.Columns ;
            for (var col = 0; col < mTable.Columns.Count; col++)
            {
                if (typerror)
                    break;
                if (col > 0) //Start from 2nd column
                    colHeaders[col - 1] = mTable.Columns[col].ToString();
                for (var row = 0; row < mTable.Rows.Count; row++)
                {
                    if (typerror)
                        break;
                    if (col == 0) //Mass Tags
                        rowNames[row] = mTable.Rows[row].ItemArray[0].ToString();
                    else // string data
                    {
                        cellValue = mTable.Rows[row].ItemArray[col].ToString();
                        if (cellValue.Length > 0) //not an empty cell
                            matrix[row, col - 1] = cellValue;
                        else
                            matrix[row, col - 1] = "NA";
                    }
                }
            }
            if (!typerror)
            {
                mRary.rowNames = rowNames;
                mRary.colHeaders = colHeaders;
                mRary.mstrMatrix = matrix;
            }
            else
            {
                _mRarray = null;
            }
            return mRary;
        }
Пример #14
0
        private clsRarray DataTable2Rarray(DataTable mTable)
        {
            var matrix = new double[mTable.Rows.Count, mTable.Columns.Count - 1];
            var rowNames = new string[mTable.Rows.Count];
            var colHeaders = new string[mTable.Columns.Count - 1];
            var mRary = new clsRarray();
            var typerror = false;

            //DataColumnCollection columnHeaders = mTable.Columns ;
            for (var col = 0; col < mTable.Columns.Count; col++)
            {
                if (typerror)
                    break;
                if (col > 0) //Start from 2nd column
                    colHeaders[col - 1] = mTable.Columns[col].ToString();
                for (var row = 0; row < mTable.Rows.Count; row++)
                {
                    if (typerror)
                        break;
                    if (col == 0) //Mass Tags
                        rowNames[row] = mTable.Rows[row].ItemArray[0].ToString();
                    else // numeric data
                    {
                        var cellValue = mTable.Rows[row].ItemArray[col].ToString();
                        if (cellValue.Length > 0) //not an empty cell
                            try
                            {
                                matrix[row, col - 1] = Convert.ToDouble(cellValue, NumberFormatInfo.InvariantInfo);
                            }
                            catch (FormatException ex)
                            {
                                MessageBox.Show("Invalid data type. Check for example, " +
                                    "if you have text strings mixed with numerical data.\n\nError:" +
                                    ex.Message, "File type error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                                typerror = true;
                            }
                        else
                            matrix[row, col - 1] = 0;
                    }
                }
            }
            if (!typerror)
            {
                mRary.rowNames = rowNames;
                mRary.colHeaders = colHeaders;
                mRary.matrix = matrix;
            }
            else
            {
                _mRarray = null;
            }
            return mRary;
        }
Пример #15
0
        public bool GetTableFromRvector(string varName)
        {
            clsRarray mRarr;
            try
            {
                _rcmd = "X<-sendmatrix(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);
                _rcmd = "Headers<-colnames(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);
                _rcmd = "Rows<-rownames(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);

                var matrix = _rdn.GetSymbolAsNumberMatrix("X");
                var colheaders = _rdn.GetSymbolAsStrings("Headers");
                var rownames = _rdn.GetSymbolAsStrings("Rows");

                var rowH = rownames as string[];
                var colH = colheaders[0];
                mRarr = new clsRarray(((double[,])matrix), rowH, colH);
                DataTable.Clear();
                DataTable = RDoubleVector2DataTable(mRarr);

                return true;
            }
            catch (Exception e)
            {
                var errmsg = _rcmd + " " + e.Message;
                Console.WriteLine(errmsg);
                Message = e.Message;
                return false;
            }
        }
Пример #16
0
        public bool GetTableFromRProtInfoMatrix(string varName)
        {
            clsRarray mRarr;
            try
            {
                _rcmd = "X<-sendmatrix(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);
                _rcmd = "Headers<-colnames(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);
                _rcmd = "Rows<-rownames(" + varName + ")";
                _rdn.EvaluateNoReturn(_rcmd);

                var matrix = _rdn.GetSymbolAsStringMatrix("X");
                var colheaders = _rdn.GetSymbolAsStrings("Headers");
                var rownames = _rdn.GetSymbolAsStrings("Rows");

                //mRarr = new clsRarray(matrix, rownames, colheaders);
                ////var m = ConvertZ(matrix);
                mRarr = new clsRarray(matrix, (string[])rownames, (string[])colheaders);

                DataTable = RproteinInfoArray2DataTable(mRarr);

                return true;
            }
            catch (Exception e)
            {
                var errmsg = _rcmd + " " + e.Message;
                Console.WriteLine(errmsg);
                Message = e.Message;
                return false;
            }
        }
Пример #17
0
        private clsRarray DataTable2Rarray(DataTable mTable, string varName)
        {
            var matrix     = new double[mTable.Rows.Count, mTable.Columns.Count - 1];
            var rowNames   = new string[mTable.Rows.Count];
            var colHeaders = new string[mTable.Columns.Count - 1];
            var rArray     = new clsRarray();
            var typerror   = false;

            //DataColumnCollection columnHeaders = mTable.Columns ;
            for (var col = 0; col < mTable.Columns.Count; col++)
            {
                if (col > 0)
                {
                    // Populate colHeaders with the user-supplied headers, starting with the second column
                    // The header for the first column is always Row_ID
                    colHeaders[col - 1] = mTable.Columns[col].ToString();
                }

                for (var row = 0; row < mTable.Rows.Count; row++)
                {
                    if (col == 0)
                    {
                        // Row identifier, typically the MassTagID (an integer), but can be a peptide sequence or any string
                        rowNames[row] = mTable.Rows[row].ItemArray[0].ToString();
                    }
                    else
                    {
                        // numeric data
                        var cellValue = mTable.Rows[row].ItemArray[col].ToString();
                        if (cellValue.Length > 0)
                        {
                            //not an empty cell
                            try
                            {
                                matrix[row, col - 1] = Convert.ToDouble(cellValue, NumberFormatInfo.InvariantInfo);
                            }
                            catch (FormatException)
                            {
                                var errMsg = string.Format("Invalid data, '{0}' is not numeric in dataset {1}",
                                                           cellValue, varName);
                                MessageBox.Show(errMsg, "Loading error", MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                                typerror = true;
                            }
                        }
                        else
                        {
                            // Empty cell
                            matrix[row, col - 1] = 0;
                        }
                    }

                    if (typerror)
                    {
                        break;
                    }
                }

                if (typerror)
                {
                    break;
                }
            }

            if (typerror)
            {
                return(rArray);
            }

            rArray.rowNames   = rowNames;
            rArray.colHeaders = colHeaders;
            rArray.matrix     = matrix;

            return(rArray);
        }
Пример #18
0
        private clsRarray DataTable2Rarray(DataTable mTable)
        {
            var matrix     = new double[mTable.Rows.Count, mTable.Columns.Count - 1];
            var rowNames   = new string[mTable.Rows.Count];
            var colHeaders = new string[mTable.Columns.Count - 1];
            var mRary      = new clsRarray();
            var typerror   = false;

            //DataColumnCollection columnHeaders = mTable.Columns ;
            for (var col = 0; col < mTable.Columns.Count; col++)
            {
                if (typerror)
                {
                    break;
                }
                if (col > 0) //Start from 2nd column
                {
                    colHeaders[col - 1] = mTable.Columns[col].ToString();
                }
                for (var row = 0; row < mTable.Rows.Count; row++)
                {
                    if (typerror)
                    {
                        break;
                    }
                    if (col == 0) //Mass Tags
                    {
                        rowNames[row] = mTable.Rows[row].ItemArray[0].ToString();
                    }
                    else // numeric data
                    {
                        var cellValue = mTable.Rows[row].ItemArray[col].ToString();
                        if (cellValue.Length > 0) //not an empty cell
                        {
                            try
                            {
                                matrix[row, col - 1] = Convert.ToDouble(cellValue, NumberFormatInfo.InvariantInfo);
                            }
                            catch (FormatException ex)
                            {
                                MessageBox.Show("Invalid data type. Check for example, " +
                                                "if you have text strings mixed with numerical data.\n\nError:" +
                                                ex.Message, "File type error", MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                                typerror = true;
                            }
                        }
                        else
                        {
                            matrix[row, col - 1] = 0;
                        }
                    }
                }
            }
            if (!typerror)
            {
                mRary.rowNames   = rowNames;
                mRary.colHeaders = colHeaders;
                mRary.matrix     = matrix;
            }
            else
            {
                _mRarray = null;
            }
            return(mRary);
        }