Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RMassBank_by_MaliRemorker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
RMassBank_by_MaliRemorker
Commits
1cd9179c
Commit
1cd9179c
authored
9 years ago
by
ermueller
Browse files
Options
Downloads
Patches
Plain Diff
Added fallback for nonbabelusers in case Cactus is down
parent
a838cc36
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/createMassBank.R
+13
-2
13 additions, 2 deletions
R/createMassBank.R
R/webAccess.R
+58
-0
58 additions, 0 deletions
R/webAccess.R
with
71 additions
and
2 deletions
R/createMassBank.R
+
13
−
2
View file @
1cd9179c
...
...
@@ -330,6 +330,13 @@ createMolfile <- function(id_or_smiles, fileName = FALSE)
if
(
is.na
(
babeldir
))
{
res
<-
getCactus
(
smiles
,
"sdf"
)
if
(
is.na
(
res
)){
res
<-
getPcSDF
(
smiles
)
}
if
(
is.na
(
res
)){
stop
(
"Pubchem and Cactus both seem to be down."
)
}
if
(
is.character
(
fileName
))
writeLines
(
res
,
fileName
)
}
...
...
@@ -492,8 +499,12 @@ gatherData <- function(id)
inchikey_split
<-
system
(
cmdinchikey
,
intern
=
TRUE
,
input
=
smiles
,
ignore.stderr
=
TRUE
)
}
else
{
inchikey
<-
getCactus
(
smiles
,
'stdinchikey'
)
##Split the "InChiKey=" part off the key
inchikey_split
<-
strsplit
(
inchikey
,
"="
,
fixed
=
TRUE
)[[
1
]][[
2
]]
if
(
!
is.na
(
inchikey
)){
##Split the "InChiKey=" part off the key
inchikey_split
<-
strsplit
(
inchikey
,
"="
,
fixed
=
TRUE
)[[
1
]][[
2
]]
}
else
{
inchikey
<-
getPcInchiKey
(
smiles
)
}
}
##Use Pubchem to retrieve information
...
...
This diff is collapsed.
Click to expand it.
R/webAccess.R
+
58
−
0
View file @
1cd9179c
...
...
@@ -313,6 +313,8 @@ CTS.externalIdTypes <- function(data)
}
}
getPcCHEBI
<-
function
(
query
,
from
=
"inchikey"
)
{
# Get the JSON-Data from Pubchem
...
...
@@ -466,3 +468,59 @@ getPcIUPAC <- function (query, from = "inchikey")
return
(
IUPACEntries
[[
1
]]
$
value
$
sval
)
}
}
getPcInchiKey
<-
function
(
query
,
from
=
"smiles"
){
# Get the JSON-Data from Pubchem
baseURL
<-
"http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound"
url
<-
paste
(
baseURL
,
from
,
query
,
"record"
,
"json"
,
sep
=
"/"
)
errorvar
<-
0
currEnvir
<-
environment
()
tryCatch
(
data
<-
getURL
(
URLencode
(
url
),
timeout
=
5
),
error
=
function
(
e
){
currEnvir
$
errorvar
<-
1
})
if
(
errorvar
){
return
(
NA
)
}
r
<-
fromJSON
(
data
)
# This happens if the InChI key is not found:
if
(
!
is.null
(
r
$
Fault
))
return
(
NA
)
# Find the entries which contain Chebi-links
if
(
!
is.null
(
r
$
PC_Compounds
[[
1
]]
$
props
)){
INKEYindex
<-
which
(
sapply
(
r
$
PC_Compounds
[[
1
]]
$
props
,
function
(
x
)
x
$
urn
$
label
)
==
"InChIKey"
)
if
(
length
(
INKEYindex
)
>
0
){
return
(
r
$
PC_Compounds
[[
1
]]
$
props
[[
INKEYindex
]]
$
value
$
sval
)
}
else
{
return
(
NA
)}
}
else
{
return
(
NA
)}
}
getPcSDF
<-
function
(
query
,
from
=
"smiles"
){
baseURL
<-
"http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound"
url
<-
paste
(
baseURL
,
from
,
query
,
"sdf"
,
sep
=
"/"
)
errorvar
<-
0
currEnvir
<-
environment
()
tryCatch
(
data
<-
getURL
(
URLencode
(
url
),
timeout
=
5
),
error
=
function
(
e
){
currEnvir
$
errorvar
<-
1
})
if
(
errorvar
){
return
(
NA
)
}
molEnd
<-
regexpr
(
data
,
pattern
=
"M END"
,
fixed
=
TRUE
)
+5
data
<-
c
(
strsplit
(
substring
(
data
,
1
,
molEnd
),
"\n"
)[[
1
]],
"$$$$"
)
return
(
data
)
}
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