Soldato
- Joined
- 24 Nov 2002
- Posts
- 16,378
- Location
- 38.744281°N 104.846806°W
Okidoke. Another question.... I thought I'd start a new thread as it is different to my other things.
I have a data file formatted like this with 812 lines (each line has NP_xxxxxx.x at the start):
Now, I want to read this file and count the number of occurences of each number, e.g. just in above "0003674" occurs thrice - once on each line.
I'd ideally like to output a table like the following:
And so on.... I'll sort the mysql lookup later to fetch the name.
At the moment I'm using:
And this returns the number of times the term occurs per line - which isn't really what I want plus I have to declare each term manually.
Any help or pointers would be greatly appreciated!
I have a data file formatted like this with 812 lines (each line has NP_xxxxxx.x at the start):
Code:
NP_004125.3 0006457 0003674 0008219 0005737 0005515 0008152 0016265 0005488 0005739 0008150 0005623 0043067 0044260 0006916 0044424 0005575 0050789 0044444 0050791 0017076 0043118 0048523 0043069 0050794 0051244 0009986 0019538 0051243 0005524 0051082 0042981 0043229 0043226 0006915 0044237 0044464 0043227 0005622 0043231 0009987 0007582 0000166 0043066 0043170 0044267 0012501 0048519 0030554 0050875 0044238
NP_001311.3 0030234 0042802 0005956 0003674 0005515 0007165 0005488 0008150 0008605 0019207 0005623 0044424 0005575 0016055 0003824 0019887 0007166 0044464 0005622 0016772 0009987 0007154 0016740 0016301 0043234
NP_001605.1 0005200 0003674 0005515 0044422 0005488 0015629 0005623 0044424 0005575 0017076 0005198 0043232 0044430 0005884 0005524 0005856 0043229 0043226 0044464 0005622 0043228 0044446 0000166 0030554
Now, I want to read this file and count the number of occurences of each number, e.g. just in above "0003674" occurs thrice - once on each line.
I'd ideally like to output a table like the following:
Code:
*number* *name* frequency* *NPs*
------------------------------------------------------------------------------------
0003674 {mysql lookup} 3 NP_004125.3/NP_001311.3/NP_001605.1
0042802 {mysql lookup} 1 NP_001311.3
And so on.... I'll sort the mysql lookup later to fetch the name.
At the moment I'm using:
Code:
<?php
$lines = file('data.txt');
foreach ($lines as $line_num => $line) {
echo "" . substr_count($line, '0003674') . "<br />\n";
}
?>
And this returns the number of times the term occurs per line - which isn't really what I want plus I have to declare each term manually.
Any help or pointers would be greatly appreciated!