def main(): try: app = QApplication(sys.argv) window = MainWindow() sys.exit(app.exec_()) except Exception as e: logger.critical(f"{e}") logger.critical(e, exc_info=True)
def connection(self): if isinstance(self.db, str): self._connectSQLite3(self.db) elif isinstance(self.db, Dict): self._connectMySQL() else: logger.critical(f"unknown databse instance passed: {type(self.db)}")
def saveWorkbook(self): logger.critical("saving workbook") # remove empty default sheet try: self.book.remove_sheet(self.book.get_sheet_by_name("Sheet")) except Exception as e: logger.warn(f'{e}') self.book.save(self.fileName)
def tblastn(file, blast): """ parse a xml file result of a tblastn """ count = 0 #counter of result in blast xml #verification if file is a xml f = open(file, 'r') header = f.readline() if '<?xml version="1.0"?>' not in header: log.critical("Make sure of your file is an xml") return False f.close() #initialisation for parsing file tree = ET.parse(file) root = tree.getroot() for iteration in root.findall('./BlastOutput_iterations/Iteration'): #a iteration is a query sequence numberQuery = int(iteration[0].text) name = iteration[2].text lenght = iteration[3].text blast[numberQuery] = Query(numberQuery, name, lenght) for hit in iteration[4]: #a hit is a resultat of blast, a hit in xml file id = hit[1].text queryDef = hit[2].text log.debug(queryDef) for hsp in hit[5]: #a hsp is result of blast hit, like sequence or score… ; is hit_hsps°in xml eValue = float(hsp.find('Hsp_evalue').text) gaps = int(hsp.find('Hsp_gaps').text) identity = int(hsp.find('Hsp_identity').text) positive = int(hsp.find('Hsp_positive').text) qSeq = hsp.find('Hsp_qseq').text mSeq = hsp.find('Hsp_midline').text hSeq = hsp.find('Hsp_hseq').text hSeqLen = int(hsp.find('Hsp_align-len').text) scores = { 'eValue': eValue, 'gaps': gaps, 'identity': identity, 'positive': positive } blast[numberQuery][id] = Hit(id, queryDef, scores, qSeq, hSeq, mSeq, hSeqLen) count += 1 log.info(str(len(blast)) + ' sequences was submited') log.info(str(count) + ' sequences in total')
def seqUniprot(self): """ get sequence from Uniprot database """ if self.accession == "": log.info('no sequence because no accession code for ' + self.id) return "" queryURL = "https://www.ebi.ac.uk/proteins/api/proteins?offset=0&size=-1&accession=" + self.accession r = requests.get(queryURL, headers={"Accept": "text/x-fasta"}) if not r.ok: try: r.raise_for_status() except requests.exceptions.HTTPError as e: log.critical(str(e) + " with id " + self.id) log.warning("error to download the sequence from uniprot") self.sequence = "" else: self.sequence = "".join(r.text.split("\n")[1:])
def getXPaths(self, url, filename): if not self.subSystem._setupScrap(): logger.critical(f"driver setup failed") self.subSystem.driver.get(url) #self.subSystem.driver.mana manage().timeouts().implicitlyWait(10) try: WebDriverWait(self.subSystem.driver, 10).until( EC.presence_of_all_elements_located((By.CSS_SELECTOR, '*'))) except: print("webwait failed") #time.sleep(5) '''EC.element_to_be_clickable((By.CLASS_NAME, 'playButton')) self.subSystem.driver.find_element(By.CLASS_NAME,"ule-onboarding-continue-button").click() self.subSystem.driver.find_element(By.CLASS_NAME,"playButton").click()''' elements = self.subSystem.driver.find_elements(By.TAG_NAME, 'html') tags = [] self.subSystem.driver.implicitly_wait(0.00001) self.subSystem.paths = [] #self.subSystem.index = 0 self.subSystem.paths.append('/html') self.trigger = True for x in elements: #print(x.get_attribute("innerHTML")) subElems = x.find_elements_by_xpath(".//*") self.elemSize = len(subElems) print(f'Final Total: {self.xPath(subElems,"/html", 1)}') allpaths = "" for x in self.subSystem.paths: #print(x) #x = x.replace('[1]', '') #print(x) allpaths += f"\n{x}" file = open(filename + ".txt", 'w') file.write(allpaths) file.close() return self.subSystem.paths
def accEnsembl(self): """ Get accession from Ensemble ID to Uniprot """ url = 'https://www.uniprot.org/uploadlists/' params = {'from': 'ENSEMBL_ID', 'to': 'ACC', 'format': 'tab', 'query': self.id} data = urllib.parse.urlencode(params) data = data.encode('utf-8') req = urllib.request.Request(url, data) essai = 1 #request API Uniprot while True: try: response = urllib.request.urlopen(req).read() break except urllib.error.HTTPError as e: if e.code == 503 and essai < 5: log.info('Error 503, renew in 10 secondes') time.sleep(5) essai += 1 pass elif e.code == 400 and essai < 5: log.critical('Error 400 with ' + url + str(urllib.parse.urlencode(params))) time.sleep(5) essai += 1 elif essai > 5: log.warning('Error ' + str(e.code)) break else: log.debug(e.code) essai += 1 accList = re.findall('[0-9A-Z]+',response.decode('utf-8')) #Verification of good request if len(accList[-1]) >= 5: self.accession = accList[-1] elif len(accList) == 2: #maybe no have accession found self.accession = "" log.warning("no accession uniprot found with id " + self.id) else: log.critical("unknow error with id " + self.id)
from flask import Flask from src.logger import logger from src.connectors.redis_helper import RedisHelper from src.thread_pool import ThreadPoolExecutorStackTraced app = Flask(__name__) CACHE = RedisHelper().create_client() # ANA_CACHE = RedisHelper().create_ana_client() DB_CONNECTION = os.environ.get("DB_CONNECTION") or "mongodb://localhost:27027/anachatdb" MONGO_CLIENT = MongoClient(DB_CONNECTION) MessageHandlerPool = ThreadPoolExecutorStackTraced(max_workers=20) EventLogPool = ThreadPoolExecutorStackTraced(max_workers=2) try: MONGO_CLIENT.server_info() DB = MONGO_CLIENT["anachatdb"] logger.info("Connected to anachatdb") except pymongo.errors.ServerSelectionTimeoutError as err: logger.error(f"Error connecting to mongodb {err}") raise except: logger.critical("Server could not start.\n Unexpected error occured") raise