<jupyter_start><jupyter_text><jupyter_code>!wget https://d28rh4a8wq0iu5.cloudfront.net/ads1/data/ERR037900_1.first1000.fastq
def readFastq(filename):
    sequences = []
    qualities = []
    with open(filename) as fh:
        while True:
            fh.readline() # skip name line
            seq = fh.readline().rstrip() # read base sequence
            fh.readline() # skip placeholder line
            qual = fh.readline().rstrip() #base quality line
            if len(seq) == 0:
                break
            sequences.append(seq)
            qualities.append(qual)
    return sequences, qualities
seqs, quals = readFastq('ERR037900_1.first1000.fastq')

def phred33ToQ(qual):
    return ord(qual) - 33
def createHist(qualities):
    # Create a histogram of quality scores
    hist = [0]*50
    for qual in qualities:
        for phred in qual:
            q = phred33ToQ(phred)
            hist[q] += 1
    return hist
h = createHist(quals)
print(h)
# Plot the histogram
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(range(len(h)), h)
plt.show()
def readFastq(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


def createHist(qualities):
    sequences, qualities = readFastq('ERR037900_1.first1000.fastq')
    phredscore = []
    qualities = qualities[-5]
    for phred in qualities:
        q = ord(phred)-33
        phredscore.append(q)
    return phredscore
h = createHist('qualities')
print (h)
import matplotlib.pyplot as plt
plt.bar(range(len(h)), h)
plt.show()
min_h = min(h)
index_min_h = h.index(min_h)
print (index_min_h)
def findGCByPos(reads):
    ''' Find the GC ratio at each position in the read '''
    # Keep track of the number of G/C bases and the total number of bases at each position
    gc = [0] * 100
    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
    # Divide G/C counts by total counts to get the average at each position
    for i in range(len(gc)):
        if totals[i] > 0:
            gc[i] /= float(totals[i])
    return gc

gc = findGCByPos(seqs)
plt.plot(range(len(gc)), gc)
plt.show()
import collections
count = collections.Counter()
for seq in seqs:
    count.update(seq)
count
print('offset of leftmost occurrence: %d' % min(gc))
def createHist(sequences):
    # Create a histogram of quality scores
    hist = [0]*50
    for seq in sequences:
        for s in seq:
            q = numSeq('sequences')
            hist[q] += 1
    return hist
h = createHist(sequences)
print(h)





def createHist(seqs):
    # Create a histogram of quality scores
    hist = [0]*50
    for seq in seqs:
        for phred in seqs:
            q = numSeq(phred)
            hist[q] += 1
    return hist
h = createHist(seqs)
print(h)
# Plot the histogram
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(range(len(seqs)), seqs)
plt.show()
def findGCByPos(reads):
    ''' Find the GC ratio at each position in the read '''
    # Keep track of the number of G/C bases and the total number of bases at each position
    gc = [0] * 100
    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
    # Divide G/C counts by total counts to get the average at each position
    for i in range(len(gc)):
        if totals[i] > 0:
            gc[i] /= float(totals[i])
    return gc

gc = findGCByPos(seqs)
plt.plot(range(len(gc)), gc)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11578678908441724, 'fraction_numerical': 0.021678143330782964, 'mean_word_length': 2.3550042771599657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 1, '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': '14561', 'license': 'Unlicense', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1288, 'n_words': 392, 'path': 'Class_Worksheet.ipynb', 'repo_name': 'newcooldiscoveries/Algorithms-DNA-Sequencing', 'size': '3921'}