Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/xieguigang/mzkit
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Nov 11, 2024
2 parents a5e5ed9 + 81a4069 commit 90f3f05
Show file tree
Hide file tree
Showing 1,220 changed files with 4,659 additions and 4,430 deletions.
44 changes: 44 additions & 0 deletions Rscript/Library/mzkit_app/man/mzkit/math/math/cosine.1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,50 @@ Do evaluate the spectra cosine similarity score
.PP
\fBenv\fB \fR\- -.
.PP
.SH DETAILS
.PP
this function andalso produce the jaccard/entropy similarity of the spectrum inside the similarity result object
.PP
.SH EXAMPLES
.PP
# create the spectrum matrix object
# fragment data tagged with the source name title
let spec1 = libraryMatrix(
matrix = data.frame(
mz = c(169.071, 186.066, 186.0769),
intensity = c(7.917962, 1.021589, 100.0)
),
title = "Demo MS1 Spectra",
centroid = TRUE
);
let spec2 = libraryMatrix(
matrix = data.frame(
mz = c(120.212, 169.071, 186.066),
intensity = c(37.16, 66.83, 999.0)
),
title = "Demo MS1 Spectra",
centroid = TRUE
);
let compares = math::cosine(spec1, spec2);
let scores = as.data.frame(compares, scores_df = TRUE);

print(scores);
# dimension scores
# ----------------------------------
# <mode> <string> <double>
# [1, ] "forward cosine" 0.999925
# [2, ] "reverse cosine" 0.999925
# [3, ] "cosine" 0.999925
# [4, ] "jaccard" 1
# [5, ] "entropy" 0.999949
# [6, ] "mirror" 1
# [7, ] "mean" 0.99995
# [8, ] "fragment hits" 2

svg(file = "figures/00_Mass_spectrometry/Math/03_compares.svg") {
plot(compares);
}
.PP
.SH SEE ALSO
math
.SH FILES
Expand Down
1 change: 1 addition & 0 deletions Rscript/Library/mzkit_app/src/mzDIA/mzDIA.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<ProjectReference Include="../../..\..\..\src\visualize\KCF\KCF.IO\KCF_IO.NET5.vbproj" />
<ProjectReference Include="../../..\..\..\src\visualize\MsImaging\MsImaging.NET5.vbproj" />
<ProjectReference Include="..\..\..\..\..\..\GCModeller\src\R-sharp\Library\shares\graphics.common_runtime\R_graphics.common_runtime.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\assembly\mzPack\mzpack.NET5.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\metadb\FormulaSearch.Extensions\FormulaSearch.Extensions.NET5.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\metadb\Massbank\massbank.NET5.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\metadb\SMILES\SMILES.NET5.vbproj" />
Expand Down
10 changes: 5 additions & 5 deletions Rscript/Library/mzkit_app/src/mzkit/comprehensive/GCxGC.vb
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ Module GCxGC
''' </param>
''' <returns></returns>
<ExportAPI("TIC2D")>
<RApiReturn(GetType(D2Chromatogram))>
<RApiReturn(GetType(Chromatogram2DScan))>
Public Function TIC2D(TIC As ChromatogramTick(), modtime As Double) As Object
Return TIC.Demodulate2D(modtime)
End Function

