Skip to content

Commit

Permalink
fix of the possible null reference error in the metadata creator
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Jan 20, 2023
1 parent e909bff commit 971c3b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/assembly/Comprehensive/MsImaging/Metadata.vb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ Namespace MsImaging

<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Function GetMetadata() As Dictionary(Of String, String)
Return New Dictionary(Of String, String) From {
Dim datalist As New Dictionary(Of String, String) From {
{"width", scan_x},
{"height", scan_y},
{"resolution", resolution},
{"mzmin", mass_range.Min},
{"mzmax", mass_range.Max}
{"resolution", resolution}
}

If Not mass_range Is Nothing Then
datalist!mzmin = mass_range.Min
datalist!mzmax = mass_range.Max
End If

Return datalist
End Function

End Class
Expand Down
11 changes: 11 additions & 0 deletions src/assembly/Comprehensive/MsImaging/MsImagingRaw.vb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Imports BioNovoGene.Analytical.MassSpectrometry.Assembly.mzData.mzWebCache
Imports BioNovoGene.Analytical.MassSpectrometry.Math.Spectra
Imports Microsoft.VisualBasic.CommandLine.InteropService.Pipeline
Imports Microsoft.VisualBasic.ComponentModel.Ranges.Model
Imports Microsoft.VisualBasic.DataStorage.netCDF.Components
Imports Microsoft.VisualBasic.Imaging.Math2D
Imports Microsoft.VisualBasic.Language
Imports Microsoft.VisualBasic.Linq
Expand Down Expand Up @@ -131,6 +132,9 @@ Namespace MsImaging
Dim pixels As New List(Of ScanMS1)
Dim cutoff As New RelativeIntensityCutoff(intocutoff)
Dim metadata As New Metadata
Dim mzmin As New List(Of Double)
Dim mzmax As New List(Of Double)
Dim mzvals As Double()

If progress Is Nothing Then
progress = Sub(msg)
Expand All @@ -141,12 +145,19 @@ Namespace MsImaging
' each row is a small sample in current sample batch
For Each row As mzPack In src
pixels += row.MeasureRow(yscale, correction, cutoff, sumNorm, labelPrefix, progress)
mzvals = row.MS.Select(Function(a) a.mz).IteratesALL.ToArray

If mzvals.Length > 0 Then
mzmin.Add(mzvals.Min)
mzmax.Add(mzvals.Max)
End If
Next

Dim polygon As New Polygon2D(pixels.Select(Function(scan) scan.GetMSIPixel))

metadata.scan_x = polygon.xpoints.Max
metadata.scan_y = polygon.ypoints.Max
metadata.mass_range = New DoubleRange(mzmin.Min, mzmax.Max)

Return New mzPack With {
.MS = pixels.ToArray,
Expand Down
2 changes: 1 addition & 1 deletion src/mzkit
Submodule mzkit updated from 4a5519 to 64e1b0

0 comments on commit 971c3b9

Please sign in to comment.