def run(): # получаем все чанки chunks = cutter() files = [] for chunk in chunks: files.append(synthesize('your_folder_id', iam_token, chunk)) for i, audio_file in enumerate(files): with open(f'audio_{i}.ogg', mode='w+b') as af: af.write(audio_file)
def run(self): # call parent's function to parse CL. Examine results -> fast failing for # typos in parameters etc, IOErrors. r = self.parse_cl() if r != 0: return # call parent's function to actually construct objects -> not so fast, # could be doing restraints etc. r = self.read_and_validate_inputs() if r != 0: return # Now we should have all necessary parsed objects in internal structures # like pdb_h etc print("Parsed model in form of pdb_hierarchy:", self.rmodel, file=self.log) # # So do the job like we are in pipeline # If needed, this could be wrapped in try...except to catch errors. c = cutter(self.rmodel, self.work_params.cutter, self.log) # super-fast init # validation if the work can be done. # The outcome is to be determined. c.validate_inputs() c.run( ) # actually work, may be time-consuming, maybe call-backs are needed result = c.get_results() # implementation of run() could be long and complicated, so let's do # results preparation separately, so everybody could understand what's there # at a glance. # If something is not there - go to the class and implement new function like: # extra_result_value = c.get_extra_result_value() # Or use cutting-edge technology: # inherit from cutter, overload get_results() and adjust them for your needs. # # That's it. We got result, now we just need to display it # and the job of CL-tool is over. print("Result, in form of pdb_hierarchy", result.answer, file=self.log) result.answer.write_pdb_file(file_name="%s.pdb" % self.work_params.output_prefix)
def load_data(self, use_cutter=False): ''' This method load the data into predefined data structures edges, is a list of tuples and then it is converted into edge, which is a matrix papers, a list of tuples to store all paper informations each paper in this class is assigned an index so that the matrix is easier to query ''' # edges are stored as a list of tuples, first element cites the second one # (A, B) A cites B, both A and B are integers self.edges = [] with open(self.cite_file, 'r') as f: for line in f: ll = line.split('\t') self.edges.append((int(ll[0]), int(ll[1]))) # There are 5429 edges # papers are stored as dictionary of (key, list) # key is index # for the list # first element is index, # second element is name(also in int) # third element is list of word count # fourth element is label # [A, B, C, D] where A is int, B is int, C is np.array of int, D is string self.papers = {} # name_dict is a dictionary of name to index # name_dict[name(int)] = index self.name_dict = {} with open(self.word_file, 'r') as f: for i, line in enumerate(f): ll = line.split('\t') self.papers[i] = [ i, int(ll[0]), np.array(ll[1:-1]).astype(int), ll[-1].rstrip('\n') ] self.name_dict[int(ll[0])] = i # There are 2708 papers self.num_paper = len(self.papers) # edge matrix # for [i, j] if edge[i, j] == 1 then i cites j, else i does not # i, j are index of papers self.edge = np.zeros(shape=(self.num_paper, self.num_paper)) for e in self.edges: self.edge[self.name_dict[e[0]], self.name_dict[e[1]]] = 1 # if we use cutter to create train and test if use_cutter: self.cutter = cutter.cutter(file_name=self.cite_file) # change here for the amount of nodes to be cut as test test_nodes = self.cutter.cut(start=56112, num_test=200, verbose=False) # divide all papers into two self.train_papers = {} self.test_papers = {} for p in self.papers.values(): if p[1] in test_nodes: self.test_papers[p[0]] = p else: self.train_papers[p[0]] = p self.train_edges = [] self.test_edges = [] self.train_edge = np.zeros(shape=(self.num_paper, self.num_paper)) self.test_edge = np.zeros(shape=(self.num_paper, self.num_paper)) for e in self.edges: if (e[0] in test_nodes) or (e[1] in test_nodes): self.test_edges.append(e) self.test_edge[self.name_dict[e[0]], self.name_dict[e[1]]] = 1 else: self.train_edges.append(e) self.train_edge[self.name_dict[e[0]], self.name_dict[e[1]]] = 1 else: self.train_papers = self.papers self.train_edges = self.edges self.train_edge = self.edge self.test_papers = None self.test_edges = None self.test_edge = None self.num_train_paper = len(self.train_papers)
__author__ = 'doctor' from cutter import cutter from animatornew import animatorFunc import os filelist = cutter("results.csv", 10) animatorFunc(filelist, "HeatMap") os.system("rm -f output* Heat.gif") os.system("ffmpeg -i HeatMap.avi Heat.gif")