You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R语言中拆分鸟枪法基因组FASTA文件的编码与非编码区

Alright, let's walk through how to split your shotgun genome sequence (205,000 bp, accession NZ_LRPF01000001) into coding (CDS) and non-coding regions using R. I'll break this down into straightforward steps you can follow easily:

Step 1: Install Required Packages

We'll use Bioconductor's Biostrings for sequence manipulation and rentrez to pull the sequence directly from NCBI. Install them if you haven't already:

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install(c("Biostrings", "rentrez"))
Step 2: Fetch the Genome Sequence

Load the packages and retrieve your sequence using the accession ID (no need to navigate to external URLs manually):

library(Biostrings)
library(rentrez)

# Fetch the FASTA record from NCBI
seq_record <- entrez_fetch(db = "nuccore", id = "NZ_LRPF01000001", rettype = "fasta")
# Convert to a DNAStringSet object for easy manipulation
genome_seq <- readDNAStringSet(textConnection(seq_record))

Note: If you already have the FASTA file saved locally, replace the above with genome_seq <- readDNAStringSet("your_local_sequence.fasta").

Step 3: Define Your Known CDS Regions

Based on your data, we'll formalize the CDS intervals (remember these are 1-based positions, which matches standard genomic formatting):

# Create a data frame with CDS start and end positions
cds_regions <- data.frame(
    start = c(343, 937),
    end = c(780, 1866)
)
Step 4: Extract Coding Sequences

Use extractAt() to pull out the CDS regions from the full genome sequence:

# Convert CDS positions to an IRanges object
cds_ranges <- IRanges(start = cds_regions$start, end = cds_regions$end)
# Extract CDS sequences
cds_seqs <- extractAt(genome_seq, cds_ranges)
# Rename sequences for clarity
names(cds_seqs) <- paste0("CDS_", 1:nrow(cds_regions))
Step 5: Calculate and Extract Non-Coding Sequences

To get non-coding regions, we'll subtract the CDS ranges from the full genome range. This automatically captures all the non-CDS intervals you mentioned (1-342, 781-936, 1867-205000):

# Define the full range of the genome
full_genome_range <- IRanges(start = 1, end = width(genome_seq))
# Get non-coding ranges by removing CDS regions from the full genome
non_cds_ranges <- setdiff(full_genome_range, cds_ranges)
# Extract non-coding sequences
non_cds_seqs <- extractAt(genome_seq, non_cds_ranges)
# Rename non-coding sequences
names(non_cds_seqs) <- paste0("NonCDS_", 1:length(non_cds_ranges))
Step 6: Save the Results

If you want to export the sequences to FASTA files for downstream analysis:

# Save coding sequences
writeXStringSet(cds_seqs, "coding_sequences.fasta")
# Save non-coding sequences
writeXStringSet(non_cds_seqs, "non_coding_sequences.fasta")
Quick Notes
  • Double-check your CDS start/end positions to ensure they're 1-based (this is standard for genomic sequences from public databases).
  • If you need to add more CDS regions later, just extend the cds_regions data frame with new start/end pairs.

内容的提问来源于stack exchange,提问作者Scavenger23

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:23:00