Skip to content

Commit

Permalink
fixes for gene resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
hpratt committed Dec 3, 2021
1 parent f3e7b54 commit b3a6095
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion api/api/data_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def _re_detail_linkedGenes(self, j, accession):

def _re_detail_rampage(self, j, accession):
cre = CRE(self.pgSearch, accession, self.cache)
nearbyGenes = cre.nearbyPcGenes()
nearbyGenes = self._re_detail_nearbyGenomic(self, accession)[accession]["nearby_genes"]
nearest = min(nearbyGenes, key=lambda x: x["distance"])
rampage = Rampage(self.assembly, self.pgSearch, self.cache)
ret = rampage.getByGene(nearest)
Expand Down
6 changes: 3 additions & 3 deletions api/api/geneexp_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ def abort(err):
r = {"assembly": self.assembly,
"gene": gene}
for assay_name in ["total RNA-seq", "polyA RNA-seq", "all"]:
single = cge.computeHorBars(name, compartments, biosample_types_selected, assay_name if assay_name != "all" else None)
mean = cge.computeHorBarsMean(name, compartments, biosample_types_selected, assay_name if assay_name != "all" else None)
single = cge.computeHorBars(gene, compartments, biosample_types_selected, assay_name if assay_name != "all" else None)
mean = cge.computeHorBarsMean(gene, compartments, biosample_types_selected, assay_name if assay_name != "all" else None)
itemsByRID = cge.itemsByRID
r[assay_name] = {"assembly": self.assembly,
"gene": name,
"gene": gene,
"strand": strand,
"ensemblid_ver": gi.ensemblid_ver,
"coords": {"chrom": gi.chrom,
Expand Down
2 changes: 1 addition & 1 deletion api/common/pg_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _exactGeneMatch(self, s, usetss, tssDist):
ac.chrom, ac.start, ac.stop,
ac.altchrom, ac.altstart, ac.altstop,
similarity(ac.name, %s) AS sm, ac.pointer,
gi.approved_symbol, gi.strand
gi.info->'symbol' AS approved_symbol, gi.strand
FROM {assembly}_gene_search ac
INNER JOIN {assembly}_gene_info gi
ON gi.id = ac.pointer
Expand Down
26 changes: 14 additions & 12 deletions api/common/pg_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def crePos(self, accession):

def _getGenes(self, accession, chrom, allOrPc):
rows = self.pw.fetchall("_getGenes", """
SELECT gi.approved_symbol, g.distance, gi.ensemblid_ver,
SELECT gi.info->>'symbol' AS approved_symbol, g.distance, gi.ensemblid_ver,
gi.chrom, gi.start, gi.stop
FROM
(SELECT UNNEST(gene_{allOrPc}_id) geneid,
Expand All @@ -159,8 +159,9 @@ def geneInfo(self, gene):
WHERE approved_symbol = %s
OR ensemblid = %s
OR ensemblid_ver = %s
OR info->>'symbol' = %s
""".format(gtn=self.assembly + "_gene_info"),
(gene, gene, gene))
(gene, gene, gene, gene))
return r

def intersectingSnps(self, accession, coord, halfWindow):
Expand Down Expand Up @@ -405,13 +406,14 @@ def genePos(self, gene):
ensemblid = gene.split('.')[0]

r = self.pw.fetchone("cre_pos", """
SELECT chrom, start, stop, approved_symbol, ensemblid_ver FROM {tn}
SELECT chrom, start, stop, info->>'symbol' AS approved_symbol, ensemblid_ver FROM {tn}
WHERE chrom != ''
AND (approved_symbol = %s
OR ensemblid = %s
OR ensemblid_ver = %s)
OR ensemblid_ver = %s
OR info->>'symbol' = %s)
""".format(tn=self.assembly + "_gene_info"),
(gene, ensemblid, gene))
(gene, ensemblid, gene, gene))
if not r:
print("ERROR: missing", gene)
return None, None
Expand Down Expand Up @@ -518,15 +520,15 @@ def datasets(self, assay):

