Hello,
From my script below, I need a way to determine the number of times each ID appears in my hash. The file contains two IDs on each line:
AT1G09700 AT1G01040
AT2G28380 AT1G01040
.
.
.
Each line represents an interaction between the two IDs. I need to determine the number of interactions a particular ID has (called the degree), as well as how many times that degree appears in the entire network (over 60,000 interactions)
How could I go about doing this? Subroutines would be very useful.
Thank you very much, below is my code.
#!/local/bin/perl
use strict;
use warnings;
my %hash;
my $holder = ""; #used because it was asked of me
open (EDGES, "<edges.txt") or die "Failed to open edges.txt.\n";
while (<EDGES>){
chomp ($_);
if ($_ =~ m/(\S*)(\t)(\S*)/) {
$hash{$1,$3} = "$holder";
}}
#below isn't needed, just ensures I populated the hash correctly
my $key;
foreach $key (keys %hash){
print "$key\n";
}
Update: I should make this a little more clear. On each line contains only two IDs separated by a tab delimiter (notice my match operator). Now each hash has two IDs as the key and a holder variable as the value. I need to determine how many time each ID interacts with (i.e. is in the same key with) another ID. So if it appears in the first position ($1) in 3 keys and the second position ($3) in 2 keys that totals 5 (it can be in the same key as well, i.e. interact with itself). I need to do this for every ID (and have some way to report this in an output file in excel).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.