-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from OBOFoundry/revised
COB Revised -- Wait for James to Merge
Showing
17 changed files
with
2,375 additions
and
9,662 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,11 @@ | ||
Ontology ID Label Type Definition Deprecated Term Replaced By | ||
ID LABEL TYPE A IAO:0000115 AT owl:deprecated^^xsd:boolean AI IAO:0100001 | ||
COB:0000005 obsolete elementary charge owl:Class true | ||
COB:0000014 obsolete macromolecular entity owl:Class true | ||
COB:0000020 obsolete subcellular structure owl:Class true GO:0110165 | ||
COB:0000032 obsolete geographical location owl:Class true | ||
COB:0000056 obsolete immaterial anatomical entity owl:Class true UBERON:0000466 | ||
COB:0000073 obsolete gene product owl:Class true | ||
COB:0000077 obsolete action specification owl:Class true IAO:0000007 | ||
COB:0000116 obsolete cellular membrane owl:Class true | ||
COB:0000122 obsolete physical information carrier owl:Class true |
This file contains 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,98 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Split the cob-edit.tsv file into three ROBOT templates: | ||
# cob-base.tsv cob-full.tsv cob-root.tsv | ||
|
||
import argparse | ||
import csv | ||
import os | ||
import re | ||
|
||
|
||
def initialize_tsv(output_dir, filename, fieldnames, robot_row): | ||
'''Initialize and return a DictWriter for a ROBOT template.''' | ||
path = os.path.join(output_dir, filename) | ||
path_fh = open(path, 'w') | ||
writer = csv.DictWriter(path_fh, fieldnames, delimiter='\t', lineterminator='\n', extrasaction='ignore') | ||
writer.writeheader() | ||
writer.writerow(robot_row) | ||
return writer | ||
|
||
|
||
def split(input_path, output_dir): | ||
'''Split the COB term template into base, full, and root templates.''' | ||
header_row = None | ||
robot_row, terms, replacements = {}, {}, {} | ||
|
||
with open(input_path) as f: | ||
rows = csv.DictReader(f, delimiter='\t') | ||
for row in rows: | ||
if not header_row: | ||
header_row = list(row.keys()) | ||
id = row['Ontology ID'].strip() | ||
if id == '': | ||
continue | ||
if id == 'ID': | ||
robot_row = row | ||
continue | ||
|
||
# Handle the Replacement columns | ||
# by collecting a dictionary of replacements. | ||
replacement_id = row['Replacement ID'].strip() | ||
replacement_label = row['Replacement Label'].strip() | ||
if replacement_label and replacement_label != '': | ||
# removed exception for non-base IDs... TBD if needed/wanted | ||
replacements[row['Label'].strip()] = { | ||
'ID': id, | ||
'Replacement Label': replacement_label, | ||
'Replacement ID': replacement_id, | ||
} | ||
# Otherwise just add this row to 'terms'. | ||
else: | ||
terms[id] = row | ||
|
||
ignore = [ | ||
'COB Module', 'COB Module Reason', | ||
'Replacement ID', 'Replacement Label', | ||
'Comment' | ||
] | ||
fieldnames = [x for x in header_row if x not in ignore] | ||
|
||
# Apply replacements to the axioms in all the logical columns | ||
axiom_cols = [ | ||
'Parent Class', 'Subclass Axiom', 'Equivalent Class Axiom', | ||
'Disjoint Class', 'Parent Property', 'Domain', 'Range', | ||
'Inverse Property' | ||
] | ||
for id, row in terms.items(): | ||
for repl_label, repl_dict in replacements.items(): | ||
for col in axiom_cols: | ||
if col not in row: | ||
continue | ||
row[col] = re.sub(repl_label, repl_dict['Replacement Label'], row[col]) | ||
|
||
base_writer = initialize_tsv(output_dir, 'cob-base.tsv', fieldnames, robot_row) | ||
full_writer = initialize_tsv(output_dir, 'cob-full.tsv', fieldnames, robot_row) | ||
root_writer = initialize_tsv(output_dir, 'cob-root.tsv', fieldnames, robot_row) | ||
|
||
for id, row in terms.items(): | ||
module = row['COB Module'].strip() | ||
if module == 'BASE': | ||
base_writer.writerow(row) | ||
if module not in ['', 'ROOT']: | ||
full_writer.writerow(row) | ||
if module != '': | ||
root_writer.writerow(row) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Split the main COB term template into multiple module templates') | ||
parser.add_argument('input', type=str, help='The input COB term template') | ||
parser.add_argument('outdir', type=str, help='The output directory') | ||
args = parser.parse_args() | ||
|
||
split(args.input, args.outdir) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |