I work with single sequence read classification and want to filter based on the quality of classification. However, the output format needs to be changed in order to do this. I have a classification statistics (a score) like below for each read, which represents ["taxonomy":"kmers assigned to that taxonomy" "taxonomy":"kmers assigned to that taxonomy" etc.], and each taxonomy can occur multiple times.
classification_stats<-c("3:1 7:4 0:34 3:7 0:27",
"0:110 561:19 0:37",
"0:3 562:5 0:7 543:55 0:47")
read_ID<-c("read1", "read2", "read3")
df<-data.frame(read_ID, classification_stats)
> df
read_ID classification_stats
1 read1 3:1 7:4 0:34 3:7 0:27
2 read2 0:110 561:19 0:37
3 read3 0:3 562:5 0:7 543:55 0:47
For each read (each row) I want to count the total number of kmers assigned to a taxonomy (in classification_stats), but since each taxonomy occurs multiple times non-consecutively, this becomes more difficult. What it means is that for e.g. read1 taxonomy 3 has 1+7 kmers, taxonomy 7 has 4 kmers and taxonomy 0 has 34 + 27 kmers.
My desired output looks like this, preferably sorted so that tax1 is the taxonomy with the highest number of kmers.
read_ID classification_stats tax1 kmer1 tax2 kmer2 tax3 kmer3
read1 3:1 7:4 0:34 3:7 0:27 0 61 3 8 7 4
read2 0:110 561:19 0:37 0 147 561 19 NA NA
read3 0:3 562:5 0:7 543:55 0:47 0 57 543 55 562 5
Either R or bash solutions are interesting.