예제 #1
0
 def test_sort_lists(self):
     """Tests sorting two lists
     """
     order_list = [2, 1, 3]
     label_list = ['A', 'B', 'C']
     order_list, label_list = collections.sort_lists(order_list, label_list)
     self.assertEqual(order_list, [1, 2, 3])
     self.assertEqual(label_list, ['B', 'A', 'C'])
예제 #2
0
    def sort_data(self, max_size=0, reverse=True):
        """

        Args:
            max_size: The maximum number of barcodes and count to be returned.
            reverse: Indicates whether to sort the data in reverse order (from large to small).

        Returns: A 2-tuple: (Number of Reads, Barcode)

        """
        barcodes = []
        counts = []
        for k, v in self.barcode_dict.items():
            barcodes.append(k)
            counts.append(v)
        counts, barcodes = sort_lists(counts, barcodes, reverse=reverse)
        if max_size and len(counts) > max_size:
            counts = counts[:max_size]
            barcodes = barcodes[:max_size]
        return counts, barcodes
예제 #3
0
    def major_barcodes(self):
        """Returns a list of major barcodes from the statistics.

        The barcodes will be divided into two groups (clusters) if possible, i.e. major and minor.
        The gap between min. reads major and max. reads minor barcodes must be greater than
            twice the gap between any barcodes within the same group.
        A gap between counter1 and counter2 is defined as counter1 / counter2.
        If such groups does not exist, an empty list will be returned.

        Returns: A list of major barcodes. An empty list will be returned if there are less than 3 barcodes.

        """
        counts, barcodes = self.sort_data()
        if len(counts) < 3:
            return []
        gaps = [counts[i] / counts[i + 1] for i in range(len(counts) - 1)]
        indices = list(range(len(counts) - 1))
        gaps, indices = sort_lists(gaps, indices, reverse=True)
        if gaps[0] > 2 * gaps[1]:
            return barcodes[:indices[0] + 1]
        return []