1 from __future__
import print_function
9 from collections
import defaultdict
11 from scipy.spatial.distance
import cdist
14 """A class to read RMF files and make a network contact map"""
15 def __init__(self,model,selections,cutoff,frequency_cutoff,
16 colors=
None,fixed=
None,pos=
None,proteomic_edges=
None,quantitative_proteomic_data=
None):
17 """Set up a new graphXL object
18 @param model The IMP model
19 @param selection_dict A dictionary containing component names.
21 values are either moleculename or start,stop,moleculename
22 @param cutoff The distance cutoff
23 @param frequency_cutoff The frequency cutoff
24 @param colors A dictionary of colors (HEX code,values) for subunits (keywords)
25 @param fixed A list of subunits that are kept fixed
26 @param pos A dictionary with positions (tuple, values) of subunits (keywords)
27 @param proteomic_edges A list edges to represent proteomic data
28 @param quantitative_proteomic_data A dictionary of edges to represent
29 quantitative proteomic data such as PE Scores, or genetic interactions
34 self.selections = selections
35 self.contact_counts={}
36 self.edges=defaultdict(int)
37 for (name1,name2)
in itertools.combinations(self.selections.keys(),2):
38 self.edges[tuple(sorted((name1,name2)))]=0
40 self.frequency_cutoff=frequency_cutoff
42 self.gcpf.set_distance(self.cutoff)
43 self.names = list(self.selections.keys())
47 self.proteomic_edges=proteomic_edges
48 self.quantitative_proteomic_data=quantitative_proteomic_data
52 """Add selections from an RMF file"""
53 print(
'reading from RMF file',rmf_fn)
54 rh = RMF.open_rmf_file_read_only(rmf_fn)
58 ps_per_component=defaultdict(list)
60 self.size_per_component=defaultdict(int)
65 all_particles_by_resolution = []
66 for name
in part_dict:
67 all_particles_by_resolution += part_dict[name]
69 for component_name
in self.selections:
70 for seg
in self.selections[component_name]:
73 elif type(seg) == tuple:
75 residue_indexes=range(seg[0], seg[1] + 1))
77 raise Exception(
'could not understand selection tuple '+str(seg))
78 parts = list(set(s.get_selected_particles()) & set(all_particles_by_resolution))
79 ps_per_component[component_name] += IMP.get_indexes(parts)
83 for n1,name1
in enumerate(self.names):
84 for name2
in self.names[n1+1:]:
85 ncontacts = len(self.gcpf.get_close_pairs(self.mdl,
86 ps_per_component[name1],
87 ps_per_component[name2]))
89 self.edges[tuple(sorted((name1,name2)))]+=1.0
93 def make_plot(self,groups,out_fn,quantitative_proteomic_data=False):
95 plot the interaction matrix
96 @param groups is the list of groups of domains, eg,
97 [["protA_1-10","prot1A_11-100"],["protB"]....]
98 it will plot a space between different groups
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)
A class to read RMF files and make a network contact map.
atom::Hierarchies create_hierarchies(RMF::FileConstHandle fh, kernel::Model *m)
def make_plot
plot the interaction matrix
void load_frame(RMF::FileConstHandle file, unsigned int frame)
def add_rmf
Add selections from an RMF file.
def __init__
Set up a new graphXL object.
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.
Python classes to represent, score, sample and analyze models.
Functionality for loading, creating, manipulating and scoring atomic structures.
Select hierarchy particles identified by the biological name.
Support for the RMF file format for storing hierarchical molecular data and markup.