예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="masicOptions"></param>
        /// <param name="peakFinder"></param>
        /// <param name="parentIonProcessor"></param>
        protected clsDataImport(
            clsMASICOptions masicOptions,
            MASICPeakFinder.clsMASICPeakFinder peakFinder,
            clsParentIonProcessing parentIonProcessor,
            clsScanTracking scanTracking)
        {
            mOptions            = masicOptions;
            mPeakFinder         = peakFinder;
            mParentIonProcessor = parentIonProcessor;
            mScanTracking       = scanTracking;

            mDatasetFileInfo = new DatasetFileInfo();

            mInterferenceCalculator = new InterDetect.InterferenceCalculator();

            mInterferenceCalculator.StatusEvent  += OnStatusEvent;
            mInterferenceCalculator.ErrorEvent   += OnErrorEvent;
            mInterferenceCalculator.WarningEvent += InterferenceWarningEventHandler;

            mCachedPrecursorIons = new List <InterDetect.Peak>();
            mCachedPrecursorScan = 0;

            mIsolationWidthNotFoundCount = 0;
            mPrecursorNotFoundCount      = 0;
        }
예제 #2
0
 public clsDataImportMGFandCDF(
     clsMASICOptions masicOptions,
     MASICPeakFinder.clsMASICPeakFinder peakFinder,
     clsParentIonProcessing parentIonProcessor,
     clsScanTracking scanTracking)
     : base(masicOptions, peakFinder, parentIonProcessor, scanTracking)
 {
 }
예제 #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="masicOptions"></param>
 /// <param name="peakFinder"></param>
 /// <param name="parentIonProcessor"></param>
 /// <param name="scanTracking"></param>
 public clsDataImportThermoRaw(
     clsMASICOptions masicOptions,
     clsMASICPeakFinder peakFinder,
     clsParentIonProcessing parentIonProcessor,
     clsScanTracking scanTracking)
     : base(masicOptions, peakFinder, parentIonProcessor, scanTracking)
 {
 }
예제 #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        public clsMRMProcessing(clsMASICOptions masicOptions, clsDataOutput dataOutputHandler)
        {
            mOptions         = masicOptions;
            mDataAggregation = new clsDataAggregation();
            RegisterEvents(mDataAggregation);

            mDataOutputHandler = dataOutputHandler;
        }
예제 #5
0
        public void TestFilterData()
        {
            const int MAX_ALLOWABLE_ION_COUNT = 2000;

            var options      = new clsMASICOptions(string.Empty, string.Empty);
            var peakFinder   = new MASICPeakFinder.clsMASICPeakFinder();
            var reporterIons = new clsReporterIons();

            var parentIonProcessor = new clsParentIonProcessing(reporterIons);
            var scanTracking       = new clsScanTracking(reporterIons, peakFinder);

            var dataImportUtilities = new MASIC.DataInput.clsDataImportThermoRaw(options, peakFinder, parentIonProcessor, scanTracking);

            var mReporterIons = new clsReporterIons();

            var msSpectrum = new clsMSSpectrum(1000);

            for (var mz = 500.0; mz < 1000; mz += 0.1)
            {
                msSpectrum.IonsMZ.Add(mz);
                msSpectrum.IonsIntensity.Add(100 + Math.Sin(mz / 10) * 50 - Math.Abs(750 - mz) / 10);
            }

            dataImportUtilities.DiscardDataToLimitIonCount(msSpectrum,
                                                           mReporterIons.MZIntensityFilterIgnoreRangeStart,
                                                           mReporterIons.MZIntensityFilterIgnoreRangeEnd,
                                                           MAX_ALLOWABLE_ION_COUNT);

            var pointsToCheck = new Dictionary <int, KeyValuePair <double, double> >
            {
                { 0, new KeyValuePair <double, double>(508.500, 103.43985) },
                { 10, new KeyValuePair <double, double>(509.500, 107.56497) },
                { 250, new KeyValuePair <double, double>(574.500, 121.65772) },
                { 500, new KeyValuePair <double, double>(637.800, 129.39681) },
                { 750, new KeyValuePair <double, double>(698.500, 128.37793) },
                { 1000, new KeyValuePair <double, double>(756.800, 113.22312) },
                { 1500, new KeyValuePair <double, double>(841.500, 122.01680) },
                { 1999, new KeyValuePair <double, double>(968.600, 103.38958) }
            };

            foreach (var item in pointsToCheck)
            {
                var index = item.Key;
                Console.WriteLine(
                    "Data point {0,4}: {1:F4} m/z, {2:F4} counts",
                    item.Key, msSpectrum.IonsMZ[index], msSpectrum.IonsIntensity[index]);

                Assert.AreEqual(item.Value.Key, msSpectrum.IonsMZ[index], 0.00001);
                Assert.AreEqual(item.Value.Value, msSpectrum.IonsIntensity[index], 0.00001);
            }
        }
