From f3c18d0c1e0cd9daad8f47d74bf40e48bc4b0d46 Mon Sep 17 00:00:00 2001
From: tcarver <tjc>
Date: Tue, 5 Nov 2013 09:44:17 +0000
Subject: [PATCH] optionally remove products from pseudogenes

---
 .../artemis/components/EntryFileDialog.java   |  4 +--
 .../sanger/artemis/io/ReadAndWriteEntry.java  | 32 +++++++++++++++++--
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/uk/ac/sanger/artemis/components/EntryFileDialog.java b/uk/ac/sanger/artemis/components/EntryFileDialog.java
index d70d48d1b..96a708d55 100644
--- a/uk/ac/sanger/artemis/components/EntryFileDialog.java
+++ b/uk/ac/sanger/artemis/components/EntryFileDialog.java
@@ -471,7 +471,7 @@ public class EntryFileDialog extends StickyFileChooser
             ReadAndWriteEntry.writeDatabaseEntryToFile(entry, file, 
                 flattenGeneModel.isSelected(), 
                 ignoreObsoleteFeatures.isSelected(), false, 
-                include_diana_extensions, destination_type, owner);
+                include_diana_extensions, false, destination_type, owner);
           else if(include_diana_extensions) 
             entry.save(file, destination_type, false);
           else 
@@ -491,7 +491,7 @@ public class EntryFileDialog extends StickyFileChooser
                 ReadAndWriteEntry.writeDatabaseEntryToFile(entry, file, 
                     flattenGeneModel.isSelected(), 
                     ignoreObsoleteFeatures.isSelected(), true, 
-                    include_diana_extensions, destination_type, null);
+                    include_diana_extensions, false, destination_type, null);
               else if(include_diana_extensions) 
                 entry.save(file, destination_type, true);
               else 
diff --git a/uk/ac/sanger/artemis/io/ReadAndWriteEntry.java b/uk/ac/sanger/artemis/io/ReadAndWriteEntry.java
index bba787324..714e35c26 100644
--- a/uk/ac/sanger/artemis/io/ReadAndWriteEntry.java
+++ b/uk/ac/sanger/artemis/io/ReadAndWriteEntry.java
@@ -136,6 +136,7 @@ public class ReadAndWriteEntry
                                               final boolean ignoreObsolete,
                                               final boolean force,
                                               final boolean include_diana_extensions,
+                                              final boolean removeProductForPseudo,
                                               final int destination_type,
                                               final JFrame parent) 
          throws IOException, EntryInformationException
@@ -183,7 +184,27 @@ public class ReadAndWriteEntry
     if(include_diana_extensions)
       entry.save(file, destination_type, force, artemis_entry_information);
     else
+    {
+      if(removeProductForPseudo)
+      {
+        uk.ac.sanger.artemis.io.FeatureVector features = entry.getEMBLEntry().getAllFeatures();
+        for(Feature f: features)
+        {
+          if(f.getKey().equals("polypeptide"))
+          {
+            Qualifier q = f.getQualifierByName("product");
+            if(q != null)
+            {
+              Feature gene = ((GFFStreamFeature) f).getChadoGene().getGene();
+              if(gene.getKey().equals("pseudogene"))
+                f.getQualifiers().remove(q);
+            }
+          }
+        }
+      }
+      
       entry.saveStandardOnly(file, destination_type, force);
+    }
   }
   
   
@@ -304,6 +325,7 @@ public class ReadAndWriteEntry
         System.out.println("-z\t[y|n] gzip output, default is y");
         System.out.println("-a\t[y|n] for EMBL submission format change to n, default is y");
         System.out.println("-pp\t[y|n] read polypeptide domain features, default is n");
+        System.out.println("-r\t[y|n] remove product qualifiers from pseudogene, default is n");
         System.out.println("-c\tthe URL for your Chado database e.g. db.genedb.org:5432/snapshot?genedb_ro (if not using default)");
         System.out.println("-u\t[swing|console|script] the UI mode : run in swing (with popup dialog boxes) mode, run in console mode (choices entered in the console window), or in script mode (all choices default to continue, all parameters passed on command line) ");
         System.out.println("-p\tthe password for connecting to the Chado database");
@@ -320,6 +342,7 @@ public class ReadAndWriteEntry
       String suffix = ".embl";
       boolean gzip = true;
       boolean noprivates = true;
+      boolean removeProductForPseudo = false;
       
       String filePath = "";
       
@@ -375,6 +398,11 @@ public class ReadAndWriteEntry
         {
         	System.setProperty("chado", args[i + 1]);
         }
+        else if (key.equals("-r"))
+        {
+          if(i + 1 < args.length && args[i + 1].toLowerCase().equals("y"))
+            removeProductForPseudo = true;
+        }
         else if (key.equals("-p"))
         {
         	System.setProperty("chadoPassword", args[i + 1]);
@@ -443,7 +471,7 @@ public class ReadAndWriteEntry
         {
           ReadAndWriteEntry.writeDatabaseEntryToFile(
             entry, new File(filePath + names[i]+suffix), flatten, ignoreObsolete, 
-            false, include_diana_extensions,
+            false, include_diana_extensions, removeProductForPseudo,
             format, null);
           System.out.println("done");
           logger4j.info("done");
@@ -457,7 +485,7 @@ public class ReadAndWriteEntry
         	{
         		ReadAndWriteEntry.writeDatabaseEntryToFile(entry, new File(filePath + names[i] + suffix), 
         				flatten, ignoreObsolete, true,
-        			include_diana_extensions, format, null);
+        			include_diana_extensions, removeProductForPseudo, format, null);
         		System.out.println("done");
         		logger4j.info("done");
         	}
-- 
GitLab