I need to edit the fragment IDs in a MiSeq fastq file. I'm using ShortRead to load the fastq and I've successfully managed to insert the substring needed but I can't use my code to substitute the new ID into the id slot of my fastq. Here is my current code:
fqr <- sub(" ",barcodestr, ShortRead::id(fqr))
In this case, the result is a list with only the ids. I've lost the reads and quality values.
ShortRead::id(fqr)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘id’ for signature ‘"character"’
> head(fqr)
[1] "M00967:43:000000000-A3JHG:1:1101:17304:1428;barcodelabel=F3D8; 1:N:0:196"
[2] "M00967:43:000000000-A3JHG:1:1101:17368:2241;barcodelabel=F3D8; 1:N:0:196"
[3] "M00967:43:000000000-A3JHG:1:1101:15330:2396;barcodelabel=F3D8; 1:N:0:196"
[4] "M00967:43:000000000-A3JHG:1:1101:11983:2593;barcodelabel=F3D8; 1:N:0:196"
[5] "M00967:43:000000000-A3JHG:1:1101:20789:2650;barcodelabel=F3D8; 1:N:0:196"
[6] "M00967:43:000000000-A3JHG:1:1101:12794:3085;barcodelabel=F3D8; 1:N:0:196"
I've also tried:
fqr@id <- sub(" ",barcodestr, ShortRead::id(fqr))
Error in checkAtAssignment("ShortReadQ", "id", "character") :
assignment of an object of class “character” is not valid for @‘id’ in an object of class “ShortReadQ”; is(value, "BStringSet") is not TRUE
Please suggest how I access and overwrite the ID in my fastq.
Many thanks, Susan
Thank you. I will try that strategy. A moment ago, before I checked for an answer, I tried one more approach that appears to work.
fqr@id[ ] <- sub(" ",barcodestr, ShortRead::id(fqr))
then to check-
head(fqr@id) A BStringSet instance of length 6 width seq [1] 72 M00967:43:000000000-A3JHG:1:1101:17304:1428;barcodelabel=F3D8; 1:N:0:196 [2] 72 M00967:43:000000000-A3JHG:1:1101:17368:2241;barcodelabel=F3D8; 1:N:0:196 [3] 72 M00967:43:000000000-A3JHG:1:1101:15330:2396;barcodelabel=F3D8; 1:N:0:196 [4] 72 M00967:43:000000000-A3JHG:1:1101:11983:2593;barcodelabel=F3D8; 1:N:0:196 [5] 72 M00967:43:000000000-A3JHG:1:1101:20789:2650;barcodelabel=F3D8; 1:N:0:196 [6] 72 M00967:43:000000000-A3JHG:1:1101:12794:3085;barcodelabel=F3D8; 1:N:0:196
Generally it's very bad practice to access slots directly. The recommended way to update these objects is simply to create a new version --
fqr <- ShortReadQ(sread(fqr), quality(frq), BStringSet(sub("", barcodestr, id(fqr))))