-
Notifications
You must be signed in to change notification settings - Fork 45
Add uspto data from drfp #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
phalem
wants to merge
15
commits into
OpenBioML:main
Choose a base branch
from
phalem:add_uspto500k_raw
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5c20bd9
Add uspto data from drfp
phalem 0303bf3
Update data/USPTO_500k/meta.yaml
phalem dfdf3fd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f5bf910
Add files via upload
phalem 69af75c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4748c4c
Merge branch 'OpenBioML:main' into add_uspto500k_raw
phalem 8ec54af
Delete data/USPTO_500k directory
phalem 5c12078
Add files via upload
phalem 5716744
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b00d228
Update data/uspto_500k/meta.yaml
phalem a368cd2
Merge branch 'OpenBioML:main' into add_uspto500k_raw
phalem f231ca9
Remove Benchmark field
phalem 0bdd4aa
Remove benchmark field
phalem d55bfd9
Remove benchmark field
phalem 8cf5f1a
feat: uspto_500k clean up
MicPie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: USPTO_500k | ||
description: United States Patent and Trademark Office reaction dataset with yields. | ||
targets: | ||
- id: yield | ||
description: Reaction yields analyzed by UPLC | ||
units: '%' | ||
type: continuous | ||
names: | ||
- Reaction yield | ||
- yield | ||
uris: | ||
- https://bioportal.bioontology.org/ontologies/AFO?p=classes&conceptid=http%3A%2F%2Fpurl.allotrope.org%2Fontologies%2Fquality%23AFQ_0000227 | ||
- https://en.wikipedia.org/wiki/Yield_(chemistry) | ||
identifiers: | ||
- id: reaction_SMILES | ||
type: SMILES | ||
phalem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description: reaction SMILES | ||
license: CC0 | ||
links: | ||
- url: https://doi.org/10.17863/CAM.16293 | ||
description: corresponding publication | ||
- url: https://github.com/reymond-group/drfp/blob/main/data/uspto_yields_below.csv | ||
description: data source | ||
- url: https://github.com/reymond-group/drfp/blob/main/data/uspto_yields_above.csv | ||
description: data source | ||
- url: https://tdcommons.ai/single_pred_tasks/yields/#uspto | ||
description: other source | ||
num_points: 498721 | ||
bibtex: | ||
- |- | ||
@article{https://doi.org/10.17863/cam.16293, | ||
doi = {10.17863/CAM.16293}, | ||
url = {https://www.repository.cam.ac.uk/handle/1810/244727}, | ||
author = {Lowe, Daniel Mark}, | ||
keywords = {Name to structure, OPSIN, Chemical text mining, Text mining, Patent reaction extraction, Reaction mining, Patents}, | ||
language = {en}, | ||
title = {Extraction of chemical structures and reactions from the literature}, | ||
publisher = {Apollo - University of Cambridge Repository}, | ||
year = {2012}, | ||
copyright = {All Rights Reserved}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import pandas as pd | ||
import yaml | ||
from tdc.single_pred import Tox | ||
|
||
|
||
def get_and_transform_data(): | ||
# get raw data | ||
df1 = pd.read_csv('https://github.com/reymond-group/drfp/raw/main/data/uspto_yields_above.csv') | ||
df2 = pd.read_csv('https://github.com/reymond-group/drfp/raw/main/data/uspto_yields_below.csv') | ||
data = pd.concat([df1,df2]) | ||
data = data[['rxn','yield']] | ||
data= data.drop_duplicates(subset='rxn') | ||
fn_data_original = "uptso.csv" | ||
data.to_csv(fn_data_original, index=False) | ||
|
||
# create dataframe | ||
df = pd.read_csv(fn_data_original, | ||
delimiter="," | ||
)# not necessary but ensure we can load the saved data | ||
|
||
# check if fields are the same | ||
fields_orig = df.columns.tolist() | ||
assert fields_orig == ['rxn', 'yield'] | ||
fields_clean = [ | ||
"reaction_SMILES", | ||
"yield" | ||
] | ||
|
||
# overwrite column names = fields | ||
df.columns = fields_clean | ||
assert fields_orig != fields_clean | ||
|
||
# remove leading and trailing white space characters | ||
assert not df.duplicated().sum() | ||
|
||
# save to csv | ||
fn_data_csv = "data_clean.csv" | ||
df.to_csv(fn_data_csv, index=False) | ||
|
||
|
||
# create meta yaml | ||
meta = { | ||
"name": "USPTO_500k", # unique identifier, we will also use this for directory names | ||
"description": """United States Patent and Trademark Office reaction dataset with yields.""", | ||
"targets": [ | ||
{ | ||
"id": "yield", # name of the column in a tabular dataset | ||
"description": "Reaction yields analyzed by UPLC", # description of what this column means | ||
"units": "%", # units of the values in this column (leave empty if unitless) | ||
"type": "continuous", # can be "categorical", "ordinal", "continuous" | ||
"names": [ # names for the property (to sample from for building the prompts) | ||
"Reaction yield", | ||
"yield", | ||
], | ||
"uris":[ | ||
"https://bioportal.bioontology.org/ontologies/AFO?p=classes&conceptid=http%3A%2F%2Fpurl.allotrope.org%2Fontologies%2Fquality%23AFQ_0000227", | ||
"https://en.wikipedia.org/wiki/Yield_(chemistry)", | ||
], | ||
}, | ||
], | ||
"identifiers": [ | ||
{ | ||
"id": "reaction_SMILES", # column name | ||
"type": "SMILES", # can be "SMILES", "SELFIES", "IUPAC", "Other" | ||
"description": "reaction SMILES", # description (optional, except for "Other") | ||
}, | ||
], | ||
"license": "CC0", # license under which the original dataset was published | ||
"links": [ # list of relevant links (original dataset, other uses, etc.) | ||
{ | ||
"url": "https://doi.org/10.17863/CAM.16293", | ||
"description": "corresponding publication", | ||
}, | ||
{ | ||
"url": "https://github.com/reymond-group/drfp/blob/main/data/uspto_yields_below.csv", | ||
"description": "data source", | ||
}, | ||
{ | ||
"url": "https://github.com/reymond-group/drfp/blob/main/data/uspto_yields_above.csv", | ||
"description": "data source", | ||
}, | ||
{ | ||
"url": "https://tdcommons.ai/single_pred_tasks/yields/#uspto", | ||
"description": "other source", | ||
} | ||
], | ||
"num_points": len(df), # number of datapoints in this dataset | ||
"bibtex": [ | ||
"""@article{https://doi.org/10.17863/cam.16293, | ||
doi = {10.17863/CAM.16293}, | ||
url = {https://www.repository.cam.ac.uk/handle/1810/244727}, | ||
author = {Lowe, Daniel Mark}, | ||
keywords = {Name to structure, OPSIN, Chemical text mining, Text mining, Patent reaction extraction, Reaction mining, Patents}, | ||
language = {en}, | ||
title = {Extraction of chemical structures and reactions from the literature}, | ||
publisher = {Apollo - University of Cambridge Repository}, | ||
year = {2012}, | ||
copyright = {All Rights Reserved}}""", | ||
], | ||
} | ||
|
||
def str_presenter(dumper, data): | ||
"""configures yaml for dumping multiline strings | ||
Ref: https://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data | ||
""" | ||
if data.count("\n") > 0: # check for multiline string | ||
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|") | ||
return dumper.represent_scalar("tag:yaml.org,2002:str", data) | ||
|
||
yaml.add_representer(str, str_presenter) | ||
yaml.representer.SafeRepresenter.add_representer( | ||
str, str_presenter | ||
) # to use with safe_dum | ||
fn_meta = "meta.yaml" | ||
with open(fn_meta, "w") as f: | ||
yaml.dump(meta, f, sort_keys=False) | ||
|
||
print(f"Finished processing {meta['name']} dataset!") | ||
|
||
|
||
if __name__ == "__main__": | ||
get_and_transform_data() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the "id" in the ontology table, but I can show you at an example when we discuss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kjappelbaum I'm not sure what you mean here?