You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -26,58 +22,120 @@ When we manually search for a compound on PubChem (https://pubchem.ncbi.nlm.nih.
26
22
27
23
First, we need to get the PubChem ID (CID) of the compound. This can be done using the `get_cid()` function. Throughout this vignette, we will mostly work with paracetamol, so let's get its CID:
28
24
29
-
```{r}
25
+
26
+
```r
30
27
get_cid("paracetamol")
28
+
#> # A tibble: 1 × 2
29
+
#> query cid
30
+
#> <chr> <chr>
31
+
#> 1 paracetamol 1983
31
32
```
33
+
32
34
Now that we know the CID, we can retrieve any section of the PubChem web page using `pc_sect()` (short for PubChem Section). Here is an example:
Notice that the function returns a data frame rather than a string. `pc_sect()` always returns a data frame but the variables it contains depends on the section. The first four variable names sown above are very common because they follow a standard schema for sections where the data consists of a single string, number, or similar value: the queried CID and section, the compound name, and the result.
45
+
Notice that the function returns a data frame rather than a string. `pc_sect()` always returns a data frame but the variables it contains depends on the section. The first five variable names shown above are common because they follow a standard schema for sections whose data consists of a single string, number, or similar value: the queried section, domain, ID (e.g., CID or SID), name, and result. For simplicity, this vignette only shows the first six variables of each tibble. Check the full output if you want to see all available variables.
39
46
40
47
Returning a data frame offers several advantages over returning only the result string. For example, we can query multiple compounds at the same time and simply get a data frame with additional rows:
Another advantage of the data frame structure is that it also includes any reference data stored in PubChem for each data element.
46
60
47
-
The `section` argument is not case sensitive but it is sensitive to typing errors and requires the full name of the section as it is printed on the content page. The PubChem Table of Contents Tree can also be found at https://pubchem.ncbi.nlm.nih.gov/classification/#hid=72. As a general rule, `pc_sect()` works with the lowest level section before the data. For example, it works with "IUPAC Name" but not with "Names and Identifiers".
61
+
The `section` argument is not case sensitive but it is sensitive to typing errors and requires the full name of the section as it is printed on the content page. The PubChem Table of Contents Tree can also be found at https://pubchem.ncbi.nlm.nih.gov/classification/#hid=72. As a general rule, `pc_sect()` works with the lowest level section before the data. For example, it works with "IUPAC Name" but not with "Names and Identifiers".
48
62
49
63
Let's look at some of the sections in more detail.
50
64
51
65
## Names and Identifiers
52
66
53
67
Here are a few more examples from the "Names and Identifiers" section:
54
68
55
-
```{r}
56
-
pc_sect(1983, "IUPAC Name")
69
+
70
+
```r
71
+
pc_sect(1983, "IUPAC Name") |>dplyr::select(1:6)
72
+
#> # A tibble: 1 × 6
73
+
#> Section Domain ID Name Result SourceName
74
+
#> <chr> <chr> <chr> <chr> <chr> <chr>
75
+
#> 1 iupac name compound 1983 Acetaminophen N-(4-hydroxyphenyl)acetamide PubChem
57
76
```
58
77
59
-
```{r}
60
-
pc_sect(1983, "CAS")
78
+
79
+
```r
80
+
pc_sect(1983, "CAS") |>dplyr::select(1:6)
81
+
#> # A tibble: 19 × 6
82
+
#> Section Domain ID Name Result SourceName
83
+
#> <chr> <chr> <chr> <chr> <chr> <chr>
84
+
#> 1 cas compound 1983 Acetaminophen 103-90-2 Australian Industrial Chemicals Introduction Scheme (AICIS)
85
+
#> 2 cas compound 1983 Acetaminophen 103-90-2 CAMEO Chemicals
86
+
#> 3 cas compound 1983 Acetaminophen 103-90-2 CAS Common Chemistry
87
+
#> 4 cas compound 1983 Acetaminophen 103-90-2 ChemIDplus
88
+
#> 5 cas compound 1983 Acetaminophen 103-90-2 DrugBank
89
+
#> 6 cas compound 1983 Acetaminophen 103-90-2 DTP/NCI
90
+
#> 7 cas compound 1983 Acetaminophen 103-90-2 DTP/NCI
91
+
#> 8 cas compound 1983 Acetaminophen 103-90-2 DTP/NCI
92
+
#> 9 cas compound 1983 Acetaminophen 103-90-2 EFSA OpenFoodTox
93
+
#> 10 cas compound 1983 Acetaminophen 103-90-2 EPA Chemicals under the TSCA
94
+
#> 11 cas compound 1983 Acetaminophen 103-90-2 EPA DSSTox
95
+
#> 12 cas compound 1983 Acetaminophen 103-90-2 European Chemicals Agency (ECHA)
96
+
#> 13 cas compound 1983 Acetaminophen 103-90-2 FDA Global Substance Registration System (GSRS)
97
+
#> 14 cas compound 1983 Acetaminophen 103-90-2 Hazardous Substances Data Bank (HSDB)
98
+
#> 15 cas compound 1983 Acetaminophen 103-90-2 Human Metabolome Database (HMDB)
99
+
#> 16 cas compound 1983 Acetaminophen 103-90-2 ILO-WHO International Chemical Safety Cards (ICSCs)
100
+
#> 17 cas compound 1983 Acetaminophen 103-90-2 New Zealand Environmental Protection Authority (EPA)
101
+
#> 18 cas compound 1983 Acetaminophen 103-90-2 NIAID ChemDB
102
+
#> 19 cas compound 1983 Acetaminophen 103-90-2 Risk Assessment Information System (RAIS)
61
103
```
62
104
63
-
```{r}
64
-
pc_sect(1983, "ChEMBL ID")
105
+
106
+
```r
107
+
pc_sect(1983, "ChEMBL ID") |>dplyr::select(1:6)
108
+
#> # A tibble: 2 × 6
109
+
#> Section Domain ID Name Result SourceName
110
+
#> <chr> <chr> <chr> <chr> <chr> <chr>
111
+
#> 1 chembl id compound 1983 Acetaminophen CHEMBL112 ChEMBL
112
+
#> 2 chembl id compound 1983 Acetaminophen CHEMBL112 Open Targets
Notice that we need to use `form = "long"` to get the desired result. So far "MeSH Entry Terms" appear to be the only section where where `form` needs to be set manually, but let us know if you find other sections.
@@ -86,61 +144,130 @@ Notice that we need to use `form = "long"` to get the desired result. So far "Me
86
144
87
145
In the "Computed Properties" section, the lowest-level section names that can be retrieved are the property names. For example:
The PubChem web pagealso displays a figure, which can be retrieved from the URL in the `Thumbnail` variable. However, if we want to generate the figure ourselves, the peaks are available in the `Shifts [ppm]:Intensity` variable. Notice that this section returns several data variables instead of a single `Result` variable. This is because the retrieved data set is a data frame, so `form = "auto"` detects this and converts the output to wide format.
183
+
The PubChem web page also displays a figure, which can be retrieved from the URL in the `Thumbnail` variable. However, if we want to generate the figure ourselves, the peaks are available in the `Shifts [ppm]:Intensity` variable. Notice that this section returns several data variables instead of a single `Result` variable. This is because the retrieved data set is a data frame, so `form = "auto"` detects this and converts the output to wide format.
109
184
110
185
## Drug and Medical Information
111
186
112
187
I included this section in the vignette because its output is a little more complicated. When we look at this section of the PubChem web page (https://pubchem.ncbi.nlm.nih.gov/compound/1983#section=Drug-Indication) we see that it contains both a table and textual data. When we retrieve the data, `pc_sect()` returns the table in wide format while using the standard schema with the `Result` column for the textual data. Downstream processing of this data frame may require some extra attention.
#> 1 other toxicity values compound 1983 Acetaminophen <NA> 37
142
269
```
143
270
144
271
## Help Us Improve PubChem Access
145
272
146
-
PubChem web pages contain a huge amount of information about chemicals. Most of this data can be retrieved in `webchem` using `pc_sect()`. However, there may still be cases that are not handled properly. If you find any examples where you are not satisfied with the output from `pc_sect()`, please open an issue and we will look into it.
273
+
PubChem web pages contain a huge amount of information about chemicals. Most of this data can be retrieved in `webchem` using `pc_sect()`. However, there may still be cases that are not handled properly. If you find any examples where you are not satisfied with the output from `pc_sect()`, please open an issue and we will look into it.
0 commit comments