I have several files with aprox 1M rows.
This is a sample of the file content:
begin(model(tb4)).
...
sequence_length(187).
amino_acid_pair_ratio(a,a,24.8).
amino_acid_pair_ratio(a,c,0.0).
...
tb_to_tb_evalue(tb3671,1.100000e-01).
tb_to_tb_evalue(tb405,4.300000e-01).
tb_to_tb_evalue(tb3225,5.600000e-01).
...
end(model(tb4))
begin(model(tb56)).
......
end(model(tb56))
By having an input like
myarray = (tb4, tb56..)
I need to calculate how many lines of the type "tb_to_tb_evalue" are contained in each model.
In this case, with the sample text, the output should be: tb4 = 3 tb56 = 0
I have done this so far but I realized I will have to read all file as many times as len(myarray)
def readorfs():
# Declaramos la ruta de la carpeta que almacena los ficheros
path = "data/orfs"
# Recogemos los nombres de los ficheros
all_files = glob.glob(path + "/*.txt")
# Leemos los ficheros line a linea
for filename in all_files:
with open(filename) as f:
lines = f.readlines() # Lee el fichero line a linea
for line in lines:
if line.startswith("begin(model(") and (myarray[i]) in line:
print(line)