def loadProps(path): props = Properties() try: propReader = FileReader(path) props.load(propReader) propReader.close() except: type, value, traceback = sys.exc_info() print "Error loading properties from file:" + path + ":" + ` value ` return props
def _parse_and_rewrite_svg_file(svg_input_path, svg_output_path): write_str = "" file_reader = FileReader(svg_input_path) buffered_reader = BufferedReader(file_reader) read_line = "" check = False while True: read_line = buffered_reader.readLine() if read_line is None: break if "viewBox" in read_line: view_box_content = _get_viewbox_content(read_line) view_box_values = _get_viewbox_values(view_box_content) if view_box_values[0] != 0: view_box_values[2] = abs(view_box_values[2]) + abs( view_box_values[0]) view_box_values[0] = 0 if view_box_values[1] != 0: view_box_values[3] = abs(view_box_values[3]) + abs( view_box_values[1]) view_box_values[1] = 0 read_line = re.sub(r"viewBox=\"[\-|0-9| ]+\"", "", read_line, 1) read_line = re.sub(r"width=\"[0-9]+\"", "width=\"" + str(view_box_values[2]) + "\"", read_line, 1) read_line = re.sub(r"height=\"[0-9]+\"", "height=\"" + str(view_box_values[3]) + "\"", read_line, 1) check = True if "g id=\"ID" in read_line and not check: if "transform=" in read_line: _log.info(read_line) read_line = read_line[0:read_line.find("transform")] + ">" check = True write_str += read_line + "\n" buffered_reader.close() file_reader.close() file_writer = PrintWriter(svg_output_path) file_writer.print(write_str) file_writer.close()
def assign_ids_from_list(tax, filename): count = 0 if True: infile = FileReader(filename) r = CSVReader(infile) while True: row = r.readNext() if row == None: break [qid, ids] = row taxon = tax.lookupQid(QualifiedId(qid)) if taxon != None: for id in ids.split(';'): z = tax.lookupId(id) if z == None: taxon.taxonomy.addId(taxon, id) count += 1 infile.close() print '| Assigned %s ids from %s' % (count, filename)
def _parse_and_rewrite_svg_file(svg_input_path, svg_output_path): write_str = "" file_reader = FileReader(svg_input_path) buffered_reader = BufferedReader(file_reader) read_line = "" check = False while True: read_line = buffered_reader.readLine() if read_line is None: break if "viewBox" in read_line: view_box_content = _get_viewbox_content(read_line) view_box_values = _get_viewbox_values(view_box_content) if view_box_values[0] != 0: view_box_values[2] = abs(view_box_values[2]) + abs(view_box_values[0]) view_box_values[0] = 0 if view_box_values[1] != 0: view_box_values[3] = abs(view_box_values[3]) + abs(view_box_values[1]) view_box_values[1] = 0 read_line = re.sub(r"viewBox=\"[\-|0-9| ]+\"", "", read_line, 1) read_line = re.sub(r"width=\"[0-9]+\"", "width=\""+ str(view_box_values[2]) + "\"", read_line, 1) read_line = re.sub(r"height=\"[0-9]+\"", "height=\""+ str(view_box_values[3]) + "\"", read_line, 1) check = True if "g id=\"ID" in read_line and not check: if "transform=" in read_line: _log.info(read_line) read_line = read_line[0:read_line.find("transform")] + ">" check = True write_str += read_line + "\n" buffered_reader.close() file_reader.close() file_writer = PrintWriter(svg_output_path) file_writer.print(write_str) file_writer.close()
def _parse_and_rewrite_svg_file(svg_input_path, svg_output_path): write_str = "" file_reader = FileReader(svg_input_path) buffered_reader = BufferedReader(file_reader) read_line = "" while True: read_line = buffered_reader.readLine() if read_line is None: break if "viewBox" in read_line: view_box_content = _get_viewbox_content(read_line) view_box_values = _get_viewbox_values(view_box_content) if view_box_values[0] != 0: view_box_values[2] += view_box_values[0] view_box_values[0] = 0 if view_box_values[1] != 0: view_box_values[3] += view_box_values[1] view_box_values[1] = 0 new_view_box = str(view_box_values[0]) + " " + str(view_box_values[1]) + " " + \ str(view_box_values[2]) + " " + str(view_box_values[3]) read_line = re.sub(r"viewBox=\"[\-|0-9| ]+\"", "viewBox=\"" + new_view_box + "\"", read_line, 1) read_line = re.sub(r"width=\"[0-9]+\"", "width=\""+ str(view_box_values[2]) + "\"", read_line, 1) read_line = re.sub(r"height=\"[0-9]+\"", "height=\""+ str(view_box_values[3]) + "\"", read_line, 1) write_str += read_line + "\n" buffered_reader.close() file_reader.close() file_writer = PrintWriter(svg_output_path) file_writer.print(write_str) file_writer.close()
def retain_ids_from_list(tax, filename): count = 0 change_count = 0 infile = FileReader(filename) r = CSVReader(infile) while True: row = r.readNext() if row == None: break [qid_string, ids] = row tracep = (qid_string == 'ncbi:33543' or qid_string == 'gbif:2433391' or qid_string == 'gbif:2467506' or qid_string == 'ncbi:28376') if tracep: print '# Tracing %s %s' % (qid_string, ids) qid = QualifiedId(qid_string) taxon = tax.lookupQid(qid) if taxon != None: id_list = ids.split(';') qid_id = id_list[0] if tracep == False: tracep = (qid_id == '565578' or qid_id == '5541322') if tracep: print '# qid %s, id_list %s' % (qid, id_list) # Look for collision tenant = tax.lookupId(qid_id) if tenant != None: # qid_id is unavailable # Happens 7700 or so times; most cases ought to be homonymized, # but not all if tracep: print '# %s (for %s) is in use by %s' % (qid_id, taxon, tenant) False # Qid from list is one of the taxon's qids. # Use the proposed id if the qid's node has no id elif taxon.id == None: # Happens 87854 for OTT 3.0 if tracep: print '# Setting %s as id of %s' % (qid_id, taxon) taxon.setId(qid_id) # Deal with aliases for id in id_list[1:]: if tax.lookupId(id) == None: if tracep: print '# adding %s as id for %s' % (id, taxon) tax.addId(taxon, id) else: if tracep: print '# alias %s (for %s) is in use by %s' % ( id, taxon, tax.lookupId(id)) count += 1 # If it has an id, but qid is not the primary qid, skip it elif taxon.sourceIds != None and taxon.sourceIds[0] != qid: if tracep: print '# %s is minor for %s' % (qid_id, taxon) False # Use the id in the id_list if it's smaller than the one in taxon elif int(qid_id) < int(taxon.id): if tracep: print '# %s is replacing %s as the id of %s' % ( qid_id, taxon.id, taxon) taxon.setId(qid_id) for id in id_list[1:]: if tax.lookupId(id) == None: tax.addId(taxon, id) change_count += 1 else: if tracep: print '# %s has id %s < %s' % (qid, qid_id, taxon) else: if tracep: print '# no taxon with qid %s; ids %s' % (qid, ids) infile.close() print '| Assigned %s ids, changed %s ids from %s' % (count, change_count, filename)
from java.io import FileWriter from java.io import File from java.io import FileReader f1 = File("file2.txt") fr = FileReader(f1) f2 = File("file3.txt") fw = FileWriter(f2) while True: ch = fr.read() if ch != -1: fw.write(ch) else: break fr.close() fw.close()
if line[:eqPos] == 'passwd': passwd = line[eqPos+1:].strip() if line[:eqPos] == 'fromQuery': fromQuery = line[eqPos+1:].strip() if line[:eqPos] == 'toQuery': toQuery = re.sub(r'\/\w+?\/', r'%s', line[eqPos+1:]).strip() file.close() else: inform('configuration file (config.ini) is missing') sys.exit() inform('getting database connection') dbHandler = MySQLAccess(url, user, passwd, toQuery) db = dbHandler.connect() arffFile = FileReader(TrainData) data = Instances(arffFile) data.setClassIndex(data.numAttributes() - 1) arffFile.close() arffFileNum = FileReader(TrainDataNum) dataNum = Instances(arffFileNum) dataNum.setClassIndex(dataNum.numAttributes() - 1) arffFileNum.close() if not Path.isfile(model): inform('training J48') j48 = J48() j48.setOptions('-R -N 3 -Q 1 -M 2'.split()) # reduced error pruning, use j48.setOptions('-C 0.1 -M 2'.split()) for confidence interval pruning j48.buildClassifier(data) serialize.write(model, j48) inform('saved model to '+model) else: inform('import '+model)