src/org/gel/mauve/format/GenbankEmblFormat.java

Go to the documentation of this file.
00001 package org.gel.mauve.format;
00002 
00003 import java.awt.BasicStroke;
00004 import java.awt.Color;
00005 import java.util.StringTokenizer;
00006 import java.util.Iterator;
00007 import java.util.Set;
00008 
00009 import org.biojava.bio.Annotation;
00010 import org.biojava.bio.gui.sequence.RectangularBeadRenderer;
00011 import org.biojava.bio.seq.Feature;
00012 import org.biojava.bio.seq.FeatureFilter;
00013 import org.biojava.bio.seq.FeatureHolder;
00014 import org.biojava.bio.seq.Sequence;
00015 import org.biojava.bio.seq.StrandedFeature;
00016 import org.biojava.utils.ChangeVetoException;
00017 import org.biojavax.Note;
00018 import org.biojavax.RichObjectFactory;
00019 import org.biojavax.bio.seq.RichFeature;
00020 import org.biojavax.bio.seq.RichSequence;
00021 import org.biojavax.bio.taxa.NCBITaxon;
00022 import org.biojavax.ontology.ComparableTerm;
00023 import org.gel.mauve.FilterCacheSpec;
00024 import org.gel.mauve.MauveConstants;
00025 import org.gel.mauve.gui.navigation.AnnotationContainsFilter;
00026 import org.gel.mauve.gui.sequence.ZiggyRectangularBeadRenderer;
00027 
00028 public abstract class GenbankEmblFormat extends BaseFormat {
00029         private static FilterCacheSpec [] specs = new FilterCacheSpec [11];
00030         static {
00031                 RectangularBeadRenderer renderer = null;
00032                 ZiggyRectangularBeadRenderer zrenderer;
00033                 try {
00034                         zrenderer = new ZiggyRectangularBeadRenderer (10.0, 0.0,
00035                                         Color.BLACK, Color.WHITE, new BasicStroke ());
00036                         specs[0] = new FilterCacheSpec (new FeatureFilter.And (
00037                                         new FeatureFilter.ByType ("CDS"),
00038                                         new FeatureFilter.StrandFilter (StrandedFeature.POSITIVE)),
00039                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00040                                         zrenderer);
00041 
00042                         renderer = new RectangularBeadRenderer (10.0, 0.0, Color.BLACK,
00043                                         Color.RED, new BasicStroke ());
00044                         renderer.setHeightScaling (false);
00045                         specs[1] = new FilterCacheSpec (new FeatureFilter.And (
00046                                         new FeatureFilter.ByType ("rRNA"),
00047                                         new FeatureFilter.StrandFilter (StrandedFeature.POSITIVE)),
00048                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00049                                         renderer);
00050 
00051                         renderer = new RectangularBeadRenderer (10.0, 0.0, Color.BLACK,
00052                                         Color.GREEN, new BasicStroke ());
00053                         renderer.setHeightScaling (false);
00054                         specs[2] = new FilterCacheSpec (new FeatureFilter.And (
00055                                         new FeatureFilter.ByType ("tRNA"),
00056                                         new FeatureFilter.StrandFilter (StrandedFeature.POSITIVE)),
00057                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00058                                         renderer);
00059 
00060                         renderer = new RectangularBeadRenderer (10.0, 0.0, Color.BLACK,
00061                                         Color.BLUE, new BasicStroke ());
00062                         renderer.setHeightScaling (false);
00063                         specs[3] = new FilterCacheSpec (new FeatureFilter.And (
00064                                         new FeatureFilter.ByType ("misc_RNA"),
00065                                         new FeatureFilter.StrandFilter (StrandedFeature.POSITIVE)),
00066                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00067                                         renderer);
00068 
00069                         zrenderer = new ZiggyRectangularBeadRenderer (10.0, 10.0,
00070                                         Color.BLACK, Color.WHITE, new BasicStroke ());
00071                         specs[4] = new FilterCacheSpec (new FeatureFilter.And (
00072                                         new FeatureFilter.ByType ("CDS"),
00073                                         new FeatureFilter.StrandFilter (StrandedFeature.NEGATIVE)),
00074                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00075                                         zrenderer);
00076 
00077                         renderer = new RectangularBeadRenderer (10.0, 10.0, Color.BLACK,
00078                                         Color.RED, new BasicStroke ());
00079                         renderer.setHeightScaling (false);
00080                         specs[5] = new FilterCacheSpec (new FeatureFilter.And (
00081                                         new FeatureFilter.ByType ("rRNA"),
00082                                         new FeatureFilter.StrandFilter (StrandedFeature.NEGATIVE)),
00083                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00084                                         renderer);
00085 
00086                         renderer = new RectangularBeadRenderer (10.0, 10.0, Color.BLACK,
00087                                         Color.GREEN, new BasicStroke ());
00088                         renderer.setHeightScaling (false);
00089                         specs[6] = new FilterCacheSpec (new FeatureFilter.And (
00090                                         new FeatureFilter.ByType ("tRNA"),
00091                                         new FeatureFilter.StrandFilter (StrandedFeature.NEGATIVE)),
00092                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00093                                         renderer);
00094 
00095                         renderer = new RectangularBeadRenderer (10.0, 10.0, Color.BLACK,
00096                                         Color.BLUE, new BasicStroke ());
00097                         renderer.setHeightScaling (false);
00098                         specs[7] = new FilterCacheSpec (new FeatureFilter.And (
00099                                         new FeatureFilter.ByType ("misc_RNA"),
00100                                         new FeatureFilter.StrandFilter (StrandedFeature.NEGATIVE)),
00101                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00102                                         renderer);
00103 
00104                         // for repeats
00105                         renderer = new RectangularBeadRenderer (6.0, 26.0, Color.BLACK,
00106                                         Color.PINK, new BasicStroke ());
00107                         renderer.setHeightScaling (false);
00108                         specs[8] = new FilterCacheSpec (new FeatureFilter.And (
00109                                         new FeatureFilter.ByType ("repeat_region"),
00110                                         new FeatureFilter.StrandFilter (StrandedFeature.NEGATIVE)),
00111                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00112                                         renderer);
00113                         renderer.setHeightScaling (false);
00114                         renderer = new RectangularBeadRenderer (6.0, 20.0, Color.BLACK,
00115                                         Color.PINK, new BasicStroke ());
00116                         specs[9] = new FilterCacheSpec (new FeatureFilter.And (
00117                                         new FeatureFilter.ByType ("repeat_region"),
00118                                         new FeatureFilter.StrandFilter (StrandedFeature.POSITIVE)),
00119                                         new String [] {"gene", "locus_tag", "product", "db_xref"},
00120                                         renderer);
00121                         renderer.setHeightScaling (false);
00122                         specs[10] = new FilterCacheSpec (
00123                                         new FeatureFilter.ByType ("source"),
00124                                         new String [] {FilterCacheSpec.ALL_ANNOTATIONS});
00125                 } catch (ChangeVetoException e) {
00126                         e.printStackTrace ();
00127                 }
00128         }
00129 
00130         public String getChromosomeName (Sequence s) {
00131                 FeatureHolder fh = s.filter(new FeatureFilter.ByType("source"));
00132         String name = null;
00133         Annotation a = null;
00134         if (fh.countFeatures() != 0)
00135         {
00136             Feature f2 = (Feature) fh.features().next();
00137             a = f2.getAnnotation();
00138         }
00139         if (a != null) {
00140             if (a.containsProperty("chromosome"))
00141             {
00142                 name = (String) a.getProperty("chromosome");
00143             }
00144             else if (a.containsProperty("biojavax:chromosome"))
00145             {
00146                 name = (String) a.getProperty("biojavax:chromosome");
00147             }
00148             else if (a.containsProperty("plasmid"))
00149             {
00150                 name = (String) a.getProperty("plasmid");
00151             }
00152             else if (a.containsProperty("biojavax:plasmid"))
00153             {
00154                 name = (String) a.getProperty("biojavax:plasmid");
00155             }
00156                 }
00157         if (name != null) {
00158                 name = name.trim();
00159                 if (name.length() == 0)
00160                         name = null;
00161         }
00162         if (name == null && s.getAnnotation() != null) {
00163                 name = (String) s.getName();
00164         }
00165         if (name == null && 
00166                         AnnotationContainsFilter.getKeyIgnoreCase ("definition",
00167                                 s.getAnnotation()) != null) {
00168                         name = getChromNameFromDescription (s);
00169                 }
00170                 return name;
00171         }
00172 
00173         public String getChromNameFromDescription (Sequence seq) {
00174                 String desc = ((String) AnnotationContainsFilter.getValueIgnoreCase (
00175                                 "definition", seq.getAnnotation ()));
00176         if(desc == null) {
00177             return null;
00178         } else {
00179             desc = desc.toLowerCase();
00180         }
00181 
00182                 int ind = desc.indexOf ("contig");
00183                 if (ind > -1) {
00184                         ind = desc.lastIndexOf (" ", ind);
00185                         if (ind < 0)
00186                                 ind = 0;
00187                         int ind2 = desc.indexOf (" ", ind + 1);
00188                         if (ind2 < 0)
00189                                 ind2 = desc.length ();
00190                         desc = desc.substring (ind, ind2);
00191                 }
00192                 else if (desc.indexOf("chromosome") > 0)
00193                         desc = "chromosome";
00194                 else if (desc.indexOf("plasmid") > 0)
00195                         desc = "plasmid";
00196                 /*else {
00197                         StringTokenizer toke = new StringTokenizer (getSequenceName (seq));
00198                         while (toke.hasMoreTokens ()) {
00199                                 String [] pieces = desc.split (toke.nextToken ().toLowerCase ());
00200                                 desc = "";
00201                                 for (int i = 0; i < pieces.length; i++)
00202                                         desc += pieces[i].trim () + " ";
00203                                 desc = desc.trim ();
00204                         }
00205                 }*/
00206                 return desc;
00207         }
00208 
00209         public String getSequenceName (Sequence s) {
00210                 FeatureHolder fh = s.filter (new FeatureFilter.ByType ("source"));
00211                 if (fh.countFeatures () != 0) {
00212                         Feature f2 = (Feature) fh.features ().next ();
00213                         Annotation a = f2.getAnnotation ();
00214                         String name = "";
00215                         String add = null;
00216                         if (a.containsProperty ("organism")) {
00217                                 name += a.getProperty ("organism") + " ";
00218                         }
00219                         if (a.containsProperty ("serovar")) {
00220                                 add = a.getProperty ("serovar").toString ();
00221                                 if (name.indexOf (add) == -1)
00222                                         name += add + " ";
00223                         }
00224                         if (a.containsProperty ("strain")) {
00225                                 add = a.getProperty ("strain").toString ();
00226                                 if (name.indexOf (add) == -1)
00227                                         name += add + " ";
00228                         }
00229                         if (name != "")
00230                                 return name.trim ();
00231                 }
00232                 // if a source feature didn't exist
00233                 // try getting the source from the headers
00234                 try {
00235                         Object source = s.getAnnotation ().getProperty ("SOURCE");
00236                         if (source != null) {
00237                                 return (String) source;
00238                         }
00239                 } catch (Exception e) {
00240                 }
00241                 return null;
00242         }
00243 
00244         public FilterCacheSpec [] getFilterCacheSpecs () {
00245                 return specs;
00246         }
00247 
00248 }

Generated on Mon Aug 19 06:03:41 2013 for Mauve by doxygen 1.3.6