Skip to content

Commit

Permalink
doc: replace mono part by dotnet
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanse committed Nov 3, 2024
1 parent 450c451 commit ed853d8
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 65 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ importFrom(stats,predict)
importFrom(tools,R_user_dir)
importFrom(utils,download.file)
importFrom(utils,head)
importFrom(utils,object.size)
importFrom(utils,packageVersion)
importFrom(utils,read.csv2)
importFrom(utils,read.table)
Expand Down
3 changes: 2 additions & 1 deletion R/benchmark.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#R

#' f <- "/Users/cp/Library/Caches/org.R-project.R/R/ExperimentHub/46314c3933e2_4590.raw"
#' @importFrom utils object.size
# f <- "/Users/cp/Library/Caches/org.R-project.R/R/ExperimentHub/46314c3933e2_4590.raw"
.benchmark <- function(f){
stopifnot(file.exists(f))

Expand Down
52 changes: 28 additions & 24 deletions R/dotNetAssembly.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ rawrrAssemblyPath <- function(){
rv
}

#' dotnet nuget add source /Users/cp/Library/Caches/org.R-project.R/R/rawrr/rawrrassembly/
#' dotnet nuget remove source "Package source 1"
#' dotnet nuget list source
# dotnet nuget add source /Users/cp/Library/Caches/org.R-project.R/R/rawrr/rawrrassembly/
# dotnet nuget remove source "Package source 1"
# dotnet nuget list source
.addNupkgSource <- function(){
system2('dotnet', args = c('nuget', 'add', 'source', rawrrAssemblyPath()))
}
Expand All @@ -163,7 +163,7 @@ rawrrAssemblyPath <- function(){
})
}

