Skip to content

Instantly share code, notes, and snippets.

@balhoff
Created October 7, 2021 15:58
Show Gist options
  • Save balhoff/6c0d434b1601de4d4006bff76b858ac1 to your computer and use it in GitHub Desktop.
Save balhoff/6c0d434b1601de4d4006bff76b858ac1 to your computer and use it in GitHub Desktop.
Ontobot script for GO.
#!/bin/bash
#Set ONT_ID
#Set ONT_NAME
ROBOT=1.6.0
DT=0.14
BRANCH_BASE="update-$ONT_ID-import"
#check that ontobot doesn't already have an open PR
if [ ! $(curl 'https://api.github.com/repos/geneontology/go-ontology/pulls?state=open' | jq 'map(select(.user.login == "ontobot")) | .[].head.ref' | grep $BRANCH_BASE) ]; then
mkdir bin
echo "-Xmx16G" >bin/owltools.vmoptions
curl -L -O 'https://github.com/owlcollab/owltools/releases/download/2020-04-06/owltools'
chmod +x owltools
mv owltools bin/
curl -L -O https://github.com/INCATools/dosdp-tools/releases/download/v$DT/dosdp-tools-$DT.tgz
tar -zxf dosdp-tools-$DT.tgz
curl -L -O https://github.com/ontodev/robot/releases/download/v$ROBOT/robot.jar
curl -L -O https://github.com/ontodev/robot/raw/master/bin/robot
mv robot.jar bin/
chmod +x robot
mv robot bin/
export PATH=$PATH:`pwd`/bin:`pwd`/dosdp-tools-$DT/bin
export ROBOT_JAVA_ARGS=-Xmx12G
json_escape () {
python -c 'import json,sys; print(json.dumps(sys.stdin.read())[1:-1])'
}
git clone --depth 2 https://github.com/geneontology/go-ontology.git
cd go-ontology/src/ontology
DATE=`date +%Y-%m-%d`
BRANCH=$BRANCH_BASE-$DATE
git checkout -b $BRANCH
make reasoned.owl
mv reasoned.owl reasoned-prev.owl
make imports/${ONT_ID}_import.obo
make reasoned.owl
robot diff --left reasoned-prev.owl --right reasoned.owl -f markdown -o go-diff.md
GO_DIFF=`json_escape <go-diff.md`
# Check if only version line has changed
if [ $(git diff --numstat imports/${ONT_ID}_import.obo | grep -E '1\s+1' | wc -l) != 1 ]; then
git add imports/${ONT_ID}_import.owl
git add imports/${ONT_ID}_import.obo
q='"'
if ! $(git diff --cached --quiet) ; then
git -c "user.name=OntoBot" -c "user.email=ontolobot@gmail.com" commit -m "Update $ONT_NAME import."
git push https://ontobot:$PASSKEY@github.com/ontobot/go-ontology.git $BRANCH
echo "{${q}title${q}: ${q}Update $ONT_NAME import${q}, ${q}body${q}: ${q}I've updated the $ONT_NAME import. Here's a diff of how this impacts the classified ontology:\n\n$GO_DIFF${q}, ${q}head${q}: ${q}ontobot:$BRANCH${q}, ${q}base${q}: ${q}master${q}}" >json_body.txt
curl -X POST -d @json_body.txt "https://ontobot:$PASSKEY@api.github.com/repos/geneontology/go-ontology/pulls"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment