Created
January 6, 2012 18:52
-
-
Save gingi/1571893 to your computer and use it in GitHub Desktop.
Fetch Ensembl gene IDs based on external ID.
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
#!/bin/sh | |
mysqluser='anonymous'; | |
mysqlpass=''; | |
mysqlhost='mysql.ebi.ac.uk'; | |
mysqlport=4157; | |
function usage () { | |
[ -n "$1" ] && echo $1 | |
cat <<USAGE | |
Fetches the EnsEMBL gene IDs associated with the specified external object ID. | |
Usage: $0 [-hHupP] database-name object-id | |
[options] | |
-u user : The MySQL user | |
-p password : The MySQL password | |
-h host : The MySQL host | |
-P port : The MySQL TCP port | |
-H : This help message | |
USAGE | |
exit 1 | |
} | |
while getopts "Hu:p:h:P:" opt; do | |
case $opt in | |
u) mysqluser="$OPTARG" ;; | |
p) mysqlpass="$OPTARG" ;; | |
h) mysqlhost="$OPTARG" ;; | |
P) mysqlport="$OPTARG" ;; | |
H) usage ;; | |
?) echo invalid or missing argument, type $0 -H for help; exit 1 ;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
db_name=$1 | |
object_id=$2 | |
if [ -z "$db_name" -o -z "$object_id" ]; then | |
usage "Missing required argument" | |
fi | |
mysql -t -h$mysqlhost -P$mysqlport -u$mysqluser --password=$mysqlpass $db_name <<SQL; | |
select external_db.db_name as source, | |
gene_stable_id.stable_id as ensembl_id | |
from gene | |
left join gene_stable_id using (gene_id) | |
left join transcript using (gene_id) | |
left join transcript_stable_id using (transcript_id) | |
left join translation using (transcript_id) | |
join object_xref on ( | |
(ensembl_id = transcript_id and ensembl_object_type = 'Transcript') or | |
(ensembl_id = translation_id and ensembl_object_type = 'Translation') | |
) | |
left join xref using (xref_id) | |
left join external_db using (external_db_id) | |
where xref.display_label like '$object_id' | |
group by 1,2; | |
SQL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By default this script connects to the public EnsEMBL genomes database. An example usage is:
Run with the
-H
option to get the options (mostly related to MySQL connections).