ragtag_utilities/ContigAlignment.py
def _get_best_ref_header(self):
        """ From the alignments, determine the reference sequence that is the most covered by this query sequence. """
        all_ref_headers = set(self._ref_headers)
        if len(all_ref_headers) == 1:
            self.best_ref_header = self._ref_headers[0]
            self.grouping_confidence = 1.0
            return

        # Get all the alignment intervals for each reference sequence
        all_intervals = defaultdict(list)
        for i in range(len(self._ref_headers)):
            this_range = (self._ref_starts[i], self._ref_ends[i])
            this_seq = self._ref_headers[i]
            all_intervals[this_seq].append(this_range)

        # For each reference header, sort the intervals and get the union interval length.
        ranges = defaultdict(int)
        for i in all_intervals.keys():
            sorted_intervals = sorted(all_intervals[i], key=lambda tup: tup[0])
            max_end = -1
            for j in sorted_intervals:
                start_new_terr = max(j[0], max_end)
                ranges[i] += max(0, j[1] - start_new_terr)
                max_end = max(max_end, j[1])

        # Convert to a list and sort the ranges.items() in order to have ties broken in a deterministic way.
        max_seq = max(sorted(list(ranges.items())), key=operator.itemgetter(1))[0]
        self.best_ref_header = max_seq

        # Now get the confidence of this chromosome assignment
        # Equal to the max range over all ranges
        self.grouping_confidence = ranges[max_seq] / sum(ranges.values())
 From the alignments, determine the reference sequence that is the most covered by this query sequence. 
From the alignments, determine the reference sequence that is the most covered by this query sequence.
From the alignments determine the reference sequence that is the most covered by this query sequence .
def _get_best_ref_header(self):
        all_ref_headers = set(self._ref_headers)
        if len(all_ref_headers) == 1:
            self.best_ref_header = self._ref_headers[0]
            self.grouping_confidence = 1.0
            return
        all_intervals = defaultdict(list)
        for i in range(len(self._ref_headers)):
            this_range = (self._ref_starts[i], self._ref_ends[i])
            this_seq = self._ref_headers[i]
            all_intervals[this_seq].append(this_range)
        ranges = defaultdict(int)
        for i in all_intervals.keys():
            sorted_intervals = sorted(all_intervals[i], key=lambda tup: tup[0])
            max_end = -1
            for j in sorted_intervals:
                start_new_terr = max(j[0], max_end)
                ranges[i] += max(0, j[1] - start_new_terr)
                max_end = max(max_end, j[1])
        max_seq = max(sorted(list(ranges.items())), key=operator.itemgetter(1))[0]
        self.best_ref_header = max_seq
        self.grouping_confidence = ranges[max_seq] / sum(ranges.values())
def _get_best_ref_header ( self ) : all_ref_headers = set ( self . _ref_headers ) if len ( all_ref_headers ) == 1 : self . best_ref_header = self . _ref_headers [ 0 ] self . grouping_confidence = 1.0 return all_intervals = defaultdict ( list ) for i in range ( len ( self . _ref_headers ) ) : this_range = ( self . _ref_starts [ i ] , self . _ref_ends [ i ] ) this_seq = self . _ref_headers [ i ] all_intervals [ this_seq ] . append ( this_range ) ranges = defaultdict ( int ) for i in all_intervals . keys ( ) : sorted_intervals = sorted ( all_intervals [ i ] , key = lambda tup : tup [ 0 ] ) max_end = - 1 for j in sorted_intervals : start_new_terr = max ( j [ 0 ] , max_end ) ranges [ i ] += max ( 0 , j [ 1 ] - start_new_terr ) max_end = max ( max_end , j [ 1 ] ) max_seq = max ( sorted ( list ( ranges . items ( ) ) ) , key = operator . itemgetter ( 1 ) ) [ 0 ] self . best_ref_header = max_seq self . grouping_confidence = ranges [ max_seq ] / sum ( ranges . values ( ) )
From the alignments, determine the reference sequence that is the most covered by this query sequence.
From the alignments determine the reference sequence that is the most covered by this query sequence .
""" From the alignments, determine the reference sequence that is the most covered by this query sequence. """ # Get all the alignment intervals for each reference sequence # For each reference header, sort the intervals and get the union interval length. # Convert to a list and sort the ranges.items() in order to have ties broken in a deterministic way. # Now get the confidence of this chromosome assignment # Equal to the max range over all ranges
self