src/org/gel/mauve/Genome.java

Go to the documentation of this file.
00001 package org.gel.mauve;
00002 
00003 import java.util.ArrayList;
00004 
00005 import java.util.Collections;
00006 import java.util.Iterator;
00007 import java.util.List;
00008 import java.util.Vector;
00009 
00010 import org.biojava.bio.seq.FeatureFilter;
00011 import org.biojava.bio.seq.FeatureHolder;
00012 import org.biojava.bio.seq.Sequence;
00013 import org.biojava.bio.seq.StrandedFeature;
00014 import org.biojava.bio.symbol.LocationTools;
00015 import org.biojavax.bio.seq.Position;
00016 import org.biojavax.bio.seq.RichLocation;
00017 import org.biojavax.bio.seq.SimplePosition;
00018 import org.biojavax.bio.seq.SimpleRichLocation;
00019 
00020 public class Genome {
00021         private long length;
00022 
00023         private BaseViewerModel model;
00024 
00025         private Sequence annotationSequence;
00026 
00027         private List<Chromosome> chromosomes = new ArrayList<Chromosome> ();
00028 
00029         private String displayName;
00030 
00031         private SupportedFormat format;
00032 
00033         private String id;
00034 
00035         private long viewStart;
00036 
00037         private long viewLength;
00038 
00039         private int viewIndex;
00040 
00041         private Vector sortedMatches;
00042 
00043         private int sourceIndex;
00044         private boolean visible = true;
00045         public Genome (long length, BaseViewerModel model, int sourceIndex) {
00046                 this.length = length;
00047                 this.model = model;
00048                 this.sourceIndex = sourceIndex;
00049         }
00050 
00051         public int getSourceIndex () {
00052                 return sourceIndex;
00053         }
00054 
00055         public long getLength () {
00056                 return length;
00057         }
00058 
00059         public void setAnnotationSequence (Sequence annotationSequence,
00060                         SupportedFormat format) {
00061                 this.format = format;
00062                 this.annotationSequence = annotationSequence;
00063         }
00064 
00065         public BaseViewerModel getModel () {
00066                 return model;
00067         }
00068 
00069         // list must be in order by position in sequence!
00070         public void setChromosomes (List list) {
00071                 this.chromosomes = list;
00072         }
00073 
00074         public Sequence getAnnotationSequence () {
00075                 return annotationSequence;
00076         }
00077 
00078         public SupportedFormat getAnnotationFormat () {
00079                 return format;
00080         }
00081         
00092         public FeatureHolder getAnnotationsAt(long left, long right, boolean rev){
00093                 Position min = new SimplePosition((int) left);
00094                 Position max = new SimplePosition((int) right);
00095                 RichLocation loc = new SimpleRichLocation (min,max,0,rev?
00096                                                                 RichLocation.Strand.NEGATIVE_STRAND : 
00097                                                                 RichLocation.Strand.POSITIVE_STRAND);
00098                 return annotationSequence.filter(new FeatureFilter.OverlapsLocation(loc));
00099         }
00100 
00101         public String getDisplayName () {
00102                 return displayName;
00103         }
00104 
00105         public void setDisplayName (String displayName) {
00106                 this.displayName = displayName;
00107         }
00108 
00114         public List<Chromosome> getChromosomes () {
00115                 return Collections.unmodifiableList (chromosomes);
00116         }
00117 
00118         public Chromosome getChromosomeAt (long loc) {
00119 
00120                 if (loc < 1 || loc > length)
00121                         return null;
00122 
00123                 // This could be done smarter, if there are many chromosomes, since the
00124                 // list is sorted.
00125                 Iterator i = chromosomes.iterator ();
00126                 while (i.hasNext ()) {
00127                         Chromosome c = (Chromosome) i.next ();
00128                         if (c.getStart () <= loc && loc <= c.getEnd ()) {
00129                                 return c;
00130                         }
00131                 }
00132                 return null;
00133         }
00134 
00135         public void setID (String id) {
00136                 this.id = id;
00137         }
00138 
00139         public String getID () {
00140                 return id;
00141         }
00142 
00143         public long getViewLength () {
00144                 return viewLength;
00145         }
00146 
00147         public void setViewLength (long viewLength) {
00148                 this.viewLength = viewLength;
00149         }
00150 
00151         public long getViewStart () {
00152                 return viewStart;
00153         }
00154 
00155         public void setViewStart (long viewStart) {
00156                 this.viewStart = viewStart;
00157         }
00158 
00159         public int getViewIndex () {
00160                 return viewIndex;
00161         }
00162 
00163         // TODO: Fire an event?
00164         public void setViewIndex (int viewIndex) {
00165                 this.viewIndex = viewIndex;
00166 
00167                 // Clear cache of matches.
00168                 sortedMatches = null;
00169         }
00170 
00171         public Vector getSortedMatches () {
00172                 try {
00173                         if (sortedMatches == null) {
00174                                 sortedMatches = model
00175                                                 .sortedMatches (new MatchStartComparator (this));
00176                         }
00177                 } catch (Exception e) {
00178                         // TODO Auto-generated catch block
00179                         e.printStackTrace();
00180                 }
00181                 return sortedMatches;
00182         }
00183         
00184         public boolean getVisible(){
00185         return visible;
00186     }
00187     public void setVisible(boolean v){
00188         visible = v;
00189         }
00190 
00191         public String toString () {
00192                 return getDisplayName ();
00193         }
00200         public boolean isCircular(int chrI){
00201                 return ((Chromosome) chromosomes.get(chrI)).circular;
00202         }
00203         
00204 }

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