ascii_table = read.table("ascii_table",sep=" ") ascii_symbol = ascii_table[,2] ascii_number = ascii_table[,1] - 64 phred = exp(-ascii_number/10) close(input) input = file("7C_1_partial.fq",open="r") while(length(line <- readLines(input,n=1,warn=F)) > 0) { if( (match <- regexpr("AGTCTAAC",line,perl=T)) >= 0) { hline = readLines(input,n=1,warn=F) qline = readLines(input,n=1,warn=F) low_q = 0 for(i in 0:7) { s = substr(qline,match+i,match+i) if(phred[ascii_symbol == s] > 0.05) { low_q = 1; } } if(low_q == 0) { print(previous_line) } } previous_line = line } close(input)