示例#1
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="dbData">DB data</param>
        /// <returns>error code</returns>
        public SIMCA_READ_ERR_CODE Update(SimcaDbData dbData)
        {
            SIMCA_READ_ERR_CODE result = SIMCA_READ_ERR_CODE.OK;

            foreach (SimcaDataItem item in _simcaDataList)
            {
                if (item.IsTitle)
                {
                    continue;
                }

                // Set peak ID
                result = SetPeakId(dbData, item);
                if (result == SIMCA_READ_ERR_CODE.OK)
                {
                    // Set score plot parameter
                    result = SetScorePlotParam(dbData, item);
                }

                if (result != SIMCA_READ_ERR_CODE.OK)
                {
                    break;
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Set score plot parameter
        /// </summary>
        /// <param name="dbData">DB data</param>
        /// <param name="item">File data item</param>
        /// <returns>T=Success F=Fail</returns>
        private SIMCA_READ_ERR_CODE SetScorePlotParam(SimcaDbData dbData, SimcaDataItem item)
        {
            if (this.DataType != SIMCA_DATA_TYPE.SCORE_PLOT)
            {   // type is different
                return(SIMCA_READ_ERR_CODE.OK);
            }

            item.Color     = Color.LightGreen;
            item.GroupId   = -1;
            item.SampleId  = -1;
            item.GroupName = string.Empty;

            // Get primary Id (string)
            string primaryId;

            if (!item.TryGetStrValue(PRIMARY_ID_INDEX, out primaryId))
            {
                return(SIMCA_READ_ERR_CODE.NG_FORMAT);
            }

            // Find sample name(sample name == primary Id)
            int groupIdx;
            int sampleIdx;

            if (dbData.FindSampleName(primaryId, out groupIdx, out sampleIdx))
            {
                item.Color     = dbData.GetGroupColor(groupIdx);
                item.GroupId   = dbData.GetGroupId(groupIdx);
                item.SampleId  = dbData.GetSampleId(groupIdx, sampleIdx);
                item.GroupName = dbData.GetGroupName(groupIdx);
            }

            return(SIMCA_READ_ERR_CODE.OK);
        }
示例#3
0
        /// <summary>
        /// Set peak ID
        /// </summary>
        /// <param name="dbData">DB data</param>
        /// <param name="item">File data item</param>
        /// <returns>error code</returns>
        private SIMCA_READ_ERR_CODE SetPeakId(SimcaDbData dbData, SimcaDataItem item)
        {
            if (this.DataType != SIMCA_DATA_TYPE.SCORE_PLOT)
            {
                item.PeakId = -1;
                if (this.HasRt && _secondaryIdIndexList.Count() >= 2)
                {
                    double rt, mz;
                    if (!item.TryGetDoubleValue(_secondaryIdIndexList[0], out rt))
                    {
                        return(SIMCA_READ_ERR_CODE.NG_FORMAT);
                    }
                    if (!item.TryGetDoubleValue(_secondaryIdIndexList[1], out mz))
                    {
                        return(SIMCA_READ_ERR_CODE.NG_FORMAT);
                    }
                    item.PeakId = dbData.FindPeakId(rt, mz);
                }
                else if (!this.HasRt && _secondaryIdIndexList.Count() >= 1)
                {
                    double mz;
                    if (!item.TryGetDoubleValue(_secondaryIdIndexList[0], out mz))
                    {
                        return(SIMCA_READ_ERR_CODE.NG_FORMAT);
                    }
                    item.PeakId = dbData.FindPeakId(mz);
                }
            }

            return(SIMCA_READ_ERR_CODE.OK);
        }
示例#4
0
        /// <summary>
        /// Check DB update(Matrix ID specification)
        /// </summary>
        /// <param name="selMatrixId">Matrix ID</param>
        /// <returns>>T:changed F:not changed</returns>
        public bool IsChanged(int selMatrixId)
        {
            SimcaDbData newData = new SimcaDbData();

            newData.ReadDb(selMatrixId);   // Read DB

            return(CheckChanged(newData));
        }
示例#5
0
        /// <summary>
        /// Check DB update
        /// </summary>
        /// <returns>T:changed F:not changed</returns>
        public bool IsChanged()
        {
            SimcaDbData newData = new SimcaDbData();

            newData.ReadDb();   // Read DB

            return(CheckChanged(newData));
        }
示例#6
0
        /// <summary>
        /// Check skip data
        /// </summary>
        /// <param name="dbData">DB data</param>
        /// <param name="item">File data item</param>
        /// <returns>error code</returns>
        private SIMCA_READ_ERR_CODE CheckSkipData(SimcaDbData dbData, SimcaDataItem item)
        {
            if (this.DataType == SIMCA_DATA_TYPE.SCORE_PLOT)
            {
                return(SIMCA_READ_ERR_CODE.OK);
            }

            double dummy;
            int    count = 0;

            foreach (int index in _secondaryIdIndexList)
            {
                if (!item.TryGetDoubleValue(index, out dummy))
                {
                    return(SIMCA_READ_ERR_CODE.SKIP);
                }

                count++;
                if (count >= 2)
                {
                    break;
                }
            }
            foreach (int index in _dataIndexList)
            {
                if (!item.TryGetDoubleValue(index, out dummy))
                {
                    return(SIMCA_READ_ERR_CODE.SKIP);
                }
                if (this.DataType == SIMCA_DATA_TYPE.S_PLOT)
                {
                    if (!item.TryGetDoubleValue(index + 1, out dummy))
                    {
                        return(SIMCA_READ_ERR_CODE.SKIP);
                    }
                }
            }
            return(SIMCA_READ_ERR_CODE.OK);
        }
示例#7
0
        /// <summary>
        /// Check DB data changed
        /// </summary>
        /// <param name="newData">New read data</param>
        /// <returns>T:changed F:not changed</returns>
        private bool CheckChanged(SimcaDbData newData)
        {
            bool changed = false;

            if ((!newData._matrixIdList.SequenceEqual(_matrixIdList)) ||
                (!newData._matrixNameList.SequenceEqual(_matrixNameList)) ||
                (newData.SelectedMatrixId != this.SelectedMatrixId) ||
                (!newData._groupIdList.SequenceEqual(_groupIdList)) ||
                (!newData._groupNameList.SequenceEqual(_groupNameList)) ||
                (!newData._groupColorList.SequenceEqual(_groupColorList)) ||
                (!newData._peakIdList.SequenceEqual(_peakIdList)) ||
                (!newData._peakRtList.SequenceEqual(_peakRtList)) ||
                (!newData._peakMzList.SequenceEqual(_peakMzList)))
            {
                changed = true;
            }

            if (newData._sampleIdList.Count() == _sampleIdList.Count())
            {
                for (int lp = 0; lp < newData._sampleIdList.Count(); lp++)
                {
                    if (!newData._sampleIdList[lp].SequenceEqual(_sampleIdList[lp]))
                    {
                        changed = true;
                    }
                }
            }
            else
            {
                changed = true;
            }

            if (newData._sampleNameList.Count() == _sampleNameList.Count())
            {
                for (int lp = 0; lp < newData._sampleNameList.Count(); lp++)
                {
                    if (!newData._sampleNameList[lp].SequenceEqual(_sampleNameList[lp]))
                    {
                        changed = true;
                    }
                }
            }
            else
            {
                changed = true;
            }

            // Update Data
            if (changed)
            {
                this.SelectedMatrixId = newData.SelectedMatrixId;
                _matrixIdList         = newData._matrixIdList;
                _matrixNameList       = newData._matrixNameList;
                _groupIdList          = newData._groupIdList;
                _groupNameList        = newData._groupNameList;
                _groupColorList       = newData._groupColorList;
                _sampleIdList         = newData._sampleIdList;
                _sampleNameList       = newData._sampleNameList;
                _peakIdList           = newData._peakIdList;
                _peakRtList           = newData._peakRtList;
                _peakMzList           = newData._peakMzList;
            }

            return(changed);
        }
示例#8
0
        /// <summary>
        /// Set paste data
        /// </summary>
        /// <param name="paste">paste data</param>
        /// <param name="dbdata">data base data</param>
        /// <returns>error code</returns>
        public SIMCA_READ_ERR_CODE SetPasteData(string paste, SimcaDbData dbdata)
        {
            SIMCA_READ_ERR_CODE result = SIMCA_READ_ERR_CODE.NG_FORMAT;

            // Empty data
            if (paste == string.Empty)
            {
                return(result);
            }

            // DB data
            SimcaDbData tempDbData = dbdata;

            if (dbdata == null)
            {
                tempDbData = new SimcaDbData();
            }

            // Set data
            try
            {
                Stream stream = new MemoryStream(System.Text.Encoding.GetEncoding("Shift_JIS").GetBytes(paste));

                using (TextFieldParser parser = new TextFieldParser(
                           stream,
                           System.Text.Encoding.GetEncoding("Shift_JIS")))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(",");
                    while (parser.EndOfData == false)
                    {
                        result = Add(parser.ReadFields(), tempDbData);
                        if (result != SimcaData.SIMCA_READ_ERR_CODE.OK)
                        {
                            return(result);
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(SimcaData.SIMCA_READ_ERR_CODE.NG_READ);
            }

            // Check data
            if (GetDataCount() <= 0)
            {
                result = SimcaData.SIMCA_READ_ERR_CODE.NG_FORMAT;
            }

            if (SIMCA_READ_ERR_CODE.OK != result)
            {
                return(result);
            }

            result = CheckData(tempDbData.GetSelectedMatrixIndex());
            if (SIMCA_READ_ERR_CODE.NG_CLASS == result)
            {
                if (dbdata == null)
                {
                    result = SIMCA_READ_ERR_CODE.OK;
                }
            }

            return(result);
        }
示例#9
0
        /// <summary>
        /// Add data(1 line)
        /// </summary>
        /// <param name="newData">1 line data</param>
        /// <param name="dbData">DB data</param>
        /// <returns>error code</returns>
        public SIMCA_READ_ERR_CODE Add(string[] newData, SimcaDbData dbData)
        {
            SIMCA_READ_ERR_CODE result = SIMCA_READ_ERR_CODE.OK;

            SimcaDataItem item = new SimcaDataItem();

            item.SetData(newData, Color.LightGreen, -1, -1);

            // Split line data
            if (newData == null)
            {
                return(SIMCA_READ_ERR_CODE.NG_FORMAT);
            }

            if (_simcaDataList.Count() == 0)
            {   // title line
                item.IsTitle = true;

                // Set column count
                this.ColumnCount = newData.Count();

                // Set index data
                result = SetIndexData(newData);
            }
            else
            {   // data line
                if (this.ColumnCount != newData.Count())
                {
                    result = SIMCA_READ_ERR_CODE.NG_FORMAT;
                }
                else
                {
                    // Check loading plot skip data
                    result = CheckSkipData(dbData, item);

                    // Set peak ID
                    if (result == SIMCA_READ_ERR_CODE.OK)
                    {
                        result = SetPeakId(dbData, item);
                    }

                    // Set score plot parameter
                    if (result == SIMCA_READ_ERR_CODE.OK)
                    {
                        result = SetScorePlotParam(dbData, item);
                    }
                }
            }

            if (result == SIMCA_READ_ERR_CODE.OK)
            {
                _simcaDataList.Add(item);
            }

            if (result == SIMCA_READ_ERR_CODE.SKIP)
            {
                result = SIMCA_READ_ERR_CODE.OK;
            }

            return(result);
        }