Skip to content

Commit

Permalink
Added multiprocessing and covariance metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
wrochira committed Aug 12, 2022
1 parent 653d2fb commit 913a345
Show file tree
Hide file tree
Showing 16 changed files with 1,476 additions and 1,249 deletions.
8 changes: 7 additions & 1 deletion iris-validation/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
t0 = time.time()

generate_report(latest_model_path=ROOT_PATH.format(suffix='_final.pdb'),
previous_model_path=ROOT_PATH.format(suffix='_0cyc.pdb'),
latest_reflections_path=ROOT_PATH.format(suffix='_final.mtz'),
latest_sequence_path=ROOT_PATH.format(suffix='.fasta'),
latest_distpred_path=ROOT_PATH.format(suffix='.npz'),
previous_model_path=ROOT_PATH.format(suffix='_0cyc.pdb'),
previous_reflections_path=ROOT_PATH.format(suffix='_0cyc.mtz'),
previous_sequence_path=ROOT_PATH.format(suffix='.fasta'),
previous_distpred_path=ROOT_PATH.format(suffix='.npz'),
run_covariance=False,
run_molprobity=False,
multiprocessing=True,
output_dir=OUTPUT_DIR)

t1 = time.time()
Expand Down
17 changes: 15 additions & 2 deletions iris-validation/iris_validation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@


def generate_report(latest_model_path,
previous_model_path=None,
latest_reflections_path=None,
latest_sequence_path=None,
latest_distpred_path=None,
previous_model_path=None,
previous_reflections_path=None,
previous_sequence_path=None,
previous_distpred_path=None,
run_covariance=False,
run_molprobity=False,
multiprocessing=True,
wrap_in_html=True,
output_dir=None):

model_paths = (previous_model_path, latest_model_path)
reflections_paths = (previous_reflections_path, latest_reflections_path)
sequence_paths = (previous_sequence_path, latest_sequence_path)
distpred_paths = (previous_distpred_path, latest_distpred_path)

model_series = metrics_model_series_from_files(model_paths,
reflections_paths,
run_molprobity)
sequence_paths,
distpred_paths,
run_covariance,
run_molprobity,
multiprocessing)
model_series_data = model_series.get_raw_data()
panel = Panel(model_series_data)
panel_string = panel.dwg.tostring()
Expand Down
78 changes: 61 additions & 17 deletions iris-validation/iris_validation/_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,73 @@

CONTINUOUS_METRICS = ( { 'id' : 0,
'type' : 'continuous',
'long_name' : 'Avg. B-factor',
'long_name' : 'Average B-factor',
'short_name' : 'Avg. B',
'ring_color' : COLORS['CYAN'],
'polarity' : -1,
'is_molprobity' : False
'is_covariance' : False,
'is_molprobity' : False,
'is_reflections': False
},
{ 'id' : 1,
'type' : 'continuous',
'long_name' : 'Max. B-factor',
'long_name' : 'Maximum B-factor',
'short_name' : 'Max. B',
'ring_color' : COLORS['TEAL'],
'polarity' : -1,
'is_molprobity' : False
'is_covariance' : False,
'is_molprobity' : False,
'is_reflections': False
},
{ 'id' : 2,
'type' : 'continuous',
'long_name' : 'Std. B-factor',
'long_name' : 'Stdev B-factor',
'short_name' : 'Std. B',
'ring_color' : COLORS['SLATE'],
'polarity' : -1,
'is_molprobity' : False
'is_covariance' : False,
'is_molprobity' : False,
'is_reflections': False
},
{ 'id' : 3,
'type' : 'continuous',
'long_name' : 'Residue Fit',
'short_name' : 'Res. Fit',
'ring_color' : COLORS['MAGENTA'],
'polarity' : -1,
'is_molprobity' : False
'is_covariance' : False,
'is_molprobity' : False,
'is_reflections': True
},
{ 'id' : 4,
'type' : 'continuous',
'long_name' : 'Main Chain Fit',
'short_name' : 'M.C. Fit',
'short_name' : 'Main Fit',
'ring_color' : COLORS['BLUE'],
'polarity' : -1,
'is_molprobity' : False
'is_covariance' : False,
'is_molprobity' : False,
'is_reflections': True
},
{ 'id' : 5,
'type' : 'continuous',
'long_name' : 'Side Chain Fit',
'short_name' : 'S.C. Fit',
'short_name' : 'Side Fit',
'ring_color' : COLORS['INDIGO'],
'polarity' : -1,
'is_molprobity' : False
'is_covariance' : False,
'is_molprobity' : False,
'is_reflections': True
},
{ 'id' : 6,
'type' : 'continuous',
'long_name' : 'Covariance Score',
'short_name' : 'Cov. Score',
'ring_color' : COLORS['ORANGE'],
'polarity' : -1,
'is_covariance' : True,
'is_molprobity' : False,
'is_reflections': False
}
)

