1 from __future__
import print_function
9 from collections
import defaultdict
13 """A class to read RMF files and make a network contact map"""
14 def __init__(self,model,selections,cutoff,frequency_cutoff,
15 colors=
None,fixed=
None,pos=
None,proteomic_edges=
None,quantitative_proteomic_data=
None):
16 """Set up a new graphXL object
17 @param model The IMP model
18 @param selection_dict A dictionary containing component names.
20 values are either moleculename or start,stop,moleculename
21 @param cutoff The distance cutoff
22 @param frequency_cutoff The frequency cutoff
23 @param colors A dictionary of colors (HEX code,values) for subunits (keywords)
24 @param fixed A list of subunits that are kept fixed
25 @param pos A dictionary with positions (tuple, values) of subunits (keywords)
26 @param proteomic_edges A list edges to represent proteomic data
27 @param quantitative_proteomic_data A dictionary of edges to represent
28 quantitative proteomic data such as PE Scores, or genetic interactions
33 self.selections = selections
34 self.contact_counts={}
35 self.edges=defaultdict(int)
36 for (name1,name2)
in itertools.combinations(self.selections.keys(),2):
37 self.edges[tuple(sorted((name1,name2)))]=0
39 self.frequency_cutoff=frequency_cutoff
41 self.gcpf.set_distance(self.cutoff)
42 self.names = list(self.selections.keys())
46 self.proteomic_edges=proteomic_edges
47 self.quantitative_proteomic_data=quantitative_proteomic_data
51 """Add selections from an RMF file"""
52 print(
'reading from RMF file',rmf_fn)
53 rh = RMF.open_rmf_file_read_only(rmf_fn)
57 ps_per_component=defaultdict(list)
59 self.size_per_component=defaultdict(int)
64 all_particles_by_resolution = []
65 for name
in part_dict:
66 all_particles_by_resolution += part_dict[name]
68 for component_name
in self.selections:
69 for seg
in self.selections[component_name]:
72 elif type(seg) == tuple:
74 residue_indexes=range(seg[0], seg[1] + 1))
76 raise Exception(
'could not understand selection tuple '+str(seg))
77 parts = list(set(s.get_selected_particles()) & set(all_particles_by_resolution))
82 for n1,name1
in enumerate(self.names):
83 for name2
in self.names[n1+1:]:
84 ncontacts = len(self.gcpf.get_close_pairs(self.mdl,
85 ps_per_component[name1],
86 ps_per_component[name2]))
88 self.edges[tuple(sorted((name1,name2)))]+=1.0
92 def make_plot(self,groups,out_fn,quantitative_proteomic_data=False):
94 plot the interaction matrix
95 @param groups is the list of groups of domains, eg,
96 [["protA_1-10","prot1A_11-100"],["protB"]....]
97 it will plot a space between different groups
98 @param out_fn name of the plot file
99 @param quantitative_proteomic_data plot the quantitative proteomic data
102 import matplotlib.pyplot
as plt
103 from matplotlib
import cm
106 ax.set_aspect(
'equal',
'box')
107 ax.xaxis.set_major_locator(plt.NullLocator())
108 ax.yaxis.set_major_locator(plt.NullLocator())
117 xoffset=squaredistance
118 yoffset=squaredistance
124 for subgroup
in group:
127 for domain
in subgroup:
128 domain_xlocations[domain]=xoffset
129 domain_ylocations[domain]=yoffset
135 xoffset+=squaredistance
136 yoffset+=squaredistance
138 for edge,count
in self.edges.items():
140 if quantitative_proteomic_data:
142 maxqpd=max(self.quantitative_proteomic_data.values())
143 minqpd=min(self.quantitative_proteomic_data.values())
144 if edge
in self.quantitative_proteomic_data:
145 value=self.quantitative_proteomic_data[edge]
146 elif (edge[1],edge[0])
in self.quantitative_proteomic_data:
147 value=self.quantitative_proteomic_data[(edge[1],edge[0])]
151 density=(1.0-(value-minqpd)/(maxqpd-minqpd))
153 density=(1.0-float(count)/self.num_rmf)
154 color=(density,density,1.0)
155 x=domain_xlocations[edge[0]]
156 y=domain_ylocations[edge[1]]
157 if x>y: xtmp=y; ytmp=x; x=xtmp; y=ytmp
158 rect = plt.Rectangle([x - squaresize / 2, y - squaresize / 2], squaresize, squaresize,
159 facecolor=color, edgecolor=
'Gray', linewidth=0.1)
161 rect = plt.Rectangle([y - squaresize / 2, x - squaresize / 2], squaresize, squaresize,
162 facecolor=color, edgecolor=
'Gray', linewidth=0.1)
170 def make_graph(self,out_fn):
173 print(
'num edges',len(self.edges))
174 for edge,count
in self.edges.items():
176 if float(count)/self.num_rmf>self.frequency_cutoff:
179 weights.append(count)
180 for nw,w
in enumerate(weights):
181 weights[nw]=float(weights[nw])/max(weights)
182 IMP.pmi.output.draw_graph(edges,
183 node_size=dict(self.size_per_component),
184 node_color=self.colors,
191 validation_edges=self.proteomic_edges)
195 def draw_component_composition(DegreesOfFreedom, max=1000, draw_pdb_names=False):
196 """A function to plot the representation on the sequence
197 @param DegreesOfFreedom input a IMP.pmi.dof.DegreesOfFreedom instance"""
198 import matplotlib
as mpl
200 from matplotlib
import pyplot
201 from operator
import itemgetter
205 movers_mols_res=IMP.pmi.tools.OrderedDict()
206 for mv
in DegreesOfFreedom.movers_particles_map:
207 hs=DegreesOfFreedom.movers_particles_map[mv]
218 while not is_molecule:
222 if not mv
in movers_mols_res:
223 movers_mols_res[mv]=IMP.pmi.tools.OrderedDict()
226 if not name
in movers_mols_res[mv]:
229 movers_mols_res[mv][name].add(res)
234 for mv
in movers_mols_res:
241 srb_movers.append(mv)
245 for mol
in movers_mols_res[mv]:
246 for i
in movers_mols_res[mv][mol].get_flatten():
247 for mv_rb
in rb_movers:
249 movers_mols_res[mv_rb][mol].remove(i)
254 c=IMP.pmi.tools.Colors()
255 colors=c.get_list_distant_colors()
256 colors=[
"blue",
"red",
"green",
"pink",
"cyan",
"purple",
"magenta",
"orange",
"grey",
"brown",
"gold",
"khaki",
"olive drab",
"deep blue sky"]
258 for mv
in movers_mols_res:
262 if not mv
in mvrb_color:
263 color=colors[len(mvrb_color.keys())]
265 for mol
in movers_mols_res[mv]:
266 if not mol
in elements: elements[mol]=[]
267 for seg
in movers_mols_res[mv][mol].segs:
268 elements[mol].append((seg[0],seg[-1],
" ",
"pdb",mvrb_color[mv]))
271 for mol
in movers_mols_res[mv]:
272 if not mol
in elements: elements[mol]=[]
273 for seg
in movers_mols_res[mv][mol].segs:
274 elements[mol].append((seg[0],seg[-1],
" ",
"bead"))
280 elements[mol].sort(key=
lambda tup: tup[0])
281 elements[mol].append((elements[mol][-1][1],elements[mol][-1][1],
" ",
"end"))
283 for name
in elements:
285 tmplist = sorted(elements[name], key=itemgetter(0))
287 endres = tmplist[-1][1]
289 print(
"draw_component_composition: missing information for component %s" % name)
291 fig = pyplot.figure(figsize=(26.0 * float(endres) / max + 2, 2))
292 ax = fig.add_axes([0.05, 0.475, 0.9, 0.15])
297 norm = mpl.colors.Normalize(vmin=5, vmax=10)
301 for n, l
in enumerate(tmplist):
305 if bounds[-1] != l[0]:
306 colors.append(
"white")
309 colors.append(
"#99CCFF")
311 colors.append(
"white")
313 colors.append(
"#33CCCC")
315 bounds.append(l[1] + 1)
320 colors.append(
"white")
322 colors.append(
"#33CCCC")
324 bounds.append(l[1] + 1)
326 if bounds[-1] - 1 == l[0]:
330 colors.append(
"white")
333 bounds.append(bounds[-1])
334 colors.append(
"white")
335 cmap = mpl.colors.ListedColormap(colors)
336 cmap.set_over(
'0.25')
337 cmap.set_under(
'0.75')
339 norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
340 cb2 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
346 spacing=
'proportional',
347 orientation=
'horizontal')
356 mid = 1.0 / endres * float(l[0])
361 l[2], xy=(mid, 1), xycoords=
'axes fraction',
362 xytext=(mid + 0.025, float(npdb - 1) / 2.0 + 1.5), textcoords=
'axes fraction',
363 arrowprops=dict(arrowstyle=
"->",
364 connectionstyle=
"angle,angleA=0,angleB=90,rad=10"),
366 extra_artists.append(t)
369 title = ax.text(-0.005, 0.5, k, ha=
"right", va=
"center", rotation=90,
372 extra_artists.append(title)
374 labels = len(bounds) * [
" "]
375 ax.set_xticklabels(labels)
376 mid = 1.0 / endres * float(bounds[0])
377 t = ax.annotate(bounds[0], xy=(mid, 0), xycoords=
'axes fraction',
378 xytext=(mid - 0.01, -0.5), textcoords=
'axes fraction',)
379 extra_artists.append(t)
380 offsets = [0, -0.5, -1.0]
382 for n
in range(1, len(bounds)):
383 if bounds[n] == bounds[n - 1]:
385 mid = 1.0 / endres * float(bounds[n])
386 if (float(bounds[n]) - float(bounds[n - 1])) / max <= 0.01:
388 offset = offsets[nclashes % 3]
394 bounds[n], xy=(mid, 0), xycoords=
'axes fraction',
395 xytext=(mid, -0.5 + offset), textcoords=
'axes fraction')
398 bounds[n], xy=(mid, 0), xycoords=
'axes fraction',
399 xytext=(mid, -0.5 + offset), textcoords=
'axes fraction', arrowprops=dict(arrowstyle=
"-"))
400 extra_artists.append(t)
402 cb2.add_lines(bounds, [
"black"] * len(bounds), [1] * len(bounds))
static bool get_is_setup(const IMP::ParticleAdaptor &p)
A class to read RMF files and make a network contact map.
static bool get_is_setup(const IMP::ParticleAdaptor &p)
A decorator to associate a particle with a part of a protein/DNA/RNA.
atom::Hierarchies create_hierarchies(RMF::FileConstHandle fh, Model *m)
Modify the transformation of a rigid body.
def make_plot
plot the interaction matrix
Move continuous particle variables by perturbing them within a ball.
def add_rmf
Add selections from an RMF file.
static bool get_is_setup(Model *m, ParticleIndex pi)
A decorator for keeping track of copies of a molecule.
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
def __init__
Set up a new graphXL object.
void load_frame(RMF::FileConstHandle file, RMF::FrameID frame)
Load the given RMF frame into the state of the linked objects.
def get_particles_at_resolution_one
Get particles at res 1, or any beads, based on the name.
Tools for clustering and cluster analysis.
Find all nearby pairs by testing all pairs.
Classes for writing output files and processing them.
A decorator for a residue.
The general base class for IMP exceptions.
int get_copy_index(Hierarchy h)
Walk up the hierarchy to find the current copy index.
Python classes to represent, score, sample and analyze models.
Functionality for loading, creating, manipulating and scoring atomic structures.
A decorator for a molecule.
Select hierarchy particles identified by the biological name.
Support for the RMF file format for storing hierarchical molecular data and markup.