From 72a6bf7737cd828f83bf68930a36abe261c722ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?=
 <ak4@sanger.ac.uk>
Date: Thu, 15 Mar 2007 15:02:07 +0000
Subject: [PATCH] When writing to XREF, default to '' (empty string) for stuff
 that might be undefined.  Removes a whole lot of warnings when running with
 -w.

---
 .../xref_mapping/XrefMapper/BasicMapper.pm    | 108 +++++++++++++++---
 1 file changed, 93 insertions(+), 15 deletions(-)

diff --git a/misc-scripts/xref_mapping/XrefMapper/BasicMapper.pm b/misc-scripts/xref_mapping/XrefMapper/BasicMapper.pm
index 53fc265feb..abcc7479b2 100644
--- a/misc-scripts/xref_mapping/XrefMapper/BasicMapper.pm
+++ b/misc-scripts/xref_mapping/XrefMapper/BasicMapper.pm
@@ -1627,10 +1627,16 @@ PSQL
 	if(!defined($updated_source{$external_db_id})){
 	  $self->cleanup_sources_file($external_db_id);
 	}
-	print XREF ($xref_id+$xref_id_offset) . "\t" . $external_db_id . "\t" . $accession . 
-	  "\t" . $label . "\t" . $version . "\t" . $description . "\tMISC\tNo match\n";
-	
-	#dump out dependencies aswell
+
+        print XREF ( $xref_id + $xref_id_offset ) . "\t"
+          . ( $external_db_id || '' ) . "\t"
+          . ( $accession      || '' ) . "\t"
+          . ( $label          || '' ) . "\t"
+          . ( $version        || '' ) . "\t"
+          . ( $description    || '' ) . "\t" . "MISC" . "\t"
+          . "No match\n";
+
+        #dump out dependencies aswell
 
 	$XXXxref_id_to_accession{$xref_id} = $accession;
 	if(!defined($accession) or $accession eq ""){
@@ -1742,7 +1748,15 @@ sub dump_orphan_xrefs() {
 	  $self->cleanup_sources_file($external_db_id);
 	}
 	if(!defined($priority_xref_source_id{$xref_id})){
-	  print XREF ($xref_id+$xref_id_offset) . "\t" . $external_db_id . "\t" . $accession . "\t" . $label . "\t" . $version . "\t" . $description . "\tMISC\tNo match\n";
+
+            print XREF ( $xref_id + $xref_id_offset ) . "\t"
+              . ( $external_db_id || '' ) . "\t"
+              . ( $accession      || '' ) . "\t"
+              . ( $label          || '' ) . "\t"
+              . ( $version        || '' ) . "\t"
+              . ( $description    || '' ) . "\t" . "MISC" . "\t"
+              . "No match\n";
+
 	  $xrefs_written{$xref_id} = 1;
 	  $count++;
 	}
@@ -1901,7 +1915,17 @@ sub dump_direct_xrefs {
 	  }
           next; # do not store XREF or OBJECT. do much later
 	}
-        print XREF ($xref_id+$xref_id_offset) . "\t" . $external_db_id . "\t" . $accession . "\t" . $label . "\t" . $version . "\t" . $description ."\t". "DIRECT" . "\t" . "Externally assigned relationship between $ensembl_stable_id and $accession" . "\n";
+
+        print XREF ( $xref_id + $xref_id_offset ) . "\t"
+          . ( $external_db_id || '' ) . "\t"
+          . ( $accession      || '' ) . "\t"
+          . ( $label          || '' ) . "\t"
+          . ( $version        || '' ) . "\t"
+          . ( $description    || '' ) . "\t"
+          . "DIRECT" . "\t"
+          . "Externally assigned relationship between "
+          . $ensembl_stable_id . " and "
+          . $accession . "\n";
 
         $xrefs_written{$xref_id} = 1;
       }
@@ -1936,7 +1960,18 @@ sub dump_direct_xrefs {
               if(!defined($updated_source{$external_db_id})){
                 $self->cleanup_sources_file($external_db_id);
               }
-              print XREF ($xref_id+$xref_id_offset) . "\t" . $external_db_id . "\t" . $accession . "\t" . $label . "\t" . $version . "\t" . $description ."\t". "DIRECT" . "\t" . "Externally assigned relationship between $ensembl_stable_id and $accession" ."\n";
+
+                print XREF ( $xref_id + $xref_id_offset ) . "\t"
+                  . ( $external_db_id || '' ) . "\t"
+                  . ( $accession      || '' ) . "\t"
+                  . ( $label          || '' ) . "\t"
+                  . ( $version        || '' ) . "\t"
+                  . ( $description    || '' ) . "\t"
+                  . "DIRECT" . "\t"
+                  . "Externally assigned relationship between "
+                  . $ensembl_stable_id . " and "
+                  . $accession . "\n";
+
               $xrefs_written{$xref_id} = 1;
             }
             $ensembl_internal_id = $stable_id_to_internal_id{$type}->{$stable_id};