Expand All @@ -83,7 +105,9 @@
'seq_labels' : ('Outlier',
'Allowed',
'Favoured'),
'is_molprobity' : False
'is_covariance' : False,
'is_molprobity' : False,
'is_reflections': False
},
{ 'id' : 1,
'type' : 'discrete',
Expand All @@ -96,7 +120,9 @@
'seq_labels' : ('Outlier',
'Allowed',
'Favoured'),
'is_molprobity' : False
'is_covariance' : False,
'is_molprobity' : False,
'is_reflections': False
},
{ 'id' : 2,
'type' : 'discrete',
Expand All @@ -109,8 +135,23 @@
'seq_labels' : ('Multiple Clashes',
'One Clash',
'No Clashes'),
'is_molprobity' : True
}
'is_covariance' : False,
'is_molprobity' : True,
'is_reflections': False
},
{ 'id' : 3,
'type' : 'discrete',
'long_name' : 'Misalignment',
'short_name' : 'CMO',
'ring_color' : COLORS['L_GREY'],
'seq_colors' : (COLORS['RED'],
COLORS['GREEN']),
'seq_labels' : ('Misaligned',
'Aligned'),
'is_covariance' : True,
'is_molprobity' : False,
'is_reflections': False
}
)

CHAIN_VIEW_GAP_ANGLE = 0.35
Expand All @@ -119,14 +160,17 @@
CHAIN_VIEW_RINGS = [ DISCRETE_METRICS[0],
DISCRETE_METRICS[1],
DISCRETE_METRICS[2],
DISCRETE_METRICS[3],
CONTINUOUS_METRICS[0],
CONTINUOUS_METRICS[1],
CONTINUOUS_METRICS[4],
CONTINUOUS_METRICS[5] ]
CONTINUOUS_METRICS[5],
CONTINUOUS_METRICS[6] ]

RESIDUE_VIEW_BOXES = [ DISCRETE_METRICS[0],
DISCRETE_METRICS[1],
DISCRETE_METRICS[2] ]
DISCRETE_METRICS[2],
DISCRETE_METRICS[3] ]