예제 #6
0
        private void TestDatasetLookup(string datasetName, int expectedDatasetID, string user, string password)
        {
            const string strDatasetLookupFilePath = "";

            var connectionString = GetConnectionString("Gigasax", "DMS5", user, password);

            var options = new clsMASICOptions(mMasic.FileVersion, mMASICPeakFinder.ProgramVersion)
            {
                DatabaseConnectionString = connectionString
            };

            var dbAccessor = new clsDatabaseAccess(options);

            var datasetID = dbAccessor.LookupDatasetID(datasetName, strDatasetLookupFilePath, 1);

            Console.WriteLine("Data file " + datasetName + " is dataset ID " + datasetID);

            Assert.AreEqual(expectedDatasetID, datasetID, "DatasetID Mismatch");
        }
예제 #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 public clsExtendedStatsWriter(clsMASICOptions masicOptions)
 {
     mExtendedHeaderNameMap = new List <KeyValuePair <string, int> >();
     mOptions = masicOptions;
 }
예제 #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 public clsSpectrumDataWriter(clsBPIWriter bpiWriter, clsMASICOptions masicOptions)
 {
     mBPIWriter = bpiWriter;
     mOptions   = masicOptions;
 }
예제 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="masicOptions"></param>
 public clsXMLResultsWriter(clsMASICOptions masicOptions)
 {
     mOptions = masicOptions;
 }
예제 #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="masicOptions"></param>
 public clsReporterIonProcessor(clsMASICOptions masicOptions)
 {
     mOptions = masicOptions;
 }
