“CFINDER” output data importation and calculation of mean of pairs

#1
Hi,

I face a problem: I have to import a text file (from_soft.txt, which is output from "CFINDER" software). It looks like this:

[...]CFINDER_output/from_soft:
Code:
# text-text-text-text-text-text-text-text-text-text-
# text-text-text-text-text-text-text-text-text-text-
# text-text-text-text-text-text-text-text-text-text-
# text-text-text-text-text-text-text-text-text-text-

1: SpeciesA SpeciesB SpeciesC SpeciesD SpeciesE
2: SpeciesA SpeciesC SpeciesE SpeciesD SpeciesF SpeciesG SpeciesH
3: SpeciesB SpeciesC SpeciesF
4: SpeciesB SpeciesC SpeciesD SpeciesF SpeciesH
[...]
I manage to import it into R thanks to readLines:

Code:
cliques<-readLines("from_soft.txt",n=-1,ok=T,warn=T,encoding="unknow",skipNul=F)
And I delete first rows thanks to:

Code:
from_soft<-as.data.frame(from_soft)[-(1:5),]
The table from_soft is like that :

Code:
head(from_soft)
[1] 0: SpeciesA SpeciesB SpeciesC SpeciesD SpeciesE   1: SpeciesA SpeciesB SpeciesC SpeciesD SpeciesE   2: SpeciesA SpeciesB SpeciesC SpeciesD SpeciesE  
[4] 3: SpeciesB SpeciesC SpeciesD SpeciesF SpeciesH [...]
On another side I have a table ref that indicates a 'value' for each pair of species. It looks like this:

Code:
print(ref)
3324   SpeciesA  SpeciesB       1
3325   SpeciesA  SpeciesC       2
3326   SpeciesA  SpeciesD      12
3327   SpeciesA  SpeciesE       1
3328   SpeciesA  SpeciesF      71
3329   SpeciesA  SpeciesG       6
3330   SpeciesA  SpeciesH      15
3331   SpeciesB  SpeciesC       2
3332   SpeciesB  SpeciesF       4
3333   SpeciesB  SpeciesD      17
[...]
Each row of from_soft correspond to a 'clique' in a graph. It means that each species are interconnected to each other. I would like to calculate for each row the 'mean connection'.

As an example for row 1: here are all the existing pairs :

Code:
1: SpeciesASpeciesB|SpeciesASpeciesC|SpeciesASpeciesD|SpeciesASpeciesE|SpeciesBSpeciesC|SpeciesBSpeciesD|SpeciesBSpeciesE|SpeciesCSpeciesD|SpeciesCSpeciesE|SpeciesDSpeciesE|
Each existing pair has a value given in ref. The output file I would like to have is a table like that :

Code:
1: 3.5 (= mean of all pairs in the clique '1:')
2: 4.2
3: 1.5
4: 6
[...]
Any idea to perform that?

Thanks for your help!!

R.