RESIDUE_VIEW_BARS = [ CONTINUOUS_METRICS[0],
CONTINUOUS_METRICS[5] ]
7 changes: 4 additions & 3 deletions iris-validation/iris_validation/graphics/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _draw(self):
text_anchor='middle',
alignment_baseline='central'))
if self.data['has_molprobity']:
self.dwg.add(self.dwg.text(text='MolProbity Enabled',
self.dwg.add(self.dwg.text(text='MolProbity',
insert=(self.center[0], self.center[1]+48),
font_size=16,
font_family='Arial',
Expand Down Expand Up @@ -216,8 +216,9 @@ def _add_ring(self, ring_id, metric):
value = datapoint * metric['polarity']
all_valid_values.append(value)
ring_avg = 0
if len(all_valid_values) > 0:
ring_avg = sum(all_valid_values) / len(all_valid_values)
if len(all_valid_values) == 0:
return
ring_avg = sum(all_valid_values) / len(all_valid_values)

# Calculate deltas from the ring average
deltas = [ ]
Expand Down
22 changes: 16 additions & 6 deletions iris-validation/iris_validation/graphics/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def _verify_chosen_metrics(self):
if not isinstance(metric_list, list):
raise ValueError('Chosen metrics in the _defs.py file must be lists')
for metric_index in reversed(range(len(metric_list))):
if (metric_list[metric_index]['is_molprobity'] and not self.data[0]['has_molprobity']):
if (metric_list[metric_index]['is_covariance'] and not self.data[0]['has_covariance']):
del metric_list[metric_index]
elif (metric_list[metric_index]['is_molprobity'] and not self.data[0]['has_molprobity']):
del metric_list[metric_index]
elif (metric_list[metric_index]['is_reflections'] and not self.data[0]['has_reflections']):
del metric_list[metric_index]

def _generate_javascript(self):
Expand Down Expand Up @@ -81,6 +85,8 @@ def _draw(self):
middle_gap = 30
view_border = 10
view_title_font = 24
button_width = 38
button_height = 32
view_width, view_height = [ dim - view_border for dim in self.canvas_size ]
view_divider_x = round(2/3 * view_width, 2)
chain_view_bounds = (view_border,
Expand All @@ -95,6 +101,9 @@ def _draw(self):
# Initialise drawing
self.dwg = svgwrite.Drawing(profile='full')

# Disable text selection
self.dwg.attribs['style'] = 'user-select: none;'

# Draw background
self.dwg.add(self.dwg.polygon(points=[ (0, 0),
(0, self.canvas_size[1]),
Expand Down Expand Up @@ -134,24 +143,25 @@ def _draw(self):
stroke_width=2))

# Chain selector buttons
#self.chain_ids = [ chr(65+i) for i in range(20) ] # TODO: remove this
for chain_index, chain_id in enumerate(self.chain_ids[:12]):
selector_color = self.swtich_colors[1] if chain_index == 0 else self.swtich_colors[0]
self.dwg.add(self.dwg.rect(insert=(chain_view_bounds[0] + 75 + 50*chain_index, chain_view_bounds[1]),
size=(38, 32),
size=(button_width, button_height),
rx=5,
stroke_opacity=0,
fill_opacity=0.5,
fill=selector_color,
id=f'{self.svg_id}-chain-selector-{chain_index}'))

self.dwg.add(self.dwg.text(text=chain_id,
insert=(chain_view_bounds[0] + 85 + 50*chain_index, chain_view_bounds[1]+view_title_font),
insert=(chain_view_bounds[0] + 75 + button_width/2 + 50*chain_index, chain_view_bounds[1] + button_height/2),
font_size=view_title_font,
font_family='Arial'))
font_family='Arial',
text_anchor='middle',
alignment_baseline='central'))

self.dwg.add(self.dwg.rect(insert=(chain_view_bounds[0] + 75 + 50*chain_index, chain_view_bounds[1]),
size=(38, 32),
size=(button_width, button_height),
rx=5,
stroke_opacity=0,
fill_opacity=0,
Expand Down
4 changes: 2 additions & 2 deletions iris-validation/iris_validation/graphics/residue.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _draw(self):
stroke_opacity=1,
id=f'{self.svg_id}-box-{box_id}'))
self.dwg.add(self.dwg.text('',
insert=((box_bounds[0]+box_bounds[2])/2, (box_bounds[1]+box_bounds[3]+10)/2),
insert=((box_bounds[0]+box_bounds[2])/2, (box_bounds[1]+box_bounds[3])/2),
font_size=20,
font_family='Arial',
font_weight='bold',
Expand All @@ -76,7 +76,7 @@ def _draw(self):
alignment_baseline='central',
id=f'{self.svg_id}-box-{box_id}-text'))
self.dwg.add(self.dwg.text(box_title,
insert=(left_indent + 0.125*self.canvas_size[0], (box_bounds[1]+box_bounds[3])/2+5),
insert=(left_indent + 0.125*self.canvas_size[0], (box_bounds[1]+box_bounds[3])/2),
font_size=18,
font_family='Arial',
fill=COLORS['BLACK'],
Expand Down
Loading

0 comments on commit 913a345

Please sign in to comment.