3 from __future__
import print_function, division
6 from IMP
import OptionParser
8 __doc__ =
"Align proteomics graph with the EM map."
14 def __init__(self, minValue=0, maxValue=10, totalWidth=12):
18 self.span = maxValue - minValue
19 self.width = totalWidth
23 def updateAmount(self, newAmount=0):
24 if newAmount < self.min:
26 if newAmount > self.max:
28 self.amount = newAmount
31 diffFromMin = float(self.amount - self.min)
32 percentDone = (diffFromMin / float(self.span)) * 100.0
33 percentDone = round(percentDone)
34 percentDone = int(percentDone)
37 allFull = self.width - 2
38 numHashes = (percentDone / 100.0) * allFull
39 numHashes = int(round(numHashes))
42 self.progBar =
"[" +
'#' * numHashes + \
43 ' ' * (allFull - numHashes) +
"]"
46 percentPlace = (len(self.progBar) // 2) - len(str(percentDone))
47 percentString = str(percentDone) +
"%"
50 self.progBar = self.progBar[
51 0:percentPlace] + percentString + self.progBar[
56 return str(self.progBar)
60 usage =
"""%prog [options] <asmb> <asmb.proteomics> <asmb.mapping>
61 <alignment.params> <combinations[output]>
62 <Fitting scores[output]>
64 Align proteomics graph with the EM map.
66 parser = OptionParser(usage)
67 parser.add_option(
"-m",
"--max", type=
"int", dest=
"max", default=999999999,
68 help=
"maximum number of fits considered")
70 options, args = parser.parse_args()
72 parser.error(
"incorrect number of arguments")
76 def report_solutions(asmb, mdl, mhs, restraint_set, dmap, mapping_data, combs,
77 combs_fn_output_fn, scored_comb_output_fn, max_comb):
80 for i, mh
in enumerate(mhs):
81 fn = asmb.get_component_header(i).get_transformations_fn()
82 ensmb.add_component_and_fits(mh,
89 all_leaves = all_leaves + s1.get_selected_particles()
90 print(
"number of leaves:", len(all_leaves))
91 print(
"Get number of restraints:", len(restraint_set.get_restraints()))
92 pb = progressBar(0, len(combs))
96 print(
"going to calculate fits for:", len(combs))
97 for i, comb
in enumerate(combs):
100 ensmb.load_combination(comb)
101 ranked_combs.append([comb, fitr.evaluate(
False)])
102 ensmb.unload_combination(comb)
107 ranked_combs.sort(key=
lambda a: a[1])
109 print(
"ranked combs:", len(ranked_combs))
110 ranked_combs[max_comb:] = []
111 print(
"ranked combs:", len(ranked_combs))
112 for comb
in ranked_combs:
113 sorted_combs.append(comb[0])
115 output = open(scored_comb_output_fn,
"w")
116 for comb, score
in ranked_combs:
119 output.write(str(ind) +
" ")
120 output.write(
"|" + str(1. - score) +
"|\n")
124 def run(asmb_fn, proteomics_fn, mapping_fn, params_fn,
125 combs_fn_output_fn, scored_comb_output_fn, max_comb):
127 asmb.set_was_used(
True)
129 dmap.get_header().set_resolution(
131 threshold = asmb.get_assembly_header().get_threshold()
132 dmap.update_voxel_size(asmb.get_assembly_header().get_spacing())
133 dmap.set_origin(asmb.get_assembly_header().get_origin())
136 alignment_params = IMP.multifit.AlignmentParams(params_fn)
137 alignment_params.show()
144 em_anchors = mapping_data.get_anchors()
150 align.set_fast_scoring(
False)
151 align.set_density_map(dmap, threshold)
152 align.add_states_and_filters()
153 align.add_all_restraints()
155 print(
"before align")
158 combs = align.get_combinations()
161 f = open(combs_fn_output_fn,
"w")
162 f.write(
"NO SOLUTIONS FOUND\n")
166 report_solutions(asmb, align.get_model(), align.get_molecules(),
167 align.get_restraint_set(), dmap,
168 mapping_data, combs, combs_fn_output_fn,
169 scored_comb_output_fn, max_comb)
173 options, args = parse_args()
174 run(args[0], args[1], args[2], args[3], args[4], args[5],
176 if __name__ ==
"__main__":
An ensemble of fitting solutions.
def main
Run a set of tests; similar to unittest.main().
void write_paths(const IntsList &paths, const std::string &txt_filename)
SettingsData * read_settings(const char *filename)
ProteinsAnchorsSamplingSpace read_protein_anchors_mapping(multifit::ProteomicsData *prots, const std::string &anchors_prot_map_fn, int max_paths=INT_MAX)
Align proteomics graph to EM density map.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
Gather all the molecular particles of a certain level in the hierarchy.
Fitting atomic structures into a cryo-electron microscopy density map.
DensityMap * read_map(std::string filename)
Read a density map from a file and return it.
ProteomicsData * read_proteomics_data(const char *proteomics_fn)
Proteomics reader.
void set_log_level(LogLevel l)
Set the current global log level.
Calculate score based on fit to EM map.
FittingSolutionRecords read_fitting_solutions(const char *fitting_fn)
Fitting solutions reader.
double get_resolution(Model *m, ParticleIndex pi)
Estimate the resolution of the hierarchy as used by Representation.
Select hierarchy particles identified by the biological name.