# Path: SDDetector/Entities/Alignment.py
# class Alignment(object):
# 
#     __slots__ = ['query','sbjct','qstart','qend','sstart','send',
#                  'length', 'identities', 'qstrand', 'sstrand','id']
# 
#     def __init__(self, query, sbjct, qstart, qend, sstart, send, length, identities, qstrand, sstrand, id=''):
#         """Alignment constructor"""
# 
#         self.query = query
#         self.sbjct = sbjct
#         self.qstart = qstart
#         self.qend = qend
#         self.sstart = sstart
#         self.send = send
#         self.length = length
#         self.identities = identities
#         self.qstrand = qstrand
#         self.sstrand = sstrand
#         self.id = id
# 
#     def __eq__(self, other):
#         """Equality on all args"""
#       
#         return (self.query,self.sbjct,self.qstart,self.qend,self.sstart,self.send,self.length,self.identities,self.qstrand,self.sstrand, self.id) == (other.query,other.sbjct,other.qstart,other.qend,other.sstart,other.send,other.length,other.identities,other.qstrand,other.sstrand, other.id)
# 
#     def __repr__(self):
#         """representation"""
# 
#         return ('{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}'.format(self.query,self.sbjct,self.qstart,self.qend,self.sstart,self.send,self.length,self.identities,self.qstrand,self.sstrand, self.id))
# 
#     def convertToGff3(self):
#         """Write alignment in gff3 format"""
# 
#         if self.sstrand == 1:
#             strand = '+'
#         else:
#             strand = '-'
# 
#         gff3line = '{}\tSQLiteDB\tmatch\t{}\t{}\t.\t{}\t.\tID=match{};Target={} {} {}\n'.format(self.sbjct,self.sstart,self.send,strand,self.id,self.query,self.qstart,self.qend)
#         return gff3line
# 
# Path: SDDetector/Parser/Blast/BlastTabParser.py
# class BlastTabParser(object):
# 
#     def __init__(self, inputBlastTabFile=""):
#         """Constructor"""
#         self.inputBlastTabFile = inputBlastTabFile
# 
#     def getAllAlignments(self):
#         """Return list of all Alignments"""
# 
#         lAlignments = []
#         with open(self.inputBlastTabFile,  'r') as input :
#             index = 0
#             nb_hsp = 0
#             for line in input:
#                 index += 1
#                 nb_hsp += 1
#                 qseqid,sseqid,qstart,qend,sstart,send,length,nident = line.split('\t')
#                 qframe = 1
#                 sframe = None
#                 if int(sstart) < int(send):
#                     sframe = 1
#                 else:
#                     sframe = -1
# 
#                 if sframe == 1: 
#                     lAlignments.append(Alignment(qseqid, sseqid, int(qstart), int(qend), int(sstart), int(send), int(length),
#                                                  int(nident), int(qframe), int(sframe), id=index))
#                 if sframe == -1:
#                     lAlignments.append(Alignment(qseqid, sseqid, int(qstart), int(qend), int(send), int(sstart), int(length),
#                                                  int(nident), int(qframe), int(sframe), id=index))
# 
#             logging.debug('{} HSP parsed'.format(nb_hsp))
# 
#         input.closed
#         return lAlignments


import sqlite3
import unittest
from SDDetector.Entities.Alignment import Alignment
from SDDetector.Parser.Blast.BlastTabParser import BlastTabParser
#!/usr/bin/env python



