JAL-4090 JAL-4334 position status when start, end or pos is unknown is stored in...
[jalview.git] / src / jalview / ws / dbsources / Uniprot.java
index c9db7f2..b125ba5 100644 (file)
@@ -39,6 +39,7 @@ import javax.xml.stream.XMLStreamReader;
 import com.stevesoft.pat.Regex;
 
 import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
@@ -292,19 +293,68 @@ public class Uniprot extends DbSourceProxyImpl
         LocationType location = uf.getLocation();
         int start = 0;
         int end = 0;
+        String uncertain_start = null, uncertain_end = null,
+                uncertain_pos = null;
         if (location.getPosition() != null)
         {
-          start = location.getPosition().getPosition().intValue();
-          end = start;
+          if (location.getPosition().getPosition() == null
+                  || !"unknown".equals(location.getPosition().getStatus()))
+          {
+            Console.warn(
+                    "Ignoring single position feature with uncertain location "
+                            + uf.getType() + ":" + getDescription(uf));
+            uncertain_pos = location.getPosition().getStatus() == null
+                    ? "unknown"
+                    : location.getPosition().getStatus();
+          }
+          else
+          {
+            start = location.getPosition().getPosition().intValue();
+            end = start;
+          }
         }
         else
         {
-          start = location.getBegin().getPosition().intValue();
-          end = location.getEnd().getPosition().intValue();
+          if (location.getBegin().getPosition() == null)
+          {
+            Console.warn(
+                    "Setting start position of feature with uncertain start to 1: "
+                            + uf.getType() + ":" + getDescription(uf));
+            start = sequence.getStart();
+            uncertain_start = location.getBegin().getStatus();
+          }
+          else
+          {
+            start = location.getBegin().getPosition().intValue();
+          }
+          if (location.getEnd().getPosition() == null)
+          {
+            Console.warn(
+                    "Setting start position of feature with uncertain start to 1: "
+                            + uf.getType() + ":" + getDescription(uf));
+            end = sequence.getEnd();
+            uncertain_end = location.getEnd().getStatus();
+          }
+          else
+          {
+            end = location.getEnd().getPosition().intValue();
+          }
         }
         SequenceFeature sf = new SequenceFeature(uf.getType(),
                 getDescription(uf), start, end, "Uniprot");
         sf.setStatus(uf.getStatus());
+        if (uncertain_end != null)
+        {
+          sf.setValue("end_status", uncertain_end);
+        }
+        if (uncertain_start != null)
+        {
+          sf.setValue("start_status", uncertain_start);
+        }
+        if (uncertain_pos != null)
+        {
+          sf.setValue("pos_status", uncertain_pos);
+        }
         sequence.addSequenceFeature(sf);
       }
     }