예제 #1
0
파일: cap3.py 프로젝트: SiriusShiu/Mungo
def parseContents(contents, section):
    if section==1:
        readNames = []
        contained = {}
        for line in contents:
            if line[0]!=' ':
                readNames.append(line.strip())
            else:
                tokens = line.strip().split()
                readNames.append(tokens[0])
                contained[tokens[0]] = tokens[-1]
        return readNames, contained
    elif section==2:
        aln = Alignment()
        iSeqStart = -1
        L = 0
        for line in contents:
            if line==Tokens.ruler:
                # Ruler line
                iSeqStart = line.find('.')-4 # = 22 ???
                if iSeqStart!=22: print "!!! iSeqStart:", iSeqStart
            elif line[0]==' ':
                # Separator line
                pass
            else:
                line = line.rstrip()
                name = line[0:iSeqStart].strip()
                seq = line[iSeqStart:]
                if name!='consensus':
                    if not name in aln.seqDict:
                        seq = seq.replace(' ', '.')
                        seq = '.'*L + seq
                    aln.append(name, seq)
                else:
                    aln.append(name, seq)
                    L = len(aln['consensus'])
        
        # Pad short sequences with '.'
        for name in aln:
            aln[name] = aln[name] + '.'*(L-len(aln[name]))
        return aln
    else:
        raise Exception("cap3.parseContents")