class TestBlastTabParser(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_getAllAlignments(self):
        """Test getAllAlignments method"""

        iBlastTabParser = BlastTabParser("test-data/blast.tab")
        lAlignments = [Alignment('seq1','seq1',1,167,1,167,167,167,1,1,id=1),
                       Alignment('seq1','seq2',1,164,237,400,164,164,1,-1,id=2),
                       Alignment('seq1','seq2',50,113,54,118,66,63,1,1,id=3),
                       Alignment('seq2','seq2',1,400,1,400,400,400,1,1,id=4),
                       Alignment('seq2','seq2',288,351,54,118,66,63,1,-1,id=5),

# Path: SDDetector/Entities/Alignment.py
# class Alignment(object):
# 
#     __slots__ = ['query','sbjct','qstart','qend','sstart','send',
#                  'length', 'identities', 'qstrand', 'sstrand','id']
# 
#     def __init__(self, query, sbjct, qstart, qend, sstart, send, length, identities, qstrand, sstrand, id=''):
#         """Alignment constructor"""
# 
#         self.query = query
#         self.sbjct = sbjct
#         self.qstart = qstart
#         self.qend = qend
#         self.sstart = sstart
#         self.send = send
#         self.length = length
#         self.identities = identities
#         self.qstrand = qstrand
#         self.sstrand = sstrand
#         self.id = id
# 
#     def __eq__(self, other):
#         """Equality on all args"""
#       
#         return (self.query,self.sbjct,self.qstart,self.qend,self.sstart,self.send,self.length,self.identities,self.qstrand,self.sstrand, self.id) == (other.query,other.sbjct,other.qstart,other.qend,other.sstart,other.send,other.length,other.identities,other.qstrand,other.sstrand, other.id)
# 
#     def __repr__(self):
#         """representation"""
# 
#         return ('{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}'.format(self.query,self.sbjct,self.qstart,self.qend,self.sstart,self.send,self.length,self.identities,self.qstrand,self.sstrand, self.id))
# 
#     def convertToGff3(self):
#         """Write alignment in gff3 format"""
# 
#         if self.sstrand == 1:
#             strand = '+'
#         else:
#             strand = '-'
# 
#         gff3line = '{}\tSQLiteDB\tmatch\t{}\t{}\t.\t{}\t.\tID=match{};Target={} {} {}\n'.format(self.sbjct,self.sstart,self.send,strand,self.id,self.query,self.qstart,self.qend)
#         return gff3line
# 
# Path: SDDetector/Parser/Blast/BlastTabParser.py
# class BlastTabParser(object):
# 
#     def __init__(self, inputBlastTabFile=""):
#         """Constructor"""
#         self.inputBlastTabFile = inputBlastTabFile
# 
#     def getAllAlignments(self):
#         """Return list of all Alignments"""
# 
#         lAlignments = []
#         with open(self.inputBlastTabFile,  'r') as input :
#             index = 0
#             nb_hsp = 0
#             for line in input:
#                 index += 1
#                 nb_hsp += 1
#                 qseqid,sseqid,qstart,qend,sstart,send,length,nident = line.split('\t')
#                 qframe = 1
#                 sframe = None
#                 if int(sstart) < int(send):
#                     sframe = 1
#                 else:
#                     sframe = -1
# 
#                 if sframe == 1: 
#                     lAlignments.append(Alignment(qseqid, sseqid, int(qstart), int(qend), int(sstart), int(send), int(length),
#                                                  int(nident), int(qframe), int(sframe), id=index))
#                 if sframe == -1:
#                     lAlignments.append(Alignment(qseqid, sseqid, int(qstart), int(qend), int(send), int(sstart), int(length),
#                                                  int(nident), int(qframe), int(sframe), id=index))
# 
#             logging.debug('{} HSP parsed'.format(nb_hsp))
# 
#         input.closed
#         return lAlignments


# Path: tests/test_BlastTabParser.py
import sqlite3
import unittest
from SDDetector.Entities.Alignment import Alignment
from SDDetector.Parser.Blast.BlastTabParser import BlastTabParser

#!/usr/bin/env python



class TestBlastTabParser(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_getAllAlignments(self):
        """Test getAllAlignments method"""

        iBlastTabParser = BlastTabParser("test-data/blast.tab")
        lAlignments = [Alignment('seq1','seq1',1,167,1,167,167,167,1,1,id=1),
                       Alignment('seq1','seq2',1,164,237,400,164,164,1,-1,id=2),
                       Alignment('seq1','seq2',50,113,54,118,66,63,1,1,id=3),
                       Alignment('seq2','seq2',1,400,1,400,400,400,1,1,id=4),
                       Alignment('seq2','seq2',288,351,54,118,66,63,1,-1,id=5),

                       Alignment('seq2','seq2',54,118,288,351,66,63,1,-1,id=6),