Skip to content

Commit

Permalink
aggregate_sum in centroid function
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Jan 9, 2024
1 parent 7c94c29 commit 42c1f86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Rscript/Library/mzkit_app/src/mzkit/math/Math.vb
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ Module MzMath
Optional tolerance As Object = "da:0.1",
Optional intoCutoff As Double = 0.05,
Optional parallel As Boolean = False,
Optional aggregate_sum As Boolean = False,
Optional env As Environment = Nothing) As Object

Dim inputType As Type = ions.GetType
Expand Down Expand Up @@ -736,7 +737,7 @@ Module MzMath

Return ms2
ElseIf inputType Is GetType(dataframe) Then
Return DirectCast(ions, dataframe).centroidDataframe(errors, threshold, env)
Return DirectCast(ions, dataframe).centroidDataframe(errors, threshold, aggregate_sum, env)
ElseIf inputType Is GetType(ScanMS1) Then
Dim scan1 As ScanMS1 = DirectCast(ions, ScanMS1)
Dim msdata As ms2() = scan1 _
Expand Down Expand Up @@ -764,6 +765,7 @@ Module MzMath
Private Function centroidDataframe(msdata As dataframe,
errors As Tolerance,
threshold As LowAbundanceTrimming,
aggregate_sum As Boolean,
env As Environment) As Object

Dim mz As Double() = CLRVector.asNumeric(msdata.getBySynonym("mz", "m/z", "MZ"))
Expand All @@ -790,7 +792,7 @@ Module MzMath
.ToArray
}

Return ms2.CentroidMode(errors, threshold)
Return ms2.CentroidMode(errors, threshold, sum:=aggregate_sum)
End Function

''' <summary>
Expand Down
14 changes: 12 additions & 2 deletions src/mzmath/ms2_math-core/Spectra/LibraryMatrixExtensions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,19 @@ Namespace Spectra
<Extension>
Public Function CentroidMode([lib] As LibraryMatrix,
tolerance As Tolerance,
Optional cutoff As LowAbundanceTrimming = Nothing) As LibraryMatrix
Optional cutoff As LowAbundanceTrimming = Nothing,
Optional sum As Boolean = False) As LibraryMatrix

If sum Then
[lib].ms2 = [lib].ms2 _
.CentroidSum(tolerance, cutoff Or LowAbundanceTrimming.Default) _
.ToArray
Else
[lib].ms2 = [lib].ms2 _
.Centroid(tolerance, cutoff Or LowAbundanceTrimming.Default) _
.ToArray
End If

[lib].ms2 = [lib].ms2.Centroid(tolerance, cutoff Or LowAbundanceTrimming.Default).ToArray
[lib].centroid = True

Return [lib]
Expand Down

0 comments on commit 42c1f86

Please sign in to comment.