Created
January 9, 2020 17:26
-
-
Save kylebarlow/1579edd50fc2bb86a3c369cdad626457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_weblogo(input_seqs, title, resolution, file_format = 'png', add_n = True, labels = None): | |
seqs = weblogo.seq.SeqList( alphabet = weblogo.seq.unambiguous_protein_alphabet ) | |
seq_len = None | |
for seq in input_seqs: if seq_len == None: seq_len = len(seq) else: assert( seq_len == len(seq) ) seqs.append(seq) data = weblogo.LogoData.from_seqs(seqs) options = weblogo.LogoOptions() if add_n: | |
options.logo_title = '%s (n=%d)' % (title, len(input_seqs)) | |
else: | |
options.logo_title = title | |
if labels != None: | |
if len(labels) != seq_len: | |
print( len(labels), seq_len ) | |
options.annotate = labels | |
options.show_fineprint = False | |
# options.annotate = wt_seq | |
# options.unit_name = 'probability' | |
options.number_fontsize = 2.4 | |
# options.show_yaxis = False | |
options.fontsize = 2 | |
options.logo_margin = 5 | |
options.show_boxes = False | |
options.stack_width = 100 | |
options.small_fontsize = 28 | |
options.fontsize = 20 | |
options.title_fontsize = 30 | |
options.number_fontsize = 21 | |
options.color_scheme = weblogo.std_color_schemes['chemistry'] | |
#options.stack_height = 200 | |
# options.shrink_fraction = False | |
options.resolution = resolution | |
if file_format == 'png': | |
return weblogo.png_formatter( data, weblogo.LogoFormat(data, options) ) | |
elif file_format == 'svg': | |
return weblogo.svg_formatter( data, weblogo.LogoFormat(data, options) ) | |
else: | |
raise Exception('Bad file format') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment