@staticmethod <EOL><INDENT>def read_transfac( fin, alphabet = None) :<DEDENT>
items = []<EOL>start=True<EOL>for line in fin :<EOL><INDENT>if line.isspace() or line[<NUM_LIT:0>] =='<STR_LIT:#>' : continue<EOL>stuff = line.split()<EOL>if start and stuff[<NUM_LIT:0>] != '<STR_LIT>' and stuff[<NUM_LIT:0>] != '<STR_LIT>': continue<EOL>if stuff[<NUM_LIT:0>]=='<STR_LIT>' or stuff[<NUM_LIT:0>]=='<STR_LIT>': break<EOL>start = False<EOL>items.append(stuff)<EOL><DEDENT>if len(items) < <NUM_LIT:2>  :<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>header = items.pop(<NUM_LIT:0>)<EOL>hcols = len(header)<EOL>rows = len(items)<EOL>cols = len(items[<NUM_LIT:0>])<EOL>if not( header[<NUM_LIT:0>] == '<STR_LIT>' or header[<NUM_LIT:0>] =='<STR_LIT>' or hcols == cols-<NUM_LIT:1> or hcols == cols-<NUM_LIT:2>) :<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>cols = len(items[<NUM_LIT:0>])<EOL>for i in range(<NUM_LIT:1>, len(items)) :<EOL><INDENT>if cols != len(items[i]) :<EOL><INDENT>raise ValueError("<STR_LIT>" % i)<EOL><DEDENT><DEDENT>if header[<NUM_LIT:0>] == '<STR_LIT>' or header[<NUM_LIT:0>] == '<STR_LIT>': header.pop(<NUM_LIT:0>)<EOL>position_header = True    <EOL>alphabet_header = True    <EOL>for h in header :<EOL><INDENT>if not corebio.utils.isint(h) : position_header = False<EOL><DEDENT>on-alphabetic            if not str.isalpha(h) : alphabet_header = False<EOL>if not position_header and not alphabet_header :<EOL><INDENT>raise ValueError("<STR_LIT>" % str(header))<EOL><DEDENT>if position_header and alphabet_header :<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if alphabet_header :<EOL><INDENT>for i,r in enumerate(items) :<EOL><INDENT>if not corebio.utils.isint(r[<NUM_LIT:0>]) and r[<NUM_LIT:0>][<NUM_LIT:0>]!='<STR_LIT:P>' : <EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % i)<EOL><DEDENT>r.pop(<NUM_LIT:0>)<EOL>defacto_alphabet = '<STR_LIT>'.join(header)<EOL><DEDENT><DEDENT>else :<EOL><INDENT>a = []<EOL>for i,r in enumerate(items) :<EOL><INDENT>if not ischar(r[<NUM_LIT:0>]) and r[<NUM_LIT:0>][<NUM_LIT:0>]!='<STR_LIT:P>' : <EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" % i)<EOL><DEDENT>a.append(r.pop(<NUM_LIT:0>))<EOL><DEDENT>defacto_alphabet = '<STR_LIT>'.join(a)                <EOL><DEDENT>defacto_alphabet = corebio.seq.Alphabet(defacto_alphabet)<EOL>if alphabet :<EOL><INDENT>if not defacto_alphabet.alphabetic(alphabet) :<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>% (alphabet, defacto_alphabet))<EOL><DEDENT><DEDENT>else :            <EOL><INDENT>alphabets = (unambiguous_rna_alphabet,<EOL>unambiguous_dna_alphabet,                      <EOL>unambiguous_protein_alphabet,<EOL>)<EOL>for a in alphabets :<EOL><INDENT>if defacto_alphabet.alphabetic(a) :<EOL><INDENT>alphabet = a<EOL>break<EOL><DEDENT><DEDENT>if not alphabet :<EOL><INDENT>alphabet = defacto_alphabet<EOL><DEDENT><DEDENT>if len(items[<NUM_LIT:0>]) == len(header) +<NUM_LIT:1> :<EOL><INDENT>for r in items :<EOL><INDENT>r.pop()<EOL><DEDENT><DEDENT>rows = len(items)<EOL>cols = len(items[<NUM_LIT:0>])<EOL>matrix = numpy.zeros( (rows,cols) , dtype=numpy.float64) <EOL>for r in range( rows) :<EOL><INDENT>for c in range(cols):<EOL><INDENT>matrix[r,c] = float( items[r][c]) <EOL><DEDENT><DEDENT>if position_header :<EOL><INDENT>matrix.transpose() <EOL><DEDENT>return _my_Motif(defacto_alphabet, matrix).reindex(alphabet)<EOL>
Parse a sequence matrix from a file. 
        Returns a tuple of (alphabet, matrix)