#' dotnet add package ThermoFisher.CommonCore.MassPrecisionEstimator
# dotnet add package ThermoFisher.CommonCore.MassPrecisionEstimator
.addPackages <- function(dir, version = "8.0.6"){
tempOut <- tempfile(pattern = "rawrr.add.packages.stdout.", tmpdir = dir, fileext = ".txt")
tempErr <- tempfile(pattern = "rawrr.add.packages.stderr.", tmpdir = dir, fileext = ".txt")
Expand All @@ -188,8 +188,8 @@ rawrrAssemblyPath <- function(){
}

.clean <- function(){
message("Removing ", rawrr:::.rawrrAssembly())
file.remove(rawrr:::.rawrrAssembly())
message("Removing ", .rawrrAssembly())
file.remove(.rawrrAssembly())
}

.build <- function(dir){
Expand All @@ -204,7 +204,7 @@ rawrrAssemblyPath <- function(){
message("Write stderr to", tempErr)

system2('dotnet', args = c('publish', '-c', 'Release', '-a', 'x64', '-p',
'PublishReadyToRun=true', '-o', dirname(rawrr:::.rawrrAssembly())),
'PublishReadyToRun=true', '-o', dirname(.rawrrAssembly())),
stdout = tempOut,
stderr = tempErr) -> rv

Expand Down Expand Up @@ -314,21 +314,14 @@ installRawrrExe <-
#' .NET SDK. The console application \code{rawrr.exe}
#' is used by the package's reader functions through a \link{system2} call
#' or a \link{textConnection}.
#'
#' To use this function, ensure that the local RawFileReader NuGet packages
#' are added to the NuGet source list. You can accomplish this by
#' downloading the necessary packages with
#' \code{rawrr:::.downloadNupkgs()} and subsequently running
#' \code{rawrr:::.addNupkgSource()}.
#'
#' @details The rawrr package implementation consists of two language layers,
#' the top R layer and the hidden C# layer. Specifically, R functions requesting
#' access to data stored in binary raw files invoke compiled C# wrapper methods
#' using a \link{system2} call. Calling a wrapper method typically results in the
#' execution of methods defined in the RawFileReader dynamic link library
#' provided by Thermo Fisher Scientific. Our precompiled wrapper methods are
#' bundled in the \code{rawrr.exe} executable file (.NET assembly) and shipped
#' with the released R package.
#' Our package also contains the C# source code \code{rawrr.cs}.
#' In order to return extracted data back to the R layer we use file I/O.
#' More specifically, the extracted information is written to a temporary
#' location on the harddrive, read back into memory and parsed into R objects.
#'
#' @author Tobias Kockmann, Christian Panse <[email protected]>, 2021, 2024
#' @author Christian Panse <[email protected]>, 2021, 2024
#'
#' @seealso \link{installRawrrExe}
#'
Expand Down Expand Up @@ -362,9 +355,20 @@ buildRawrrExe <- function(){

.copySourceCode(dir = buildDir)

## TODO: check if already exists
# .downloadNupkgs()
# .addNupkgSource()
(system2("dotnet", args =c('nuget', 'list', 'source'),
stdout = TRUE) |>
grepl(pattern = "rawrrassembly") |>
sum() >= 1) -> nugetPkgsPresent

if(nugetPkgsPresent){
warning("Have you downloaded the 'thermofisherlsms/RawFileReader' NuGet packages? \n",
"If not, please consider executing the methods:\n",
" -> rawrr:::.downloadNupkgs()\n",
" -> rawrr:::.addNupkgSource()\n",
"These steps should be performed once to ensure proper setup.")
# .downloadNupkgs()
# .addNupkgSource()
}

.addPackages(dir = buildDir)
.build(dir = buildDir)
Expand Down
15 changes: 0 additions & 15 deletions man/dot-addNupkgSource.Rd

This file was deleted.

11 changes: 0 additions & 11 deletions man/dot-addPackages.Rd

This file was deleted.

11 changes: 0 additions & 11 deletions man/dot-benchmark.Rd

This file was deleted.

44 changes: 41 additions & 3 deletions vignettes/rawrr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,45 @@ We strongly believe that a library providing raw data reading would finally clos

# Implementation

Our implementation consists of two language layers, the top `R` layer and the hidden `C#` layer. Specifically, `R` functions requesting access to data stored in binary raw files (reader family functions listed in Table 1) invoke compiled `C#` wrapper methods using a system call. Calling a wrapper method typically results in the execution of methods defined in the `RawFileReader` dynamic link library provided by Thermo Fisher Scientific. Our precompiled wrapper methods are bundled in the `r BiocStyle::Biocpkg('rawrr')` executable file and shipped with the released `R` package. Running `rawrr.exe` requires the [Mono](https://www.mono-project.com/) environment on non-Microsoft operating systems. Mono is a cross platform, open source .NET framework. On Microsoft Windows the Microsoft .NET framework is typically already installed and sufficient. Our package also contains the `C#` source code (rawrr.cs), hopefully allowing other developers to follow and improve our code (open source). In order to return extracted data back to the `R` layer we use file I/O. More specifically, the extracted information is written to a temporary location on the harddrive, read back into memory and parsed into `R` objects.
Our implementation consists of two language layers, the top `R` layer and the hidden `C#` layer. Specifically, `R` functions requesting access to data stored in binary raw files (reader family functions listed in Table 1) invoke compiled `C#` wrapper methods using a system call. Calling a wrapper method typically results in the execution of methods defined in the `RawFileReader` dynamic link library provided by Thermo Fisher Scientific. Our `.NET 8.0` [@dotnet] precompiled wrapper methods are bundled, including the runtime, in the `r BiocStyle::Biocpkg('rawrr')` executable file and shipped with the released `R` package.
Our package also contains the `C#` source code (rawrr.cs), hopefully allowing other developers to follow and improve our code (open source). In order to return extracted data back to the `R` layer we use file I/O. More specifically, the extracted information is written to a temporary location on the harddrive, read back into memory and parsed into `R` objects.
The graphic below depicts the described software stack.

<table>
<tr style="border:2px solid black">
<td style="padding:15px">
`R>`
</td>
</tr>

<tr style="background-color:yellow;color:black; border:2px solid black">
<td style="padding:15px">
`system2` or
`text connection`
</td>
</tr>

<tr style="background-color:yellowgreen;color:black; border:2px solid black">
<td style="padding:15px">
.NET or Mono Runtime
</td>
</tr>

<tr style="background-color:orange;color:black; border:2px solid black">
<td style="padding:15px">
Managed Assembly
(CIL/.NET code)
<br>
rawrr.exe
</td>
</tr>

<tr style="background-color:orange;color:black; border:2px solid black">
<td style="padding:15px">
ThermoFisher.CommonCore.*.dll
</td>
</tr>
</table>

Since mass spectrometry typically uses two basic data items, the mass spectrum and the mass chromatogram, we decided to implement corresponding objects following `R`'s `S3` OOP system [@newS] named `rawrrSpectrum` and `rawrrChromatogram`. These objects function as simplistic interface to almost all data stored in raw-formatted files. The package provides functions to create and validate class instances. While class constructors primarily exist for (unit) testing purposes, instances are typically generated by the reader family of functions enumerated in Table 1 and returned as object sets (`rawrrSpectrumSet`, `rawrrChromatogramSet`). The names of objects encapsulated within `rawrrSpectrum` instances are keys returned by the `RawFileReader` API and the corresponding values become data parts of the objects, typically vectors of type `numeric`, `logical` or `character`. It needs to be mentioned that the `rawrrSpectrum` content partially depends on the instrument model and installed instrument control software version. For instance, the keys `FAIMS Voltage On:` and `FAIMS CV:` are only written by instruments that support FAIMS acquisition. We also implemented basic generics for printing and plotting of objects in base `R` to minimize dependencies.

Expand Down Expand Up @@ -104,7 +142,7 @@ The Orbitrap detector has been a tremendous success story in MS, since it offers
|`readTrailer()` |Reads trailer values for each scan event |`vector` |
|`readChromatogram()`|Reads chromatographic data from a raw file |`rawrrChromatogram(Set)` |

Table: lists `r BiocStyle::Biocpkg('rawrr')` package functions connected to reading functionality. More details can be found in the package documentation (see supporting information, S-20 onwards [@Kockmann2021]).
Table: lists `r BiocStyle::Biocpkg('rawrr')` package functions connected to reading functionality. More details can be found in the package man pages.

Individual scans or scan collections (sets) can be read by the function `readSpectrum()` which returns a `rawrrSpectrum` object or `rawrrSpectrumSet`. Our package also provides generics for printing and plotting these objects. The following code chunk depicts how a set of scans is read from the raw file (scan numbers were selected based on a database search). The corresponding Figure 1 shows the resulting plot for scan `9594` (USI: [mzspec:MSV000086542:20181113_010_autoQC01:scan:9594:LGGNEQVTR/2](http://massive.ucsd.edu/ProteoSAFe/usi.jsp#{%22usi%22:%22mzspec:MSV000086542:20181113_010_autoQC01:scan:9594:LGGNEQVTR/2%22})) assigned to the doubly-charged iRT peptide LGGNEQVTR by MS-GF+ (Score: 144, SpecProb: 1.9e-12, DB E-Value: 4.4e-4, see [MassIVE RMSV000000336.1](https://massive.ucsd.edu/ProteoSAFe/dataset.jsp?task=575538e190e84cbfbf6c17aa1219e403#reanalyses_header) for details of the search):

Expand Down Expand Up @@ -369,7 +407,7 @@ See also [#fgcz/rawDiag/issues/33](https://github.com/fgcz/rawDiag/issues/33).
sessionInfo()
```

# Mono information {-}
# .NET information {-}

```{bash dotnet--info, echo=TRUE, error=TRUE}
dotnet --info
Expand Down
7 changes: 7 additions & 0 deletions vignettes/rawrr.bib
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ @ONLINE{mono
year = {2021}
}

@ONLINE{dotnet,
url = {https://dotnet.microsoft.com/en-us/},
author = {Microsoft},
title = {.NET | Build. Test. Deploy.},
year = {2021}
}

@ONLINE{rawfilereader,
url = {https://github.com/thermofisherlsms/RawFileReader},
author = {Jim Shofstahl},
Expand Down

0 comments on commit ed853d8

Please sign in to comment.