@@ -2229,7 +2264,16 @@ sub dump_core_xrefs {
 	  if(!defined($updated_source{$external_db_id})){
 	    $self->cleanup_sources_file($external_db_id);
 	  }
-	  print XREF ($xref_id+$xref_id_offset) . "\t" . $external_db_id . "\t" . $accession . "\t" . $label . "\t" . $version . "\t" . $description . "\t" . "SEQUENCE_MATCH\t" . "Relationship generated from exonerate mapping" . "\n";
+
+            print XREF ( $xref_id + $xref_id_offset ) . "\t"
+              . ( $external_db_id || '' ) . "\t"
+              . ( $accession      || '' ) . "\t"
+              . ( $label          || '' ) . "\t"
+              . ( $version        || '' ) . "\t"
+              . ( $description    || '' ) . "\t"
+              . "SEQUENCE_MATCH" . "\t"
+              . "Relationship generated from exonerate mapping\n";
+
 	  $xrefs_written{$xref_id} = 1;
 	  $source_ids{$source_id} = $source_id;
 	}
@@ -2270,7 +2314,17 @@ sub dump_core_xrefs {
 	}
 	
 	if(!defined($priority_xref_source_id{$xref_id})){
-	  print XREF ($xref_id+$xref_id_offset) . "\t" . $external_db_id . "\t" . $accession . "\t" . $label . "\t" . $version . "\t" . $description . "\t" . "DEPENDENT" . "\t" . "Generated via $master_accession\n";
+
+            print XREF ( $xref_id + $xref_id_offset ) . "\t"
+              . ( $external_db_id || '' ) . "\t"
+              . ( $accession      || '' ) . "\t"
+              . ( $label          || '' ) . "\t"
+              . ( $version        || '' ) . "\t"
+              . ( $description    || '' ) . "\t"
+              . "DEPENDENT" . "\t"
+              . "Generated via "
+              . $master_accession . "\n";
+
 	}
 	$xrefs_written{$xref_id} = 1;
 	$source_ids{$source_id} = $source_id;
@@ -4041,7 +4095,17 @@ sub dump_all_dependencies{
 	}
 	
 	if(!defined($priority_xref_source_id{$xref_id})){
-	    print XREF ($xref_id+$xref_id_offset) . "\t" . $external_db_id . "\t" . $accession . "\t" . $label . "\t" . $version . "\t" . $description .  "\t" . "DEPENDENT" . "\t" . "Generated via $master_accession\n";
+
+            print XREF ( $xref_id + $xref_id_offset ) . "\t"
+              . ( $external_db_id || '' ) . "\t"
+              . ( $accession      || '' ) . "\t"
+              . ( $label          || '' ) . "\t"
+              . ( $version        || '' ) . "\t"
+              . ( $description    || '' ) . "\t"
+              . "DEPENDENT" . "\t"
+              . "Generated via "
+              . $master_accession . "\n";
+
 	    push @return, ($xref_id+$xref_id_offset);
 	    $xrefs_written{$xref_id} = 1;
 	}
@@ -4155,8 +4219,14 @@ PSQL
 	  $self->cleanup_sources_file($external_db_id);
 	}
 	if(!defined($priority_xref_source_id{$xref_id})){
-	  print XREF ($xref_id+$xref_id_offset) . "\t" . $external_db_id . "\t" . $accession . 
-	             "\t" . $label . "\t" . $version . "\t" . $description . "\tMISC\tNo match\n";
+
+            print XREF ( $xref_id + $xref_id_offset ) . "\t"
+              . ( $external_db_id || '' ) . "\t"
+              . ( $accession      || '' ) . "\t"
+              . ( $label          || '' ) . "\t"
+              . ( $version        || '' ) . "\t"
+              . ( $description    || '' ) . "\t" . "MISC" . "\t"
+              . "No match\n";
 
 #dump out dependencies aswell
 	  
@@ -4437,9 +4507,17 @@ PSQL
 
 
       if (!$xrefs_written{$xref_id}) {
-        print XREF ($xref_id+$xref_id_offset) . "\t" . $external_db_id . "\t" . $accession . "\t" .
-          $label . "\t" . $version . "\t" . $description .  "\t" . "DEPENDENT" . "\t" .
-            "No mapping ".$unmapped_primary_xref{$xref_id}. "\n";
+
+        print XREF ( $xref_id + $xref_id_offset ) . "\t"
+          . ( $external_db_id || '' ) . "\t"
+          . ( $accession      || '' ) . "\t"
+          . ( $label          || '' ) . "\t"
+          . ( $version        || '' ) . "\t"
+          . ( $description    || '' ) . "\t"
+          . "DEPENDENT" . "\t"
+          . "No mapping "
+          . $unmapped_primary_xref{$xref_id} . "\n";
+
         $xrefs_written{$xref_id} = 1;
       }
       if(!defined($object_succesfully_mapped{$xref_id})){
-- 
GitLab