0

I have a file (Fasta) imported as list in R

library("seqinr")

F300 <- read.fasta(file = "files300.fasta", seqtype = "DNA", as.string = TRUE, set.attributes = TRUE, strip.desc = TRUE)

class(F300)
[1] "list"

just to show the structure of the list with any element

F300[100]
$IMEHDJCA_00190
[1] "atgcttaacaacatcaatctcaatttactgcgttctttgctcgtgttgctcgaagagtgtcatgttagccgag"
attr(,"name")
[1] "IMEHDJCA_00190"
attr(,"Annot")
[1] "IMEHDJCA_00190 HTH-type transcriptional regulator YidZ"
attr(,"class")
[1] "SeqFastadna"

So I want to add an extra data to attr(,"Annot") element based in a data frame.

head(DF)
          ID1                 ID2       pident length mismatch gapopen qstart  qend sstart  send evalue bitscore qcovs
1 IMEHDJCA_00190 VFG007029(gi:27366917) 98.238   1362       24       0      1  1362      1  1362      0     2383   100
2 IMEHDJCA_00191 VFG007025(gi:27366916) 98.072   1608       31       0    499  2106      1  1608      0     2798    76
3 IMEHDJCA_00193 VFG007022(gi:37676692) 99.747    396        1       0      1   396     85   480      0      726   100
4 IMEHDJCA_00194 VFG007018(gi:27366913) 95.948  15622      631       2      1 15621      1 15621      0    25340   100
5 IMEHDJCA_00265 VFG007040(gi:27366843) 96.446   1407       50       0     10  1416      1  1407      0     2322    99
6 IMEHDJCA_00797 VFG042882(gi:27366060) 94.687    734       39       0      1   734      1   734      0     1140    99

Using the ID1 of the DF to identified the data in F300, and then add the ID2 character at begins of Annot attribute

I mean, the attributes will be

from

attr(F300[[100]],"Annot")
[1] "IMEHDJCA_00190 HTH-type transcriptional regulator YidZ"

To

attr(F300[[100]],"Annot")
[1] "VFG007029(gi:27366917) IMEHDJCA_00190 HTH-type transcriptional regulator YidZ"

I'm just a little bit lost, I have tried a for loop and something else, but I'm lost, I don't really know how to get a solution !!!

abraham
  • 661
  • 8
  • 14
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. We don't need 300 entries, but perhaps you could make a `dput` of the first three objects so we can more easily see exactly how `F300` is structured. Also `dput(DF)` is helpful so we can copy/paste into R for testing. – MrFlick Mar 11 '22 at 21:59
  • 1
    Look at the second *Usage* format on the `attr` manual page. Did you try `attr(F300[[100]],"Annot") <- "VFG007029(gi:27366917) IMEHDJCA_00190 HTH-type transcriptional regulator YidZ"`? – dcarlson Mar 12 '22 at 03:52
  • Thanks, it was not exactly the answer, but it give me a clue, Thanks so much, I already made it !!! – abraham Mar 12 '22 at 18:37

0 Answers0