使用Unix / Bash,我如何制作查找表?
|
所以我有一个基因名称和探测ID的.txt列表,originalFile.txt,如下所示:
GENE_ID PROBE_ID 10111 19873 10112 284,19983 10113 187 此文本文件中有大约30,000行.我想在第二列中创建一个没有逗号的新文本文件,例如: GENE_ID PROBE_ID 10111 19873 10112 284 10112 19983 10113 187 …而且,我希望所有的PROBE_ID来自另一个文本文件probes.txt,它看起来像: 19873 284 187 …这样我就可以制作一个看起来如下的finalProduct.txt文件: GENE_ID PROBE_ID 10111 19873 10112 284 10113 187 如果我想手动输入每行probe.txt,我想我可以通过以下方式实现这个结果: awk -F"/t" '{for(i=1;i<=NF;i++){if ($i ~ /probeID#/){print $i}}}' myGenes > test.txt
但是,当然,这不会将逗号分隔的探测ID放在不同的行上,我必须手动输入数千个probeID中的每一个. 有没有人有任何提示或更好的建议? 编辑清晰度 对于probe.txt中列出的每个探测器,查看它是否存在于originalFile.txt中; 或者您可以将它视为使用probes.txt在originalFile.txt上的过滤器之间的某种连接,其中输出文件将PROBE_ID列作为probes.txt中的探测器和来自originalFile.txt的相应GENE_ID. 或者你可以把它想象成: 编辑2
如果probes.txt足够小以至于它适合内存,您可以尝试以下awk脚本:
BEGIN {
OFS="t";
# this is to handle the given input that has spaces after the comma
# and tabs between gene and probes
FS="[t,]+";
# load probes into an array
while ((getline probe < "probes.txt") > 0) {
probes[probe] = 1;
}
close ("probes.txt");
}
{
# for each probe,check if it's in the array
# and skip it if not
for (i=2; i <= NF; i++) {
if (probes[$i] == 1) {
print $1,$i;
}
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
