arrays - How to open a text file as a character matrix in python? -
i have .fa file contains list of secuences of nucleotids. this
agctagagagactagactaga
gatcagtacatgatctaggat
gatagtacatgggggatagac
i need somehow open file in python , make 2-dim array contains rows lines of .fa file , in each column letter of file. help!!!!
if interested in having matrix list of lists, can list comprehension.
with open("myfile.fa","rt") infile: matrix = [list(line.strip()) line in infile.readlines()] print matrix
if, on other hand, prefer have numpy
matrix (note requires have installed numpy
):
import numpy open("myfile.fa","rt") infile: matrix = numpy.matrix([list(line.strip()) line in infile.readlines()]) print matrix