Skip to content

Instantly share code, notes, and snippets.

@nathandunn
Last active January 27, 2017 18:36
Show Gist options
  • Save nathandunn/b35d47bd8d200c7715307ae2fe9b5baf to your computer and use it in GitHub Desktop.
Save nathandunn/b35d47bd8d200c7715307ae2fe9b5baf to your computer and use it in GitHub Desktop.
simple python JBrowse extraction
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import cv2
url = 'https://genome.monarchinitiative.org/apollo/Honeybee/jbrowse/index.html?loc=Group1.1%3A724016..726600&tracklist=0&nav=0&tracks=Official%20Gene%20Set%20v3.2&highlight='
driver = webdriver.Chrome()
driver.get(url)
try:
element = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.ID, "label_Official Gene Set v3.2"))
)
# this should iterate over each trackList item (OR) each of the known tracks
trackElement = driver.find_element_by_id("track_Official Gene Set v3.2")
location = trackElement.location
size = trackElement.size
buffer = 80 # something with the scaling is off
total_height = location.get('y') + size.get('height') + buffer
img_name = 'screen1.png'
driver.get_screenshot_as_file(img_name)
image = cv2.imread(img_name)
orginal_width = image.shape[0]
cropped = image[0:int(total_height), 0:int(orginal_width*2)]
cv2.imwrite("screen2.png", cropped)
finally:
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment