Finding nearby genes
From genomewiki
Jump to navigationJump to search
Let's say you had a position, and you wanted to find a sample of nearby genes upstream and downstream from this position.
This can be done with a MySQL query to the public MySQL server
#!/bin/sh # given position chr1:710000-720000 # find a sample of genes near this upstream and downstream C=chr1 S=710000 E=720000 echo "three upstream genes from ${C}:${S}-${E}" mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -N -e \ 'select e.chrom,e.txStart,e.txEnd,e.alignID,j.geneSymbol FROM knownGene e, kgXref j WHERE e.alignID = j.kgID AND e.chrom="'${C}'" AND e.txEnd < '${S}' ORDER BY e.txEnd DESC limit 3;' hg18 echo "three downstream genes from ${C}:${S}-${E}" mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -N -e \ 'select e.chrom,e.txStart,e.txEnd,e.alignID,j.geneSymbol FROM knownGene e, kgXref j WHERE e.alignID = j.kgID AND e.chrom="'${C}'" AND e.txStart > '${E}' ORDER BY e.txStart ASC limit 3;' hg18
This produces the output:
three upstream genes from chr1:710000-720000 +------+--------+--------+------------+----------+ | chr1 | 690107 | 703869 | uc001abo.1 | BC006361 | | chr1 | 665195 | 665226 | uc001abn.1 | DQ599872 | | chr1 | 665086 | 665147 | uc001abm.1 | DQ600587 | +------+--------+--------+------------+----------+ three downstream genes from chr1:710000-720000 +------+--------+--------+------------+----------+ | chr1 | 752926 | 778860 | uc001abp.1 | BC102012 | | chr1 | 752926 | 778860 | uc001abq.1 | BC042880 | | chr1 | 752926 | 779603 | uc001abr.1 | CR601056 | +------+--------+--------+------------+----------+