def annotate_and_output_results(g_patient, g_reference, output_results): import forannotation as ANNO annotated_alterations = ANNO.alteration_list_to_transcrit_mutation(g_patient, g_reference) # add experiment arguments PROGRAMEND = time.time() experiment_description = {} this_timestamp = get_timestamp() experiment_description['timestamp'] = this_timestamp experiment_description['exec_time'] = PROGRAMEND - PROGRAMSTART experiment_description['parameters'] = vars(args) experiment_description['n_reads'] = g_patient.n_reads experiment_description['git_revision_hash'] = get_git_revision_hash() experiment_description['significant_alterations'] = annotated_alterations experiment_description['graphs'] = { "coverage_total": g_patient.coverage['total'], "before_cleaning": len(g_patient.dbg), "after_clearning": len(g_patient.dbgclean) } experiment_description['all_alterations'] = [] for x in g_patient.alteration_list: alteration_description = x.__dict__ del alteration_description['reference_path'] del alteration_description['alternative_path'] del alteration_description['random_alternative_count_list'] del alteration_description['random_reference_count_list'] del alteration_description['random_ratio_list'] alteration_description['edit_operations'] = find_edit_operations(x.reference_sequence, x.alternative_sequence) alteration_description['alignment'] = pairwise2.align.globalms(x.reference_sequence, x.alternative_sequence, 2, -3, -5, -2)[0] experiment_description['all_alterations'].append(alteration_description) print json.dumps(experiment_description) if output_results: with open(output_results, "w") as f: json.dump(experiment_description, f)
def serialize_results(output_file_prefix, some_alterations): # prepare alterations for output PROGRAMEND = time.time() sampling_experiment = {} described_alterations = [] for (start, end), (alt_type, alt_content, qual_content) in some_alterations.items(): described_alterations.append({ "start": start, 'end': end, 'alt_type': alt_type if alt_type != "M" else "X", # for micado compatibility "alt_content": alt_content, "qual_string": qual_content, "alt_length": len(alt_content) if alt_content else 0 }) sampling_experiment['exec_time'] = PROGRAMEND - PROGRAMSTART sampling_experiment['parameters'] = vars(args) sampling_experiment['injected_alterations'] = described_alterations sampling_experiment['input_n_reads'] = len(aligned_reads) sampling_experiment['git_revision_hash'] = get_git_revision_hash() sampling_experiment['program_name'] = __file__ with open(output_file_prefix + ".alterations.json", "w") as f: json.dump({"sampler": sampling_experiment}, f)
def serialize_results(output_file_prefix, some_alterations): # prepare alterations for output PROGRAMEND = time.time() sampling_experiment = {} described_alterations = [] for (start, end), (alt_type, alt_content, qual_content) in some_alterations.items(): described_alterations.append({ "start": start, 'end': end, 'alt_type': alt_type if alt_type != "M" else "X", # for micado compatibility "alt_content": alt_content, "qual_string": qual_content, "alt_length": len(alt_content) if alt_content else 0 }) sampling_experiment['exec_time'] = PROGRAMEND - PROGRAMSTART sampling_experiment['parameters'] = vars(args) sampling_experiment['injected_alterations'] = described_alterations sampling_experiment['input_n_reads'] = len(aligned_reads) sampling_experiment['git_revision_hash'] = get_git_revision_hash() sampling_experiment['program_name'] = __file__ with open(output_file_prefix + ".alterations.json", "w") as f: json.dump({"sampler": sampling_experiment}, f)
def annotate_and_output_results(g_patient, g_reference, output_results): import forannotation as ANNO annotated_alterations = ANNO.alteration_list_to_transcrit_mutation( g_patient, g_reference) # add experiment arguments PROGRAMEND = time.time() experiment_description = {} this_timestamp = get_timestamp() experiment_description['timestamp'] = this_timestamp experiment_description['exec_time'] = PROGRAMEND - PROGRAMSTART experiment_description['parameters'] = vars(args) experiment_description['n_reads'] = g_patient.n_reads experiment_description['git_revision_hash'] = get_git_revision_hash() # experiment_description['memory_usage'] = process.memory_info().rss experiment_description['significant_alterations'] = annotated_alterations experiment_description['graphs'] = { "coverage_total": g_patient.coverage['total'], "before_cleaning": len(g_patient.dbg), "after_clearning": len(g_patient.dbgclean) } experiment_description['all_alterations'] = [] for x in g_patient.alteration_list: alteration_description = x.__dict__ del alteration_description['reference_path'] del alteration_description['alternative_path'] del alteration_description['random_alternative_count_list'] del alteration_description['random_reference_count_list'] del alteration_description['random_ratio_list'] alteration_description['edit_operations'] = find_edit_operations( x.reference_sequence, x.alternative_sequence) alteration_description['alignment'] = pairwise2.align.globalms( x.reference_sequence, x.alternative_sequence, 2, -3, -5, -2)[0] experiment_description['all_alterations'].append( alteration_description) # print json.dumps(experiment_description) if output_results: with open(output_results, "w") as f: json.dump(experiment_description, f)
def test_get_git_revision_hash(self): print get_git_revision_hash()