<jupyter_start><jupyter_text>First line is the name of the readThen we get the reads of the genomeThen the + which is a placeholderThen the quality score, which is a symbol and can be translated into a number which designates quality. You look at the quality table and then thransform the symbol into it's unicode code point (ASCII code) and substract 33.<jupyter_code>def read_fastq(filename):
    sequences = []
    qualities = []
    with open(filename) as fh:
        while True:
            fh.readline()
            seq = fh.readline().rstrip()
            fh.readline()
            qual = fh.readline().rstrip()
            if len(seq) == 0:
                break
            sequences.append(seq)
            qualities.append(qual)
    
    return sequences, qualities

seqs, quals = read_fastq("data/bioinformatics/SRR835775_1.first1000.fastq")
seqs[:5]
quals[:5]
def phred33ToQ(qual):
    return ord(qual) - 33
phred33ToQ("#")
phred33ToQ("G")
def createHist(qualities):
    hist = [0] * 50
    for qual in qualities:
        for phred in qual:
            q = phred33ToQ(phred)
            hist[q] += 1
            
    return hist

h = createHist(quals)
print(h)
import pandas as pd
%matplotlib inline
df = pd.DataFrame(h)
df.head()
df.plot.bar()
def findGCByPOs(reads):
    gc = [0] * 100 # make the lists 100 numbers long
    totals = [0] * 100
    
    for read in reads:
        for i in range(len(read)):
            if read[i] == "C" or read[i] == "G":
                gc[i] += 1
            totals[i] += 1
        
    for i in range(len(gc)):
        if totals[i] > 0:
            gc[i] /= float(totals[i])
            
    return gc
gc = findGCByPOs(seqs)
gc_df = pd.DataFrame(gc)
gc_df.head()
# plt.plot(range(len(gc)), gc)
# plt.show()
gc_df.plot.line()
import collections
count = collections.Counter()
for seq in seqs:
    count.update(seq)
    
print(count)<jupyter_output>Counter({'G': 28742, 'C': 28272, 'T': 21836, 'A': 21132, 'N': 18})
{'fraction_non_alphanumeric': 0.12226184411614875, 'fraction_numerical': 0.033622007131940905, 'mean_word_length': 2.4275741710296685, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '587922', 'license': 'MIT', 'n_tokens_mistral': 727, 'n_tokens_neox': 667, 'n_words': 197, 'path': 'bioinformatics/fastq.ipynb', 'repo_name': 'ClaudiuCreanga/kaggle', 'size': '1963'}