Source code for k1lib.cli.mgi

# AUTOGENERATED FILE! PLEASE DON'T EDIT HERE. EDIT THE SOURCE NOTEBOOKS INSTEAD
"""All tools related to the MGI database. Expected to use behind the "mgi"
module name, like this::

    from k1lib.imports import *
    ["SOD1", "AMPK"] | mgi.batch()
"""
from k1lib import cli
from typing import List
import time
__all__ = ["batch"]
[docs]class batch(cli.BaseCli): # batch """Queries MGI database, convert list of genes to MGI ids""" # batch
[docs] def __init__(self, headless=True): # batch """ :param headless: whether to run this operation headless, or actually display the browser""" # batch super().__init__(); self.headless = headless # batch
[docs] def __ror__(self, it:List[str]): # batch super().__ror__(it) # batch import selenium; from selenium import webdriver # batch query = "\n".join(it | cli.op().strip().all() | ~cli.filt(cli.op() == "")) # batch options = selenium.webdriver.chrome.options.Options() # batch if self.headless: options.add_argument("--headless") # batch driver = selenium.webdriver.Chrome(options=options); # batch print("\r1/4 Going to website... ", end="") # batch driver.get("http://www.informatics.jax.org/batch") # batch print("\r2/4 Submitting data... ", end="") # batch driver.find_element_by_name("ids").send_keys(query) # batch driver.find_element_by_css_selector("tr.queryControls > td > input.buttonLabel").click() # batch markerIds = []; terms = []; names = []; features = [] # batch print("\r3/4 Getting data... ", end="") # batch def getStuff(classEnd:str): # batch return [elem.get_attribute("textContent") for elem in driver.find_elements_by_css_selector(f".yui-dt-col-{classEnd} > div")] # batch while len(markerIds) <= 1: # batch markerIds = getStuff("markerId"); terms = getStuff("term") # batch names = getStuff("name"); features = getStuff("feature") # batch time.sleep(1) # batch print("\r4/4 Data received! ") # batch driver.close() # batch return cli.joinColumns([markerIds, terms, features, names]) # batch