public void Close() { _rawReader.Close(); if (_mgfWriter != null) { _mgfWriter.Close(); } if (_ms1Writer != null) { _ms1Writer.Close(); } if (_ms2Writer != null) { _ms2Writer.Close(); } if (_ms3Writer != null) { _ms3Writer.Close(); } if (_mzXMLWriter != null) { _mzXMLWriter.Close(); } if (_chargeNumWriter != null) { _chargeNumWriter.Close(); } }
private bool IsNotRawfile(string fileName) { bool returnvar = false; try { //IXRawfile5 raw = (IXRawfile5) new MSFileReader_XRawfile(); RawFileName rawfile = new RawFileName(fileName); raw.Open(rawfile.FullName); raw.SetCurrentController(0, 1); int lastScanNumber = -1; raw.GetLastSpectrumNumber(ref lastScanNumber); if (lastScanNumber < 10) { returnvar = true; } if (raw != null) { raw.Close(); } } catch//can add specific exception here { return(true); } finally { //if (raw != null) // raw.Close(); } return(returnvar); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (_rawConnection != null) { _rawConnection.Close(); } } }
protected override void Dispose(bool disposing) { if (disposing) { if (_rawConnection != null) { _rawConnection.Close(); _rawConnection = null; } } base.Dispose(disposing); }
public void Dispose() { if (disposed) { return; } if (rawFile != null) { rawFile.Close(); } disposed = true; }
// Protected implementation of Dispose pattern. protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { // Free any other managed objects here. _rawConnection.Close(); } // Free any unmanaged objects here. disposed = true; }
public RawFileProcessing(IXRawfile5 raw, string rawFileName, SettingsForAnalysis settingName) { //open rawfile (add error check) raw.Open(rawFileName); raw.SetCurrentController(0, 1); raw.GetCreationDate(ref _msStart); double endtime = 0.0; raw.GetEndTime(ref endtime); _msEnd = _msStart.AddMinutes(endtime); _filecreation = File.GetCreationTime(rawFileName); raw.GetWarningMessage(ref WarningMessage); ProcessScans(raw, settingName); raw.Close(); ReduceToMetaVariables(settingName); }
private void SaveDataToCdf(MsSpectrum spec, string fpath) { DataSetFactory.SearchFolder("Microsoft.Research.Science.Data.NetCDF4.dll"); DataSetFactory.SearchFolder("Microsoft.Research.Science.Data.dll"); DataSetFactory.SearchFolder("Microsoft.Research.Science.Data.Imperative.dll"); int nControllerType = 0; // 0 == mass spec device int nContorllerNumber = 1; // first MS device int totalNumScans = 0; // Number of scans int firstScanNumber = 0, lastScanNumber = -1; // Number of first and last scan string scanFilter = null; // Scan filter line int numDataPoints = -1; // points in both the m/z and intensity arrays double retentionTimeInMinutes = -1; double minObservedMZ = -1; double maxObservedMZ = -1; double totalIonCurrent = -1; double basePeakMZ = -1; double basePeakIntensity = -1; int channel = 0; // unused int uniformTime = 0; // unused double frequency = 0; // unused int arraySize = -1; object rawData = null; // rawData wil come as Double[,] object peakFlags = null; string szFilter = null; // No filter int intensityCutoffType = 1; // No cutoff int intensityCutoffValue = 0; // No cutoff int maxNumberOfPeaks = 0; // 0 : return all data peaks double centroidPeakWidth = 0; // No centroiding int centroidThisScan = 0; // No centroiding DateTime creationDate = DateTime.MinValue; var scanPath = Path.Combine(fpath, $"{spec.Id}.cdf"); var cdf = DataSet.Open(scanPath); cdf.IsAutocommitEnabled = false; AddMetadata(cdf); IXRawfile5 rawFile = (IXRawfile5) new MSFileReader_XRawfile(); rawFile.Open(spec.RawFilePath); rawFile.SetCurrentController(nControllerType, nContorllerNumber); rawFile.GetNumSpectra(ref totalNumScans); rawFile.GetFirstSpectrumNumber(ref firstScanNumber); rawFile.GetLastSpectrumNumber(ref lastScanNumber); rawFile.GetCreationDate(ref creationDate); var massVar = cdf.Add <double>("mass_values", new[] { "point_number" }); var intensities = cdf.Add <Int32>("intensity_values", new[] { "point_number" }); var acqTimeVar = cdf.Add <double>("scan_acquisition_time", new[] { "scan_number" }); var scIndexVar = cdf.Add <int>("scan_index", new[] { "scan_number" }); var scCountVar = cdf.Add <int>("point_count", new[] { "scan_number" }); var totalIntensityVar = cdf.Add <double>("total_intensity", new[] { "scan_number" }); massVar.Metadata["scale_factor"] = 1.0; intensities.Metadata["scale_factor"] = 1.0; try { var retTimes = new double[lastScanNumber]; var ticArr = new double[lastScanNumber]; var scanIndex = new Int32[lastScanNumber]; var pointCount = new Int32[lastScanNumber]; for (int curScanNum = firstScanNumber; curScanNum <= lastScanNumber; curScanNum++) { rawFile.GetScanHeaderInfoForScanNum(curScanNum, ref numDataPoints, ref retentionTimeInMinutes, ref minObservedMZ, ref maxObservedMZ, ref totalIonCurrent, ref basePeakMZ, ref basePeakIntensity, ref channel, // unused ref uniformTime, // unused ref frequency // unused ); scanFilter = null; rawFile.GetFilterForScanNum(curScanNum, ref scanFilter); peakFlags = null; centroidPeakWidth = 0; arraySize = 0; intensityCutoffType = 1; intensityCutoffValue = (int)(0.001 * basePeakIntensity); rawFile.GetMassListFromScanNum( ref curScanNum, szFilter, // filter intensityCutoffType, // intensityCutoffType intensityCutoffValue, // intensityCutoffValue maxNumberOfPeaks, // maxNumberOfPeaks centroidThisScan, // centroid result? ref centroidPeakWidth, // centroidingPeakWidth ref rawData, // daw data ref peakFlags, // peakFlags ref arraySize); // array size ; var datArray = (Array)rawData; var massArr = new double[arraySize]; var intArr = new int[arraySize]; for (var j = 0; j < arraySize; j++) { massArr[j] = (double)datArray.GetValue(0, j); intArr[j] = Convert.ToInt32(datArray.GetValue(1, j)); } //Console.Write($"curScan = {curScanNum}\n"); var ind = curScanNum - 1; pointCount[ind] = arraySize; if (ind == 0) { scanIndex[ind] = 0; scanIndex[ind + 1] = arraySize; } else { scanIndex[ind] += scanIndex[ind - 1]; if (ind + 1 < lastScanNumber) { scanIndex[ind + 1] = arraySize; } } retTimes[ind] = TimeSpan.FromMinutes(retentionTimeInMinutes).TotalSeconds; ticArr[ind] = totalIonCurrent; massVar.Append(massArr); intensities.Append(intArr); rawData = null; } totalIntensityVar.PutData(ticArr); scIndexVar.PutData(scanIndex); acqTimeVar.PutData(retTimes); scCountVar.PutData(pointCount); cdf.Commit(); } catch (Exception e) { Console.WriteLine(e.Message); } finally { cdf.Dispose(); rawFile.Close(); } }
public static ThermoStaticData LoadAllStaticData(string filePath, IFilteringParams filterParams = null) { if (!File.Exists(filePath)) { throw new FileNotFoundException(); } if (CheckForMsFileReader() == false) { throw new MzLibException("MsFileReader Not Installed"); } var ok = new ManagedThermoHelperLayer.HelperClass(); IXRawfile5 theConnection = (IXRawfile5) new MSFileReader_XRawfile(); theConnection.Open(filePath); int pbSMData = 0; theConnection.IsThereMSData(ref pbSMData); if (pbSMData == 0) { throw new MzLibException("Could not read data from file " + Path.GetFileName(filePath)); } theConnection.SetCurrentController(0, 1); var precursorInfosArray = ok.GetAllPrecursorInfos(filePath); for (int i = 0; i < precursorInfosArray.Length; i++) { if (precursorInfosArray[i].nScanNumber == 0) { precursorInfosArray[i].nScanNumber = -1; } } int pnFirstSpectrum = 0; theConnection.GetFirstSpectrumNumber(ref pnFirstSpectrum); int pnLastSpectrum = 0; theConnection.GetLastSpectrumNumber(ref pnLastSpectrum); ThermoGlobalParams p = GetAllGlobalStuff(theConnection, precursorInfosArray, filePath); MsDataScan[] scans = new MsDataScan[pnLastSpectrum - pnFirstSpectrum + 1]; for (int nScanNumber = pnFirstSpectrum; nScanNumber <= pnLastSpectrum; nScanNumber++) { scans[nScanNumber - pnFirstSpectrum] = GetMsDataOneBasedScanFromThermoFile(theConnection, nScanNumber, p, filterParams); } theConnection.Close(); string sendCheckSum; using (FileStream stream = File.OpenRead(filePath)) { using (SHA1Managed sha = new SHA1Managed()) { byte[] checksum = sha.ComputeHash(stream); sendCheckSum = BitConverter.ToString(checksum) .Replace("-", string.Empty); } } SourceFile sourceFile = new SourceFile( @"Thermo nativeID format", @"Thermo RAW format", sendCheckSum, @"SHA-1", filePath, Path.GetFileNameWithoutExtension(filePath)); return(new ThermoStaticData(scans, p, sourceFile)); }
public void Exit() { _rawConnect.Close(); }