#! /usr/bin/env perl

use strict;
use warnings;
use File::Basename;
use File::Path;
use Cwd 'getcwd';

my $nodes_dmp = $ARGV[0];
use Cwd 'abs_path';
$nodes_dmp = abs_path($nodes_dmp);

my $CWD=dirname(${0});
my $DB=basename(${0}, '.pl');
chdir $CWD;
$CWD=getcwd;
my $PWD=dirname($CWD);
my $ESROOT=$PWD;

my @URI=();
my @ENTRY=();

my $URL="http://identifiers.org/taxonomy";
$URI[0]="http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=";
$URI[1]="http://purl.uniprot.org/taxonomy/";
$URI[2]="http://www.ebi.ac.uk/ena/data/view/Taxon:";
$URI[3]="http://purl.bioontology.org/ontology/NCBITAXON/";
$URI[4]="http://taxonomy.bio2rdf.org/describe/?url=http://bio2rdf.org/taxonomy:";
$URI[5]="http://www.ebi.ac.uk/ols/ontologies/ncbitaxon/terms?short_form=NCBITaxon_";
#$URI[6]="http://purl.obolibrary.org/obo/NCBITaxon_";

$ENTRY[0]="http://identifiers.org/miriam.resource/MIR:00100007";
$ENTRY[1]="http://identifiers.org/miriam.resource/MIR:00100019";
$ENTRY[2]="http://identifiers.org/miriam.resource/MIR:00100299";
$ENTRY[3]="http://identifiers.org/miriam.resource/MIR:00100507";
$ENTRY[4]="http://identifiers.org/miriam.resource/MIR:00100695";
$ENTRY[5]="http://identifiers.org/miriam.resource/MIR:00100770";
#$ENTRY[6]="";

my $collection = "http://identifiers.org/miriam.collection/MIR:00000006";


printf "\@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n";
printf "\@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
#printf "\@prefix owl: <http://www.w3.org/2002/07/owl#> .\n";
printf "\@prefix dcterms: <http://purl.org/dc/terms/> .\n";
printf "\@prefix idoo: <http://rdf.identifiers.org/ontology/> .\n";

my %taxid = ();
open(FD, $nodes_dmp);
while( my $line = <FD> ){
  my $id = (split(/\s+/, $line))[0];
  $taxid{$id} = "";
}
close(FD);

my %T=();

my $num = $#URI + 1;
foreach my $id (sort(keys %taxid)){
  chomp($id);
  for(my $i=0; $i < $num; $i++){
    printf "<%s/%s> rdfs:seeAlso <%s%s> .\n", $URL, $id, $URI[$i], $id;
    printf "<%s%s> rdfs:seeAlso <%s/%s> .\n", $URI[$i], $id, $URL, $id;
    if($ENTRY[$i]){
      printf "<%s%s> dcterms:publisher <%s> .\n", $URI[$i], $id, $ENTRY[$i];
    }
  }
  printf "<%s/%s> dcterms:source <%s> .\n", $URL, $id, $collection;
  printf "<%s/%s> idoo:database <%s> .\n", $URL, $id, $URL;
}
close(FD);
