#!/usr/bin/python ################################################################# # # # MAD MAPPING PROGRAM # # PART 3 ( VISUALIZATION ) # # # # COPYRIGHT 2004 # # Alexander Kozik # # # # http://www.atgc.org/ # # # # UCD Genome Center. R.Michelmore group # # # ################################################################# ################################################################# # +-------+ # # | BIT | # # SCORING SYSTEM: | | # # | REC | # # +-------+ # # # # . +-------+-------+-------+-------+-------+-------+ # # . | | | | | | | # # . | A | B | C | D | H | - | # # .| | | | | | | # # +-------*-------+-------+-------+-------+-------+-------+ # # | | . 6 | -6 | -4 | 4 | -2 | 0 | # # | A | | | | | | | # # | | 0 .| 1 | 1 | 0 | 0.5 | 0 | # # +-------+-------*-------+-------+-------+-------+-------+ # # | | -6 | . 6 | 4 | -4 | -2 | 0 | # # | B | | | | | | | # # | | 1 | 0 .| 0 | 1 | 0.5 | 0 | # # +-------+-------+-------*-------+-------+-------+-------+ # # | | -4 | 4 | . 4 | -4 | 0 | 0 | # # | C | | | | | | | # # | | 1 | 0 | 0 .| 1 | 0 | 0 | # # +-------+-------+-------+-------*-------+-------+-------+ # # | | 4 | -4 | -4 | . 4 | 0 | 0 | # # | D | | | | | | | # # | | 0 | 1 | 1 | 0 .| 0 | 0 | # # +-------+-------+-------+-------+-------*-------+-------+ # # | | -2 | -2 | 0 | 0 | . 2 | 0 | # # | H | | | | | | | # # | | 0.5 | 0.5 | 0 | 0 | 0 .| 0 | # # +-------+-------+-------+-------+-------+-------*-------+ # # | | 0 | 0 | 0 | 0 | 0 | . 0 | # # | - | | | | | | | # # | | 0 | 0 | 0 | 0 | 0 | 0 .| # # +-------+-------+-------+-------+-------+-------+-------*. # # # # # # NOTES: # # C - NOT A ( H or B ) # # D - NOT B ( H or A ) # # H - A and B # # # ################################################################# ################################################################# # # # EXAMPLES OF SCORING: # # # # # # POSITIVE LINKAGE: # # # # AAAAAAAAAAAAAAAAAAAA BIT SCORE = 6*20 = 120 # # AAAAAAAAAAAAAAAAAAAA REC SCORE = 0 (0.0) # # .. # # AAAAAAAAAAAAAAAAAAAA BIT SCORE = 6*18 - 6*2 = 96 # # AAAAAAAAAAAAAAAAAABB REC SCORE = 2 (2/20 = 0.1) # # # # AAAAAAAAAABBBBBBBBBB BIT SCORE = 6*10 + 6*10 = 120 # # AAAAAAAAAABBBBBBBBBB REC SCORE = 0 (0.0) # # .. # # AAAAAAAAABABBBBBBBBB BIT SCORE = 6*18 - 6*2 = 96 # # AAAAAAAAAABBBBBBBBBB REC SCORE = 2 (2/20 = 0.1) # # # # # # NO LINKAGE: # # .......... # # AAAAAAAAAAAAAAAAAAAA BIT SCORE = 6*10 - 6*10 = 0 # # AAAAAAAAAABBBBBBBBBB REC SCORE = 10 (10/20 = 0.5) # # . . . . . . . . . . # # BBBAABBAAAAAAABAABBB BIT SCORE = 6*10 - 6*10 = 0 # # BABBAABBABABABBBAABA REC SCORE = 10 (10/20 = 0.5) # # # # # # NEGATIVE LINKAGE: # # .................. # # AAAAAAAAAAAAAAAAAAAA BIT SCORE = 6*2 - 6*18 = -96 # # AABBBBBBBBBBBBBBBBBB REC SCORE = 18 (18/20 = 0.9) # # .................. # # ABABABABABABABABABAB BIT SCORE = 6*2 - 6*18 = -96 # # ABBABABABABABABABABA REC SCORE = 18 (18/20 = 0.9) # # # # # ################################################################# def Seqs_Matrix(in_name, list_id, out_name, column_n, diag_fill, dummy_fill, \ rgb_coeff, chick_sat, link_limit, purple_list, red_list, loc_file, data_type): print "INPUT FILE: " + in_name print "LIST ID: " + list_id print "LOC FILE: " + loc_file print "OUTPUT FILE: " + out_name print "COLUMN N: " + `column_n` print "DIAG FILL: " + `diag_fill` print "DUMMY FILL: " + dummy_fill print "RGB COEFF: " + `rgb_coeff` print "YELLOW SAT: " + `chick_sat` print "LINKG LIMIT: " + `link_limit` in_file = open(in_name, "rb") id_file = open(list_id, "rb") out_file1 = open(out_name + '.tab', "wb") out_file2 = out_name + '.large.png' id_list = [] loc_id_list = [] sorted_list = [] id_array = {} loc_id_array = {} map_array = {} sorted_array = {} matrix_array = {} frame_array = {} high_array = {} sequence_array = {} print_frame = "FALSE" ### TRY TO READ FRAME MARKERS LIST ### try: frame_file = open(purple_list) print "USING FRAME MARKERS LIST" while 1: u = frame_file.readline() if u == '': break if '\n' in u: u = u[:-1] if '\r' in u: u = u[:-1] u = u.split('\t') fm = u[1] fl = u[0] frame_array[fm] = fl print_frame = "TRUE" except: print "DID NOT FIND FILE: " + purple_list # continue print_high = "FALSE" try: high_file = open(red_list) print "USING MARKERS LIST TO HIGHLIGHT" while 1: g = high_file.readline() if g == '': break if '\n' in g: g = g[:-1] if '\r' in g: g = g[:-1] g = g.split('\t') hm = g[0] high_array[hm] = hm print_high = "TRUE" except: print "DID NOT FIND FILE: " + red_list work_with_loc = "FALSE" ### TRY TO OPEN LOC FILE ##### try: loc_file_open = open(loc_file) work_with_loc = "TRUE" except: print "DID NOT FIND FILE: " + loc_file ############################################### ### PROCESSING LOC FILE ### if work_with_loc == "TRUE": ### READ LOCUS FILE ### print "=============================================" n = 0 d = 0 l = 1 pool_AB = {} pool_A = {} pool_B = {} ratio_AB = {} init_len = 10000 duplic_id = [] while 1: t = loc_file_open.readline() if t == '': break if '\n' in t: t = t[:-1] if '\r' in t: t = t[:-1] tl = t.split('\t') curr_len = len(tl) if tl[0][0] == ";": print "=============================================" print tl print "JUNK LINE" print "=============================================" time.sleep(2) if l == 1 and curr_len >= 12 and tl[0][0] != ";": init_len = curr_len if curr_len == init_len and tl[0][0] != ";": #### id = tl[0] # if id not in id_list: try: id_test = loc_id_array[id] duplic_id.append(id) print '\n' print id + " IS DUPLICATED -=- CHECK DATA FOR DUPLICATION" d = d + 1 except: count_A = 0 count_B = 0 loc_id_array[id] = 1 loc_id_list.append(id) q = 1 while q < init_len: data_point = tl[q] if data_point == "A" or data_point == "B" or data_point == "C" \ or data_point == "D" or data_point == "H" or data_point == "-": sequence_array[id,q] = data_point if data_point == "A": count_A = count_A + 1 if data_point == "B": count_B = count_B + 1 if data_point == "C": count_B = count_B + 1 if data_point == "D": count_A = count_A + 1 else: print '\n' print "WRONG DATA FORMAT" print "CHECK LINE: " + `l` + '\n' print t print "=============================================" print "VALUE: " + data_point print "=============================================" print "TERMINATED.........." print "=============================================" sys.exit() q = q + 1 sys.stdout.write(".") n = n + 1 count_ALL = count_A + count_B if count_ALL >= 20: pool_AB[id] = int(round(((count_A - count_B)*1.0/count_ALL)*100)) pool_A[id] = int(round((count_A*1.0/count_ALL)*100)) pool_B[id] = int(round((count_B*1.0/count_ALL)*100)) if count_ALL < 20: pool_AB[id] = "no_data" l = l + 1 if curr_len != init_len and l > 1: print '\n' print "WRONG NUMBER OF DATA POINTS" print "CHECK LINE: " + `l` + '\n' print t print "=============================================" print "TERMINATED.........." print "=============================================" sys.exit() print '\n' print "=============================================" print `n` + " UNIQ IDs IN THE SET FOUND" print `d` + " IDs ARE DUPLICATED" duplic_id.sort() print duplic_id print "CONTINUE ANALYSIS WITH " + `n` + " SEQUENCES OUT OF " + `n+d` print "=============================================" print "SUCCESS!!!" print "=============================================" loc_file_open.close() ### END OF LOC FILE ### ############################################### ### DRAW OR NOT TO DRAW MAP ###++> map_status = "TRUE" map_max = 0 ###############################++< font = ImageFont.load_default() ### READ SORTED IDs ### while 1: t = id_file.readline() if t == '': break if '\n' in t: t = t[:-1] if '\r' in t: t = t[:-1] t = t.split('\t') test_t = len(t) if test_t == 2: id = t[0] if test_t >= 3: id = t[1] ###### EXTRACT DATA FOR MAP ######++> try: if test_t == 2: map_array[id] = float(t[1]) if test_t >= 3: map_array[id] = float(t[2]) if map_array[id] >= map_max: map_max = map_array[id] except: map_array[id] = "NO_DATA" map_status = "FALSE" ####################################++< try: id_test = sorted_array[id] print "DUPLICATES: " + id except: sorted_array[id] = 1 sorted_list.append(id) ### READ ALL HITS FILE ### while 1: t = in_file.readline() if t == '': break if '\n' in t: t = t[:-1] if '\r' in t: t = t[:-1] t = t.split('\t') #### # if t[0] != ";" and t != "" and t[0:4] != 'name': if t[0] != ";" and t != "" and t[0:4] != 'name' and len(t) >= 3: id_a = t[0] id_b = t[1] matrix_values = t[column_n + 1] # print matrix_values # if id_a not in id_list: try: id_test = id_array[id_a] except: id_array[id_a] = 1 id_list.append(id_a) try: id_test = id_array[id_b] except: id_array[id_b] = 1 id_list.append(id_b) matrix_array[id_a,id_b] = matrix_values matrix_array[id_b,id_a] = matrix_values id_list.sort() print id_list print "------------------------------" print "FOUND " + `len(id_list)` + " UNIQ IDs IN MATRIX FILE" print "------------------------------" print sorted_list print "------------------------------" print "FOUND " + `len(sorted_list)` + " UNIQ IDs IN MAP FILE" print "------------------------------" #####################################++> print "MAX POSITION: " + `map_max` print "MAP STATUS: " + map_status #####################################++< # xn = len(id_list) xn = len(sorted_list) # size of cell in pixels c = 10 # margin ml = 75 ; # LEFT MARGIN mr = 200 ; # RIGHT MARGIN #####################################==> # INCREASE RIGHT MARGIN IN THE CASE OF MAP DRAWING m_map = 0 #####################################==< #####################################++> if map_status == "TRUE": map_unit = c*xn/map_max print "MAP UNIT: " + `map_unit` + " PIXELS" ### MARGIN FOR MAP m_map = 200 print "MARGIN FOR MAP: " + str(m_map) ab_margin = 0 if work_with_loc == "TRUE": ab_margin = 150 my_lovely_image = Image.new("RGB", ((xn*c+ml+mr+m_map), (xn*c+ml+ml+ab_margin)), (255, 255, 255)) #####################################==< draw_png = ImageDraw.Draw(my_lovely_image) q = 0 ################## BIT SCORES ####################### if data_type == "BIT": test_list = [250, 200, 150, 100, 50, 0, -50, -100, -150, -200, -250] draw_png.text([100,12],fill=(0,0,0),text=("BIT SCORE SCALE: "),font=font) for item in test_list: # print item item_value = float(item) rc = 255 # gc = int(round(item_value*rgb_coeff))*chick_sat gc = int(round(item_value)) # gc = 255 ### REVERT GREEN VALUE ### gc = 255 - gc + link_limit*2 if gc >= 255: gc = 255 if gc <= 0: gc = 0 bc = 0 if item_value <= link_limit: rc = 0 gc = 255 bc = 0 # if item_value >= 0.7: if item_value <= -50: rc = 0 gc = 255 bc = 255 if item_value <= -100: rc = 0 gc = 200 bc = 255 if item_value <= -150: rc = 0 gc = 150 bc = 255 if item_value <= -200: rc = 0 gc = 50 bc = 255 #####################################==> if item_value != -250: draw_png.rectangle([200+q*2.5*c,15,200+2.5*c+q*2.5*c,25],fill=(rc,gc,bc),outline=(0,0,0)) draw_png.text([190+q*2.5*c,28],fill=(0,0,124),text=(str(item)),font=font) if item_value == -250: draw_png.rectangle([200+q*2.5*c+30,15,200+2.5*c+q*2.5*c+30,25],fill=(82,82,82),outline=(0,0,0)) draw_png.text([190+q*2.5*c+40,28],fill=(82,82,82),text=("no data"),font=font) #####################################==< q = q+1 ####### END OF BIT SCORES ####### ################## REC SCORES ####################### if data_type == "REC": test_list = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] draw_png.text([100,12],fill=(0,0,0),text=("LINKAGE SCALE: "),font=font) for item in test_list: # print item item_value = float(item) rc = 255 gc = int(round(item_value*rgb_coeff))*chick_sat # gc = 255 if gc >= 255: gc = 255 if gc <= 0: gc = 0 bc = 0 if item_value >= link_limit: rc = 0 gc = 255 bc = 0 if item_value >= 0.6: rc = 0 gc = 255 bc = 255 if item_value >= 0.7: rc = 0 gc = 200 bc = 255 if item_value >= 0.8: rc = 0 gc = 150 bc = 255 if item_value >= 0.9: rc = 0 gc = 50 bc = 255 #####################################==> if item_value != 1.0: draw_png.rectangle([200+q*2.5*c,15,200+2.5*c+q*2.5*c,25],fill=(rc,gc,bc),outline=(0,0,0)) draw_png.text([190+q*2.5*c,28],fill=(0,0,124),text=(str(item)),font=font) if item_value == 1.0: draw_png.rectangle([200+q*2.5*c+30,15,200+2.5*c+q*2.5*c+30,25],fill=(82,82,82),outline=(0,0,0)) draw_png.text([190+q*2.5*c+40,28],fill=(82,82,82),text=("no data"),font=font) #####################################==< q = q+1 ####### END OF REC SCORES ####### ################## LOD SCORES ####################### if data_type == "LOD": test_list = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] draw_png.text([100,12],fill=(0,0,0),text=("LOD SCORE SCALE: "),font=font) for item in test_list: # print item item_value = float(item) rc = 255 # gc = int(round(item_value*rgb_coeff))*chick_sat gc = int(round(item_value*25)) ### REVERT GREEN VALUE ### gc = 255 - gc + link_limit*25 # gc = 255 if gc >= 255: gc = 255 if gc <= 0: gc = 0 bc = 0 if item_value <= link_limit: rc = 0 gc = 255 bc = 0 # if item_value >= 0.7: if item_value <= 2: rc = 0 gc = 255 bc = 255 if item_value <= 1: rc = 0 gc = 164 bc = 255 if item_value <= 0: rc = 0 gc = 82 bc = 255 #####################################==> if item_value != 0: draw_png.rectangle([200+q*2.5*c,15,200+2.5*c+q*2.5*c,25],fill=(rc,gc,bc),outline=(0,0,0)) draw_png.text([190+q*2.5*c,28],fill=(0,0,124),text=(str(item)),font=font) if item_value == 0: draw_png.rectangle([200+q*2.5*c+30,15,200+2.5*c+q*2.5*c+30,25],fill=(82,82,82),outline=(0,0,0)) draw_png.text([190+q*2.5*c+40,28],fill=(82,82,82),text=("no data"),font=font) #####################################==< q = q+1 ####### END OF LOD SCORES ####### k = 0 out_file1.write("#" + '\t') #####################################++> if map_status == "TRUE": draw_png.text([(mr+xn*c+m_map-25),(ml-c/2-25)],text=('MAP:'),font=font,fill=(0,0,124)) draw_png.line([(mr+xn*c+m_map-20),(ml-c/2),(mr+xn*c+m_map-20),(ml+map_max*map_unit+c/2)],fill=(0,0,64)) draw_png.text([(mr+xn*c+m_map-5),(ml-c/2-5)],text=('0'),font=font,fill=(0,0,124)) draw_png.text([(mr+xn*c+m_map-8),(ml+map_max*map_unit+c/2)],text=(str(round(map_max,1))),font=font,fill=(0,0,124)) #### DRAW TICKS ON MAP #### tic = 0 while tic <= map_max: draw_png.line([(mr+xn*c+m_map-18),(ml+map_unit*tic),(mr+xn*c+m_map-15),(ml+map_unit*tic)],fill=(0,0,64)) if tic != 0: draw_png.text([(mr+xn*c+m_map-8),(ml+map_unit*tic-5)],text=(`tic`),font=font,fill=(0,0,124)) tic = tic + 10 #####################################++< for id in sorted_list: #####################################==> tick_update = math.fmod(k+1,5) #####################################==< if tick_update == 0: #####################################==> draw_png.text([(ml+k*c),(ml-18)],fill=(0,0,0),text=(`k+1`),font=font) draw_png.line([ml+k*c+c/2,ml-2,ml+k*c+c/2,ml-6],fill=(0,0,0)) #####################################==< out_file1.write(sorted_list[k]) if k < xn - 1: out_file1.write('\t') if k == xn - 1: out_file1.write('\n') #####################################++> if map_status == "TRUE": draw_png.line([(ml+xn*c+m_map-195),(ml+k*c+c/2),(ml+xn*c+m_map-170),(ml+k*c+c/2)],fill=(0,0,64)) draw_png.text([(ml+xn*c+m_map-160),(ml+k*c+c/2-5)],fill=(0,0,0),text=(id),font=font) if print_frame == "TRUE": try: frame_id = frame_array[id] draw_png.text([(ml+xn*c+m_map-160),(ml+k*c+c/2-5)],fill=(255,0,255),text=(id),font=font) draw_png.text([(ml+xn*c+m_map-40),(ml+k*c+c/2-5)],fill=(255,0,255),text=(frame_id),font=font) print id + '\t' + " ++++ IT IS A FRAME MARKER ++++ " except: # continue print id + '\t' + "--- IT IS NOT A FRAME MARKER ---" if print_high == "TRUE": try: high_id = high_array[id] draw_png.text([(ml+xn*c+m_map-160),(ml+k*c+c/2-5)],fill=(255,0,0),text=(id),font=font) draw_png.text([(ml+xn*c+m_map-40),(ml+k*c+c/2-5)],fill=(255,0,0),text=("N"),font=font) print id + '\t' + "IT IS A NEW MARKER" except: print id + '\t' + "IT IS NOT A NEW MARKER" draw_png.line([(ml+xn*c+m_map-30),(ml+k*c+c/2),(ml+xn*c+m_map-10),(ml+k*c+c/2)],fill=(0,0,64)) draw_png.line([(ml+xn*c+m_map-10),(ml+k*c+c/2),(ml+xn*c+m_map+80),(ml+map_array[id]*map_unit)],fill=(0,0,64)) draw_png.line([(ml+xn*c+m_map+80),(ml+map_array[id]*map_unit),(ml+xn*c+m_map+100),(ml+map_array[id]*map_unit)],fill=(0,0,64)) #####################################++< k = k + 1 # y position on image yn = 0 for id in sorted_list: k = 0 out_file1.write(id + '\t') #####################################==> tick_update = math.fmod(yn+1,5) #####################################==< if tick_update == 0: #####################################==> draw_png.text([(ml-25),(ml+yn*c-3)],fill=(0,0,0),text=(`yn+1`),font=font) #####################################==< #####################################==> draw_png.line([ml-5,ml+yn*c+c/2,ml-2,ml+yn*c+c/2],fill=(0,0,0)) #####################################==< ######## BIT SCORE CONDITION ########### while k < xn and data_type == "BIT": idx = sorted_list[k] try: current_value = matrix_array[id,idx] image_value = current_value except: current_value = dummy_fill # image_value = 0 # Maria settings image_value = 1 # if id == idx: # current_value = diag_fill # image_value = diag_fill # text file out_file1.write(str(current_value)) if k < xn - 1: out_file1.write('\t') if k == xn - 1: out_file1.write('\n') # image processing # red green blue image_value = float(image_value) rc = 255 # JM settings gc = int(round(image_value)) # gc = 255 ### REVERT GREEN VALUE ### gc = 255 - gc + link_limit*2 if gc >= 255: gc = 255 if gc <= 0: gc = 0 bc = 0 if image_value <= link_limit: rc = 0 gc = 255 bc = 0 # if image_value >= 0.7: if image_value <= -50: rc = 0 gc = 255 bc = 255 # if image_value >= 0.8: if image_value <= -100: rc = 0 gc = 200 bc = 255 # if image_value >= 0.9: if image_value <= -150: rc = 0 gc = 150 bc = 255 if image_value <= -200: rc = 0 gc = 50 bc = 255 # dummy condition if current_value == dummy_fill: rc = 82 gc = 82 bc = 82 # draw cell draw_png.rectangle([(ml+k*c),(ml+yn*c),(ml+k*c+c),(ml+yn*c+c)],fill=(rc,gc,bc),outline=(0,0,0)) k = k + 1 ####### END OF BIT SCORE CONDITION ######## ####### REC SCORE CONDITION ######## while k < xn and data_type == "REC": idx = sorted_list[k] try: current_value = matrix_array[id,idx] image_value = current_value except: current_value = dummy_fill # image_value = 0 # Maria settings image_value = 1 if id == idx: current_value = diag_fill image_value = diag_fill # text file out_file1.write(str(current_value)) if k < xn - 1: out_file1.write('\t') if k == xn - 1: out_file1.write('\n') # image processing # red green blue image_value = float(image_value) rc = 255 # JM settings gc = int(round(image_value*rgb_coeff))*chick_sat # gc = 255 if gc >= 255: gc = 255 if gc <= 0: gc = 0 bc = 0 if image_value >= link_limit: rc = 0 gc = 255 bc = 0 if image_value >= 0.6: rc = 0 gc = 255 bc = 255 if image_value >= 0.7: rc = 0 gc = 200 bc = 255 if image_value >= 0.8: rc = 0 gc = 150 bc = 255 if image_value >= 0.9: rc = 0 gc = 50 bc = 255 # dummy condition if current_value == dummy_fill: rc = 82 gc = 82 bc = 82 # draw cell draw_png.rectangle([(ml+k*c),(ml+yn*c),(ml+k*c+c),(ml+yn*c+c)],fill=(rc,gc,bc),outline=(0,0,0)) k = k + 1 ####### END OF REC SCORE CONDITION ######## ####### LOD SCORE CONDITION ######## while k < xn and data_type == "LOD": idx = sorted_list[k] try: current_value = matrix_array[id,idx] image_value = current_value except: current_value = dummy_fill # image_value = 0 # Maria settings image_value = 1 # if id == idx: # current_value = diag_fill # image_value = diag_fill # text file out_file1.write(str(current_value)) if k < xn - 1: out_file1.write('\t') if k == xn - 1: out_file1.write('\n') # image processing # red green blue image_value = float(image_value) rc = 255 # JM settings gc = int(round(image_value*25)) ### REVERT GREEN VALUE ### gc = 255 - gc + link_limit*25 # gc = 255 if gc >= 255: gc = 255 if gc <= 0: gc = 0 bc = 0 if image_value <= link_limit: rc = 0 gc = 255 bc = 0 # if image_value >= 0.7: if image_value <= 2: rc = 0 gc = 255 bc = 255 # if image_value >= 0.8: if image_value <= 1: rc = 0 gc = 164 bc = 255 # if image_value >= 0.9: if image_value <= 0: rc = 0 gc = 82 bc = 255 # dummy condition if current_value == dummy_fill: rc = 82 gc = 82 bc = 82 # draw cell draw_png.rectangle([(ml+k*c),(ml+yn*c),(ml+k*c+c),(ml+yn*c+c)],fill=(rc,gc,bc),outline=(0,0,0)) k = k + 1 ####### END OF LOD SCORE CONDITION ######## yn = yn + 1 if work_with_loc == "TRUE": k = 0 for id in sorted_list: try: ab_value = pool_AB[id] a_value = pool_A[id] b_value = pool_B[id] ab_diff = a_value - b_value except: ab_value == "no_data" if ab_value != "no_data": if ab_value >=0: rc = 255 gc = 255 bc = 0 if ab_value < 0: rc = 0 gc = 255 bc = 255 draw_png.rectangle([(ml+k*c),(ml+yn*c+ab_margin/2+10),(ml+k*c+c),\ (ml+yn*c+ab_margin/2-a_value+10)],fill=(255,0,0),outline=(255,0,0)) draw_png.rectangle([(ml+k*c),(ml+yn*c+ab_margin/2+10),(ml+k*c+c),\ (ml+yn*c+ab_margin/2+b_value+10)],fill=(0,0,255),outline=(0,0,255)) draw_png.rectangle([(ml+k*c),(ml+yn*c+ab_margin/2+10),(ml+k*c+c),\ (ml+yn*c+ab_margin/2+10-ab_value)],fill=(rc,gc,bc),outline=(rc,gc,bc)) k = k + 1 if ab_value == "no_data": rc = 82 gc = 82 bc = 82 draw_png.rectangle([(ml+k*c),(ml+yn*c+ab_margin/2-10+10),(ml+k*c+c),\ (ml+yn*c+ab_margin/2+10+10)],fill=(rc,gc,bc),outline=(rc,gc,bc)) k = k + 1 draw_png.line([ml,(ml+yn*c+ab_margin/2+60+20),(ml+k*c),\ (ml+yn*c+ab_margin/2+60+20)],fill=(64,64,64)) draw_png.line([ml,(ml+yn*c+ab_margin/2-60),(ml+k*c),\ (ml+yn*c+ab_margin/2-60)],fill=(64,64,64)) draw_png.line([ml,(ml+yn*c+ab_margin/2-60),ml,\ (ml+yn*c+ab_margin/2+60+20)],fill=(64,64,64)) draw_png.line([(ml+k*c),(ml+yn*c+ab_margin/2-60),\ (ml+k*c),(ml+yn*c+ab_margin/2+60+20)],fill=(64,64,64)) draw_png.text([(ml+k*c+30),(ml+yn*c+ab_margin/2-20)],fill=(0,0,0),text=\ ("proportion of \"A\" alleles"),font=font) draw_png.text([(ml+k*c+30),(ml+yn*c+ab_margin/2+20)],fill=(0,0,0),text=\ ("proportion of \"B\" alleles"),font=font) draw_png.text([ml,(ml+yn*c+35+ab_margin)],fill=(0,0,0),text=("MAP: " + list_id),font=font) draw_png.text([ml+250,(ml+yn*c+35+ab_margin)],fill=(0,0,0),text=("MATRIX: " + in_name),font=font) link_limit = round(link_limit,2) link_limit = str(link_limit) draw_png.text([ml+500,(ml+yn*c+35+ab_margin)],fill=(0,0,0),text=("CUTOFF: " + link_limit),font=font) in_file.close() id_file.close() out_file1.close() print "PROCESSING LARGE SIZE" my_lovely_image.save(out_file2) ######### SCALING THE IMAGE ########### im = Image.open(out_file2) width, height = im.size print "===========================================" print "IMAGE SIZE: " + `width` + " X " + `height` print "===========================================" out_medium_name = out_name + '.medium.png' out_5000_name = out_name + '.5000.png' out_2000_name = out_name + '.2000.png' out_small_name = out_name + '.small.png' if width > 1000 and height > 750: print "PROCESSING MEDIUM SIZE" im_m = im.resize((1000,750),Image.ANTIALIAS) im_m = im_m.filter(ImageFilter.SHARPEN) im_m.save(out_medium_name, im_m.format) if width > 2000 and height > 1500: print "PROCESSING 2000 PIXELS SIZE" im_2 = im.resize((2000,1500),Image.ANTIALIAS) im_2 = im_2.filter(ImageFilter.SHARPEN) im_2.save(out_2000_name, im_2.format) if width >= 10000: print "PROCESSING 5000 PIXELS SIZE" im_5 = im.resize((5500,5000),Image.ANTIALIAS) im_5 = im_5.filter(ImageFilter.SHARPEN) im_5.save(out_5000_name, im_5.format) print "PROCESSING SMALL SIZE" im_s = im.resize((200,150),Image.ANTIALIAS) im_s = im_s.filter(ImageFilter.SHARPEN) im_s.save(out_small_name, im_s.format) ########################################### print "====================================" print " DONE! " print "====================================" import sys import math import time import Image import ImageDraw import ImageFont import ImageFilter if __name__ == "__main__": if len(sys.argv) <= 7 or len(sys.argv) > 8: print "" print "Program usage: " print "[matrix_file] [map_file] [output_file] [frame_marker_list] [red_list] [loc_file] [REC/BIT/LOD]" print "frame_marker_list is optional, if you do not have it just type X" print "red_list is a list of markers to highlight in red" print "red_list is optional, if you do not have it just type Y" print "loc_file is optional, if you do not have it just type Z" print "" sys.exit() if len(sys.argv) == 8: in_matrix = sys.argv[1] in_map = sys.argv[2] out_name = sys.argv[3] purple_list = sys.argv[4] red_list = sys.argv[5] loc_file = sys.argv[6] data_type = sys.argv[7] if data_type != "REC" and data_type != "BIT" and data_type != "LOD": print "last value must be REC or BIT or LOD" sys.exit() if data_type == "REC": column_n = 1 link_limit = 0.4 data_type = "REC" link_limit = float(link_limit) if data_type == "BIT": column_n = 2 link_limit = 50 data_type = "BIT" link_limit = int(link_limit) if data_type == "LOD": column_n = 2 link_limit = 3 data_type = "LOD" link_limit = int(link_limit) diag_fill = 0 dummy_fill = "-" # rgb_coeff and chick_sat in use only for REC scores rgb_coeff = 255 chick_sat = 4 column_n = int(column_n) rgb_coeff = float(rgb_coeff) chick_sat = int(chick_sat) # link_limit = float(link_limit) Seqs_Matrix(in_matrix, in_map, out_name, column_n, diag_fill, dummy_fill, \ rgb_coeff, chick_sat, link_limit, purple_list, red_list, loc_file, data_type) ### THE END ###