<ExportAPI("TIC1D")>
Public Function TIC1D(matrix As D2Chromatogram()) As ChromatogramTick()
Public Function TIC1D(matrix As Chromatogram2DScan()) As ChromatogramTick()
Return matrix _
.Select(Function(i)
Return New ChromatogramTick With {
Expand Down Expand Up @@ -181,7 +181,7 @@ Module GCxGC
''' this function will extract the TIC data by default.
''' </remarks>
<ExportAPI("extract_xic_layer")>
<RApiReturn(GetType(D2Chromatogram))>
<RApiReturn(GetType(Chromatogram2DScan))>
Public Function create2DPeaks(raw As mzPack,
Optional mz As Double = Double.NaN,
Optional mzdiff As Object = "ppm:30",
Expand All @@ -195,7 +195,7 @@ Module GCxGC
End If

Dim test As Tolerance = mzErr.TryCast(Of Tolerance)
Dim extract As Func(Of ScanMS1, D2Chromatogram)
Dim extract As Func(Of ScanMS1, Chromatogram2DScan)

If extract_XIC Then
extract = ExtractXIC(mz, mzdiff:=test)
Expand Down Expand Up @@ -251,7 +251,7 @@ Module GCxGC
''' <returns></returns>
<ExportAPI("save.cdf")>
<RApiReturn(TypeCodes.boolean)>
Public Function saveCDF(TIC As D2Chromatogram(), <RRawVectorArgument> file As Object, Optional env As Environment = Nothing) As Object
Public Function saveCDF(TIC As Chromatogram2DScan(), <RRawVectorArgument> file As Object, Optional env As Environment = Nothing) As Object
Dim filestream As [Variant](Of Stream, Message) = SMRUCC.Rsharp.GetFileStream(file, FileAccess.Write, env)

If filestream Like GetType(Message) Then
Expand Down
93 changes: 81 additions & 12 deletions Rscript/Library/mzkit_app/src/mzkit/math/Math.vb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ Imports SMRUCC.Rsharp.Runtime.Internal.Object
Imports SMRUCC.Rsharp.Runtime.Interop
Imports SMRUCC.Rsharp.Runtime.Vectorization
Imports REnv = SMRUCC.Rsharp.Runtime
Imports RInternal = SMRUCC.Rsharp.Runtime.Internal
Imports std = System.Math
Imports stdVector = Microsoft.VisualBasic.Math.LinearAlgebra.Vector
Imports RInternal = SMRUCC.Rsharp.Runtime.Internal

''' <summary>
''' mass spectrometry data math toolkit
Expand Down Expand Up @@ -206,19 +206,46 @@ Module MzMath
''' <returns></returns>
<RGenericOverloads("as.data.frame")>
Private Function getAlignmentTable(align As AlignmentOutput, args As list, env As Environment) As dataframe
Dim mz As Double() = align.alignments.Select(Function(a) a.mz).ToArray
Dim query As Double() = align.alignments.Select(Function(a) a.query).ToArray
Dim reference As Double() = align.alignments.Select(Function(a) a.ref).ToArray
Dim da As String() = align.alignments.Select(Function(a) a.da).ToArray
Dim scores_df As Boolean = args.getValue("scores_df", env, [default]:=False)

Return New dataframe With {
.columns = New Dictionary(Of String, Array) From {
{"m/z", mz},
{"query", query},
{"ref", reference},
{"da", da}
If scores_df Then
Dim df As New dataframe With {
.columns = New Dictionary(Of String, Array)
}
}

Call df.add("dimension", {
"forward cosine", "reverse cosine",
"cosine",
"jaccard",
"entropy",
"mirror",
"mean",
"fragment hits"})
Call df.add("scores", {
align.forward, align.reverse,
align.cosine,
align.jaccard,
align.entropy,
align.mirror,
align.mean,
align.nhits})

Return df
Else
Dim mz As Double() = align.alignments.Select(Function(a) a.mz).ToArray
Dim query As Double() = align.alignments.Select(Function(a) a.query).ToArray
Dim reference As Double() = align.alignments.Select(Function(a) a.ref).ToArray
Dim da As String() = align.alignments.Select(Function(a) a.da).ToArray

Return New dataframe With {
.columns = New Dictionary(Of String, Array) From {
{"m/z", mz},
{"query", query},
{"ref", reference},
{"da", da}
}
}
End If
End Function

Private Function printCalculator(type As MzCalculator) As String
Expand Down Expand Up @@ -620,6 +647,48 @@ Module MzMath
''' <param name="intocutoff"></param>
''' <param name="env"></param>
''' <returns></returns>
''' <remarks>
''' this function andalso produce the jaccard/entropy similarity of the spectrum inside the similarity result object
''' </remarks>
''' <example>
''' # create the spectrum matrix object
''' # fragment data tagged with the source name title
''' let spec1 = libraryMatrix(
''' matrix = data.frame(
''' mz = c(169.071, 186.066, 186.0769),
''' intensity = c(7.917962, 1.021589, 100.0)
''' ),
''' title = "Demo MS1 Spectra",
''' centroid = TRUE
''' );
''' let spec2 = libraryMatrix(
''' matrix = data.frame(
''' mz = c(120.212, 169.071, 186.066),
''' intensity = c(37.16, 66.83, 999.0)
''' ),
''' title = "Demo MS1 Spectra",
''' centroid = TRUE
''' );
''' let compares = math::cosine(spec1, spec2);
''' let scores = as.data.frame(compares, scores_df = TRUE);
'''
''' print(scores);
''' # dimension scores
''' # ----------------------------------
''' # &lt;mode> &lt;string> &lt;double>
''' # [1, ] "forward cosine" 0.999925
''' # [2, ] "reverse cosine" 0.999925
''' # [3, ] "cosine" 0.999925
''' # [4, ] "jaccard" 1
''' # [5, ] "entropy" 0.999949
''' # [6, ] "mirror" 1
''' # [7, ] "mean" 0.99995
''' # [8, ] "fragment hits" 2
'''
''' svg(file = "figures/00_Mass_spectrometry/Math/03_compares.svg") {
''' plot(compares);
''' }
''' </example>
<ExportAPI("cosine")>
<RApiReturn(GetType(AlignmentOutput))>
Public Function cosine(<RRawVectorArgument> query As Object, ref As Object,
Expand Down
1 change: 1 addition & 0 deletions Rscript/Library/mzkit_app/src/mzkit/mzkit.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@
<ProjectReference Include="..\..\..\..\..\src\metadb\SMILES\SMILES.NET5.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\metadb\XrefEngine\XrefEngine.NET5.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\metadna\metaDNA\metaDNA.NET5.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\mzmath\GCxGC\GCxGC.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\mzmath\MoleculeNetworking\MoleculeNetworking.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\mzmath\ms2_math-core\mzmath-netcore5.vbproj" />
<ProjectReference Include="..\..\..\..\..\src\mzmath\MSEngine\MSEngine.vbproj" />
Expand Down
Loading

0 comments on commit 90f3f05

Please sign in to comment.