Example #1
0
        private void root_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var p = e.GetPosition(root);

            // 已选中项,红框显示,无法形成链接
            VisualTreeHelper.HitTest(root, null, f =>
            {
                var element = f.VisualHit;

                if (element is Border)
                {
                    object tag = ((Border)element).Tag;
                    if (tag != null)
                    {
                        string columnName = tag.ToString();

                        var target = targetItemList.FirstOrDefault(item => item.ColumnName == columnName);

                        if (target != null && sourceItem != null)
                        {
                            targetItem = target;

                            if (!ColumnMap.ContainsKey(targetItem.ColumnName))
                            {
                                drawLine(sourceItem.ColumnName, targetItem.ColumnName);
                                ColumnMap.Add(targetItem.ColumnName, sourceItem.ColumnName);

                                targetItem.ColumnValue = sourceItem.ColumnName;

                                TableDAL.Comment(TableName, targetItem.ColumnName, sourceItem.ColumnName);
                            }
                        }
                    }
                }

                return(HitTestResultBehavior.Continue);
            }, new PointHitTestParameters(p));
            // 未选中项,记录选中项,画线
            root.ReleaseMouseCapture();

            root.Children.Remove(tempLine);
            tempLine   = null;
            sourceItem = null;
        }
        private bool PassesFilters(MSFeature msFeature)
        {
            if (ColumnMap.ContainsKey("MSFeature.Frame"))
            {
                if (msFeature.ScanLC < Settings.ScanLCMin || msFeature.ScanLC > Settings.ScanLCMax)
                {
                    return(false);
                }
            }

            if (ColumnMap.ContainsKey("MSFeature.ScanIMS"))
            {
                if (msFeature.ScanIMS < Settings.ScanIMSMin || msFeature.ScanIMS > Settings.ScanIMSMax)
                {
                    return(false);
                }
            }

            if (ColumnMap.ContainsKey("MSFeature.MassMonoisotopic"))
            {
                if (msFeature.MassMonoisotopic < Settings.MassMonoisotopicStart || msFeature.MassMonoisotopic > Settings.MassMonoisotopicEnd)
                {
                    return(false);
                }
            }

            if (ColumnMap.ContainsKey("MSFeature.ErrorFlag"))
            {
                if (msFeature.ErrorFlag == 1)
                {
                    return(false);
                }
            }


            var deconToolsFilterTableIsBeingUsed = (Settings.FilterUsingHardCodedFilters && Settings.DeconToolsFilterList != null && Settings.DeconToolsFilterList.Count > 0);

            if (deconToolsFilterTableIsBeingUsed)
            {
                if (!DeconToolsFilterUtil.IsValidMSFeature(msFeature, Settings.DeconToolsFilterList))
                {
                    return(false);
                }
            }
            else
            {
                if (ColumnMap.ContainsKey("MSFeature.Fit"))
                {
                    if (msFeature.Fit > Settings.FitMax)
                    {
                        return(false);
                    }
                }

                if (ColumnMap.ContainsKey("MSFeature.InterferenceScore"))
                {
                    if (msFeature.InterferenceScore > Settings.InterferenceScoreMax)
                    {
                        return(false);
                    }
                }

                if (ColumnMap.ContainsKey("MSFeature.Abundance"))
                {
                    if (msFeature.Abundance < Settings.IntensityMin)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        /// <summary>
        /// Saves the data from a ISOS csv file to an List of MSFeature Objects.
        /// </summary>
        private List <MSFeature> SaveDataToMSFeatureList()
        {
            var    msFeatureList = new List <MSFeature>();
            string line;

            NumOfUnfilteredMSFeatures = 0;
            var msFeatureIndex = 0;
            var currentFrame   = 0;

            // Read the rest of the Stream, 1 line at a time, and save the appropriate data into new Objects
            for (var i = 0; (line = m_isosFileReader.ReadLine()) != null; i++)
            {
                try
                {
                    var columns = line.Split(',', '\t', '\n');

                    var msFeature = new MSFeature {
                        IndexInFile = i
                    };

                    if (ColumnMap.ContainsKey("MSFeature.Frame"))
                    {
                        var frame = Int32.Parse(columns[ColumnMap["MSFeature.Frame"]]);

                        ScanLCToFrameTypeMap.Mapping.TryGetValue(frame, out var frameType);

                        // Ignore this MS Feature if it belongs to a Frame Type that is not correct
                        if (Settings.FrameTypeFilter != UIMFData.FrameType.Calibration && frameType != Settings.FrameTypeFilter)
                        {
                            continue;
                        }

                        if (i == 0)
                        {
                            currentFrame = frame;
                            ScanLCMap.Mapping.Add(ScanLCMap.ScanLCIndex, frame);
                        }
                        if (frame != currentFrame)
                        {
                            currentFrame = frame;
                            ScanLCMap.ScanLCIndex++;
                            ScanLCMap.Mapping.Add(ScanLCMap.ScanLCIndex, frame);
                        }

                        msFeature.ScanLC = ScanLCMap.ScanLCIndex;
                    }

                    if (ColumnMap.ContainsKey("MSFeature.ScanIMS"))
                    {
                        msFeature.ScanIMS = Int32.Parse(columns[ColumnMap["MSFeature.ScanIMS"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.Charge"))
                    {
                        msFeature.Charge = (byte)Int16.Parse(columns[ColumnMap["MSFeature.Charge"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.Abundance"))
                    {
                        msFeature.Abundance = (int)float.Parse(columns[ColumnMap["MSFeature.Abundance"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.IntensityUnSummed"))
                    {
                        msFeature.IntensityUnSummed = (int)float.Parse(columns[ColumnMap["MSFeature.IntensityUnSummed"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.Mz"))
                    {
                        msFeature.Mz = double.Parse(columns[ColumnMap["MSFeature.Mz"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.Fit"))
                    {
                        msFeature.Fit = float.Parse(columns[ColumnMap["MSFeature.Fit"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.InterferenceScore"))
                    {
                        msFeature.InterferenceScore = float.Parse(columns[ColumnMap["MSFeature.InterferenceScore"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.MassMonoisotopic"))
                    {
                        msFeature.MassMonoisotopic = double.Parse(columns[ColumnMap["MSFeature.MassMonoisotopic"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.MassMostAbundant"))
                    {
                        msFeature.MassMostAbundantIsotope = double.Parse(columns[ColumnMap["MSFeature.MassMostAbundant"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.Fwhm"))
                    {
                        msFeature.Fwhm = float.Parse(columns[ColumnMap["MSFeature.Fwhm"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.DriftTimeIMS"))
                    {
                        msFeature.DriftTime = float.Parse(columns[ColumnMap["MSFeature.DriftTimeIMS"]], System.Globalization.NumberStyles.Any);
                    }
                    if (ColumnMap.ContainsKey("MSFeature.ErrorFlag"))
                    {
                        msFeature.ErrorFlag = (byte)(columns[ColumnMap["MSFeature.ErrorFlag"]].Equals(string.Empty) ? 0 : Int16.Parse(columns[ColumnMap["MSFeature.ErrorFlag"]], System.Globalization.NumberStyles.Any));
                    }
                    if (ColumnMap.ContainsKey("MSFeature.IsSaturated"))
                    {
                        msFeature.IsSaturated = Convert.ToBoolean(Int16.Parse(columns[ColumnMap["MSFeature.IsSaturated"]], System.Globalization.NumberStyles.Any));
                    }

                    if (PassesFilters(msFeature))
                    {
                        msFeature.Id = msFeatureIndex;
                        msFeatureList.Add(msFeature);
                        m_isosFileWriter.WriteLine(line);
                        msFeatureIndex++;
                    }

                    NumOfUnfilteredMSFeatures++;
                }
                catch (Exception e)
                {
                    Logger.Log("Error while reading line in isos file. Skipping Line #" + (i + 2));
                    Console.WriteLine(e.StackTrace);
                }
            }

            m_isosFileReader.Close();
            m_isosFileWriter.Close();

            return(msFeatureList);
        }