from rpy import * ## R handles the plotting for us. All we need to do is to make the R code. ## This first function plots the overlap for all the helices in the TM bundle def Plot( table1, title1, xaxis1, yaxis1, psplotfilename, modes, bundle, suffix, names, legendposWeight=5.5): #Aug07: legendposWeight argument added to allow different placement of legend for kinkvectors(which have more text) #this could possible by calcualted from the size if names #for i in range(0, len(bundle)): # print table1[i][130] lower = 0 for i in range(0, len(bundle)): if table1[i][len(modes)-7] < len(bundle)*0.04: lower += 1 if lower < (len(bundle) / 2): x = len(modes)-(min(len(modes),len(modes)/legendposWeight))#len(modes)-(min(len(modes),len(modes)/5.5)) y = 0.036*len(bundle) else: x = 0 y = 1 if suffix == 'pdf': r.pdf(psplotfilename+suffix, horizontal=r.TRUE,height=7, width=7, pointsize=10,onefile=r.FALSE) #r.pdf(psplotfilename+suffix, horizontal=r.TRUE,height=7, width=7, pointsize=10,onefile=r.FALSE,paper='a4') #if suffix == 'png': #r.bitmap(psplotfilename+suffix, res=100 ) #r.png(psplotfilename+suffix, res=100 ) #r.jpeg(psplotfilename+suffix, horizontal=r.TRUE,height=7, width=7, pointsize=10,onefile=r.FALSE,paper='a4') r.par(mfrow=r.c(1,1)) if title1[0:2] == 'Cu': r.plot(table1[0], type='n', xlab=xaxis1, ylab=yaxis1, main=title1, ylim=r.c(0,1) ) else: r.plot(table1[0], type='n', xlab=xaxis1, ylab=yaxis1, main=title1 ) color_dict = dict() line_dict = dict() for name in names: color_dict[name] = '' line_dict[name] = '' co = [] li = [] c=1 j=1 for i in range(0,len(table1)): if ( i%7 == 0 ): j=j+1 helix_id = bundle[i] name = names[helix_id] if name != '': if color_dict[name] != '': color = color_dict[name] line = line_dict[name] else: color_dict[name] = c line_dict[name] = j color = c line = j j+=1 c+=1 else: color = c line = j j+=1 c+=1 r.lines(table1[i], col=color,type='l', lty=line, lwd=0.9) co.append(color) li.append(line) new_bundle = [] # #Aug07: #when plotting of kinvectors is done there should be no '' names #make sure that the naming convetion of helices for kinkvectors is kept consistent with this. #we might want to move all naming responsibilities out of plotR #/ for i in range(len(bundle)): helix_id = bundle[i] name = names[helix_id] if name == '': new_bundle.append('Helix ' + str(helix_id)) else: new_bundle.append('Helix ' + str(name)) r.legend(x,y, r.c(new_bundle), col=r.c(co), lty=r.c(li) ) r.dev_off() r.graphics_off() os.system('convert -size 120x120 ./'+ psplotfilename+suffix + ' ./' + psplotfilename+'png') os.system('convert ./'+ psplotfilename+'png' + ' -resize 120x120 ./' + psplotfilename+'THUMB.png') os.system('convert ./'+ psplotfilename+'THUMB.png'+ ' -sharpen 10 ./'+ psplotfilename+'THUMB.png') ## if suffix == 'pdf': ## os.system('gv '+ psplotfilename+suffix) ## if suffix == 'png': ## os.system('display '+ psplotfilename+suffix) return def sort_by_value(d): """ Returns the keys of dictionary d sorted by their values """ items=d.items() backitems=[ [v[1],v[0]] for v in items] backitems.sort() backitems.reverse() return [ int(backitems[i][1]) for i in range(0,len(backitems)) ] ## This function plots the overlap for the movement of the bundle. def Plot2(table1, title1, xaxis1, yaxis1, psplotfilename, modes, suffix): import operator best_mode = 0 sec_mode = 0 third_mode = 0 new_table = [] for key in range(len(table1)): value = table1[key] new_table.append( (value[1], key) ) new_table.sort() #print new_table best_mode = new_table[len(new_table)-1][1] sec_mode = new_table[len(new_table)-2][1] third_mode = new_table[len(new_table)-3][1] value_1 = table1[best_mode][1] value_2 = table1[sec_mode][1] value_3 = table1[third_mode][1] #print best_mode #print sec_mode #print third_mode if suffix == 'pdf': r.pdf(psplotfilename+suffix, horizontal=r.TRUE,height=7, width=7, pointsize=10,onefile=r.FALSE) #r.pdf(psplotfilename+suffix, horizontal=r.TRUE,height=7, width=7, pointsize=10,onefile=r.FALSE,paper='a4') #if suffix == 'png': # r.bitmap(psplotfilename+suffix, res=100 ) #r.bitmap(psplotfilename, res=100 ) #r.pdf(psplotfilename, horizontal=r.TRUE,onefile=r.TRUE,paper='a4') r.par(mfrow=r.c(1,1)) r.plot(table1, type='l', xlab=xaxis1, ylab=yaxis1, main=title1 ) r.text(best_mode+len(table1)/10, value_1, ' <-- mode ' + str(best_mode+1)) r.text(sec_mode+len(table1)/10, value_2, ' <-- mode ' + str(sec_mode+1)) r.text(third_mode+len(table1)/10, value_3, ' <-- mode ' + str(third_mode+1)) #r.plot(best_mode, value_1, pch="+") #r.plot(sec_mode, value_2, pch="+") r.dev_off() r.graphics_off() #if suffix == 'png': # os.system('convert ./'+ psplotfilename+suffix + ' -resize 120x120 ./' + psplotfilename+'THUMB.'+suffix) # os.system('convert ./'+ psplotfilename+'THUMB.'+suffix + ' -sharpen 10 ./'+ psplotfilename+'THUMB.'+suffix) os.system('convert -size 120x120 ./'+ psplotfilename+suffix + ' ./' + psplotfilename+'png') os.system('convert ./'+ psplotfilename+'png' + ' -resize 120x120 ./' + psplotfilename+'THUMB.png') os.system('convert ./'+ psplotfilename+'THUMB.png'+ ' -sharpen 10 ./'+ psplotfilename+'THUMB.png') return ## cumulative bundle rotation def Plot3(table1, title1, xaxis1, yaxis1, psplotfilename, modes, suffix): if suffix == 'pdf': r.pdf(psplotfilename+suffix, horizontal=r.TRUE,height=7, width=7, pointsize=10,onefile=r.FALSE) #r.pdf(psplotfilename+suffix, horizontal=r.TRUE,height=7, width=7, pointsize=10,onefile=r.FALSE,paper='a4') if suffix == 'png': r.bitmap(psplotfilename+suffix, res=100 ) #r.bitmap(psplotfilename, res=100 ) #r.pdf(psplotfilename, horizontal=r.TRUE,onefile=r.TRUE,paper='a4') r.par(mfrow=r.c(1,1)) r.plot(table1, type='l', xlab=xaxis1, ylab=yaxis1, main=title1, ylim=r.c(0,1) ) r.dev_off() r.graphics_off() #if suffix == 'png': # os.system('convert ./'+ psplotfilename+suffix + ' -resize 120x120 ./' + psplotfilename+ 'THUMB.'+suffix) # os.system('convert ./'+ psplotfilename+'THUMB.'+suffix + ' -sharpen 10 ./'+ psplotfilename+'THUMB.'+suffix) os.system('convert -size 120x120 ./'+ psplotfilename+suffix + ' ./' + psplotfilename+'png') os.system('convert ./'+ psplotfilename+'png' + ' -resize 120x120 ./' + psplotfilename+'THUMB.png') os.system('convert ./'+ psplotfilename+'THUMB.png'+ ' -sharpen 10 ./'+ psplotfilename+'THUMB.png') return