Best Python code snippet using slash
MOLITOR_MOROFF_nussinov_predictor.py
Source:MOLITOR_MOROFF_nussinov_predictor.py  
...103            # Finally, find maximum104            value = max(opt1, opt2, opt3, opt4)105            mat[row][column + row] = value106    return mat107def create_traceback(matrix, row=0, column=0):108    """Generates a traceback of the Nussinov algorithm109    :param list matrix: list of list filled by fill_matrix110    :param int row: Index in which row the traceback currently is111    :param int column: Index in which column the traceback currently is112    :return list alignment: list of tuples of all bonds113    """114    # Initialisations115    alignment = []116    done = False117    # Traceback118    while matrix[row][column] != 0: # As long as there is atleast one more bond <--> value != 0119        if matrix[row][column] == matrix[row][column - 1]: # If the value left to it is the same move there120            column = column - 1121        elif matrix[row][column] == matrix[row + 1][column]: # If the value below is the same move there122            row = row + 1123        # Check for a bond and move diagonally down-left...124        elif matrix[row][column] == matrix[row + 1][column - 1] + score_au or matrix[row][column] == matrix[row + 1][125            column - 1] + score_gc or matrix[row][column] == matrix[row + 1][column - 1] + score_gu:126            alignment.append((row + 1, column + 1)) # ...add bond to alignment list127            row = row + 1128            column = column - 1129        # If there were two sub-structures continue the traceback of these two substructures130        else:131            for k in range(row + 1, column - 1):132                if matrix[row][column] == matrix[row][k] + matrix[k + 1][column] and not done:133                    alignment += create_traceback(matrix, row=row, column=k)134                    alignment += create_traceback(matrix, row=k + 1, column=column)135                    return alignment136    return alignment137def write_file(alignment, file_name, min_l, gc, au, gu, matrix, seq):138    """Write Output file in a .txt-format139    :param list alignment: list of tuples of the coordinates of bonds140    :param string file_name: Original file name141    :param int min_l: minimum number of residues in loop142    :param int gc: value of gc bonds, for unmodified Nussinov set to 1143    :param int au: value of au bonds, for unmodified Nussinov set to 1144    :param int gu: value of gu bonds, for unmodified Nussinov set to 1145    :param list matrix: List of list which is used as a matrix for Nussinov146    :param str seq: Original RNA sequence147    """148    with open("OutPut.txt", 'a') as file:149        dot_bracket = ""150        file.writelines("Filename: {}\n".format(file_name))151        file.writelines("Min-loop: {}\n".format(min_l))152        file.writelines("GC: {}\n".format(gc))153        file.writelines("AU: {}\n".format(au))154        file.writelines("GU: {}\n".format(gu))155        file.writelines("score: {}\n".format(matrix[0][-1]))156        for i in range(0, len(seq)):157            match = False158            for j in alignment:159                if j[0] == i + 1:160                    dot_bracket = dot_bracket + "("161                    file.writelines(str(j[0]) + "\t" + seq[i] + "\t" + str(j[1]) + "\n")162                    match = True163                elif j[1] == i + 1:164                    dot_bracket = dot_bracket + ")"165                    file.writelines(str(j[1]) + "\t" + seq[i] + "\t" + str(j[0]) + "\n")166                    match = True167            if not match:168                file.writelines(str(i + 1) + "\t" + seq[i] + "\t" + "0" + "\n")169                dot_bracket = dot_bracket + "."170        file.writelines(dot_bracket)171def print_matrix(sequences, matrix):172    """Prints matrix into command line173    :param str sequences: Original RNA sequence174    :param list matrix: List of list --> Nussinov matrix175    """176    first_line = ""177    for i in sequences:178        first_line += "\t" + i179    print(first_line)180    for val, i in enumerate(matrix):181        row = sequences[val]182        for j in i:183            row += "\t" + str(j)184        row += "\n"185        print(row)186#Basic main function187if __name__ == '__main__':188    path, min_loop_len, score_gc, score_au, score_gu = read_data_in()189    headers, sequences = read_fasta(path)190    mst = fill_matrix(sequences[0], min_loop_len, score_gc, score_au, score_gu)191    alignment = create_traceback(mst, column=len(sequences[0]) - 1)192    write_file(alignment, path, min_loop_len, score_gc, score_au, score_gu, mst, sequences[0])...profiler.py
Source:profiler.py  
...48                res = '\n'.join(r[0] for r in cursor.fetchall())49            else:50                res = '(cost=0 rows=0 width=0)\n'51            return res52    def create_traceback(self, request, callback, tracebacks, queries):53        if hasattr(callback, 'cls'):54            view_name = str(callback.cls)55        else:56            view_name = str(callback)57        path = request.build_absolute_uri()58        http_method = request.method59        for tb, q in zip(tracebacks, queries):60            q['traceback'] = tb61            explain = self.get_sql_explaination(q['sql'])62            result = sql_expain_re.search(explain.split('\n')[0])63            q['explain'] = explain64            q['explain_cost'] = result.group("cost")65            q['explain_rows'] = result.group("rows")66            q['explain_width'] = result.group("width")67        total_duration = sum(float(q['time']) for q in queries) * 100068        request_data = {69            'view_name': view_name,70            'path': path,71            'http_method': http_method,72            'total_time': total_duration,73            'total_queries': len(queries),74            'paths': json.dumps(sys.path[1:]),75            'queries': queries,76        }77        self.data = request_data78    def process_request(self, request):79        if 'api' in request.path:80            self.prof = cProfile.Profile()81    def process_view(self, request, callback, callback_args, callback_kwargs):82        if 'api' in request.path:83            logger = TracebackLogger()84            self.prof.enable()85            with connection.execute_wrapper(logger):86                response = self.prof.runcall(87                    callback,88                    request,89                    *callback_args,90                    **callback_kwargs91                )92            self.prof.disable()93            queries = connection.queries.copy()94            self.create_traceback(95                request,96                callback,97                logger.tracebacks,98                queries99            )100            return response101    def process_response(self, request, response):102        if 'api' in request.path:103            try:104                self.prof.disable()105                out = StringIO()106                old_stdout = sys.stdout107                sys.stdout = out108                stats = pstats.Stats(self.prof, stream=out)...errors.py
Source:errors.py  
...21class RTError(Error):22    def __init__(self, details, pos_start, pos_end, context):23        super().__init__(":××ש××× ×צ××¨× ×××× ××××ש ת×רק", details, pos_start, pos_end)24        self.context = context25    def create_traceback(self):26        result = ''27        pos= self.pos_start28        context = self.context29        30        while context:31            result = f'.{context.dis_name} :× .{str(pos.line + 1)} :×ר××©× {pos.file_name} :×¥×××§× ××\n' + result32            pos = context.parent_position33            context = context.parent34        return ':×¢××¨× ×ר××× ×××  ×××× ×××¨×§× ×××ר××\n\n' + result35 36    def __repr__(self):37        res = self.create_traceback()38        res += f'{self.error_title}\n'39        res += f'{self.details}\n'...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
