Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# パッケージのインストール
source("http://bioconductor.org/biocLite.R")
biocLite("Biostrings")
# パッケージのロード
library(Biostrings)
# 読み込むmultifastaファイルの指定(ここでは組み込みのデータを使用)
# 例: inFileName <- "sample.fasta"
inFileName <- system.file("extdata", "someORF.fa",package="Biostrings")
# 指定したファイルを読み込む
sample <- readDNAStringSet(inFileName)
# > sample
# A DNAStringSet instance of length 7
# width seq names
# [1] 5573 ACTTGTAAATATATCTTTTATTT...CTTATCGACCTTATTGTTGATAT YAL001C TFC3 SGDI...
# [2] 5825 TTCCAAGGCCGATGAATTCGACT...AGTAAATTTTTTTCTATTCTCTT YAL002W VPS8 SGDI...
# [3] 2987 CTTCATGTCAGCCTGCACTTCTG...TGGTACTCATGTAGCTGCCTCAT YAL003W EFB1 SGDI...
# [4] 3929 CACTCATATCGGGGGTCTTACTT...TGTCCCGAAACACGAAAAAGTAC YAL005C SSA1 SGDI...
# [5] 2648 AGAGAAAGAGTTTCACTTCTTGA...ATATAATTTATGTGTGAACATAG YAL007C ERP2 SGDI...
# [6] 2597 GTGTCCGGGCCTCGCAGGCGTTC...AAGTTTTGGCAGAATGTACTTTT YAL008W FUN14 SGD...
# [7] 2780 CAAGATAATGTCAAAGTTAGTGG...GCTAAGGAAGAAAAAAAAATCAC YAL009W SPO7 SGDI...
# for文で要素ごとに書き出す
for (i in 1:length(sample)){
outFileName <- paste("sample_",i,".fa",sep="")
writeXStringSet(sample[i], file=outFileName)
}
# 分割したファイルを読み込んでみる
sample_1 <- readDNAStringSet("sample_1.fa")
# 中身を確認
sample_1
# > sample_1
# A DNAStringSet instance of length 1
# width seq names
# [1] 5573 ACTTGTAAATATATCTTTTATTT...CTTATCGACCTTATTGTTGATAT YAL001C TFC3 SGDI...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment