-1

Here is the set up of my list of lists of lists: please see the development code for the read.GenBank function here

#must be connected to internet for this to work
library(ape)
library(plyr)
gi_sample<-c(336087836, 336087835, 336087834)
#use the read.GenBank function with apply because we ultimately have more than the max at one time (400)
my_output <- apply(gi_sample, 1, function(x) read.GenBank(x))

str(my_output)
List of 3
 $ :List of 1
  ..$ 336087836:Class 'DNAbin'  raw [1:606] 00 00 00 00 ...
  ..- attr(*, "class")= chr "DNAbin"
  ..- attr(*, "species")= chr "Flavobacterium_johnsoniae"
  ..- attr(*, "references")=List of 1
  .. ..$ 336087836:List of 2
  .. .. ..$ :List of 4
  .. .. .. ..$ pubmedid: chr(0) 
  .. .. .. ..$ authors : chr "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__
  .. .. .. ..$ title   : chr "Calcite mineralization by karstic cave bacteria"
  .. .. .. ..$ journal : chr "Unpublished"
  .. .. ..$ :List of 4
  .. .. .. ..$ pubmedid: chr(0) 
  .. .. .. ..$ authors : chr "Rusznyak,A."
  .. .. .. ..$ title   : chr "Direct Submission"
  .. .. .. ..$ journal : chr "Submitted (13-APR-2011) to the INSDC. Institute of Ecology, Aquatic"
 $ :List of 1
  ..$ 336087835:Class 'DNAbin'  raw [1:991] 00 00 00 00 ...
  ..- attr(*, "class")= chr "DNAbin"
  ..- attr(*, "species")= chr "Rhodococcus_fascians"
  ..- attr(*, "references")=List of 1
  .. ..$ 336087835:List of 2
  .. .. ..$ :List of 4
  .. .. .. ..$ pubmedid: chr(0) 
  .. .. .. ..$ authors : chr "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__
  .. .. .. ..$ title   : chr "Calcite mineralization by karstic cave bacteria"
  .. .. .. ..$ journal : chr "Unpublished"
  .. .. ..$ :List of 4
  .. .. .. ..$ pubmedid: chr(0) 
  .. .. .. ..$ authors : chr "Rusznyak,A."
  .. .. .. ..$ title   : chr "Direct Submission"
  .. .. .. ..$ journal : chr "Submitted (13-APR-2011) to the INSDC. Institute of Ecology, Aquatic"
 $ :List of 1
  ..$ 336087834:Class 'DNAbin'  raw [1:690] 00 00 00 00 ...
  ..- attr(*, "class")= chr "DNAbin"
  ..- attr(*, "species")= chr "Serratia_plymuthica"
  ..- attr(*, "references")=List of 1
  .. ..$ 336087834:List of 2
  .. .. ..$ :List of 4
  .. .. .. ..$ pubmedid: chr(0) 
  .. .. .. ..$ authors : chr "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__
  .. .. .. ..$ title   : chr "Calcite mineralization by karstic cave bacteria"
  .. .. .. ..$ journal : chr "Unpublished"
  .. .. ..$ :List of 4
  .. .. .. ..$ pubmedid: chr(0) 
  .. .. .. ..$ authors : chr "Rusznyak,A."
  .. .. .. ..$ title   : chr "Direct Submission"
  .. .. .. ..$ journal : chr "Submitted (13-APR-2011) to the INSDC. Institute of Ecology, Aquatic"

What I would like out of this list:

GI  authors     title       journal 
336087836   "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__    "Calcite mineralization by karstic cave bacteria"   "Unpublished"
336087835   "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__    "Calcite mineralization by karstic cave bacteria"   "Unpublished"
336087834   "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__    "Calcite mineralization by karstic cave bacteria"   "Unpublished"

I am sorely in need of an explanation of how these lists are nested. How can I access the "title" and keep the name of each list? I have tinkered with all sorts of "[]" subsetting combinations and ultimately do not understand how to read this list. I have read many beginner explanations, and am still at a loss.

This is changed from the earlier question, although the data remain the same.

Thank you!

Community
  • 1
  • 1
K. Brannen
  • 145
  • 1
  • 11

2 Answers2

1

It sounds like a dput of the data is very hard to have. I build an example that it might be useful (just an answer because it is too long for comment).

a <- list(list(1:5), list(5:10))
b <- list(list(letters[1:5]), list(LETTERS[5:10]))
data.frame(unlist(a), unlist(b))
   unlist.a. unlist.b.
1          1         a
2          2         b
3          3         c
4          4         d
5          5         e
6          5         E
7          6         F
8          7         G
9          8         H
10         9         I
11        10         J
SabDeM
  • 6,638
  • 2
  • 22
  • 37
1

This answer using bind_rows from dplyr should work but I can't test it on your data because you're supplied code doesn't give me a references attribute even with the development version of ape.

library("dplyr")
bind_rows(lapply(seq(refs), function(i) data.frame(GI = names(refs)[i], as.data.frame(refs[[i]][lengths(refs[[i]]) > 0]))))
Nick Kennedy
  • 12,062
  • 2
  • 26
  • 49