BLAST result-like character string display

As a test. A method for when you want to display multiple strings of the same length side by side. Output similar to the result of BLAST etc.

from math import ceil
 
hoge = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
fuga = "abcdefghijklmnopqrstuvwxyz"

def multi_line(str_list, col_length):
    # str_The length of the character string in list is the same
    for k in range(int(ceil((float(len(str_list[0])))/col_length))):
        e = (k + 1)*col_length if (k+1)*col_length < len(str_list[0]) else len(str_list[0])
        for s in str_list:
            print s[k*col_length:e]
        print "\n"

multi_line([hoge, fuga], 13)
# This will produce:
# ABCDEFGHIJKLM
# abcdefghijklm
#
# NOPQRSTUVWXYZ
# nopqrstuvwxyz
#

Recommended Posts

BLAST result-like character string display
Character range / character string range
Various character string operations
Date and time ⇔ character string
Python learning basics ~ How to output (display) a character string? ~
Python f character (formatted string)
Is it a character string operation?
Display character area from pdf pdf2xml-viewer