Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
shinyscreen
Manage
Activity
Members
Labels
Plan
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Environmental Cheminformatics
shinyscreen
Commits
3709fa5d
Commit
3709fa5d
authored
5 years ago
by
Todor Kondic
Browse files
Options
Downloads
Patches
Plain Diff
Remove mix.R
parent
5bbf7f87
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mix.R
+0
-104
0 additions, 104 deletions
mix.R
with
0 additions
and
104 deletions
mix.R
deleted
100644 → 0
+
0
−
104
View file @
5bbf7f87
## Create a temporary directory to hold the files generated on the
## fly.
rmbmix.mkdir
<-
function
()
{
nm
<-
tempfile
(
pattern
=
"rmbmix"
)
dir.create
(
nm
)
nm
}
##
rmbmix.mk_sett_file
<-
function
(
sett_alist
,
file
)
{
require
(
yaml
)
tmp
<-
tempfile
()
RmbSettingsTemplate
(
tmp
)
sett
<-
yaml.load_file
(
tmp
)
for
(
nm
in
names
(
sett_alist
))
{
sett
[[
nm
]]
<-
sett_alist
[[
nm
]]
}
write_yaml
(
x
=
sett
,
file
=
file
)
}
## Generate the RMassBank compound list from the input compound list
## in CSV file src_fn. The input compound list format is either
## Chemical Dashboard csv file with, at least, PREFERRED_NAMES and
## SMILES columns _filled_ out, or just an ordinary csv file with
## columns SMILES and Names filled. Argument dest_fn is the
## destination filename. Returns the number of compounds.
rmbmix.gen_comp_list
<-
function
(
src_fn
,
dest_fn
)
{
df
<-
read.csv
(
src_fn
)
## Names
nms
<-
if
(
"PREFERRED_NAME"
%in%
names
(
df
))
df
$
PREFERRED_NAME
else
df
$
Name
if
(
is.null
(
nms
))
stop
(
"Unable to read compound names from the input compound list."
)
## SMILES
haha
<-
df
$
SMILES
sz
<-
length
(
haha
)
## CAS
casvals
<-
if
(
"CASRN"
%in%
names
(
df
))
df
$
CASRN
else
rep
(
NA
,
sz
)
if
(
is.null
(
haha
))
stop
(
"Unable to read SMILES from the input compound list."
)
outdf
<-
data.frame
(
ID
=
1
:
sz
,
Name
=
nms
,
SMILES
=
haha
,
CAS
=
casvals
,
RT
=
rep
(
NA
,
sz
))
write.csv
(
outdf
,
file
=
dest_fn
,
row.names
=
F
,
na
=
""
)
length
(
nms
)
}
## Perform the compound mixture workflow on the data file called
## fn_data with settings named list called stgs_alist. Alternatively,
## stg_alist can be a file name which follows the RMassBank settings
## specification, also in YAML format, containing only parts that
## differ from the default. Argument fn_cmpd_list is the compound
## list. Argument wd is the scratch dir to hold generated ini files
## and the like. Arguments mode and readMethod are the same as in
## msmsRead.
rmbmix.single
<-
function
(
fn_data
,
stgs_alist
,
fn_cmpd_list
,
wd
,
mode
,
readMethod
=
"mzR"
,
archdir
=
"archive"
)
{
require
(
RMassBank
)
require
(
yaml
)
## Generate settings file and load.
stgs_alist
<-
if
(
is.character
(
stgs_alist
))
yaml.load_file
(
stgs_alist
)
else
stgs_alist
sfn
<-
file.path
(
wd
,
paste
(
fn_data
,
".ini"
,
sep
=
''
))
rmbmix.mk_sett_file
(
stgs_alist
,
sfn
)
loadRmbSettings
(
sfn
)
## Generate and load the compound list.
fn_comp
<-
file.path
(
wd
,
paste
(
fn_data
,
".comp.csv"
,
sep
=
''
))
n_cmpd
<-
rmbmix.gen_comp_list
(
fn_cmpd_list
,
fn_comp
)
loadList
(
fn_comp
)
## Generate file table.
df_table
<-
data.frame
(
Files
=
rep
(
fn_data
,
n_cmpd
),
ID
=
1
:
n_cmpd
)
fn_table
<-
file.path
(
wd
,
paste
(
"fn-table."
,
fn_data
,
".csv"
,
sep
=
''
))
write.csv
(
x
=
df_table
,
file
=
fn_table
,
row.names
=
F
)
## Make empty workspace.
w
<-
newMsmsWorkspace
()
## Run the workflow.
message
(
paste
(
"Reading in file:"
,
fn_data
))
w
<-
msmsRead
(
w
,
filetable
=
fn_table
,
readMethod
=
"mzR"
,
mode
=
mode
)
if
(
!
dir.exists
(
archdir
))
dir.create
(
archdir
)
fn_arch
<-
file.path
(
archdir
,
paste
(
fn_data
,
".archive"
,
sep
=
''
))
w
<-
msmsWorkflow
(
w
,
mode
=
mode
,
steps
=
2
:
8
,
archivename
=
fn_arch
)
mb
<-
newMbWorkspace
(
w
)
mb
<-
resetInfolists
(
mb
)
## loadInfolists
## addPeaks
bits
<-
strsplit
(
fn_data
,
split
=
"\\."
)[[
1
]]
fn_info
<-
if
(
length
(
bits
)
>
1
)
paste
(
head
(
bits
,
-1
),
collapse
=
"."
)
else
fn_data
infodir
<-
fn_info
fn_info
<-
paste
(
archdir
,
"/"
,
fn_info
,
".csv"
,
sep
=
''
)
mb
<-
mbWorkflow
(
mb
,
infolist_path
=
fn_info
)
list
(
w
=
w
,
mb
=
mb
)
}
rmbmix.mb2.single
<-
function
(
mb
,
infodir
)
{
mb
<-
resetInfolists
(
mb
)
mb
<-
loadInfolists
(
mb
,
infodir
)
mbWorkflow
(
mb
)
}
rmbmix.mb2
<-
Vectorize
(
rmbmix.mb2.single
,
vectorize.args
=
c
(
"mb"
,
"infodir"
),
SIMPLIFY
=
F
)
rmbmix
<-
Vectorize
(
rmbmix.single
,
vectorize.args
=
c
(
"fn_data"
,
"stgs_alist"
),
SIMPLIFY
=
F
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment