def main(app_name): app_path = join(curdir, app_name) xml_path = join(app_path, 'view.xml') views = parser.parse_xml(xml_path) try: globals.app = __import__(app_name + '.extensions', fromlist=[app_name]) except ImportError as e: stderr.write(e.message + '\n') return main_window = application.Application(views[0], views[1]) globals.views = main_window.extensions main_window.start(views[2])
def test_parser(): xml = """<root> <object> <field1>foo</field1> <field1>bar</field1> <field2>baz</field2> <field3> goat <nested1>rabbit</nested1> <nested2>llama</nested2> herd </field3> </object> <thing> <field>basic</field> </thing> </root>""" nodes = [] def emit(node, arg1, arg2): nodes.append(node) assert arg1 == 'arg1' assert arg2 == 'arg2' assert parse_xml(StringIO(xml), emit, 'arg1', 'arg2') == 2 assert len(nodes) == 2 assert nodes[0].name == 'object' assert len(nodes[0].fields) == 4 assert nodes[0].fields[0].name == 'field1' assert nodes[0].fields[0].value() == 'foo' assert nodes[0].fields[1].name == 'field1' assert nodes[0].fields[1].value() == 'bar' assert nodes[0].fields[2].name == 'field2' assert nodes[0].fields[2].value() == 'baz' assert nodes[0].fields[3].name == 'field3' assert nodes[0].fields[3].value() == 'goatherd' assert len(nodes[0].fields[3].fields) == 2 assert nodes[0].fields[3].fields[0].name == 'nested1' assert nodes[0].fields[3].fields[0].value() == 'rabbit' assert nodes[0].fields[3].fields[1].name == 'nested2' assert nodes[0].fields[3].fields[1].value() == 'llama' assert nodes[1].name == 'thing' assert len(nodes[1].fields) == 1 assert nodes[1].fields[0].name == 'field' assert nodes[1].fields[0].value() == 'basic'
def main(argv): # Get parameters from user input accountKey = argv[0] target_precision = float(argv[1]) query = argv[2].lower().split() precision = 0.0 # create a new search engine instance search_engine = search.SearchEngine(accountKey) while True: # search this query on Bing xml = search_engine.search(query) # print out search query parameters on interminal interface.print_parameters(search_engine, target_precision) # parse the xml search results to Siteinfo objects result = parser.parse_xml(xml) # if there are less than 10 results, break and quit if len(result) < 10: break # interact with user and let user mark relevence of each result array_score, precision = interface.interact(result) # if precision is 0, break and quit if precision == 0.0: print 'Below desired precision, but can no longer augment the query' break interface.print_transcript(precision, query, target_precision) # if precision is equal or larger than target precision, break and quit if precision >= target_precision: break # if precision is less than target precision, expand and reoder query and search again else: new_terms, new_query = search.query_expand(result, array_score, query) interface.print_new_terms(new_terms) if new_query == query: break else: query = new_query
#self.accountKey = 'KtKgk8Mo5p6/rJE0FnlmA8qKVi1F7kS3OQbxik1ZnCg' self.accountKey = key self.url = None self.query = None def search(self, siteUrl, query): #bingBaseUrl = 'https://api.datamarket.azure.com/Bing/Search/Web?Query=%27' bingBaseUrl = 'https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/v1/Composite?Query=%27site%3a' self.url = bingBaseUrl + siteUrl +'%20'+ '%20'.join(query) + "%27&$top=10&$format=Atom" self.query = query accountKeyEnc = base64.b64encode(self.accountKey + ':' + self.accountKey) headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Authorization': 'Basic ' + accountKeyEnc} req = urllib2.Request(self.url, headers = headers) response = urllib2.urlopen(req) return response def getKey(self): return self.accountKey def getUrl(self): return self.url def getQuery(self): return self.query if __name__ == '__main__': s = SearchEngine('KtKgk8Mo5p6/rJE0FnlmA8qKVi1F7kS3OQbxik1ZnCg') response = s.search('afifa.com',['premiership']) parser.parse_xml(response)
# concatenate faa file contents to temp.faa cat_faa_cmd = "cat faa/*.faa > faa/temp.faa" os.system(cat_faa_cmd) # make a blast db blast_cmd1 = "makeblastdb -parse_seqids -in faa/temp.faa -dbtype prot -out " + project_name os.system(blast_cmd1) blast_cmd2 = "diamond makedb -p N --in faa/temp.faa -d " + project_name os.system(blast_cmd2) # remove the concatenated fna files remove_cmd = "rm faa/temp.faa && rm faa/temp1.faa" os.system(remove_cmd) faa_list = [] for entry in os.scandir('faa'): if entry.is_file() and (entry.name[0] != ".") and (entry.name.split(".")[-1]) == "faa": faa_list.append(entry.name) for faa_file in faa_list: xml_name = "xml/" + faa_file.split(".")[0] + ".xml" tab_name = "tab/" + faa_file.split(".")[0] + ".tab" dict_name = project_name + ".dict" blast_command = "diamond blastp --max-target-seqs 0 --outfmt 5 --query-cover 90 --subject-cover 90 --query faa/" +\ faa_file + " --db " + project_name + " --out " + xml_name os.system(blast_command) parser.parse_xml(xml_name, tab_name, dict_name, pct_id) os.system("rm " + xml_name)