#!/usr/bin/perl if (!exists($ARGV[0])) { print "USAGE: ./parsebqcsvtogeogephi.pl INFILE\n"; exit; } ################################################################### #load our geocrossref mapping... open(FILE, "./COUNTRY-GEO-LOOKUP.TXT"); while() { ($name, $lat, $long, $cc) = split/\t/, $_; $cc=~s/\s+$//; if (abs($lat) > 0 || abs($long) > 0) { $CCNAME{$cc} = $name; $CCATT{$cc} = ""; } } close(FILE); ################################################################### ################################################################### #print our GEFX opening... open(OUT, ">$ARGV[0].gexf"); print OUT " "; ################################################################### ################################################################### #load the input CSV and write the nodes and hash up the edges... $MASTERTOTAL = 0; open(FILE, $ARGV[0]); $NODEID = 0; while() { ($from, $to, $count) = split/,/, $_; $count=~s/\s+$//; if ($count > 0 && exists($CCATT{$from}) && exists($CCATT{$to})) { if (!exists($NODEIDS{$from})) { $NODEIDS{$from} = $NODEID; $NODECNT{$from}+=$count; $NODEID++; } if (!exists($NODEIDS{$to})) { $NODEIDS{$to} = $NODEID; $NODECNT{$to}+=$count; $NODEID++; } $EDGES{"$NODEIDS{$from}\t$NODEIDS{$to}"} = $count; $MASTERTOTAL += $count; } } close(FILE); #and write the nodes to disk... foreach $node (sort keys %NODEIDS) { print OUT "\t$CCATT{$node}\n"; } ################################################################### print OUT "\n\n"; #now write the edges now that we've assigned all of the nodes their nodeids... $EDGEID = 0; foreach $edge (sort keys %EDGES) { ($node1, $node2) = split/\t/, $edge; $weight = $EDGES{$edge} / $MASTERTOTAL; print OUT "\n"; $EDGEID++; } ################################################################### ################################################################### #print our GEFX closing... print OUT " "; close(OUT); ################################################################### #done!