Esempio n. 1
0
    def _loadFromFile(self, fileName, ignoreFirst=False, keepTermGaps=False, referenceFirst=False):
        reader = SimpleFastaReader(fileName)
        self.msa = MSA()
        first = True
        for entry in reader:
            if ignoreFirst and first:
                first = False
                continue

            aSeq = AlignedSequence( entry.sequence, aligned=True, keepTermGaps=keepTermGaps )

            sStart = entry.getAnnotation('start')
            if sStart: aSeq.alignedRange.addDelta( int(sStart) )

            strand = entry.getAnnotation('strand')
            if not strand: strand = '+'

            isReference = False
            if referenceFirst == True and first:
                first = False
                isReference = True

            self.msa.add( aSeq, name=entry.name, strand=strand, isReference=isReference  )

        reader.close()
Esempio n. 2
0
class MsaReader:
    def __init__(self, fileName, ignoreFirst=False, iterate=False, keepTermGaps=False, referenceFirst=False):
        self._fileName = fileName
        self.ignoreFirst = ignoreFirst
        if not iterate:
            self._loadFromFile(self._fileName,ignoreFirst=ignoreFirst, keepTermGaps=keepTermGaps, referenceFirst=referenceFirst)
        
    def _loadFromFile(self, fileName, ignoreFirst=False, keepTermGaps=False, referenceFirst=False):
        reader = SimpleFastaReader(fileName)
        self.msa = MSA()
        first = True
        for entry in reader:
            if ignoreFirst and first:
                first = False
                continue

            aSeq = AlignedSequence( entry.sequence, aligned=True, keepTermGaps=keepTermGaps )

            sStart = entry.getAnnotation('start')
            if sStart: aSeq.alignedRange.addDelta( int(sStart) )

            strand = entry.getAnnotation('strand')
            if not strand: strand = '+'

            isReference = False
            if referenceFirst == True and first:
                first = False
                isReference = True

            self.msa.add( aSeq, name=entry.name, strand=strand, isReference=isReference  )

        reader.close()

    def nameStrandSeqIter( self ):
        reader = SimpleFastaReader( self._fileName )
        first = True
        for entry in reader:
            if self.ignoreFirst and first:
                first = False
                continue
            aSeq = AlignedSequence( entry.sequence, aligned=True )
            sStart = entry.getAnnotation('start')
            if sStart:
                aSeq.alignedRange.addDelta( int(sStart) )
            strand = entry.getAnnotation('strand')
            if not strand:
                strand = '+'
            yield entry.name, strand, aSeq
        reader.close()

    def nameStrandCrSeqIter( self ):
        reader = SimpleFastaReader( self._fileName )
        first = True
        for entry in reader:
            if self.ignoreFirst and first:
                first = False
                continue
            aSeq = AlignedSequence( entry.sequence, aligned=True )
            sStart = entry.getAnnotation('start')
            if sStart:
                aSeq.alignedRange.addDelta( int(sStart) )
            strand = entry.getAnnotation('strand')
            if not strand:
                strand = '+'
            cr = entry.getAnnotation('cr')
            yield entry.name, strand, cr, aSeq
        reader.close()
        
    def getMsa(self):
        return self.msa