Bella Bella - 1 year ago 31
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:

#the loop:
for(i in 1:(length(seqs)-1)){
for(j in (i+1):length(seqs)){

#the outcome:

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.

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.


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

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

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download