예제 #11
0
        /// <summary>
        /// Writes out a flat file containing identified peaks and statistics
        /// </summary>
        /// <param name="scanList"></param>
        /// <param name="inputFileName"></param>
        /// <param name="outputDirectoryPath"></param>
        /// <param name="masicOptions"></param>
        /// <param name="dataOutputHandler"></param>
        /// <returns></returns>
        public bool SaveSICStatsFlatFile(
            clsScanList scanList,
            string inputFileName,
            string outputDirectoryPath,
            clsMASICOptions masicOptions,
            clsDataOutput dataOutputHandler)
        {
            var outputFilePath = string.Empty;

            const char TAB_DELIMITER = '\t';

            // Old: Populate scanListArray with the scan numbers in scanList.SurveyScans
            // PopulateScanListPointerArray(scanList.SurveyScans, scanList.SurveyScans.Count, out var scanListArray);

            try
            {
                UpdateProgress(0, "Saving SIC data to flat file");

                outputFilePath = clsDataOutput.ConstructOutputFilePath(inputFileName, outputDirectoryPath, clsDataOutput.eOutputFileTypeConstants.SICStatsFlatFile);
                ReportMessage("Saving SIC flat file to disk: " + Path.GetFileName(outputFilePath));

                using (var writer = new StreamWriter(outputFilePath, false))
                {
                    // Write the SIC stats to the output file
                    // The file is tab delimited

                    var includeScanTimesInSICStatsFile = masicOptions.IncludeScanTimesInSICStatsFile;

                    if (masicOptions.IncludeHeadersInExportFile)
                    {
                        writer.WriteLine(dataOutputHandler.GetHeadersForOutputFile(scanList, clsDataOutput.eOutputFileTypeConstants.SICStatsFlatFile, TAB_DELIMITER));
                    }

                    if (scanList.SurveyScans.Count == 0 && scanList.ParentIons.Count == 0)
                    {
                        // Write out fake values to the _SICStats.txt file so that downstream software can still access some of the information
                        for (var fragScanIndex = 0; fragScanIndex < scanList.FragScans.Count; fragScanIndex++)
                        {
                            var fakeParentIon  = GetFakeParentIonForFragScan(scanList, fragScanIndex);
                            var parentIonIndex = 0;

                            var   surveyScanNumber = 0;
                            float surveyScanTime   = 0;

                            WriteSICStatsFlatFileEntry(writer, TAB_DELIMITER, masicOptions.SICOptions, scanList,
                                                       fakeParentIon, parentIonIndex, surveyScanNumber, surveyScanTime,
                                                       0, includeScanTimesInSICStatsFile);
                        }
                    }
                    else
                    {
                        for (var parentIonIndex = 0; parentIonIndex < scanList.ParentIons.Count; parentIonIndex++)
                        {
                            bool includeParentIon;

                            if (masicOptions.CustomSICList.LimitSearchToCustomMZList)
                            {
                                includeParentIon = scanList.ParentIons[parentIonIndex].CustomSICPeak;
                            }
                            else
                            {
                                includeParentIon = true;
                            }

                            if (includeParentIon)
                            {
                                for (var fragScanIndex = 0; fragScanIndex < scanList.ParentIons[parentIonIndex].FragScanIndices.Count; fragScanIndex++)
                                {
                                    var   parentIon = scanList.ParentIons[parentIonIndex];
                                    int   surveyScanNumber;
                                    float surveyScanTime;

                                    if (parentIon.SurveyScanIndex >= 0 && parentIon.SurveyScanIndex < scanList.SurveyScans.Count)
                                    {
                                        surveyScanNumber = scanList.SurveyScans[parentIon.SurveyScanIndex].ScanNumber;
                                        surveyScanTime   = scanList.SurveyScans[parentIon.SurveyScanIndex].ScanTime;
                                    }
                                    else
                                    {
                                        surveyScanNumber = -1;
                                        surveyScanTime   = 0;
                                    }

                                    WriteSICStatsFlatFileEntry(writer, TAB_DELIMITER, masicOptions.SICOptions, scanList,
                                                               parentIon, parentIonIndex, surveyScanNumber, surveyScanTime,
                                                               fragScanIndex, includeScanTimesInSICStatsFile);
                                }
                            }

                            if (scanList.ParentIons.Count > 1)
                            {
                                if (parentIonIndex % 100 == 0)
                                {
                                    UpdateProgress((short)(parentIonIndex / (double)(scanList.ParentIons.Count - 1) * 100));
                                }
                            }
                            else
                            {
                                UpdateProgress(1);
                            }

                            if (masicOptions.AbortProcessing)
                            {
                                scanList.ProcessingIncomplete = true;
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                ReportError("Error writing the Peak Stats to: " + outputFilePath, ex, clsMASIC.eMasicErrorCodes.OutputFileWriteError);
                return(false);
            }

            return(true);
        }
예제 #12
0
        /// <summary>
        /// Attempt to lookup the Dataset ID in the database
        /// </summary>
        /// <param name="masicOptions"></param>
        /// <param name="datasetName"></param>
        /// <returns></returns>
        private bool GetDatasetIDFromDatabase(clsMASICOptions masicOptions, string datasetName, out int newDatasetID)
        {
            var avoidErrorMessage = "To avoid seeing this message in the future, clear the 'SQL Server Connection String' and " +
                                    "'Dataset Info Query SQL' entries on the Advanced tab and save a new settings file. " +
                                    "Alternatively, edit a MASIC parameter file to remove the text after the equals sign " +
                                    "for parameters ConnectionString and DatasetInfoQuerySql.";

            newDatasetID = 0;

            try
            {
                var dbTools = PRISMDatabaseUtils.DbToolsFactory.GetDBTools(masicOptions.DatabaseConnectionString);

                var queryingSingleDataset = false;

                for (var iteration = 1; iteration <= 2; iteration++)
                {
                    var sqlQuery = masicOptions.DatasetInfoQuerySql;

                    if (string.IsNullOrEmpty(sqlQuery))
                    {
                        sqlQuery = "Select Dataset, ID FROM V_Dataset_Export";
                    }

                    if (sqlQuery.StartsWith("SELECT Dataset", StringComparison.OrdinalIgnoreCase))
                    {
                        // Add a where clause to the query
                        if (iteration == 1)
                        {
                            sqlQuery += " WHERE Dataset = '" + datasetName + "'";
                            queryingSingleDataset = true;
                        }
                        else
                        {
                            sqlQuery += " WHERE Dataset Like '" + datasetName + "%'";
                        }
                    }

                    var success = dbTools.GetQueryResults(sqlQuery, out var results);
                    if (success)
                    {
                        // Find the row in the lstResults that matches fileNameCompare
                        foreach (var datasetItem in results)
                        {
                            if (string.Equals(datasetItem[0], datasetName, StringComparison.OrdinalIgnoreCase))
                            {
                                // Match found
                                if (int.TryParse(datasetItem[1], out newDatasetID))
                                {
                                    return(true);
                                }

                                ReportError("Error converting Dataset ID '" + datasetItem[1] + "' to an integer", clsMASIC.eMasicErrorCodes.InvalidDatasetID);

                                break;
                            }
                        }

                        if (results.Count > 0)
                        {
                            try
                            {
                                if (queryingSingleDataset || results.First()[0].StartsWith(datasetName))
                                {
                                    if (int.TryParse(results.First()[1], out newDatasetID))
                                    {
                                        return(true);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                // Ignore errors here
                            }
                        }
                    }
                }

                return(false);
            }
            catch (NullReferenceException ex2)
            {
                ReportError("Error connecting to database: " + masicOptions.DatabaseConnectionString + Environment.NewLine + avoidErrorMessage, clsMASIC.eMasicErrorCodes.InvalidDatasetID);
                return(false);
            }
            catch (Exception ex)
            {
                ReportError("Error connecting to database: " + masicOptions.DatabaseConnectionString + Environment.NewLine + avoidErrorMessage, ex, clsMASIC.eMasicErrorCodes.InvalidDatasetID);
                return(false);
            }
        }
예제 #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="masicOptions"></param>
 public clsDatabaseAccess(clsMASICOptions masicOptions)
 {
     mOptions = masicOptions;
 }
예제 #14
0
        private void SaveICRToolsChromatogramByScan(
            clsMASICOptions masicOptions,
            IList <clsScanInfo> scanList,
            int scanCount,
            string outputFilePath,
            bool saveElutionTimeInsteadOfScan,
            bool saveTICInsteadOfBPI,
            string inputFilePathFull)
        {
            using (var writer = new StreamWriter(outputFilePath))
            {
                // ReSharper disable StringLiteralTypo

                // Write the Header text
                writer.WriteLine("ICR-2LS Data File (GA Anderson & JE Bruce); output from MASIC by Matthew E Monroe");
                writer.WriteLine("Version " + masicOptions.MASICVersion);
                writer.WriteLine("FileName:");
                if (saveTICInsteadOfBPI)
                {
                    writer.WriteLine("title:" + Path.GetFileName(inputFilePathFull) + " TIC");
                    writer.WriteLine("Ytitle:Amplitude (TIC)");
                }
                else
                {
                    writer.WriteLine("title:" + Path.GetFileName(inputFilePathFull) + " BPI");
                    writer.WriteLine("Ytitle:Amplitude (BPI)");
                }

                if (saveElutionTimeInsteadOfScan)
                {
                    writer.WriteLine("Xtitle:Time (Minutes)");
                }
                else
                {
                    writer.WriteLine("Xtitle:Scan #");
                }

                writer.WriteLine("Comment:");
                writer.WriteLine("LCQfilename: " + inputFilePathFull);
                writer.WriteLine();
                writer.WriteLine("CommentEnd");
                writer.WriteLine("FileType: 5 ");
                writer.WriteLine(" ValidTypes:1=Time,2=Freq,3=Mass;4=TimeSeriesWithCalibrationFn;5=XYPairs");
                writer.WriteLine("DataType: 3 ");
                writer.WriteLine(" ValidTypes:1=Integer,no header,2=Floats,Sun Extrel,3=Floats with header,4=Excite waveform");
                writer.WriteLine("Appodization: 0");
                writer.WriteLine(" ValidFunctions:0=Square,1=Parzen,2=Hanning,3=Welch");
                writer.WriteLine("ZeroFills: 0 ");

                // Since we're using XY pairs, the buffer length needs to be two times scanCount
                var bufferLength = scanCount * 2;
                if (bufferLength < 1)
                {
                    bufferLength = 1;
                }

                writer.WriteLine("NumberOfSamples: " + bufferLength.ToString() + " ");
                writer.WriteLine("SampleRate: 1 ");
                writer.WriteLine("LowMassFreq: 0 ");
                writer.WriteLine("FreqShift: 0 ");
                writer.WriteLine("NumberSegments: 0 ");
                writer.WriteLine("MaxPoint: 0 ");
                writer.WriteLine("CalType: 0 ");
                writer.WriteLine("CalA: 108205311.2284 ");
                writer.WriteLine("CalB:-1767155067.018 ");
                writer.WriteLine("CalC: 29669467490280 ");
                writer.WriteLine("Intensity: 0 ");
                writer.WriteLine("CurrentXmin: 0 ");
                if (scanCount > 0)
                {
                    if (saveElutionTimeInsteadOfScan)
                    {
                        writer.WriteLine("CurrentXmax: " + scanList[scanCount - 1].ScanTime.ToString(CultureInfo.InvariantCulture) + " ");
                    }
                    else
                    {
                        writer.WriteLine("CurrentXmax: " + scanList[scanCount - 1].ScanNumber.ToString() + " ");
                    }
                }
                else
                {
                    writer.WriteLine("CurrentXmax: 0");
                }

                writer.WriteLine("Tags:");
                writer.WriteLine("TagsEnd");
                writer.WriteLine("End");

                // ReSharper restore StringLiteralTypo
            }

            // Wait 500 msec, then re-open the file using Binary IO
            System.Threading.Thread.Sleep(500);

            using (var writer = new BinaryWriter(new FileStream(outputFilePath, FileMode.Append)))
            {
                // Write an Escape character (Byte 1B)
                writer.Write((byte)27);

                for (var scanIndex = 0; scanIndex < scanCount; scanIndex++)
                {
                    var scan = scanList[scanIndex];
                    // Note: Using (float) to assure that we write out single precision numbers

                    if (saveElutionTimeInsteadOfScan)
                    {
                        writer.Write((float)scan.ScanTime);
                    }
                    else
                    {
                        writer.Write((float)scan.ScanNumber);
                    }

                    if (saveTICInsteadOfBPI)
                    {
                        writer.Write(clsUtilities.CFloatSafe(scan.TotalIonIntensity));
                    }
                    else
                    {
                        writer.Write(clsUtilities.CFloatSafe(scan.BasePeakIonIntensity));
                    }
                }
            }
        }