<jupyter_start><jupyter_text>Para as aplicações será usada a linguagem python e a biblioteca Biopython, portanto o primeiro passo é a instalação da biblioteca.<jupyter_code># instalando pacotes adicionais
!pip install biopython --upgrade<jupyter_output>Collecting biopython
[?25l  Downloading https://files.pythonhosted.org/packages/28/15/8ac646ff24cfa2588b4d5e5ea51e8d13f3d35806bd9498fbf40ef79026fd/biopython-1.73-cp36-cp36m-manylinux1_x86_64.whl (2.2MB)
[K     |████████████████████████████████| 2.2MB 5.1MB/s 
[?25hRequirement already satisfied, skipping upgrade: numpy in /usr/local/lib/python3.6/dist-packages (from biopython) (1.16.3)
Installing collected packages: biopython
Successfully installed biopython-1.73<jupyter_text>Neste exemplo serão usadas sequencias do DNA humano e de uma bacteria, a seguir é feita a importação desses aqrquivos no formato FASTA.<jupyter_code>import os
import tarfile
from six.moves import urllib

FILE_BACTERIA =  "bacteria.fasta"
FILE_HUMANO =  "humano.fasta"
DOWNLOAD_ROOT = "https://github.com/JohnVictor2017/bioinformatica/raw/master/"
DATA_PATH = "dados/"

def fetch_data(data_url, data_path, file_to_download):
  if not os.path.isdir(data_path):
    os.makedirs(data_path)
  urllib.request.urlretrieve(data_url, data_path+file_to_download)
  
# baixando o arquivo bacteria.fasta
DATA_URL = DOWNLOAD_ROOT + DATA_PATH + FILE_BACTERIA
fetch_data(DATA_URL, DATA_PATH, FILE_BACTERIA)

# baixando o arquivo humano.fasta
DATA_URL = DOWNLOAD_ROOT + DATA_PATH + FILE_HUMANO
fetch_data(DATA_URL, DATA_PATH, FILE_HUMANO)


# observando se o diretório "dados" foi criado com sucesso 
!ls dados<jupyter_output>bacteria.fasta	humano.fasta<jupyter_text>Lendo os arquivos das sequências.<jupyter_code>bacteria = open(DATA_PATH+FILE_BACTERIA).read()
humano = open(DATA_PATH+FILE_HUMANO).read()

# removendo as quebras de linha
bacteria = bacteria.replace("\n","")
humano = humano.replace("\n","")

print('DNA_bacteria: ' + bacteria)
print('DNA_humano: ' + humano)<jupyter_output>DNA_bacteria: AGTTTGATCATGGCTCAGATTGAACGCTGGCGGCAGGCCTAACACATGCAAGTCGAACGGTAACAGGAAGCAGCTTGCTGCTTTGCTGACGAGTGGCGGACGGGTGAGTAATGTCTGGGAAACTGCCTGATGGAGGGGGATAACTACTGGAAACGGTAGCTAATACCGCATAACGTCGCAAGCACAAAGAGGGGGACCTTAGGGCCTCTTGCCATCGGATGTGCCCAGATGGGATTAGCTAGTAGGTGGGGTAACGGCTCACCTAGGCGACGATCCCTAGCTGGTCTGAGAGGATGACCAGCAACACTGGAACTGAGACACGGTCCAGACTCCTACGGGAGGCAGCAGTGGGGAATATTGCACAATGGGCGCAAGCCTGATGCAGCCATGCGCGTGTATGAAGAAGGCCTTCGGGTTGTAAAGTACTTTCAGCGGGGAGGAAGGGAGTAAAGTTAATACCTTTGCTCATTGACGTTACCCGCAGAAGAAGCACCGGCTAACTCCGTGCCAGCAGCCGCGGTAATACGGAGGGTGCAAGCGTTAATCGGAATTACTGGGCGTAAAGCGCACGCAGGCGGTTTGTTAAGTCAGATGTGAAATCCCCGGGCTCAACCTGGGAACTGCATCTGATACTGGCAAGCTTGAGTCTCGTAGAGGGGGGTAGAATTCCAGGTGTAGCGGTGAAATGCGTAGAGATCTGGAGGAATACCGGTGGCGAAGGCGGCCCCCTGGACGAAGACTGACGCTCAGGTGCGAAAGCGTGGGGAGCAAACAGGATTAGATACCCTGGTAGTCCACGCCGTAAACGATGTCGACTTGGAGGTTGTGCCCTTGAGGCGTGGCTTCCGGATAACGCGTTAAGTCGACCGCCTGGGGAGTACGGCCGCAAGGTTAAAACTCAAATGAATTGACGGGGGCCGCACAAGCGGTGGAGCATGTGGTTTAATTCGATGCAACGCGAAGAACCTTACCTGGTCTTGACATCC[...]<jupyter_text>Importando a função Seq do Biopython para ler as sequências e fazer algumas operações.<jupyter_code># tutorial https://biopython.org/wiki/Seq
# importando a biblioteca para ser utilizada
from Bio.Seq import Seq

#armazenando as sequencias
bacteria = Seq(bacteria)
humano = Seq(humano)

# Agora temos nossa sequência de uma bacteria
print("DNA: " + bacteria)

#gerando sequencia complementar
bacteria_complemento = bacteria.complement()
print("Complementar: " + bacteria_complemento)

# Gerando o RNA mensageiro
bacteria_RNA = bacteria.transcribe()
print("RNA: " + bacteria_RNA)<jupyter_output>DNA: AGTTTGATCATGGCTCAGATTGAACGCTGGCGGCAGGCCTAACACATGCAAGTCGAACGGTAACAGGAAGCAGCTTGCTGCTTTGCTGACGAGTGGCGGACGGGTGAGTAATGTCTGGGAAACTGCCTGATGGAGGGGGATAACTACTGGAAACGGTAGCTAATACCGCATAACGTCGCAAGCACAAAGAGGGGGACCTTAGGGCCTCTTGCCATCGGATGTGCCCAGATGGGATTAGCTAGTAGGTGGGGTAACGGCTCACCTAGGCGACGATCCCTAGCTGGTCTGAGAGGATGACCAGCAACACTGGAACTGAGACACGGTCCAGACTCCTACGGGAGGCAGCAGTGGGGAATATTGCACAATGGGCGCAAGCCTGATGCAGCCATGCGCGTGTATGAAGAAGGCCTTCGGGTTGTAAAGTACTTTCAGCGGGGAGGAAGGGAGTAAAGTTAATACCTTTGCTCATTGACGTTACCCGCAGAAGAAGCACCGGCTAACTCCGTGCCAGCAGCCGCGGTAATACGGAGGGTGCAAGCGTTAATCGGAATTACTGGGCGTAAAGCGCACGCAGGCGGTTTGTTAAGTCAGATGTGAAATCCCCGGGCTCAACCTGGGAACTGCATCTGATACTGGCAAGCTTGAGTCTCGTAGAGGGGGGTAGAATTCCAGGTGTAGCGGTGAAATGCGTAGAGATCTGGAGGAATACCGGTGGCGAAGGCGGCCCCCTGGACGAAGACTGACGCTCAGGTGCGAAAGCGTGGGGAGCAAACAGGATTAGATACCCTGGTAGTCCACGCCGTAAACGATGTCGACTTGGAGGTTGTGCCCTTGAGGCGTGGCTTCCGGATAACGCGTTAAGTCGACCGCCTGGGGAGTACGGCCGCAAGGTTAAAACTCAAATGAATTGACGGGGGCCGCACAAGCGGTGGAGCATGTGGTTTAATTCGATGCAACGCGAAGAACCTTACCTGGTCTTGACATCCACGGAAGTT[...]<jupyter_text>Como exemplo será feita um comparação visual da quantidade de pares de nucleotidios no DNA humano e na bacteria.<jupyter_code># Contando pares da bacteria 
# Sabemos que cada um da sequencia ira se juntar a seu correspondente complementar
AT_B = bacteria.count("A");
TA_B = bacteria.count("T");
GC_B = bacteria.count("G");
CG_B = bacteria.count("C");

#contando os pares do humano
AT_H = humano.count("A");
TA_H = humano.count("T");
GC_H = humano.count("G");
CG_H = humano.count("C");

cont_B = {'AT': AT_B, 'TA': TA_B, 'GC': GC_B, 'CG':CG_B}
cont_H = {'AT': AT_H, 'TA': TA_H, 'GC': GC_H, 'CG':CG_H}
 
print('Bacteria:')
print(cont_B)
print('Humano:')
print(cont_H)<jupyter_output>Bacteria:
{'AT': 366, 'TA': 289, 'GC': 463, 'CG': 329}
Humano:
{'AT': 422, 'TA': 418, 'GC': 578, 'CG': 546}<jupyter_text>Plotando os Gráficos de cada par de nucletidio.<jupyter_code>import matplotlib.pyplot as plt
import numpy as np

pares=["AT", "TA", "GC", "CG"]
bacteria= [AT_B, TA_B, GC_B, CG_B]
humano= [AT_H, TA_H, GC_H, CG_H]

plt.bar(pares, bacteria, color="red")

plt.xticks(pares)
plt.xlabel("Pares")
plt.ylabel("Quantidade")
plt.title("Nucleitídeos da Bacteria")
plt.show()


plt.bar(pares, humano, color="blue")

plt.xticks(pares)
plt.xlabel("Pares")
plt.ylabel("Quantidade")
plt.title("Nucleitídeos do Humano")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08952730916986805, 'fraction_numerical': 0.016368799064640054, 'mean_word_length': 10.027624309392266, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '577755', 'license': 'MIT', 'n_tokens_mistral': 2789, 'n_tokens_neox': 2482, 'n_words': 354, 'path': 'Hackeando_o_DNA.ipynb', 'repo_name': 'Gabrielvss/bioinformatica', 'size': '5987'}