Komut Satırına Giriş Introduction to the Command Line
Kabuk (Shell), bilgisayarınızı grafiksel bir arayüz (GUI) yerine yalnızca klavye ile kontrol etmenizi sağlayan bir komut satırı arabirimidir. İlk başta zor görünebilir; ancak kabuğa hakim olmanın biyoinformatik çalışmalar için birçok önemli nedeni vardır:
- Çoğu biyoinformatik programı yalnızca komut satırından çalıştırılabilir.
- Kabuk, işinizi daha verimli ve tekrarlanabilir biçimde yapmanızı sağlar.
- Bulut/HPC (Yüksek Performanslı Hesaplama) sunucularına yalnızca komut satırı üzerinden erişilir.
Temel Komutlar
man — Yardım Kılavuzu
Herhangi bir komut veya program hakkında ayrıntılı yardım almanızı sağlar.
$ man ls
ls — Dizin İçeriğini Listeleme
Bulunduğunuz dizindeki dosya ve klasörleri listeler.
$ ls # Kısa liste
$ ls -l # Ayrıntılı liste (izinler, boyut, tarih)
$ ls -lh # Ayrıntılı liste, okunabilir boyutlarla
$ ls -a # Gizli dosyaları da göster
pwd — Bulunduğunuz Dizini Gösterme
Mevcut çalışma dizininin tam yolunu ekrana yazdırır.
$ pwd
/home/kullanici/Desktop/proje
cd — Dizin Değiştirme
Farklı bir dizine geçmek için kullanılır.
$ cd klasor1 # klasor1'e gir
$ cd .. # Bir üst dizine çık
$ cd ~ # Ana (home) dizine git
$ cd /home/user/data # Tam yol ile git
mkdir — Klasör Oluşturma
$ mkdir yeni_klasor
$ mkdir -p proje/veri/ham # İç içe klasör oluştur
touch — Dosya Oluşturma
$ touch dosya.txt
$ touch seq1.fasta seq2.fasta
cp — Kopyalama
$ cp dosya.txt yedek.txt
$ cp -r klasor/ yedek_klasor/ # Klasör kopyala
mv — Taşıma / Yeniden Adlandırma
$ mv dosya.txt yeni_isim.txt # Yeniden adlandır
$ mv dosya.txt ../diger_klasor/ # Taşı
rm — Silme
$ rm dosya.txt
$ rm -r klasor/ # Klasör ve içeriğini sil (DİKKATLİ OLUN)
cat — Dosya İçeriğini Göster
$ cat sekans.fasta
head / tail — Dosyanın Başı/Sonu
$ head -10 reads.fastq # İlk 10 satır
$ tail -5 results.txt # Son 5 satır
less — Sayfalı Görüntüleme
$ less buyuk_dosya.txt
# Gezinti: ok tuşları, q ile çıkış
grep — Metin Arama
$ grep "ATCG" sekans.fasta
$ grep -c ">" multi.fasta # FASTA'daki dizi sayısını say
wc — Kelime/Satır Sayma
$ wc -l dosya.txt # Satır sayısı
$ wc -w dosya.txt # Kelime sayısı
chmod — Dosya İzinlerini Değiştirme
$ chmod +x script.sh # Çalıştırılabilir yap
$ chmod 755 script.sh # rwxr-xr-x izinleri
sudo — Yönetici Olarak Çalıştırma
$ sudo apt update # Paket listesini güncelle
$ sudo apt install fastqc # Program yükle
df — Disk Kullanımı
$ df -h # Disk kullanımını okunabilir biçimde göster
top / htop — Sistem Kaynakları
$ top # Çalışan işlemleri göster
$ htop # Daha kullanışlı arayüz (kurulu ise)
history — Komut Geçmişi
$ history
$ history | grep fastqc # Geçmişte fastqc ile ilgili komutlar
wget / curl — İnternet'ten İndirme
$ wget https://example.com/dosya.tar.gz
$ curl -O https://example.com/dosya.fasta
tar / gzip — Sıkıştırma ve Açma
$ tar -xzf arsiv.tar.gz # .tar.gz aç
$ tar -czf arsiv.tar.gz klasor/ # .tar.gz oluştur
$ gunzip dosya.fastq.gz # .gz aç
$ gzip dosya.fastq # .gz oluştur
Bash Scriptleri
Bash scriptleri, birden fazla komutu bir dosyada toplayarak otomatik olarak çalıştırmanızı sağlar. Biyoinformatik analizleri için tekrarlanabilir iş akışları oluşturmak açısından çok değerlidir.
Basit Script Örneği
#!/bin/bash
# Bu script FASTQ dosyalarını FastQC ile analiz eder
for file in *.fastq
do
echo "Analiz ediliyor: $file"
fastqc $file
done
echo "Tüm analizler tamamlandı."
Koşullu İfadeler (if/else)
for i in *
do
if [ -f $i ]; then
echo "$i bir dosyadır"
elif [ -d $i ]; then
echo "$i bir klasördür"
fi
done
Döngüler ile Toplu İşlem
# Tüm .zip dosyalarını aç
for filename in *.zip
do
unzip $filename
done
# İki örnek grubunu karşılaştır
for sample in sample1 sample2 sample3
do
bwa mem ref.fasta ${sample}_R1.fastq ${sample}_R2.fastq > ${sample}.sam
done
Conda ile Program Yönetimi
Biyoinformatik araçlarının çoğu Conda paket yöneticisi üzerinden kurulur.
# Conda ortamı oluştur
conda create -n biyoinf python=3.9
# Ortamı aktive et
conda activate biyoinf
# Program yükle
conda install -c bioconda fastqc trimmomatic bwa samtools
# Ortamı dışa aktar
conda env export > ortam.yaml
# Ortamı içe aktar
conda env create -f ortam.yaml
The shell is a command-line interface program that allows you to control your computer using only a keyboard, rather than through a graphical user interface (GUI). It may seem difficult at first; however, there are several important reasons for mastering the shell in bioinformatics:
- Most bioinformatics programs can only be run from the command line.
- The shell enables you to do your work more efficiently and reproducibly.
- Cloud/HPC (High-Performance Computing) servers are accessed only through the command line.
Basic Commands
man — Manual Pages
Provides detailed help about any command or program.
$ man ls
ls — List Directory Contents
$ ls # Short list
$ ls -l # Detailed list (permissions, size, date)
$ ls -lh # Detailed list with human-readable sizes
$ ls -a # Show hidden files too
pwd — Print Working Directory
$ pwd
/home/user/Desktop/project
cd — Change Directory
$ cd folder1 # Enter folder1
$ cd .. # Go up one directory
$ cd ~ # Go to home directory
$ cd /home/user/data # Go to absolute path
mkdir — Make Directory
$ mkdir new_folder
$ mkdir -p project/data/raw # Create nested directories
touch — Create Empty File
$ touch file.txt
$ touch seq1.fasta seq2.fasta
cp — Copy
$ cp file.txt backup.txt
$ cp -r folder/ backup_folder/ # Copy directory
mv — Move / Rename
$ mv file.txt new_name.txt # Rename
$ mv file.txt ../other_folder/ # Move
rm — Remove
$ rm file.txt
$ rm -r folder/ # Remove directory and contents (BE CAREFUL)
cat — Display File Contents
$ cat sequence.fasta
head / tail — First/Last Lines
$ head -10 reads.fastq # First 10 lines
$ tail -5 results.txt # Last 5 lines
less — Paged Viewing
$ less large_file.txt
# Navigate: arrow keys, q to quit
grep — Text Search
$ grep "ATCG" sequence.fasta
$ grep -c ">" multi.fasta # Count sequences in FASTA
wc — Word/Line Count
$ wc -l file.txt # Line count
$ wc -w file.txt # Word count
chmod — Change File Permissions
$ chmod +x script.sh # Make executable
$ chmod 755 script.sh # Set rwxr-xr-x permissions
sudo — Run as Administrator
$ sudo apt update # Update package list
$ sudo apt install fastqc # Install program
df — Disk Usage
$ df -h # Show disk usage in human-readable format
top / htop — System Resources
$ top # Show running processes
$ htop # More user-friendly interface (if installed)
history — Command History
$ history
$ history | grep fastqc # Search history for fastqc commands
wget / curl — Download from Internet
$ wget https://example.com/file.tar.gz
$ curl -O https://example.com/file.fasta
tar / gzip — Compression and Extraction
$ tar -xzf archive.tar.gz # Extract .tar.gz
$ tar -czf archive.tar.gz folder/ # Create .tar.gz
$ gunzip file.fastq.gz # Extract .gz
$ gzip file.fastq # Create .gz
Bash Scripts
Bash scripts allow you to combine multiple commands into a file and run them automatically. They are extremely valuable for creating reproducible workflows for bioinformatic analyses.
Simple Script Example
#!/bin/bash
# This script analyzes FASTQ files with FastQC
for file in *.fastq
do
echo "Analyzing: $file"
fastqc $file
done
echo "All analyses complete."
Conditional Statements (if/else)
for i in *
do
if [ -f $i ]; then
echo "$i is a file"
elif [ -d $i ]; then
echo "$i is a directory"
fi
done
Batch Processing with Loops
# Extract all .zip files
for filename in *.zip
do
unzip $filename
done
# Process multiple samples
for sample in sample1 sample2 sample3
do
bwa mem ref.fasta ${sample}_R1.fastq ${sample}_R2.fastq > ${sample}.sam
done
Managing Software with Conda
Most bioinformatics tools are installed via the Conda package manager.
# Create conda environment
conda create -n bioinf python=3.9
# Activate environment
conda activate bioinf
# Install tools
conda install -c bioconda fastqc trimmomatic bwa samtools
# Export environment
conda env export > environment.yaml
# Import environment
conda env create -f environment.yaml