Python ve R'a Giriş Introduction to Python and R
Biyoinformatik analizlerde iki programlama dili öne çıkmaktadır: R ve Python. Her ikisi de açık kaynaklı, ücretsiz ve geniş bir biyoinformatik kütüphane ekosistemine sahiptir. R, istatistiksel analizler ve görselleştirme konusunda güçlüdür; Python ise genel programlama, otomasyon ve makine öğrenmesi uygulamaları için tercih edilir.
Python ile Biyoinformatik
Python, okunabilir sözdizimi ve geniş kütüphane desteği sayesinde biyoinformatik için ideal bir dildir. Temel biyoinformatik görevlerin büyük çoğunluğu Python ile yapılabilir.
Temel Python Kavramları
# Değişkenler ve veri tipleri
isim = "Homo sapiens"
gen_sayisi = 20000
gc_orani = 0.41
# Listeler
bazlar = ["A", "T", "G", "C"]
# Sözlükler (dictionary)
kodon = {"ATG": "Met", "TAA": "Stop", "TGA": "Stop"}
# Döngüler
for baz in bazlar:
print(baz)
# Fonksiyonlar
def gc_hesapla(dizi):
gc = dizi.count("G") + dizi.count("C")
return gc / len(dizi) * 100
# Kullanım
dna = "ATGCGATCGATCG"
print(f"GC oranı: {gc_hesapla(dna):.1f}%")
BioPython — Biyoinformatik Kütüphanesi
BioPython, DNA/protein dizileri, FASTA dosyaları, veritabanı sorguları ve filogenetik analizler için kapsamlı araçlar sunar.
# BioPython kurulumu
# conda install -c conda-forge biopython
from Bio import SeqIO
from Bio.Seq import Seq
# FASTA dosyası okuma
for record in SeqIO.parse("sekanslar.fasta", "fasta"):
print(record.id, len(record.seq))
# Dizi işlemleri
dizi = Seq("ATGCGATCGATCG")
print("Kompleman:", dizi.complement())
print("Ters kompleman:", dizi.reverse_complement())
print("Protein:", dizi.translate())
# NCBI'den dizi indirme
from Bio import Entrez
Entrez.email = "email@ornek.com"
handle = Entrez.efetch(db="nucleotide", id="MK033133", rettype="fasta")
kayit = SeqIO.read(handle, "fasta")
print(kayit.description)
Pandas — Veri Analizi
import pandas as pd
# CSV dosyası okuma
df = pd.read_csv("sonuclar.csv")
# Temel istatistikler
print(df.describe())
# Filtreleme
yuksek_kalite = df[df["quality_score"] > 30]
# Gruplama
df.groupby("genus")["coverage"].mean()
R ile Biyoinformatik
R, istatistiksel hesaplamalar ve veri görselleştirme konusunda sektör standardı konumundadır. Bioconductor platformu, genomik analizler için binlerce özel paket barındırır.
Temel R Kavramları
# Vektörler
gc_oranlari <- c(0.41, 0.52, 0.38, 0.65)
mean(gc_oranlari) # Ortalama
sd(gc_oranlari) # Standart sapma
# Veri çerçevesi (data.frame)
sonuclar <- data.frame(
ornek = c("S1", "S2", "S3"),
kapsama = c(50, 120, 80),
kalite = c(35, 38, 32)
)
# Filtreleme
yuksek <- sonuclar[sonuclar$kapsama > 100, ]
# Fonksiyon tanımlama
gc_hesapla <- function(dizi) {
gc <- nchar(gsub("[^GC]", "", dizi))
gc / nchar(dizi) * 100
}
gc_hesapla("ATGCGCTAGC")
ggplot2 — Görselleştirme
library(ggplot2)
# Örnek veri
df <- data.frame(
organizma = c("E. coli", "S. aureus", "B. subtilis"),
gc_orani = c(50.8, 32.9, 43.5)
)
# Çubuk grafik
ggplot(df, aes(x = organizma, y = gc_orani, fill = organizma)) +
geom_bar(stat = "identity") +
labs(title = "GC Oranı Karşılaştırması",
x = "Organizma", y = "GC Oranı (%)") +
theme_minimal()
Bioconductor — Genomik Analizler
# Bioconductor kurulumu
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("Biostrings")
library(Biostrings)
# FASTA okuma
diziler <- readDNAStringSet("sekanslar.fasta")
width(diziler) # Dizi uzunlukları
letterFrequency(diziler, "GC") # GC içeriği
Jupyter Notebook
Jupyter Notebook, Python ve R kodlarını, açıklamaları ve görselleştirmeleri tek bir belgede birleştirmenizi sağlayan etkileşimli bir platformdur. Biyoinformatik analizlerin tekrarlanabilir belgelenmesi için idealdir.
# Jupyter kurulumu
conda install -c conda-forge jupyter
# Başlatma
jupyter notebook
Two programming languages stand out in bioinformatic analyses: R and Python. Both are open-source, free, and have a broad bioinformatics library ecosystem. R excels in statistical analysis and visualization; Python is preferred for general programming, automation, and machine learning applications.
Python for Bioinformatics
Python is ideal for bioinformatics thanks to its readable syntax and extensive library support. The vast majority of basic bioinformatic tasks can be done with Python.
Basic Python Concepts
# Variables and data types
name = "Homo sapiens"
gene_count = 20000
gc_ratio = 0.41
# Lists
bases = ["A", "T", "G", "C"]
# Dictionaries
codon = {"ATG": "Met", "TAA": "Stop", "TGA": "Stop"}
# Loops
for base in bases:
print(base)
# Functions
def calc_gc(sequence):
gc = sequence.count("G") + sequence.count("C")
return gc / len(sequence) * 100
# Usage
dna = "ATGCGATCGATCG"
print(f"GC content: {calc_gc(dna):.1f}%")
BioPython — Bioinformatics Library
BioPython provides comprehensive tools for DNA/protein sequences, FASTA files, database queries, and phylogenetic analyses.
# Install BioPython
# conda install -c conda-forge biopython
from Bio import SeqIO
from Bio.Seq import Seq
# Reading FASTA file
for record in SeqIO.parse("sequences.fasta", "fasta"):
print(record.id, len(record.seq))
# Sequence operations
seq = Seq("ATGCGATCGATCG")
print("Complement:", seq.complement())
print("Reverse complement:", seq.reverse_complement())
print("Protein:", seq.translate())
# Download sequence from NCBI
from Bio import Entrez
Entrez.email = "email@example.com"
handle = Entrez.efetch(db="nucleotide", id="MK033133", rettype="fasta")
record = SeqIO.read(handle, "fasta")
print(record.description)
Pandas — Data Analysis
import pandas as pd
# Read CSV file
df = pd.read_csv("results.csv")
# Basic statistics
print(df.describe())
# Filtering
high_quality = df[df["quality_score"] > 30]
# Grouping
df.groupby("genus")["coverage"].mean()
R for Bioinformatics
R is the industry standard for statistical computing and data visualization. The Bioconductor platform hosts thousands of specialized packages for genomic analyses.
Basic R Concepts
# Vectors
gc_ratios <- c(0.41, 0.52, 0.38, 0.65)
mean(gc_ratios) # Mean
sd(gc_ratios) # Standard deviation
# Data frame
results <- data.frame(
sample = c("S1", "S2", "S3"),
coverage = c(50, 120, 80),
quality = c(35, 38, 32)
)
# Filtering
high <- results[results$coverage > 100, ]
# Function definition
calc_gc <- function(sequence) {
gc <- nchar(gsub("[^GC]", "", sequence))
gc / nchar(sequence) * 100
}
calc_gc("ATGCGCTAGC")
ggplot2 — Visualization
library(ggplot2)
df <- data.frame(
organism = c("E. coli", "S. aureus", "B. subtilis"),
gc_ratio = c(50.8, 32.9, 43.5)
)
ggplot(df, aes(x = organism, y = gc_ratio, fill = organism)) +
geom_bar(stat = "identity") +
labs(title = "GC Content Comparison",
x = "Organism", y = "GC Content (%)") +
theme_minimal()
Bioconductor — Genomic Analyses
# Install Bioconductor
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("Biostrings")
library(Biostrings)
# Read FASTA
sequences <- readDNAStringSet("sequences.fasta")
width(sequences) # Sequence lengths
letterFrequency(sequences, "GC") # GC content
Jupyter Notebook
Jupyter Notebook is an interactive platform that allows you to combine Python and R code, explanations, and visualizations in a single document. It is ideal for reproducible documentation of bioinformatic analyses.
# Install Jupyter
conda install -c conda-forge jupyter
# Launch
jupyter notebook