Bella Bella - 9 months ago 21
R Question

How to apply dotPlot(seqinr) function to every possible pairwise combination in vector containing protein sequences

I'm R newbie and i would really appreciate some help.
I want to apply dotPlot(seqinr) function to every combination of two protein sequences from a vector containing 3 protein sequences. This means i want to get 3 dotPlot charts in the end.
I tried to use for loop:

#this is the vector containing 3 protein sequences. I turned each sequence to string to get 3 character vector:
seqs<-c(c2s(lepraeseq),c2s(ulceransseq),c2s(protseq))

#the loop:
for(i in 1:(length(seqs)-1)){
for(j in (i+1):length(seqs)){
print(dotPlot(as.character(i),as.character(j)))}}

#the outcome:
NULL
NULL
NULL


the plot is empty and without the protein names

Clearly its wrong and i'm struggling to find the right way.
i and j are integers and i want them to be vectors containing the sequences as characters and i just can't figure out how.

If someone have other way i would be glad to receive it.
Thank's,
Bella

Answer Source

I don't have access to the data in lepraeseq, ulceransseq, etc. but this should work. You need to create an index object with all possible combinations using combn.

Using this index, you can then generate your plots in a loop. I see you're on windows. I added a line to save your plots on your drive.

library(seqinr)
seqs<-c("lepraeseq","ulceransseq","protseq")

comb <-combn(length(seqs),2) #get all possible pairwise combinations

for (i in 1:ncol(comb)){
dotPlot(s2c(seqs[comb[1,i]]),s2c(seqs[comb[2,i]]),
 xlab=seqs[comb[1,i]],ylab=seqs[comb[2,i]])
savePlot(filename = paste0("c:/temp/",paste0(seqs[comb[1,i]],"-",seqs[comb[2,i]]),".png"), 
 type ="png")
}

enter image description here