diff --git a/mzLib/MassSpectrometry/MsDataFile.cs b/mzLib/MassSpectrometry/MsDataFile.cs index 1533bfafd..7242f2cf7 100644 --- a/mzLib/MassSpectrometry/MsDataFile.cs +++ b/mzLib/MassSpectrometry/MsDataFile.cs @@ -16,13 +16,10 @@ // You should have received a copy of the GNU Lesser General Public // License along with MassSpectrometry. If not, see . -using Chemistry; -using MzLibUtil; using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; namespace MassSpectrometry { diff --git a/mzLib/MassSpectrometry/MzSpectra/MzSpectrum.cs b/mzLib/MassSpectrometry/MzSpectra/MzSpectrum.cs index 46b8d473c..2e9fcc7a4 100644 --- a/mzLib/MassSpectrometry/MzSpectra/MzSpectrum.cs +++ b/mzLib/MassSpectrometry/MzSpectra/MzSpectrum.cs @@ -480,14 +480,17 @@ private bool Peak2satisfiesRatio(double peak1theorIntensity, double peak2theorIn public static byte[] Get64Bitarray(IEnumerable array) { - var mem = new MemoryStream(); - foreach (var okk in array) + using (var mem = new MemoryStream()) { - byte[] ok = BitConverter.GetBytes(okk); - mem.Write(ok, 0, ok.Length); + foreach (var okk in array) + { + byte[] ok = BitConverter.GetBytes(okk); + mem.Write(ok, 0, ok.Length); + } + mem.Position = 0; + var memory = mem.ToArray(); + return memory; } - mem.Position = 0; - return mem.ToArray(); } public byte[] Get64BitYarray() @@ -505,7 +508,9 @@ public override string ToString() return string.Format("{0} (Peaks {1})", Range, Size); } - public void XCorrPrePreprocessing(double scanRangeMinMz, double scanRangeMaxMz, double precursorMz, double precursorDiscardRange = 1.5, double discreteMassBin = 1.0005079, double minimumAllowedIntensityRatioToBasePeak = 0.05) + public void XCorrPrePreprocessing(double scanRangeMinMz, double scanRangeMaxMz, + double precursorMz, double precursorDiscardRange = 1.5, + double discreteMassBin = 1.0005079, double minimumAllowedIntensityRatioToBasePeak = 0.05) { //The discrete bin value 1.0005079 was from J. Proteome Res., 2018, 17 (11), pp 3644–3656 @@ -544,9 +549,13 @@ public void XCorrPrePreprocessing(double scanRangeMinMz, double scanRangeMaxMz, //we've already filtered for when multiple mzs appear in a single nominal mass bin int nominalWindowWidthDaltons = (int)(Math.Round((scanRangeMaxMz - scanRangeMinMz) / 10d, 0)); - FilteringParams secondFilter = new FilteringParams(null, minimumAllowedIntensityRatioToBasePeak, nominalWindowWidthDaltons, null, true, false, false); - WindowModeHelper.Run(ref genericIntensityArray, ref genericMzArray, secondFilter, genericMzArray.Min(), genericMzArray.Max(), true); + FilteringParams secondFilter = new FilteringParams(null, + minimumAllowedIntensityRatioToBasePeak, nominalWindowWidthDaltons, null, + true, false, false); + + WindowModeHelper.Run(ref genericIntensityArray, ref genericMzArray, secondFilter, + genericMzArray.Min(), genericMzArray.Max(), true); Array.Sort(genericMzArray, genericIntensityArray); diff --git a/mzLib/Readers/Bruker/BrukerFileReader.cs b/mzLib/Readers/Bruker/BrukerFileReader.cs index 65101885e..0c80151e9 100644 --- a/mzLib/Readers/Bruker/BrukerFileReader.cs +++ b/mzLib/Readers/Bruker/BrukerFileReader.cs @@ -81,9 +81,9 @@ public override MsDataFile LoadAllStaticData(FilteringParams? filteringParams = // close the file connection. At this point, you don't need to be connected to the sqlite database anymore. You have all the data // you need. CloseFileConnection(); - Scans = scans.OrderBy(x => x.OneBasedScanNumber).ToArray(); + Scans = scans.OrderBy(x => x.OneBasedScanNumber).ToArray(); SourceFile = GetSourceFile(); - return this; + return this; } private const string nativeIdFormat = "scan number only nativeID format"; @@ -450,7 +450,7 @@ private void OpenFileConnection(string path) _connection = new SQLiteConnection(); _connection.ConnectionString = "DataSource=" + sqlite_fn; _connection.Open(); - } + } private void CloseFileConnection() { baf2sql_array_close_storage(_handle!.Value); diff --git a/mzLib/Readers/MsDataFileReader.cs b/mzLib/Readers/MsDataFileReader.cs index 1bb192f1d..ff577f85b 100644 --- a/mzLib/Readers/MsDataFileReader.cs +++ b/mzLib/Readers/MsDataFileReader.cs @@ -11,6 +11,7 @@ namespace Readers { public static class MsDataFileReader { + public static MsDataFile GetDataFile(string filePath) { return filePath.ParseFileType() switch diff --git a/mzLib/Readers/MzML/Mzml.cs b/mzLib/Readers/MzML/Mzml.cs index c921bbb17..896a09def 100644 --- a/mzLib/Readers/MzML/Mzml.cs +++ b/mzLib/Readers/MzML/Mzml.cs @@ -18,17 +18,12 @@ using MassSpectrometry; using MzLibUtil; -using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Globalization; -using System.IO; using System.IO.Compression; -using System.Linq; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; using System.Xml; using UsefulProteomicsDatabases; @@ -161,20 +156,20 @@ public override MsDataFile LoadAllStaticData(FilteringParams filterParams = null } Loaders.LoadElements(); - - SourceFile = GetSourceFile(); + + SourceFile = GetSourceFile(); var numSpecta = _mzMLConnection.run.spectrumList.spectrum.Length; MsDataScan[] scans = new MsDataScan[numSpecta]; - Parallel.ForEach(Partitioner.Create(0, numSpecta), new ParallelOptions - { MaxDegreeOfParallelism = maxThreads }, fff => + Parallel.ForEach(Partitioner.Create(0, numSpecta), new ParallelOptions + { MaxDegreeOfParallelism = maxThreads }, fff => + { + for (int i = fff.Item1; i < fff.Item2; i++) { - for (int i = fff.Item1; i < fff.Item2; i++) - { - scans[i] = GetMsDataOneBasedScanFromConnection(_mzMLConnection, i + 1, filterParams); - } - }); + scans[i] = GetMsDataOneBasedScanFromConnection(_mzMLConnection, i + 1, filterParams); + } + }); scans = scans.Where(s => s.MassSpectrum != null).ToArray(); @@ -236,7 +231,9 @@ public override MsDataFile LoadAllStaticData(FilteringParams filterParams = null public override SourceFile GetSourceFile() { SourceFile sourceFile; - if (_mzMLConnection.fileDescription.sourceFileList != null && _mzMLConnection.fileDescription.sourceFileList.sourceFile != null && _mzMLConnection.fileDescription.sourceFileList.sourceFile[0] != null && _mzMLConnection.fileDescription.sourceFileList.sourceFile[0].cvParam != null) + if (_mzMLConnection.fileDescription.sourceFileList != null && _mzMLConnection.fileDescription.sourceFileList.sourceFile + != null && _mzMLConnection.fileDescription.sourceFileList.sourceFile[0] != null + && _mzMLConnection.fileDescription.sourceFileList.sourceFile[0].cvParam != null) { var simpler = _mzMLConnection.fileDescription.sourceFileList.sourceFile[0]; string nativeIdFormat = null; diff --git a/mzLib/Readers/MzML/ReverseLineReader.cs b/mzLib/Readers/MzML/ReverseLineReader.cs index f82c80cf9..3e42c4f0f 100644 --- a/mzLib/Readers/MzML/ReverseLineReader.cs +++ b/mzLib/Readers/MzML/ReverseLineReader.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; +using System.Collections; using System.Text; -using System.Threading.Tasks; namespace Readers { @@ -266,5 +262,5 @@ IEnumerator IEnumerable.GetEnumerator() } } - + } diff --git a/mzLib/Readers/Thermo/ThermoRawFileReader.cs b/mzLib/Readers/Thermo/ThermoRawFileReader.cs index 7686a2e30..0c5d42e4b 100644 --- a/mzLib/Readers/Thermo/ThermoRawFileReader.cs +++ b/mzLib/Readers/Thermo/ThermoRawFileReader.cs @@ -1,12 +1,9 @@ -using MassSpectrometry; +using Easy.Common.Extensions; +using MassSpectrometry; using MzLibUtil; -using System; using System.Collections.Concurrent; using System.Globalization; -using System.IO; -using System.Linq; using System.Security.Cryptography; -using System.Threading.Tasks; using ThermoFisher.CommonCore.Data.Business; using ThermoFisher.CommonCore.Data.FilterEnums; using ThermoFisher.CommonCore.Data.Interfaces; @@ -27,8 +24,6 @@ public class ThermoRawFileReaderLicence : Readers.ThermoRawFileReaderLicence } } - - // This .cs file uses: // RawFileReader reading tool. Copyright © 2016 by Thermo Fisher Scientific, Inc. All rights reserved. // See the full Software Licence Agreement for detailed requirements for use. @@ -38,6 +33,8 @@ namespace Readers // but the actual implementation details should be completely hidden. public class ThermoRawFileReader : MsDataFile { + private IRawDataPlus? dynamicConnection; + private int[] MsOrdersByScan; public ThermoRawFileReader(string path) : base(path) { } public override MsDataFile LoadAllStaticData(FilteringParams filteringParams = null, int maxThreads = 1) @@ -52,49 +49,51 @@ public override MsDataFile LoadAllStaticData(FilteringParams filteringParams = n // I don't know why this line needs to be here, but it does... var temp = RawFileReaderAdapter.FileFactory(FilePath); - var threadManager = RawFileReaderFactory.CreateThreadManager(FilePath); - var rawFileAccessor = threadManager.CreateThreadAccessor(); - - if (!rawFileAccessor.IsOpen) + using (var threadManager = RawFileReaderFactory.CreateThreadManager(FilePath)) { - throw new MzLibException("Unable to access RAW file!"); - } + var rawFileAccessor = threadManager.CreateThreadAccessor(); - if (rawFileAccessor.IsError) - { - throw new MzLibException("Error opening RAW file!"); - } + if (rawFileAccessor.IsError) + { + throw new MzLibException("Error opening RAW file!"); + } - if (rawFileAccessor.InAcquisition) - { - throw new MzLibException("RAW file still being acquired!"); - } + if (!rawFileAccessor.IsOpen) + { + throw new MzLibException("Unable to access RAW file!"); + } - rawFileAccessor.SelectInstrument(Device.MS, 1); - var msDataScans = new MsDataScan[rawFileAccessor.RunHeaderEx.LastSpectrum]; + if (rawFileAccessor.InAcquisition) + { + throw new MzLibException("RAW file still being acquired!"); + } - Parallel.ForEach(Partitioner.Create(0, msDataScans.Length), new ParallelOptions { MaxDegreeOfParallelism = maxThreads }, (fff, loopState) => - { - IRawDataPlus myThreadDataReader = threadManager.CreateThreadAccessor(); - myThreadDataReader.SelectInstrument(Device.MS, 1); + rawFileAccessor.SelectInstrument(Device.MS, 1); + var msDataScans = new MsDataScan[rawFileAccessor.RunHeaderEx.LastSpectrum]; - for (int s = fff.Item1; s < fff.Item2; s++) - { - try - { - var scan = GetOneBasedScan(myThreadDataReader, filteringParams, s + 1); - msDataScans[s] = scan; - } - catch (Exception ex) + Parallel.ForEach(Partitioner.Create(0, msDataScans.Length), + new ParallelOptions { MaxDegreeOfParallelism = maxThreads }, (fff, loopState) => { - throw new MzLibException("Error reading scan " + (s + 1) + ": " + ex.Message); - } - } - }); + using (var myThreadDataReader = threadManager.CreateThreadAccessor()) + { + myThreadDataReader.SelectInstrument(Device.MS, 1); + + for (int s = fff.Item1; s < fff.Item2; s++) + { + var scan = GetOneBasedScan(myThreadDataReader, filteringParams, s + 1); + msDataScans[s] = scan; + } + } + }); + + + rawFileAccessor.Dispose(); + Scans = msDataScans; + SourceFile = GetSourceFile(); + } + + temp.Dispose(); - rawFileAccessor.Dispose(); - Scans = msDataScans; - SourceFile = GetSourceFile(); return this; } @@ -116,6 +115,7 @@ public override SourceFile GetSourceFile() @"SHA-1", FilePath, Path.GetFileNameWithoutExtension(FilePath)); + return sourceFile; } @@ -156,6 +156,7 @@ public override void InitiateDynamicConnection() } dynamicConnection.SelectInstrument(Device.MS, 1); + GetMsOrdersByScanInDynamicConnection(); } @@ -165,12 +166,16 @@ public override void InitiateDynamicConnection() /// public override MsDataScan GetOneBasedScanFromDynamicConnection(int oneBasedScanNumber, IFilteringParams filterParams = null) { + dynamicConnection = RawFileReaderAdapter.FileFactory(FilePath); + dynamicConnection.SelectInstrument(Device.MS, 1); + if (dynamicConnection == null) { throw new MzLibException("The dynamic connection has not been created yet!"); } - if (oneBasedScanNumber > dynamicConnection.RunHeaderEx.LastSpectrum || oneBasedScanNumber < dynamicConnection.RunHeaderEx.FirstSpectrum) + if (oneBasedScanNumber > dynamicConnection.RunHeaderEx.LastSpectrum || + oneBasedScanNumber < dynamicConnection.RunHeaderEx.FirstSpectrum) { return null; } @@ -191,8 +196,10 @@ public override void CloseDynamicConnection() public override int[] GetMsOrderByScanInDynamicConnection() { + if (dynamicConnection != null) { + int lastSpectrum = dynamicConnection.RunHeaderEx.LastSpectrum; var scanEvents = dynamicConnection.GetScanEvents(1, lastSpectrum); @@ -212,13 +219,18 @@ public override int[] GetMsOrderByScanInDynamicConnection() /// /// public static MsDataFile LoadAllStaticData(string filePath, FilteringParams filteringParams = null, - int maxThreads = 1) => MsDataFileReader.GetDataFile(filePath).LoadAllStaticData(filteringParams, maxThreads); + int maxThreads = 1) + { + return MsDataFileReader.GetDataFile(filePath).LoadAllStaticData(filteringParams, maxThreads); + } - private static MsDataScan GetOneBasedScan(IRawDataPlus rawFile, IFilteringParams filteringParams, int scanNumber) + private static MsDataScan GetOneBasedScan(IRawDataPlus rawFile, IFilteringParams filteringParams, + int scanNumber) { var filter = rawFile.GetFilterForScanNumber(scanNumber); string scanFilterString = filter.ToString(); + int msOrder = (int)filter.MSOrder; if (msOrder < 1 || msOrder > 10) { @@ -267,18 +279,21 @@ private static MsDataScan GetOneBasedScan(IRawDataPlus rawFile, IFilteringParams (double?)null : double.Parse(values[i], CultureInfo.InvariantCulture); } + if (labels[i].StartsWith("Monoisotopic M/Z", StringComparison.Ordinal)) { precursorSelectedMonoisotopicIonMz = double.Parse(values[i], CultureInfo.InvariantCulture) == 0 ? (double?)null : double.Parse(values[i], CultureInfo.InvariantCulture); } + if (labels[i].StartsWith("Charge State", StringComparison.Ordinal)) { selectedIonChargeState = int.Parse(values[i], CultureInfo.InvariantCulture) == 0 ? (int?)null : int.Parse(values[i], CultureInfo.InvariantCulture); } + if (labels[i].StartsWith("Master Scan Number", StringComparison.Ordinal) || labels[i].StartsWith("Master Index", StringComparison.Ordinal)) { @@ -286,6 +301,7 @@ private static MsDataScan GetOneBasedScan(IRawDataPlus rawFile, IFilteringParams (int?)null : int.Parse(values[i], CultureInfo.InvariantCulture); } + if (labels[i].StartsWith("HCD Energy:", StringComparison.Ordinal)) { HcdEnergy = values[i]; @@ -384,7 +400,8 @@ private static MsDataScan GetOneBasedScan(IRawDataPlus rawFile, IFilteringParams hcdEnergy: HcdEnergy); } - private static MzSpectrum GetSpectrum(IRawDataPlus rawFile, IFilteringParams filterParams, int scanNumber, string scanFilter, int scanOrder) + private static MzSpectrum GetSpectrum(IRawDataPlus rawFile, IFilteringParams filterParams, + int scanNumber, string scanFilter, int scanOrder) { MzSpectrum spectrum; double[] xArray; @@ -401,6 +418,7 @@ private static MzSpectrum GetSpectrum(IRawDataPlus rawFile, IFilteringParams fil if (centroidStream.Masses == null || centroidStream.Intensities == null) { var scan = Scan.FromFile(rawFile, scanNumber); + var mzs = scan.PreferredMasses; xArray = scan.PreferredMasses; yArray = scan.PreferredIntensities; @@ -447,7 +465,7 @@ private static MzSpectrum GetSpectrum(IRawDataPlus rawFile, IFilteringParams fil double scanRangeLow = scanStats.LowMass; WindowModeHelper.Run(ref intensityArray, ref mzArray, filterParams, - scanRangeLow, scanRangeHigh); + scanRangeLow, scanRangeHigh); Array.Sort(mzArray, intensityArray); spectrum = new MzSpectrum(mzArray, intensityArray, false); @@ -502,8 +520,6 @@ private static DissociationType GetDissociationType(ActivationType activationTyp } - private IRawDataPlus dynamicConnection; - private int[] MsOrdersByScan; /// /// Gets all the MS orders of all scans in a dynamic connection. This is useful if you want to open all MS1 scans @@ -511,6 +527,11 @@ private static DissociationType GetDissociationType(ActivationType activationTyp /// private int[] GetMsOrdersByScanInDynamicConnection() { + if (MsOrdersByScan.IsNotNullOrEmpty()) + { + return MsOrdersByScan; + } + if (dynamicConnection != null) { int lastSpectrum = dynamicConnection.RunHeaderEx.LastSpectrum; @@ -518,6 +539,8 @@ private int[] GetMsOrdersByScanInDynamicConnection() int[] msorders = scanEvents.Select(p => (int)p.MSOrder).ToArray(); + MsOrdersByScan = msorders; + return msorders; } diff --git a/mzLib/Test/AveragingTests/TestAveragingSpectraWriteFile.cs b/mzLib/Test/AveragingTests/TestAveragingSpectraWriteFile.cs index dd3cb6242..c1387e273 100644 --- a/mzLib/Test/AveragingTests/TestAveragingSpectraWriteFile.cs +++ b/mzLib/Test/AveragingTests/TestAveragingSpectraWriteFile.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Linq; -using MassSpectrometry; +using MassSpectrometry; using MzLibUtil; using NUnit.Framework; using Readers; using SpectralAveraging; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; namespace Test.AveragingTests { @@ -131,7 +131,7 @@ public static void TestOutputToCustomDirectoryAndNameMzML() files = Directory.GetFiles(customDestinationDirectory); Assert.That(files.Length == 2); Assert.That(files.Contains(Path.Combine(customDestinationDirectory, customName + ".mzML"))); - + // custom destination, custom name : directory not created before run AveragedSpectraWriter.WriteAveragedScans(DdaCompositeSpectra, Parameters, SpectraPath, customDestinationDirectory2, customName); @@ -148,7 +148,7 @@ public static void TestOutputToCustomDirectoryAndNameMzML() Directory.Delete(customDestinationDirectory2, true); } - + } } diff --git a/mzLib/Test/DatabaseTests/TestDatabaseLoaders.cs b/mzLib/Test/DatabaseTests/TestDatabaseLoaders.cs index 586aecd52..c9fd100dc 100644 --- a/mzLib/Test/DatabaseTests/TestDatabaseLoaders.cs +++ b/mzLib/Test/DatabaseTests/TestDatabaseLoaders.cs @@ -15,15 +15,15 @@ // You should have received a copy of the GNU Lesser General Public // License along with Chemistry Library. If not, see -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; using Chemistry; using MassSpectrometry; using MzLibUtil; using NUnit.Framework; using Proteomics; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; using UsefulProteomicsDatabases; using Stopwatch = System.Diagnostics.Stopwatch; @@ -51,8 +51,8 @@ public static void TearDown() [Test] public static void LoadIsoforms() { - var protein = ProteinDbLoader.LoadProteinFasta(Path.Combine(TestContext.CurrentContext.TestDirectory, "DatabaseTests", "Isoform.fasta"), true, DecoyType.None, - false, out var errors, ProteinDbLoader.UniprotAccessionRegex, ProteinDbLoader.UniprotFullNameRegex, ProteinDbLoader.UniprotNameRegex, ProteinDbLoader.UniprotGeneNameRegex, + var protein = ProteinDbLoader.LoadProteinFasta(Path.Combine(TestContext.CurrentContext.TestDirectory, "DatabaseTests", "Isoform.fasta"), true, DecoyType.None, + false, out var errors, ProteinDbLoader.UniprotAccessionRegex, ProteinDbLoader.UniprotFullNameRegex, ProteinDbLoader.UniprotNameRegex, ProteinDbLoader.UniprotGeneNameRegex, ProteinDbLoader.UniprotOrganismRegex); Assert.AreEqual("Q13409", protein[0].Accession); Assert.AreEqual("Q13409-2", protein[1].Accession); @@ -144,7 +144,7 @@ public void TestUpdatePsiModObo() string expected = "psi-mod.obo database is up to date, doing nothing\r\n"; Assert.AreEqual(expected, sw.ToString()); - sw.Close (); + sw.Close(); } //create and empty obo that will be seen as different from the downloaded file and then be updated. @@ -220,18 +220,18 @@ public void TestPsiModLoading() // N6,N6,N6-trimethyllysine var trimethylLysine = psiMods.First(b => b.Id.Equals("MOD:00083")); - Assert.AreEqual("1+", + Assert.AreEqual("1+", trimethylLysine.ValuePairs .First(b => b.Value.Contains("FormalCharge")).GetFormalChargeString()); // Phosphoserine bool resultBool = psiMods.First(b => b.Id.Equals("MOD:00046")) - .ValuePairs.Any(i => i.Value.Contains("FormalCharge")); + .ValuePairs.Any(i => i.Value.Contains("FormalCharge")); Assert.IsFalse(resultBool); // ensure that there are negative numbers in the formal charges Dictionary formalChargesDictionary = Loaders.GetFormalChargesDictionary(psiMods); - bool anyNegativeValue = formalChargesDictionary.Values.Any(i => i < 0); + bool anyNegativeValue = formalChargesDictionary.Values.Any(i => i < 0); Assert.IsTrue(anyNegativeValue); } @@ -744,7 +744,7 @@ public static void TestDifferentHeaderStyles() Assert.That(targetProtein.FullName == "Apoptosis-inducing factor 1, mitochondrial"); Assert.That(targetProtein.Name == "AIFM1_MOUSE"); Assert.That(targetProtein.Organism == "Mus musculus"); - + // gencode database fastaFile = Path.Combine(TestContext.CurrentContext.TestDirectory, "DatabaseTests", "gencode_mmp20.fa"); proteins = ProteinDbLoader.LoadProteinFasta(fastaFile, true, DecoyType.Reverse, false, out errors); diff --git a/mzLib/Test/FileReadingTests/TestFileConnection.cs b/mzLib/Test/FileReadingTests/TestFileConnection.cs new file mode 100644 index 000000000..079b521d7 --- /dev/null +++ b/mzLib/Test/FileReadingTests/TestFileConnection.cs @@ -0,0 +1,37 @@ +using MassSpectrometry; +using NUnit.Framework; +using Readers; +using System.Collections.Generic; +using System.IO; +using Path = System.IO.Path; + +namespace Test.FileReadingTests +{ + [TestFixture] + public sealed class TestReaderConnection + { + [Test] + [TestCase(@"DataFiles/sliced_ethcd.mzML", "sliced_ethcd.mzML")] + [TestCase(@"DataFiles/sliced_ethcd.raw", "sliced_ethcd.raw")] + [TestCase(@"DataFiles/small.RAW", "small.RAW")] + [TestCase(@"DataFiles/SmallCalibratibleYeast.mzml", "SmallCalibratibleYeast.mzml")] + public static void TestReaderClosesConnection(string filePath, string fileName) + { + string spectraPath = Path.Combine(TestContext.CurrentContext.TestDirectory, filePath); + MsDataFile datafile = MsDataFileReader.GetDataFile(spectraPath); + + List scans = datafile.GetAllScansList(); + + string movingDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, + "FileReadingTests/MoveHere"); + + Directory.CreateDirectory(movingDirectory); + + File.Copy(spectraPath, movingDirectory + '/' + fileName); + + Directory.Delete(movingDirectory, true); + + Assert.Pass(); + } + } +} diff --git a/mzLib/Test/FileReadingTests/TestRawFileReader.cs b/mzLib/Test/FileReadingTests/TestRawFileReader.cs index 222179e7b..630431e59 100644 --- a/mzLib/Test/FileReadingTests/TestRawFileReader.cs +++ b/mzLib/Test/FileReadingTests/TestRawFileReader.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using MassSpectrometry; +using MzLibUtil; using NUnit.Framework; using Readers; @@ -23,6 +24,22 @@ public void TestFileDoesntExist() reader.InitiateDynamicConnection(); }); } + + #region Testing Exceptions + + [Test] + public void TestRawFileReaderFileNotFoundException() + { + var fakeRawFile = "asdasd.raw"; + + var ex = Assert.Throws(() => MsDataFileReader.GetDataFile(fakeRawFile).LoadAllStaticData()); + + Assert.That(ex.Message, Is.EqualTo(new FileNotFoundException().Message)); + } + + #endregion + + /// /// Tests LoadAllStaticData for ThermoRawFileReader /// diff --git a/mzLib/UsefulProteomicsDatabases/ProteinDbLoader.cs b/mzLib/UsefulProteomicsDatabases/ProteinDbLoader.cs index c3e79f8d4..b9af8edb2 100644 --- a/mzLib/UsefulProteomicsDatabases/ProteinDbLoader.cs +++ b/mzLib/UsefulProteomicsDatabases/ProteinDbLoader.cs @@ -110,10 +110,9 @@ public static List LoadProteinXML(string proteinDbLocation, bool genera targets.Add(newProtein); } } + } - } - } if (newProteinDbLocation != proteinDbLocation)