def genemap(self):
rows = self.pw.fetchall("pg::genemap", """
SELECT ensemblid, approved_symbol, strand
SELECT ensemblid, info->>'symbol' AS approved_symbol, strand
FROM {tn}
WHERE strand != ''
""".format(tn=self.assembly + "_gene_info"))
toSymbol = {r[0]: r[1] for r in rows}
toStrand = {r[0]: r[2] for r in rows}

rows = self.pw.fetchall("pg::genemap", """
SELECT ensemblid_ver, approved_symbol, strand
SELECT ensemblid_ver, info->>'symbol' AS approved_symbol, strand
FROM {tn}
WHERE strand != ''
""".format(tn=self.assembly + "_gene_info"))
Expand Down Expand Up @@ -593,9 +595,9 @@ def rampageByGene(self, ensemblid_ver):
rows = self.pw.fetchallAsDict("rampageByGene", """
SELECT *
FROM {tn}
WHERE ensemblid_ver = %s
WHERE ensemblid_ver ILIKE %s || '%%'
""".format(tn=self.assembly + "_rampage"),
(ensemblid_ver, ))
(ensemblid_ver.split('.')[0], ))

ret = []
for r in rows:
Expand Down Expand Up @@ -624,7 +626,7 @@ def rampageEnsemblID(self, gene):
r = self.pw.fetchone("rampageEnsemblID", """
SELECT ensemblid_ver
FROM {assembly}_gene_info
WHERE approved_symbol = %(gene)s
WHERE approved_symbol = %(gene)s OR info->>'symbol' = %(gene)s
""".format(assembly=self.assembly),
{"gene": gene})
return r[0]
Expand All @@ -639,15 +641,15 @@ def geBiosampleTypes(self):

def geneIDsToApprovedSymbol(self):
rows = self.pw.fetchall("geneIDsToApprovedSymbol", """
SELECT geneid, approved_symbol
SELECT geneid, info->>'symbol' AS approved_symbol
FROM {gtn}
ORDER BY 1
""".format(gtn=self.assembly + "_gene_info"))
return {r[0]: r[1] for r in rows}

def genePGIDsToApprovedSymbol(self):
rows = self.pw.fetchall("geneIDsToApprovedSymbol", """
SELECT id, approved_symbol
SELECT id, info->>'symbol' AS approved_symbol
FROM {gtn}
ORDER BY 1
""".format(gtn=self.assembly + "_gene_info"))
Expand Down
5 changes: 5 additions & 0 deletions api/main_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,8 @@ def globalData(self, ver, assembly):
@cherrypy.expose
def healthz(self):
return "ok"

@cherrypy.expose
def img(self, *args):
cherrypy.response.headers["Content-Type"] = "image/png"
return requests.get("http://gcp.wenglab.org/%s" % ('/'.join(args))).content
4 changes: 2 additions & 2 deletions api/models/cre.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def nearbyGenes(self):
ret.sort(key=lambda g: g["distance"])
return ret

def nearbyPcGenes(self):
def nearbyPcGenes(self, chromosome = None):
coord = self.coord()
if not self.genesAll or not self.genesPC:
self.genesAll, self.genesPC = self.pgSearch.creGenes(self.accession,
coord.chrom)
chromosome if chromosome is not None else coord.chrom)
ret = []
for g in self.genesPC:
ret.append({"name": g[0], "distance": g[1], "ensemblid_ver": g[2],
Expand Down
2 changes: 1 addition & 1 deletion api/models/gene_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def doComputeHorBars(self, q, gene, compartments, biosample_types_selected,
a = """
SELECT chrom, start, stop
FROM {assembly}_gene_info
WHERE approved_symbol = %(gene)s
WHERE approved_symbol = %(gene)s OR info->>'symbol' = %(gene)s
""".format(assembly=self.assembly)
grows = self.pw.fetchall("doComputeHorBars", a, {"gene": gene})

Expand Down
4 changes: 1 addition & 3 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def getRootConfig(self):
'/': {
'tools.response_headers.on': True,
'tools.response_headers.headers': [
('Access-Control-Allow-Origin', Config.uiURL),
('Access-Control-Allow-Origin', "https://screen.wenglab.org"),
('Access-Control-Allow-Origin', "https://screen.encodeproject.org")
('Access-Control-Allow-Origin', '*')
]
},
'/assets': {
Expand Down

0 comments on commit b3a6095

Please sign in to comment.