# 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


import xml.parsers.expat
import logging
import sys
from SDDetector.Entities.Alignment import Alignment
        elif self.elmt == 'Hsp_align-len':
            self.length = int(data)
        elif self.elmt == 'Hsp_qseq':
            self.qseq = data
        elif self.elmt == 'Hsp_hseq':
            self.sseq = data
        else:
            pass
            
        
    def endElementSDDetector(self, name):
        """end"""

        self.elmt = None
        if name == 'Hsp' and not self.lRegionIndex:
            self.addAlignment()
        elif name == 'Hsp' and self.lRegionIndex:
            self.getAlignmentFromRegions()
    
    
    def addAlignment(self):
        """add alignment to the list"""

        self.nbAlgmts += 1

        if self.sframe == 1:
            self.lAlgmts.append(Alignment(self.qid,self.sid,self.qstart,
                                self.qend,self.sstart,self.send,self.length,
                                self.ident, self.qframe, self.sframe, id=self.nbAlgmts))
        elif self.sframe == -1:

# 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/BlastXMLParserExpat.py
import xml.parsers.expat
import logging
import sys
from SDDetector.Entities.Alignment import Alignment

        elif self.elmt == 'Hsp_align-len':
            self.length = int(data)
        elif self.elmt == 'Hsp_qseq':
            self.qseq = data
        elif self.elmt == 'Hsp_hseq':
            self.sseq = data
        else:
            pass
            
        
    def endElementSDDetector(self, name):
        """end"""

        self.elmt = None
        if name == 'Hsp' and not self.lRegionIndex:
            self.addAlignment()
        elif name == 'Hsp' and self.lRegionIndex:
            self.getAlignmentFromRegions()
    
    
    def addAlignment(self):
        """add alignment to the list"""

        self.nbAlgmts += 1

        if self.sframe == 1:
            self.lAlgmts.append(Alignment(self.qid,self.sid,self.qstart,
                                self.qend,self.sstart,self.send,self.length,
                                self.ident, self.qframe, self.sframe, id=self.nbAlgmts))
        elif self.sframe == -1:

            self.lAlgmts.append(Alignment(self.qid,self.sid,self.qstart,