# Path: kleborate/misc.py
# def reverse_complement(seq):
#     return ''.join([complement_base(x) for x in seq][::-1])


import os
import subprocess
from .misc import reverse_complement
        self.ref_length = int(fields[2])        # slen
        self.alignment_length = int(fields[3])  # length
        self.score = float(fields[4])           # score
        self.hit_seq = fields[5]                # qseq
        self.strand = fields[6]                 # sstrand
        self.ref_start = int(fields[7])         # sstart
        self.ref_end = int(fields[8])           # send
        self.contig_name = fields[9]            # qacc
        self.contig_start = int(fields[10])     # qstart
        self.contig_end = int(fields[11])       # qend
        self.frame = fields[12]                 # qframe

        if self.strand == 'plus':
            assert self.ref_end >= self.ref_start
            self.ref_hit_len = self.ref_end - self.ref_start + 1
        else:
            assert self.strand == 'minus'
            assert self.ref_start >= self.ref_end
            self.ref_hit_len = self.ref_start - self.ref_end + 1
        assert self.contig_end >= self.contig_start

        self.ref_cov = self.ref_hit_len / self.ref_length

    def get_seq_start_end_pos_strand(self):
        # BLAST gives the aligned sequence, so we might need to remove dashes if there are
        # deletions relative to the reference.
        nucl_seq = self.hit_seq.replace('-', '')

        # BLAST also returns the contig's sequence so we might need to flip to the ref strand.
        if self.strand == 'minus':

# Path: kleborate/misc.py
# def reverse_complement(seq):
#     return ''.join([complement_base(x) for x in seq][::-1])


# Path: kleborate/blastn.py
import os
import subprocess
from .misc import reverse_complement

        self.ref_length = int(fields[2])        # slen
        self.alignment_length = int(fields[3])  # length
        self.score = float(fields[4])           # score
        self.hit_seq = fields[5]                # qseq
        self.strand = fields[6]                 # sstrand
        self.ref_start = int(fields[7])         # sstart
        self.ref_end = int(fields[8])           # send
        self.contig_name = fields[9]            # qacc
        self.contig_start = int(fields[10])     # qstart
        self.contig_end = int(fields[11])       # qend
        self.frame = fields[12]                 # qframe

        if self.strand == 'plus':
            assert self.ref_end >= self.ref_start
            self.ref_hit_len = self.ref_end - self.ref_start + 1
        else:
            assert self.strand == 'minus'
            assert self.ref_start >= self.ref_end
            self.ref_hit_len = self.ref_start - self.ref_end + 1
        assert self.contig_end >= self.contig_start

        self.ref_cov = self.ref_hit_len / self.ref_length

    def get_seq_start_end_pos_strand(self):
        # BLAST gives the aligned sequence, so we might need to remove dashes if there are
        # deletions relative to the reference.
        nucl_seq = self.hit_seq.replace('-', '')

        # BLAST also returns the contig's sequence so we might need to flip to the ref strand.
        if self.strand == 'minus':

            return reverse_complement(nucl_seq), self.ref_end, self.ref_start