2017-06-22 27 views
-1

我想要使用登錄號碼獲取Get taxonomic層次結構。我發現這樣做最簡單的方法是如何在R中編寫csv文件以獲取以下數據?

library('taxize') 
for (year in c("AY744148.1","AY656167.1","AY656168.1")){print(paste(year))} 
classification(genbank2uid(id = year), db = "ncbi") 

R的給我下面的輸出, 但是我無法從這個

enter image description here

寫一個CSV文件我想在csv文件的結果如下圖所示 需要輸出 enter image description here

您需要這方面的幫助 問候 阿里Zohaib

+1

您將需要從申請家庭爲'()'循環或者是'sapply'或一些其他功能的結果。 –

+0

謝謝先生,for()函數解決了輸入數據的問題。現在我正面臨如何從輸出中編寫csv文件。我已更新我的問題 –

回答

0

也許你是在這樣的事情之後呢?

library('taxize') 

IDs <- c("AY744148.1","AY656167.1","AY656168.1") # your sequence of ids to iterate over 
output <- vector("list", length(years)) # prepare a list to write to 

# for each ID, run the function and store the result into a list 
for (i in 1:length(years)) { 
    # output is a list of length one, so we need to subset it using "[[" 
    output[[i]] <- classification(genbank2uid(id = IDs[i]), db = "ncbi")[[1]] 
    } 

# take list elements of output and merge them row-wise (rbind == row bind) 
output <- do.call(rbind, output) 

        name rank id 
1  other sequences no rank 28384 
2 artificial sequences no rank 81077 
3    vectors no rank 29278 
4 Cloning vector pBR322 species 47470 
5  other sequences no rank 28384 
6 artificial sequences no rank 81077 
7    vectors no rank 29278 
8 Cloning vector pGEM-3 species 90108 
9  other sequences no rank 28384 
10 artificial sequences no rank 81077 
11    vectors no rank 29278 
12 Cloning vector pGEM-3 species 90108 

您可以編寫使用

write.table(output, file = "endfile.txt", row.names = FALSE, quote = FALSE) 
+0

謝謝,先生,它的工作 –

相關問題