def test_no_aln_possible(): seq1 = 'TTTTTTTTTT' seq2 = 'AAAAAAAAAAGGG' pa = PairAlignment(seq1, seq2) flag, msg = pa.align_with_window([0, 14]) assert not flag assert 'No alignment found' in msg
def homologous_recombination_proposal(self, cutsite, donor_sequence): cutsite = cutsite - 1 # check orientation and verify at least 15nt matching on both ends of ODN if reverse_complement(donor_sequence[:self.__class__.MIN_HOMOLOGY_ARM] ) in self.wt_basecalls: donor_sequence = reverse_complement(donor_sequence) if donor_sequence[:self.__class__.MIN_HOMOLOGY_ARM] in self.wt_basecalls and \ donor_sequence[-self.__class__.MIN_HOMOLOGY_ARM:] in self.wt_basecalls: # todo confirm that cutsite is inside the HDR region donor_alignment = PairAlignment(self.wt_basecalls, donor_sequence) donor_alignment.align_ssodn() proposal_bases, proposal_trace, changed_bases, odn_start_pos = self.recombined_outcome_sequence( donor_alignment.all_aligned_seqs, donor_sequence) ep = EditProposal() ep.sequence_data = proposal_bases ep.trace_data = proposal_trace ep.cutsite = cutsite ep.summary = ProposalBase.HDR ep.bases_changed = ProposalBase.HDR return ep, changed_bases, odn_start_pos, donor_alignment else: raise Exception( "Homology arms of length {} not found in control sequence". format(self.__class__.MIN_HOMOLOGY_ARM))
def test_coord_conversion(): ''' GGGAATGTCCTGATAG ---AATGT--TGATAG :return: ''' seq1 = 'GGGAATGTCCTGATAG' seq2 = 'AATGTTGATAG' pa = PairAlignment(seq1, seq2) pa.align_with_window([0,14]) assert 2 == pa.ctrl2sample_coords(5) assert 0 == pa.ctrl2sample_coords(3) assert 9 == pa.ctrl2sample_coords(14) assert None == pa.ctrl2sample_coords(9) assert 4 == pa.ctrl2sample_coords(9, closest=True) with pytest.raises(Exception): pa.ctrl2sample_coords(None)
def no_alignment(): """ returns an example alignment obj """ seq1 = 'AATGTAATGATAG' seq4 = 'GGACAGACTTAAA' pa = PairAlignment(seq1, seq4) return pa
def shorter_alignment(): """ returns an example alignment obj """ seq1 = 'AATGTAATGATAG' seq3 = 'AATGTATGATAGTGGG' pa = PairAlignment(seq1, seq3) return pa
def example_alignment(): """ returns an example alignment obj """ seq1 = 'AATGTAATGATAG' seq2 = 'AATGTATGATAG' pa = PairAlignment(seq1, seq2) return pa
def analyze_sample(self): self.quality_check() self.find_targets() if self.donor_odn: self.check_recombination() self.find_alignment_window() alignment = PairAlignment(self.control_sample.primary_base_calls, self.edited_sample.primary_base_calls) self.alignment = alignment alignment.align_all() alignment.align_with_window(self.alignment_window) if alignment.has_alignment: pass else: raise Exception( "No alignment found between control and edited sample") # aln_flag, msg = self.align_edited_to_control_sequence() aln_file = self.base_outputname + "all.txt" alignment.write_aln(alignment.all_aligned_clustal, to_file=aln_file) aln_file = self.base_outputname + "windowed.txt" alignment.write_aln(alignment.aln_clustal, to_file=aln_file) # write to jsons aln_json_file = self.base_outputname + "all.json" alignment.write_json(alignment.all_aligned_seqs, aln_json_file) aln_json_file = self.base_outputname + "windowed.json" alignment.write_json(alignment.aln_seqs, aln_json_file) self._generate_edit_proposals() if self.donor_odn: aln_file = self.base_outputname + "donor.txt" self.donor_alignment.write_aln( self.donor_alignment.all_aligned_clustal, to_file=aln_file) aln_json_file = self.base_outputname + "donor.json" self.donor_alignment.write_json( self.donor_alignment.all_aligned_seqs, aln_json_file) print("analyzing {} number of edit proposals".format( len(self.proposals))) self._calculate_inference_window() self._generate_coefficient_matrix() self._generate_outcomes_vector() self.analyze_and_rank() self.calculate_discordance() self.simple_discordance_algorithm() # output indel_file = self.base_outputname + "indel.json" trace_file = self.base_outputname + "trace.json" generate_discordance_indel_files(self, self.results, to_file=indel_file) generate_trace_files(self, to_file=trace_file) write_individual_contribs(self, to_file=self.base_outputname + "contribs.txt") write_contribs_json(self, self.base_outputname + "contribs.json") if self.allprops: write_all_proposals_json( self, self.base_outputname + "allproposals.json")