From 7edab300ca99091689b3aae05374ab9b409254b4 Mon Sep 17 00:00:00 2001
From: tcarver <tjc>
Date: Wed, 17 Aug 2011 12:46:25 +0100
Subject: [PATCH] fix for partials and UTR ordering

---
 .../artemis/io/PublicDBDocumentEntry.java     | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/uk/ac/sanger/artemis/io/PublicDBDocumentEntry.java b/uk/ac/sanger/artemis/io/PublicDBDocumentEntry.java
index a6f00db82..b8ab91767 100644
--- a/uk/ac/sanger/artemis/io/PublicDBDocumentEntry.java
+++ b/uk/ac/sanger/artemis/io/PublicDBDocumentEntry.java
@@ -250,6 +250,13 @@ public class PublicDBDocumentEntry extends SimpleDocumentEntry
     	addNewQualifier(qualifiers, newIDQualifier);
     	geneQualifiers.removeQualifierByName("ID");
       }
+      else if(ntranscripts == 1)
+      {
+        if(qualifiers.getQualifierByName("isFminPartial") != null)
+          addNewQualifier(qualifiers, qualifiers.getQualifierByName("isFminPartial"));
+        if(qualifiers.getQualifierByName("isFmaxPartial") != null)
+          addNewQualifier(qualifiers, qualifiers.getQualifierByName("isFmaxPartial"));
+      }
       combineQualifiers(qualifiers, geneQualifiers, true);
     }
     else if(GeneUtils.isNonCodingTranscripts(key))
@@ -266,6 +273,7 @@ public class PublicDBDocumentEntry extends SimpleDocumentEntry
     
     try
     {
+      location = handlePartials(qualifiers, location);
       for(int i=0; i<DATABASE_QUALIFIERS_TO_MAP.length; i++)
       {
         if(!getEntryInformation().isValidQualifier(DATABASE_QUALIFIERS_TO_MAP[i][0]))
@@ -355,6 +363,8 @@ public class PublicDBDocumentEntry extends SimpleDocumentEntry
         if(start != feature.getLocation().getTotalRange().getStart())
           return null;
         
+        if(feature.getLocation().isComplement())
+          ranges.reverse();
         location =
           new Location(ranges, feature.getLocation().isComplement());
       }
@@ -743,6 +753,40 @@ public class PublicDBDocumentEntry extends SimpleDocumentEntry
     }
   }
   
+  /**
+   * Use '<' and '>' signs in the location descriptors to
+   * indicate that the sequence is partial.
+   * @param qualifiers
+   * @param location
+   * @return
+   */
+  private Location handlePartials(QualifierVector qualifiers, Location location)
+  {
+    if(qualifiers.getQualifierByName("isFminPartial") != null)
+    {
+      try
+      {
+        location = new Location(location.toString().replaceFirst("(\\d)", "<$1"));
+      }
+      catch (LocationParseException e)
+      {
+        e.printStackTrace();
+      }
+    }
+    else if(qualifiers.getQualifierByName("isFmaxPartial") != null)
+    {
+      try
+      {
+        location = new Location(location.toString().replaceAll("^(.*)(\\.)(.*)$","$1$2>$3"));
+      }
+      catch (LocationParseException e)
+      {
+        e.printStackTrace();
+      }
+    }
+    return location;
+  }
+  
   /**
    * Change the stop_codon_redefined_as_selenocysteine SO qualifier
    * to the transl_except EMBL qualifier.
-- 
GitLab