Skip to content

Commit

Permalink
Tims tof reader (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Sol authored Jan 19, 2025
1 parent 98ea879 commit e33a478
Show file tree
Hide file tree
Showing 27 changed files with 2,081 additions and 30 deletions.
32 changes: 26 additions & 6 deletions mzLib/MassSpectrometry/MsDataScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,29 @@ namespace MassSpectrometry
{
public class MsDataScan
{
public MsDataScan(MzSpectrum massSpectrum, int oneBasedScanNumber, int msnOrder, bool isCentroid, Polarity polarity, double retentionTime, MzRange scanWindowRange, string scanFilter, MZAnalyzerType mzAnalyzer,
double totalIonCurrent, double? injectionTime, double[,] noiseData, string nativeId, double? selectedIonMz = null, int? selectedIonChargeStateGuess = null, double? selectedIonIntensity = null, double? isolationMZ = null,
double? isolationWidth = null, DissociationType? dissociationType = null, int? oneBasedPrecursorScanNumber = null, double? selectedIonMonoisotopicGuessMz = null, string hcdEnergy = null, string scanDescription = null)
public MsDataScan(MzSpectrum massSpectrum,
int oneBasedScanNumber,
int msnOrder,
bool isCentroid,
Polarity polarity,
double retentionTime,
MzRange scanWindowRange,
string scanFilter,
MZAnalyzerType mzAnalyzer,
double totalIonCurrent,
double? injectionTime,
double[,] noiseData,
string nativeId,
double? selectedIonMz = null,
int? selectedIonChargeStateGuess = null,
double? selectedIonIntensity = null,
double? isolationMZ = null,
double? isolationWidth = null,
DissociationType? dissociationType = null,
int? oneBasedPrecursorScanNumber = null,
double? selectedIonMonoisotopicGuessMz = null,
string hcdEnergy = null,
string scanDescription = null)
{
OneBasedScanNumber = oneBasedScanNumber;
MsnOrder = msnOrder;
Expand Down Expand Up @@ -61,7 +81,7 @@ public MsDataScan(MzSpectrum massSpectrum, int oneBasedScanNumber, int msnOrder,
/// </summary>
public MzSpectrum MassSpectrum { get; protected set; }

public int OneBasedScanNumber { get; private set; }
public int OneBasedScanNumber { get; protected set; }
public int MsnOrder { get; }
public double RetentionTime { get; }
public Polarity Polarity { get; }
Expand All @@ -70,7 +90,7 @@ public MsDataScan(MzSpectrum massSpectrum, int oneBasedScanNumber, int msnOrder,
public string ScanFilter { get; }
public string NativeId { get; private set; }
public bool IsCentroid { get; }
public double TotalIonCurrent { get; }
public double TotalIonCurrent { get; protected set; }
public double? InjectionTime { get; }
public double[,] NoiseData { get; }

Expand All @@ -82,7 +102,7 @@ public MsDataScan(MzSpectrum massSpectrum, int oneBasedScanNumber, int msnOrder,
public double? SelectedIonMZ { get; private set; } // May be adjusted by calibration
public DissociationType? DissociationType { get; }
public double? IsolationWidth { get; }
public int? OneBasedPrecursorScanNumber { get; private set; }
public int? OneBasedPrecursorScanNumber { get; protected set; }
public double? SelectedIonMonoisotopicGuessIntensity { get; private set; } // May be refined
public double? SelectedIonMonoisotopicGuessMz { get; private set; } // May be refined
public string HcdEnergy { get; private set; }
Expand Down
12 changes: 12 additions & 0 deletions mzLib/MzLibUtil/ClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public static T[] SubArray<T>(this T[] data, int index, int length)
return result;
}

public static bool ToEnum<T>(this int modeInt, out T result) where T : Enum
{
Type enumType = typeof(T);
if (!Enum.IsDefined(enumType, modeInt))
{
result = default(T);
return false;
}
result = (T)Enum.ToObject(enumType, modeInt);
return true;
}

/// <summary>
/// Checks if two collections are equivalent, regardless of the order of their contents
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion mzLib/MzLibUtil/MzLibUtil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CsvHelper" Version="32.0.3" />
<PackageReference Include="Easy.Common" Version="6.7.0" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="9.0.0" />
Expand Down
4 changes: 2 additions & 2 deletions mzLib/Readers/Bruker/BrukerFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private List<StepsRow> GetFullStepsTable()
/// <param name="reader">SQLiteReader object, initialized after the execution of a command.</param>
/// <returns>Return null exception if there is an error in the data format of the baf file.</returns>
/// <exception cref="ArgumentNullException"></exception>
private T SqlColumnReader<T>(SQLiteDataReader reader) where T: new()
public static T SqlColumnReader<T>(SQLiteDataReader reader) where T: new()
{
// get all the property names, then iterate over that.
// The objects should be exact 1:1 column corresponding so as
Expand Down Expand Up @@ -516,7 +516,7 @@ private static void ThrowLastBaf2SqlError()
}

/* ----------------------------------------------------------------------------------------------- */
private static byte[] ConvertStringToUTF8ByteArray(String input)
public static byte[] ConvertStringToUTF8ByteArray(String input)
{
byte[] utf8 = Encoding.UTF8.GetBytes(input);
var result = new byte[utf8.Length + 1];
Expand Down
1 change: 1 addition & 0 deletions mzLib/Readers/MsDataFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static MsDataFile GetDataFile(string filePath)
SupportedFileType.MzML => new Mzml(filePath),
SupportedFileType.Mgf => new Mgf(filePath),
SupportedFileType.BrukerD => new BrukerFileReader(filePath),
SupportedFileType.BrukerTimsTof => new TimsTofFileReader(filePath),
_ => throw new MzLibException("File type not supported"),
};
}
Expand Down
17 changes: 15 additions & 2 deletions mzLib/Readers/Readers.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Platforms>x64</Platforms>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CsvHelper" Version="32.0.3" />
<PackageReference Include="OpenMcdf" Version="2.3.1" />
<PackageReference Include="OpenMcdf.Extensions" Version="2.3.1" />
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -21,7 +23,6 @@
</ItemGroup>

<ItemGroup>

<Reference Include="ThermoFisher.CommonCore.BackgroundSubtraction">
<HintPath>Thermo\ThermoFisher.CommonCore.BackgroundSubtraction.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -70,6 +71,18 @@
<None Update="Thermo\ThermoFisher.CommonCore.RawFileReader.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="timsdata.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="timsdata.lib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="timsTOF\baf2sql_c.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="timsTOF\baf2sql_c.lib">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
2 changes: 0 additions & 2 deletions mzLib/Readers/Thermo/ThermoRawFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,6 @@ private static DissociationType GetDissociationType(ActivationType activationTyp
}
}



/// <summary>
/// Gets all the MS orders of all scans in a dynamic connection. This is useful if you want to open all MS1 scans
/// without loading all of the other MSn scans.
Expand Down
15 changes: 12 additions & 3 deletions mzLib/Readers/Util/SupportedFileTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public enum SupportedFileType
ThermoRaw,
MzML,
Mgf,
BrukerD,
psmtsv,
//osmtsv
ToppicPrsm,
Expand All @@ -27,7 +26,9 @@ public enum SupportedFileType
MsPathFinderTDecoys,
MsPathFinderTAllResults,
CruxResult,
ExperimentAnnotation
ExperimentAnnotation,
BrukerD,
BrukerTimsTof
}

public static class SupportedFileTypeExtensions
Expand All @@ -51,6 +52,7 @@ public static string GetFileExtension(this SupportedFileType type)
SupportedFileType.MzML => ".mzML",
SupportedFileType.Mgf => ".mgf",
SupportedFileType.BrukerD => ".d",
SupportedFileType.BrukerTimsTof => ".d",
SupportedFileType.psmtsv => ".psmtsv",
//SupportedFileType.osmtsv => ".osmtsv",
SupportedFileType.ToppicPrsm => "_prsm.tsv",
Expand All @@ -76,7 +78,14 @@ public static SupportedFileType ParseFileType(this string filePath)
case ".raw": return SupportedFileType.ThermoRaw;
case ".mzml": return SupportedFileType.MzML;
case ".mgf": return SupportedFileType.Mgf;
case ".d": return SupportedFileType.BrukerD;
case ".d":
if(!Directory.Exists(filePath)) throw new FileNotFoundException();
var fileList = Directory.GetFiles(filePath).Select(p => Path.GetFileName(p));
if (fileList.Any(file => file == "analysis.baf"))
return SupportedFileType.BrukerD;
if (fileList.Any(file => file == "analysis.tdf"))
return SupportedFileType.BrukerTimsTof;
throw new MzLibException("Bruker file type not recognized");
case ".psmtsv": return SupportedFileType.psmtsv;
//case ".osmtsv": return SupportedFileType.osmtsv;
case ".feature":
Expand Down
Loading

0 comments on commit e33a478

Please sign in to comment.