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 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -