my %lang_hash;
-open(language_file,"$trans_file");
-while(<language_file>) {
+open(language_File,"$trans_file");
+while(<language_File>) {
my $line = $_;
chomp $line;
my ($term, $name, $translation, $defn) = split("\t", $line);
$lang_hash{$term} = $translation;
}
-open(in_file,"$obo_file");
-open(output_file,">$out_file");
+open(in_File,"$obo_file");
+open(output_File,">$out_file");
my $line_prev = "";
my $po_id;
my @before_ids = ("id", "is_anonymous", "name", "namespace", "alt_id", "def", "comment", "subset");
my @after_ids = ("xref", "is_a", "intersection_of", "union_of", "disjoint_from", "relationship", "is_obsolete", "replaced_by", "consider");
-while(<in_file>) {
+while(<in_File>) {
my $line_curr = $_;
chomp $line_curr;
-# if($line_curr =~ m/Term/) {
-# $found_synonyms = 0;
-# }
+ if($line_curr =~ m/^\[Term\]/) {
+ $found_synonyms = 0;
+ print output_File "$line_curr\n";
+ next;
+
+ }
+
+ if($line_curr =~ m/^&/) {
+ print output_File "$line_curr\n";
+ next;
+ }
if($line_curr =~ m/^id:\s+(PO:\d+)/) {
$po_id = $1;
}
- if ($line_curr =~ m/^synonym/) {
+ if ($line_curr =~ m/^synonym:/) {
$found_synonyms = 1;
if(defined($lang_hash{$po_id})) {
my $new_synonym = "synonym: \"$lang_hash{$po_id}\" $line_end";
- if ($new_synonym lt $line_curr && $new_synonym gt $line_prev) {
- print output_file "$new_synonym\n";
+ if (lc($new_synonym) lt lc($line_curr) && lc($new_synonym) gt lc($line_prev)) { # need to lowercase the string otherwise the ascii string compare will not work right
+ print output_File "$new_synonym\n";
+ }elsif( $new_synonym eq $line_curr) {
+ # translation already in file
+ next;
}
}else{
print "po id not found\t$po_id\n";
}
}
- $line_curr =~ m/^(\w+)/;
- my $line_curr_identifier = $1;
+ my $line_curr_identifier = "no match";
+ $line_curr =~ m/^(\w+)\:/;
+ if(defined($1)) {
+ $line_curr_identifier = $1;
+ }
+
+ my $line_prev_identifier = "no match";
+ $line_prev =~ m/^(\w+)\:/;
+ if(defined($1)) {
+ $line_prev_identifier = $1;
+ }
- $line_prev =~ m/^(\w+)/;
- my $line_prev_identifier = $1;
- my $count_before = grep /$line_prev_identifier/, @before_ids;
- my $count_after = grep /$line_curr_identifier/, @after_ids;
+ my $count_before = grep /^$line_prev_identifier$/, @before_ids;
+ my $count_after = grep /^$line_curr_identifier$/, @after_ids;
if($count_before && $count_after) {
if(defined($lang_hash{$po_id})) {
if(!$found_synonyms) {
my $new_synonym = "synonym: \"$lang_hash{$po_id}\" $line_end";
- print output_file "$new_synonym\n";
+ print output_File "$new_synonym\n";
}
}else{
print "po id not found\t$po_id\n";
}
- print output_file "$line_curr\n";
+ print output_File "$line_curr\n";
$line_prev=$line_curr;
}