【发布时间】:2017-12-21 09:16:17
【问题描述】:
我正在尝试计算 Spearman 的排名相关性,其中每个实验的数据(带有名称和排名的 tsv)存储在目录中的单独文件中。
以下是输入文件的格式:
#header not present
#geneName value
ENSMUSG00000026179.14 14.5648627685587
ENSMUSG00000026179.14 0.652158034413075
ENSMUSG00000026179.14 0.652158034413075
ENSMUSG00000026179.14 1.852158034413075
ENSMUSG00000026176.13 4.13033421794948
ENSMUSG00000026176.13 4.13033421794948
ENSMUSG00000026176.13 15.4344068144428
ENSMUSG00000026176.13 15.4344068144428
ENSMUSG00000026176.13 6.9563523670728
...
我的问题是键(基因名称)是重复的,每个实验文件都包含不同但重叠的基因名称集。我需要的是每对基因名称的交集,同时执行相关性和删除重复项,可能类似于以下伪代码:
# Find correlation for all possible pairs of input(i.e. files in directory)
files = list_Of_files("directory")
for(i in files) {
for(k in files) {
CommonGenes <- intersect (i,k)
tempi <- removeRepetitive(i, CommonGenes) #Keep the gene with highest value and remove all other repeating genes. Also, keep only common genes.
tempk <- removeRepetitive(k, CommonGenes) #Keep the gene with highest value and remove all other repeating genes. Also, keep only common genes.
correlationArray[] <- spearman(tempi, tempk) #Perform correlation for only the common genes
}
}
最后,我想使用 corrplot 或 qtlcharts 绘制相关矩阵。
【问题讨论】:
-
您的 for 循环看起来不像 R 代码。
-
@ycw,对不起。我通常使用python,所以我发现用python“like”格式编写虚拟示例更容易。我将更新我的问题以反映这一点。
标签: r dataframe statistics bioinformatics