-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!

4
  • 6
    dput is much more useful than str. Commented Jul 21, 2015 at 23:27
  • Something like as.data.frame(do.call(c, seqs)) or some variation that includes unlist() might work for you. rapply() may be necessary, and dput() is essential. Commented Jul 21, 2015 at 23:38
  • You can always just give a smaller sample that represents the full data. We don't need the full list Commented Jul 21, 2015 at 23:45
  • Check out ?list.flatten from rlist library Commented Jul 22, 2015 at 0:22

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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]))))

2 Comments

Thanks, This still tells me that "arguments imply differing number of rows: 0, 1". At the top of the question I linked to the github for the development version of the function that gives the references.
try1<-bind_rows(lapply(seq(refs), function(i) data.frame(GI = names(refs)[1], as.data.frame(refs[[1]][[1]]$title)))) This worked because I wanted the title from the first list anyways. I can make a separate one for the authors and journal from this. Thank you!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.