I have a list of 58 dataframes under the list named nafilt_persample.ngsrep. Inside it are 58 df, named according to individual IDs: SVT_01...58. Each df contains 15 columns with either characters or numbers like:
Tumor_Sample_Barcode Hugo_Symbol Chromosome Start_Position End_Position Variant_Type Variant_Classification coverage VAF
1: SVT_01 DNMT3A chr2 25464495 25464495 SNP Missense_Mutation 2835 0.011
2: SVT_01 JAK2 chr9 5073770 5073770 SNP Missense_Mutation 2533 0.028
cDNA_Change Protein_Change Reference_Allele Tumor_Seq_Allele2 ref_reads var_reads
1: c.2018G>T p.Gly673Val C A 2808 27
2: c.1849G>T p.V617F G T 2455 78
I need to add to each df in the list two columns lCI and uCI with values coming from a second list that is ordered according to the same ID, (SVT_) and gene and looks like this (called cint):
$DNMT3A
[1] 0.006285366 0.013826599
attr(,"conf.level")
[1] 0.95
$JAK2
[1] 0.02441547 0.03828421
attr(,"conf.level")
[1] 0.95
I would like to obtain a result like this:
Tumor_Sample_Barcode Hugo_Symbol Chromosome Start_Position End_Position Variant_Type Variant_Classification coverage VAF
1: SVT_01 DNMT3A chr2 25464495 25464495 SNP Missense_Mutation 2835 0.011
2: SVT_01 JAK2 chr9 5073770 5073770 SNP Missense_Mutation 2533 0.028
cDNA_Change Protein_Change Reference_Allele Tumor_Seq_Allele2 ref_reads var_reads lCI uCI
1: c.2018G>T p.Gly673Val C A 2808 27 0.06 0.013
2: c.1849G>T p.V617F G T 2455 78 0.024 0.038
So far I have tried this but without success:
merged.list <- list()
for (i in names(nafilt_persample.ngsrep)){ for (k in nafilt_persample.ngsrep[[i]]$Hugo_Symbol){
merged.list[[i]] <- cbind(nafilt_persample.ngsrep[[i]], cint[[i]][[k]][1], cint[[i]][[k]][2])
}
}
The error here is that despite the two columns are added, only values from the last cycle item are added, So in the example of SVT_01 shown above this is the result:
Tumor_Sample_Barcode Hugo_Symbol Chromosome Start_Position End_Position Variant_Type Variant_Classification coverage VAF
1: SVT_01 DNMT3A chr2 25464495 25464495 SNP Missense_Mutation 2835 0.011
2: SVT_01 JAK2 chr9 5073770 5073770 SNP Missense_Mutation 2533 0.028
cDNA_Change Protein_Change Reference_Allele Tumor_Seq_Allele2 ref_reads var_reads lCI uCI
1: c.2018G>T p.Gly673Val C A 2808 27 0.024 0.038
2: c.1849G>T p.V617F G T 2455 78 0.024 0.038
That is: the CI of JAK2 is duplicated onto the DNMT3A row. How can I fix this? Hope I provided enough info
merged.listseems to have no names, whereasiis the names of the list? Perhaps you want to loop over the sequence of the list