Created
January 31, 2020 14:06
-
-
Save will-moore/79e4e18c1e8ba632773f8fd9fdce05c1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import re | |
from omero.gateway import BlitzGateway, MapAnnotationWrapper, LongAnnotationWrapper | |
conn = BlitzGateway("user", "pass", port=4064, host="localhost") | |
conn.connect() | |
# Some example chromosome regions we want to annotate Images with... | |
regions = [ | |
"hg19:chr19:15200000-15560000", | |
"hg19:chr19:14680000-15200000", | |
"hg19:chr19:13840000-14680000", | |
"hg19:chr19:13320000-13840000", | |
"hg19:chr19:12760000-13320000", | |
"hg19:chr19:11720000-12760000", | |
"hg19:chr19:9920000-11720000", | |
"hg19:chr19:8680000-9920000", | |
"hg19:chr19:7400000-8680000", | |
"hg38:chr18:41032946-41237107", | |
"hg38:chr17:71701970-71881251", | |
"hg38:chr18:48801892-48998008", | |
"hg38:chr6:31726513-31941166", | |
"hg38:chr17:81838938-82011412", | |
"hg38:chr7:100470711-100665335", | |
"hg38:chr2:24775316-24986873", | |
"hg38:chr18:48801892-48998008", | |
"hg38:chr18:36192874-36397035", | |
] | |
dataset = conn.getObject("Dataset", 52) | |
for region, image in zip(regions, dataset.listChildren()): | |
g = re.search(r'chr(\d+):(\d+)-(\d+)', region) | |
data = { | |
'chr': int(g.group(1)), | |
'start': int(g.group(2)), | |
'end': int(g.group(3)) | |
} | |
# Add map annotation | |
namespace = "chromosome.region.4dn" | |
key_value_data = [ | |
["regions", region], | |
['chromosome', str(data['chr'])], | |
['start', str(data['start'])], | |
['end', str(data['end'])] | |
] | |
map_ann = MapAnnotationWrapper(conn) | |
map_ann.setNs(namespace) | |
map_ann.setValue(key_value_data) | |
map_ann.save() | |
image.linkAnnotation(map_ann) | |
# Long annotation... | |
for name, value in data.items(): | |
a = LongAnnotationWrapper(conn) | |
a.setNs("chromosome.region.%s" % name) | |
a.setValue(value) | |
image.linkAnnotation(a) | |
conn.close() | |
# Then config MAPR to search for these | |
# omero config append omero.web.mapr.config '{"menu": "4dn", "config":{"default":["regions"], "all":["regions"], "ns":["chromosome.region.4dn"], "label":"4DN Regions"}}' | |
# omero config append omero.web.ui.top_links '["4DN Regions", {"viewname": "maprindex_4dn"}, {"title": "Find 4DN Regions"}]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment