Exemplo n.º 1
0
def multi_draw(g_pairs, segdata_list, mapfile, idpt, fct_flags, fct_colors, min_size):
    """Draw multiple alignment map with similarity shading."""
    print "Lookin\' good!"
    # compile info
    lengths = [g_pairs[0][0].len+g_pairs[0][0].nudge]
    g_to_draw = [g_pairs[0][0]]
    for ref, query in g_pairs:
        lengths.append(query.len+query.nudge)
        g_to_draw.append(query)
    max_len = max(lengths)
    # calculate main canvas dimensions - horizontal
    if max_len*u < 2000:
        seq_len = 2000
    else:
        seq_len = max_len*u
    hCan = hmar*4 + pNsize + seq_len
    # calculate main canvas dimensions - vertical
    vCan = dBL*len(g_pairs) + vmar*4
    transX = hmar + pNsize
    transY = dBL*len(g_pairs)
    init_Y = vmar*2
    # set up main canvas
    m_canvas = canvasser(hCan, vCan, transX, transY, mapfile)
    # draw scale (max_len*u)-pNsize, hmar
    seq_scale(m_canvas, 2*hCan/3, -vmar*2, incrT, incrN, dip, dop)
    # draw shading legend
    heatkey(m_canvas, hCan-hmar*5, init_Y+vmar, idpt)
    # draw ref baseline and features
    counter = 0
    for genome in g_to_draw:
        g_record = load_genbank(genome.gbk)
        g_feat = g_record.features
        g_cds = [feature for feature in g_feat
                   if feature.type == 'CDS' or feature.type == 'cds']
        ref_Y = init_Y-dBL*counter
        base_draw(m_canvas, genome, g_cds, '', doLup, ref_Y, 0, 'n', 0,
                  seq_len, 'n', 'n', fct_flags, fct_colors)
        counter +=1
    counter = 0
    for ref, query in g_pairs:
        ref_Y = init_Y-dBL*counter
        query_Y = init_Y-dBL*(counter+1)
        # draw pairwise similarity shading
        try:                                  # TODO: adapt Y
            for xa, xb, xc, xd, idp in segdata_list[counter]:
                # evaluate color shading category
                sh_color = HexColor(simcolor(idp, idpt))
                # check for split
                if abs(xa) > abs(xb) or abs(xc) > abs(xd):
                    new_segpairs = shade_split(xa, xb, xc, xd, ref, query)
                    for xa1, xb1, xc1, xd1 in new_segpairs:
                        # draw shading
                        shadowfax(m_canvas, xa1, xb1, xc1, xd1, ref_Y,
                                  query_Y, sh_color, min_size)
                else:
                    # draw shading
                    shadowfax(m_canvas, xa, xb, xc, xd, ref_Y, query_Y,
                              sh_color, min_size)
            counter +=1
        except TypeError:
            pass
    # write to file and finalize the figure
    m_canvas.showPage()
    m_canvas.save()
Exemplo n.º 2
0
def pairwise_draw(ref, query, segs, map_file, mode1, mode2, annot_mode,
                  key1, key2, idpt, fct_flags, fct_colors, min_size):
    """Draw pairwise alignment map with similarity shading."""
    # load ref record
    ref_record = load_genbank(ref.gbk)
    ref_feat = ref_record.features
    ref_cds = [feature for feature in ref_feat
               if feature.type == 'CDS' or feature.type == 'cds']
    if annot_mode != 'all':
        try:
            ref_annot_cds = [1 for cds in ref_cds
                             if cds.qualifiers.get(key1)[0] !=
                                'hypothetical protein' and \
                                cds.qualifiers.get(key1)[0] !=
                                'no match']
        except TypeError:
            ref_annot_cds = []
        ref_annot_cnt = sum(ref_annot_cds)
    else:
        ref_annot_cnt = len(ref_cds)
    # load query record
    query_record = load_genbank(query.gbk)
    if query.invert:
        query_record = query_record.reverse_complement()
    q_feat = query_record.features
    query_cds = [feature for feature in q_feat
                 if feature.type == 'CDS' or feature.type == 'cds']
    if annot_mode != 'all':
        try:
            query_annot_cds = [1 for cds in query_cds
                               if cds.qualifiers.get(key2)[0] !=
                                'hypothetical protein' and \
                                cds.qualifiers.get(key2)[0] !=
                                'no match']
        except TypeError:
            query_annot_cds = []
        query_annot_cnt = sum(query_annot_cds)
    else:
        query_annot_cnt = len(query_cds)
    # calculate main canvas dimensions - horizontal
    if ref.len+ref.nudge > query.len:
        ctg_len = ref.len+ref.nudge
    else:
        ctg_len = query.len
    if ctg_len*u < 2000:
        seq_len = 2000
    else:
        seq_len = ctg_len*u
    hCan = hmar*2 + pNsize + seq_len
    # calculate main canvas dimensions - vertical
    if mode1 == 'single' and mode2 == 'n':
        annot_cnt = ref_annot_cnt
        annot_len = annot_cnt/2
    else:
        annot_cnt = max(ref_annot_cnt, query_annot_cnt)
        annot_len = annot_cnt
    vCan = dBL + vmar*6 + annot_len*ck_vsp
    transX = hmar + pNsize
    transY = dBL + vmar*1.8 + annot_len*ck_vsp
    ref_Y = vmar*2.8
    query_Y = vmar
    # set up main canvas
    m_canvas = canvasser(hCan, vCan, transX, transY, map_file)
    # draw scale
    seq_scale(m_canvas, (ctg_len*u)-pNsize, 0, incrT, incrN, dip, dop )
    # draw shading legend
    heatkey(m_canvas, -pNsize, -pNsize/2, idpt)
    # draw ref baseline and features
    base_draw(m_canvas, ref, ref_feat, key1, doLup, ref_Y, 0,
              mode1, annot_cnt, seq_len, annot_mode, 'top', fct_flags, fct_colors)
    # draw query baseline and features
    base_draw(m_canvas, query, q_feat, key2, -doLdn, query_Y, seq_len/2,
              mode2, annot_cnt, seq_len, annot_mode, 'low', fct_flags, fct_colors)
    # draw pairwise similarity shading
    try:
        for xa, xb, xc, xd, idp in segs:
            # evaluate color shading category
            sh_color = HexColor(simcolor(idp, idpt))
            # check for split
            if abs(xa) > abs(xb) or abs(xc) > abs(xd):
                new_segpairs = shade_split(xa, xb, xc, xd, ref, query)
                for xa1, xb1, xc1, xd1 in new_segpairs:
                    # draw shading
                    shadowfax(m_canvas, xa1, xb1, xc1, xd1, ref_Y, query_Y, sh_color, min_size)
            else:
                # draw shading
                shadowfax(m_canvas, xa, xb, xc, xd, ref_Y, query_Y, sh_color, min_size)
    except TypeError:
        raise
    # write to file and finalize the figure
    m_canvas.showPage()
    m_canvas.save()