我在R中編寫了一個函數,它解析來自數據幀的參數,並輸出舊數據幀+一個包含每行統計信息的新列。在R中解釋警告需要幫助
我得到以下警告: 警告消息: 在[[.data.frame
(XX,隨心[J]): 比「精確」等命名的參數都望而卻步
我不知道這意味着什麼,是誠實。我對結果進行了抽查,對我來說似乎沒問題。 該函數本身很長,如果需要更好地回答問題,我會發布它。 編輯:
這是一個示例數據幀:
my_df<- data.frame('ALT'= c('A,C', 'A,G'),
'Sample1'= c('1/1:35,3,0,35,3,35:1:1:0:0,1,0', './.:0,0,0,0,0,0:0:0:0:0,0,0'),
'Sample2'= c('2/2:188,188,188,33,33,0:11:11:0:0,0,11', '1/1:255,99,0,255,99,255:33:33:0:0,33,0'),
'Sample3'= c('1/1:219,69,0,219,69,219:23:23:0:0,23,0', '0/1:36,0,78,48,87,120:7:3:0:4,3,0'))
而這是函數:
multi_allelic_filter_v2<- function(in_vcf, start_col, end_col, threshold=1){
#input: must have gone through biallelic_assessment first
table0<- in_vcf
#ALT_alleles is the number of alt alleles with coverage > threshold across samples
#The following function calculates coverage across samples for a single allele
single_allele_tot_cov_count<- function(list_of_unparsed_cov,
allele_pos){
single_allele_coverage_count<- 0
for (i in 1:length(list_of_unparsed_cov)) { # i is each group of coverages/sample
single_allele_coverage_count<- single_allele_coverage_count+
as.numeric(strsplit(as.character(list_of_unparsed_cov[i]),
split= ',')[[1]])[allele_pos]}
return(single_allele_coverage_count)}
#single row function
#Now we need to reiterate on each ALT allele in the row
single_row_assessment<- function(single_row){
# No. of alternative alleles over threshold
alt_alleles0 <- 0
if (single_row$is_biallelic==TRUE){
alt_alleles0<- 1
} else {
alt_coverages <- numeric() #coverages across sample of each ALT allele
altcovs_unparsed<- character() #Unparsed coverages from each sample
for (i in start_col:end_col) {
#Let's fill altcovs_unparsed
altcovs_unparsed<- c(altcovs_unparsed,
strsplit(x = as.character(single_row[1,i]), split = ':')[[1]][6])}
#Now let's calculate alt_coverages
for (i in 1:lengths(strsplit(as.character(
single_row$ALT),',',fixed = TRUE))) {
alt_coverages<- c(alt_coverages, single_allele_tot_cov_count(
list_of_unparsed_cov = altcovs_unparsed, allele_pos = i+1))}
#Now, let's see how many ALT alleles are over threshold
alt_alleles0<- sum(alt_coverages>threshold)}
return(alt_alleles0)}
#Now, let's reiterate across each row:
#ALT_alleles is no. of alt alleles with coverage >threshold across samples
table0$ALT_alleles<- -99 # Just as a marker, to make sure function works
for (i in 1:nrow(table0)){
table0[i,'ALT_alleles'] <- single_row_assessment(single_row = table0[i,])}
#Now we now how many ALT alleles >= threshold coverage are in each SNP
return(table0)}
基本上,在下面的行: 「1/1:219,69, 0,219,69,219:23:23:0:0,23,0' 字段之間用「:」分隔,我對最後一個字段(23和0)的最後兩個數字感興趣。在每一行中,我想總結那些位置的所有數字(兩個單獨的總和),並輸出有多少「總和」超過閾值。希望這是有道理的......
聽起來像你應該尋找某個地方,在裏面使用'[[''你看起來像'foo = bar'的東西,其中'foo'不是'exact'參數。 – joran
如果你提供了一個[可重現的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)來產生這個警告,它會容易得多。 – MrFlick
'exact'允許您爲data.frame子集中的列名的部分匹配提供字符名稱的向量。根據源代碼,在%c(「」,「exact」)))中的if(!all(names(sys.call())%)會得到這個錯誤。 – shayaa