# Path: seal/lib/mr/hit_processor_chain_link.py
# class HitProcessorChainLink(object):
#     def __init__(self, next_link = None):
#         self.next_link = next_link
# 
#     def set_next(self, link):
#         self.next_link = link
#         return link
# 
#     def process(self, original, aligned_pair):
#         """
#         Identity action.  Passes to the next link, if any.
#         """
#         if self.next_link:
#             self.next_link.process(original, aligned_pair)


import random
import seal.lib.io.protobuf_mapping as protobuf_mapping
import seal.seqal as seqal
from seal.lib.mr.hit_processor_chain_link import HitProcessorChainLink
        # Unmapped reads come after all positions.  None values are last.
        raise NotImplementedError("Not updated for RAPI")

        if pair[1] is None:
            ordered_pair = pair
        elif pair[0] is None:
            ordered_pair = (pair[1], pair[0])
        elif pair[1].is_unmapped(): # there are no None values
            ordered_pair = pair
        elif pair[0].is_unmapped():
            ordered_pair = (pair[1], pair[0])
        #else there are no unmapped reads
        elif (pair[0].ref_id, pair[0].get_untrimmed_left_pos(), pair[0].is_on_reverse()) > \
             (pair[1].ref_id, pair[1].get_untrimmed_left_pos(), pair[1].is_on_reverse()):
            ordered_pair = (pair[1], pair[0])
        else:
            ordered_pair = pair

        return ordered_pair

    def process(self, original, aligned_pair):
        if any(aligned_pair):
            # order pair such that left-most read is at pos 0
            ordered_pair = self.__order_pair(aligned_pair)

            record = protobuf_mapping.serialize_pair(ordered_pair)
            # emit with the left coord
            key = self.get_hit_key(ordered_pair[0])
            self.ctx.emit(key, record)
            if ordered_pair[0].is_mapped():

# Path: seal/lib/mr/hit_processor_chain_link.py
# class HitProcessorChainLink(object):
#     def __init__(self, next_link = None):
#         self.next_link = next_link
# 
#     def set_next(self, link):
#         self.next_link = link
#         return link
# 
#     def process(self, original, aligned_pair):
#         """
#         Identity action.  Passes to the next link, if any.
#         """
#         if self.next_link:
#             self.next_link.process(original, aligned_pair)


# Path: seal/lib/mr/mark_dups_emitter.py
import random
import seal.lib.io.protobuf_mapping as protobuf_mapping
import seal.seqal as seqal
from seal.lib.mr.hit_processor_chain_link import HitProcessorChainLink

        # Unmapped reads come after all positions.  None values are last.
        raise NotImplementedError("Not updated for RAPI")

        if pair[1] is None:
            ordered_pair = pair
        elif pair[0] is None:
            ordered_pair = (pair[1], pair[0])
        elif pair[1].is_unmapped(): # there are no None values
            ordered_pair = pair
        elif pair[0].is_unmapped():
            ordered_pair = (pair[1], pair[0])
        #else there are no unmapped reads
        elif (pair[0].ref_id, pair[0].get_untrimmed_left_pos(), pair[0].is_on_reverse()) > \
             (pair[1].ref_id, pair[1].get_untrimmed_left_pos(), pair[1].is_on_reverse()):
            ordered_pair = (pair[1], pair[0])
        else:
            ordered_pair = pair

        return ordered_pair

    def process(self, original, aligned_pair):
        if any(aligned_pair):
            # order pair such that left-most read is at pos 0
            ordered_pair = self.__order_pair(aligned_pair)

            record = protobuf_mapping.serialize_pair(ordered_pair)
            # emit with the left coord
            key = self.get_hit_key(ordered_pair[0])
            self.ctx.emit(key, record)
            if ordered_pair[0].is_mapped():

                self.event_monitor.count("mapped coordinates", 1)