上文件的更新中值我有2個文件(A.vcf和ref1.vcf) A.vcf這樣的:PHP讀取並從另一個文件
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT
1 5 . A C 222 . INDEL;IS=6,0.111111;DP=54;VDB=1.384012e-01;AF1=0.5;AC1=1;DP4=2,3,1,4;MQ=32;FQ=10.8;PV4=1,0.38,0.00012,0.00052 GT:PL:GQ 0/1:45,0,147:47
2 7 . G T 222 . DP=106;VDB=1.997151e-13;RPB=-2.402409e+00;AF1=1;AC1=2;DP4=1,1,44,58;MQ=20;FQ=-275;PV4=1,1,0.0029,1 GT:PL:GQ 1/1:255,248,0:99
3 15 . A G 222 . DP=106;VDB=2.982598e-04;RPB=-2.402409e+00;AF1=1;AC1=2;DP4=1,1,44,58;MQ=20;FQ=-266;PV4=1,1,0.003,1 GT:PL:GQ 1/1:255,239,0:99
4 11 . T A 222 . DP=85;VDB=3.949915e-01;AF1=1;AC1=2;DP4=0,0,29,44;MQ=22;FQ=-247 GT:PL:GQ 1/1:255,220,0:99
ref1.vcf:
#CHROM POS ID REF ALT
1 5 ref12345 A C
2 15 ref45673 A G
3 25 ref67893 C T
4 35 ref66663 C A
我想改變對應於參考文件A.vcf ref1.vcf的文件的標題。 因此,這個最初:
id = .
ref = A
alt = C
qual = 222
我想是這樣的:
id = ref12345
ref = A
alt = C
qual = 222
,但沒有發生變更。 我的代碼是否有錯誤?
<?php
$dataSNP = "A.vcf";
$handleSNP = fopen($dataSNP, "r");
if ($handleSNP)
{
while (($lineSNP = fgets($handleSNP, 4096)) !== false)
{
$lineSNP = explode("\t", $lineSNP);
//removing first with '#'
if (!empty($lineSNP[0][0]) && $lineSNP[0][0] != '#')
{
$new_dataSNP[] = $lineSNP;
}
}
if (!feof($handleSNP))
{
echo "Error: unexpected fgets() fail\n";
}
fclose($handleSNP);
}
//update 'pos', but not working
for($i = 0 ; $i < count($new_dataSNP); $i++)
{
echo '<pre>';
print("chrom = ".$new_dataSNP[$i][0]. "\n");
print("position = ".$new_dataSNP[$i][1]. "\n");
$file = "ref1.vcf";
$handle = fopen($file, "r");
if ($handle)
{
while (($line = fgets($handle, 4096)) !== false)
{
$line = explode("\t", $line);
if(($line[1] == $new_dataSNP[$i][1]) && ($line[3] == $new_dataSNP[$i][3]) && ($line[4] == $new_dataSNP[$i][4]))
{
$new_dataSNP[$i][2] = $line[2];
break;
}
}
if (!feof($handle))
{
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
print("id = ".$new_dataSNP[$i][2]. "\n");
print("ref = ".$new_dataSNP[$i][3]. "\n");
print("alt = ".$new_dataSNP[$i][4]. "\n");
}
?>
這段代碼很簡單,但我很困惑,發現錯誤。有什麼可以幫助我嗎?
你真的在你的文件的製表符?在這裏發佈的數據中,只有空格。 – Callidior
是的,我使用「標籤」,而不是「空格」。你可以幫我嗎? – user3193610