示例#1
0
文件: snp2maf.py 项目: yangjl/cgat
def alignIndels( all_alleles, colcounts, extend_by = 0 ):
    '''align all indel-regions.'''

    aa = alignlib_lite.py_makeAlignatorDPFull( alignlib_lite.py_ALIGNMENT_LOCAL, 0, 0 )     
    alignator = alignlib_lite.py_makeMultipleAlignatorSimple( aa)

    ids = all_alleles.keys()

    for x,c in enumerate(colcounts):
        if c <= 1: continue
        sequences = alignlib_lite.py_StringVector()
        for sid in ids:
            for allele in all_alleles[sid]:
                sequences.append( allele[x] )

        mali = alignlib_lite.py_makeMultAlignment()
        alignator.align( mali, sequences )
        realigned = []
        for line in str(alignlib_lite.py_MultAlignmentFormatPlain( mali, sequences )).split("\n")[:-1]:
            data = line[:-1].split("\t")
            realigned.append( data[1] )
        assert len(realigned) == len(sequences)

        l = max( [len(r) for r in realigned] )
        i = 0
        for sid in ids:
            for allele in all_alleles[sid]:
                if realigned[i]: allele[x] = realigned[i] 
                else: allele[x] = "-" * l 
                i += 1
                
        colcounts[x] = l
示例#2
0
def convertAlignlib2Mali( mali, identifiers = None, seqs = None ):
    """convert a multiple alignment into an alignlib_lite.py_multiple alignment object."""
    m = Mali()

    if not identifiers:
        identifiers = [ "%i" % x for x in range( mali.getNumSequences() ) ]

    if seqs == None:
        # old style MultipleAlignment
        for x in range(mali.getNumSequences()):
            a = mali.getRow( x )
            m.addSequence( identifiers[x], a.getFrom(), a.getTo(), a.getString() )
    else:
        import alignlib_lite
        output = alignlib_lite.py_MultAlignmentFormatPlain( mali, seqs )
        for x in range(mali.getNumSequences()):
            a = output.mData[ x ]
            m.addSequence( identifiers[x], a.getFrom(), a.getTo(), a.getString() )
        
    return m
示例#3
0
def convertAlignlib2Mali(mali, identifiers=None, seqs=None):
    """convert a multiple alignment into an alignlib_lite.py_multiple alignment object."""
    m = Mali()

    if not identifiers:
        identifiers = ["%i" % x for x in range(mali.getNumSequences())]

    if seqs == None:
        # old style MultipleAlignment
        for x in range(mali.getNumSequences()):
            a = mali.getRow(x)
            m.addSequence(identifiers[x], a.getFrom(), a.getTo(),
                          a.getString())
    else:
        import alignlib_lite
        output = alignlib_lite.py_MultAlignmentFormatPlain(mali, seqs)
        for x in range(mali.getNumSequences()):
            a = output.mData[x]
            m.addSequence(identifiers[x], a.getFrom(), a.getTo(),
                          a.getString())

    return m