From 0b7e5aee8a2f159e260ae29dbda67b4ce17dbdf3 Mon Sep 17 00:00:00 2001
From: tcarver <tjc>
Date: Tue, 23 Aug 2011 10:11:30 +0100
Subject: [PATCH] use isStrandOK() to check strand is consistent within the
 gene model

---
 .../genebuilder/GeneBuilderFrame.java         | 20 ++++++++--
 .../components/genebuilder/GeneUtils.java     | 37 ++++++++++++++++++-
 2 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/uk/ac/sanger/artemis/components/genebuilder/GeneBuilderFrame.java b/uk/ac/sanger/artemis/components/genebuilder/GeneBuilderFrame.java
index 847710b30..ad4232479 100644
--- a/uk/ac/sanger/artemis/components/genebuilder/GeneBuilderFrame.java
+++ b/uk/ac/sanger/artemis/components/genebuilder/GeneBuilderFrame.java
@@ -343,13 +343,25 @@ public class GeneBuilderFrame extends JFrame
         geneBuilderHash.put(chado_gene.getGeneUniqueName(), gbFrame);
       }
     }
-    else if(!GeneUtils.isBoundaryOK(chado_gene))
+    else 
     {
-      int result = JOptionPane.showConfirmDialog(this, 
+      if(!GeneUtils.isBoundaryOK(chado_gene))
+      {
+        int result = JOptionPane.showConfirmDialog(this, 
           "Gene model boundary needs fixing.\nFix this now?", 
           "Gene Boundary", JOptionPane.YES_NO_OPTION);
-      if(result == JOptionPane.YES_OPTION)
-        GeneUtils.checkGeneBoundary(chado_gene);
+        if(result == JOptionPane.YES_OPTION)
+          GeneUtils.checkGeneBoundary(chado_gene);
+      }
+      
+      if(!GeneUtils.isStrandOK(chado_gene))
+      {
+        JOptionPane.showMessageDialog(this, 
+          "All gene features should be on the same strand.\n"+
+          "Check the strand of each of the features (gene,\n"+
+          "transcript, CDS, polypeptide).", 
+          "Check Strand", JOptionPane.WARNING_MESSAGE);
+      }
     }
     
     super.dispose();
diff --git a/uk/ac/sanger/artemis/components/genebuilder/GeneUtils.java b/uk/ac/sanger/artemis/components/genebuilder/GeneUtils.java
index c771f0b9c..e14ddb2f1 100644
--- a/uk/ac/sanger/artemis/components/genebuilder/GeneUtils.java
+++ b/uk/ac/sanger/artemis/components/genebuilder/GeneUtils.java
@@ -90,8 +90,7 @@ import uk.ac.sanger.artemis.Selection;
 
 public class GeneUtils
 {
-  private static final long serialVersionUID = 1L;
-  private static Vector hideFeatures = new Vector();
+  private static Vector<String> hideFeatures = new Vector<String>();
   private static JCheckBox showObsolete = new JCheckBox("Show Obsolete Features",false);
   private static String nonCodingTranscripts[] =
                                 { "tRNA", "rRNA", "snRNA", "snoRNA", "ncRNA", "scRNA" };
@@ -1003,6 +1002,40 @@ public class GeneUtils
       chado_gene.deleteFeature(embl_feature);
     }
   }
+  
+  /**
+   * Check gene model strands for any inconsistencies
+   * @param chado_gene
+   * @return true is gene model ranges are correct
+   */
+  protected static boolean isStrandOK(final ChadoCanonicalGene chado_gene)
+  {
+    boolean isRev = chado_gene.getGene().getLocation().isComplement();
+    final List<Feature> transcripts = chado_gene.getTranscripts();
+    
+    for(int i=0; i<transcripts.size(); i++)
+    {
+      final Feature transcript = (Feature)transcripts.get(i);
+      
+      if(isRev ^ transcript.getLocation().isComplement())
+        return false;
+      
+      final Feature protein = 
+        chado_gene.getProteinOfTranscript(GeneUtils.getUniqueName(transcript));
+      if(protein != null && (isRev ^ protein.getLocation().isComplement()))
+        return false;
+      
+      final Set<Feature> children = chado_gene.getChildren(transcript);
+      final Iterator<Feature> it = children.iterator();
+      while(it.hasNext())
+      {
+        final Feature feature = it.next();
+        if(isRev ^ feature.getLocation().isComplement())
+          return false;
+      }
+    }
+    return true;
+  }
 
   /**
    * Check gene model boundaries for any inconsistencies
-- 
GitLab