src/org/gel/mauve/color/NormalizedMultiplicityTypeColorScheme.java

Go to the documentation of this file.
00001 package org.gel.mauve.color;
00002 
00003 import java.awt.Color;
00004 import java.util.Comparator;
00005 import java.util.Vector;
00006 
00007 import org.gel.mauve.BaseViewerModel;
00008 import org.gel.mauve.ColorScheme;
00009 import org.gel.mauve.Match;
00010 
00015 public class NormalizedMultiplicityTypeColorScheme implements ColorScheme {
00016         private final static Comparator MULTIPLICITY_TYPE_COMPARATOR = new Comparator () {
00017                 public int compare (Object o1, Object o2) {
00018                         Match a = (Match) o1;
00019                         Match b = (Match) o2;
00020                         return (int) (a.multiplicityType () - b.multiplicityType ());
00021                 }
00022         };
00023 
00024         public void apply (BaseViewerModel model) {
00025 
00026                 if (model.getSequenceCount () > 62) {
00027                         throw new RuntimeException (
00028                                         "Can't color by multiplicity type with more than 62 sequences.");
00029                 }
00030 
00031                 if (model.getMatchCount () == 0)
00032                         return; // no sense in trying to color what's not there!
00033 
00034                 Vector matchesByMT = null;
00035                 long unique_mt_count = 0;
00036                 if (matchesByMT == null) {
00037                         matchesByMT = model.sortedMatches (MULTIPLICITY_TYPE_COMPARATOR);
00038                         unique_mt_count = 1;
00039                         long last_mt = ((Match) matchesByMT.get (0)).multiplicityType ();
00040                         // go thru the sorted list in order counting the number of different
00041                         // multiplicity types
00042                         for (int matchI = 1; matchI < matchesByMT.size (); matchI++) {
00043                                 long cur_mt = ((Match) matchesByMT.get (matchI))
00044                                                 .multiplicityType ();
00045                                 if (cur_mt != last_mt)
00046                                         unique_mt_count++;
00047                                 last_mt = cur_mt;
00048                         }
00049                 }
00050 
00051                 long cur_mt_count = 0;
00052                 long prev_mt = ((Match) matchesByMT.get (0)).multiplicityType ();
00053                 // go thru the sorted list in order assigning a new color to each new
00054                 // offset
00055                 for (int matchI = 0; matchI < matchesByMT.size (); matchI++) {
00056                         long cur_mt = ((Match) matchesByMT.get (matchI))
00057                                         .multiplicityType ();
00058                         if (cur_mt != prev_mt)
00059                                 cur_mt_count++;
00060                         prev_mt = cur_mt;
00061 
00062                         // map the generalized offset of this match to a hue
00063                         Match cur_match = (Match) matchesByMT.get (matchI);
00064                         float hue = (float) ((double) cur_mt_count / (double) unique_mt_count);
00065                         cur_match.color = Color.getHSBColor (hue, MATCH_SAT, MATCH_BRIGHT);
00066                 }
00067         }
00068 
00069         public String toString () {
00070                 return "Normalized multiplicity type";
00071         }
00072 
00073 }

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