Merge develop to Release_2_8_3_Branch
[jalview.git] / src / jalview / analysis / Dna.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.analysis;
22
23 import jalview.api.AlignViewportI;
24 import jalview.bin.Cache;
25 import jalview.datamodel.AlignedCodon;
26 import jalview.datamodel.AlignedCodonFrame;
27 import jalview.datamodel.Alignment;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.Annotation;
31 import jalview.datamodel.DBRefEntry;
32 import jalview.datamodel.DBRefSource;
33 import jalview.datamodel.FeatureProperties;
34 import jalview.datamodel.GraphLine;
35 import jalview.datamodel.Mapping;
36 import jalview.datamodel.Sequence;
37 import jalview.datamodel.SequenceFeature;
38 import jalview.datamodel.SequenceI;
39 import jalview.schemes.ResidueProperties;
40 import jalview.util.Comparison;
41 import jalview.util.DBRefUtils;
42 import jalview.util.MapList;
43 import jalview.util.ShiftList;
44
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.Comparator;
48 import java.util.List;
49 import java.util.Map;
50
51 public class Dna
52 {
53   private static final String STOP_X = "X";
54
55   private static final Comparator<AlignedCodon> comparator = new CodonComparator();
56
57   /*
58    * 'final' variables describe the inputs to the translation, which should not
59    * be modified.
60    */
61   final private List<SequenceI> selection;
62
63   final private String[] seqstring;
64
65   final private int[] contigs;
66
67   final private char gapChar;
68
69   final private AlignmentAnnotation[] annotations;
70
71   final private int dnaWidth;
72
73   final private Alignment dataset;
74
75   /*
76    * Working variables for the translation.
77    * 
78    * The width of the translation-in-progress protein alignment.
79    */
80   private int aaWidth = 0;
81
82   /*
83    * This array will be built up so that position i holds the codon positions
84    * e.g. [7, 9, 10] that match column i (base 0) in the aligned translation.
85    * Note this implies a contract that if two codons do not align exactly, their
86    * translated products must occupy different column positions.
87    */
88   private AlignedCodon[] alignedCodons;
89
90   /**
91    * Constructor given a viewport and the visible contigs.
92    * 
93    * @param viewport
94    * @param visibleContigs
95    */
96   public Dna(AlignViewportI viewport, int[] visibleContigs)
97   {
98     this.selection = Arrays.asList(viewport.getSequenceSelection());
99     this.seqstring = viewport.getViewAsString(true);
100     this.contigs = visibleContigs;
101     this.gapChar = viewport.getGapCharacter();
102     this.annotations = viewport.getAlignment().getAlignmentAnnotation();
103     this.dnaWidth = viewport.getAlignment().getWidth();
104     this.dataset = viewport.getAlignment().getDataset();
105   }
106
107   /**
108    * Test whether codon positions cdp1 should align before, with, or after cdp2.
109    * Returns zero if all positions match (or either argument is null). Returns
110    * -1 if any position in the first codon precedes the corresponding position
111    * in the second codon. Else returns +1 (some position in the second codon
112    * precedes the corresponding position in the first).
113    *
114    * Note this is not necessarily symmetric, for example:
115    * <ul>
116    * <li>compareCodonPos([2,5,6], [3,4,5]) returns -1</li>
117    * <li>compareCodonPos([3,4,5], [2,5,6]) also returns -1</li>
118    * </ul>
119    * 
120    * @param ac1
121    * @param ac2
122    * @return
123    */
124   public static final int compareCodonPos(AlignedCodon ac1, AlignedCodon ac2)
125   {
126     return comparator.compare(ac1, ac2);
127     // return jalview_2_8_2compare(ac1, ac2);
128   }
129
130   /**
131    * Codon comparison up to Jalview 2.8.2. This rule is sequence order dependent
132    * - see http://issues.jalview.org/browse/JAL-1635
133    * 
134    * @param ac1
135    * @param ac2
136    * @return
137    */
138   private static int jalview_2_8_2compare(AlignedCodon ac1, AlignedCodon ac2)
139   {
140     if (ac1 == null || ac2 == null || (ac1.equals(ac2)))
141     {
142       return 0;
143     }
144     if (ac1.pos1 < ac2.pos1 || ac1.pos2 < ac2.pos2 || ac1.pos3 < ac2.pos3)
145     {
146       // one base in cdp1 precedes the corresponding base in the other codon
147       return -1;
148     }
149     // one base in cdp1 appears after the corresponding base in the other codon.
150     return 1;
151   }
152
153   /**
154    * 
155    * @return
156    */
157   public AlignmentI translateCdna()
158   {
159     AlignedCodonFrame acf = new AlignedCodonFrame();
160
161     alignedCodons = new AlignedCodon[dnaWidth];
162
163     int s;
164     int sSize = selection.size();
165     List<SequenceI> pepseqs = new ArrayList<SequenceI>();
166     for (s = 0; s < sSize; s++)
167     {
168       SequenceI newseq = translateCodingRegion(selection.get(s),
169               seqstring[s], acf, pepseqs);
170
171       if (newseq != null)
172       {
173         pepseqs.add(newseq);
174         SequenceI ds = newseq;
175         if (dataset != null)
176         {
177           while (ds.getDatasetSequence() != null)
178           {
179             ds = ds.getDatasetSequence();
180           }
181           dataset.addSequence(ds);
182         }
183       }
184     }
185
186     SequenceI[] newseqs = pepseqs.toArray(new SequenceI[pepseqs.size()]);
187     AlignmentI al = new Alignment(newseqs);
188     // ensure we look aligned.
189     al.padGaps();
190     // link the protein translation to the DNA dataset
191     al.setDataset(dataset);
192     translateAlignedAnnotations(al, acf);
193     al.addCodonFrame(acf);
194     return al;
195   }
196
197   /**
198    * fake the collection of DbRefs with associated exon mappings to identify if
199    * a translation would generate distinct product in the currently selected
200    * region.
201    * 
202    * @param selection
203    * @param viscontigs
204    * @return
205    */
206   public static boolean canTranslate(SequenceI[] selection,
207           int viscontigs[])
208   {
209     for (int gd = 0; gd < selection.length; gd++)
210     {
211       SequenceI dna = selection[gd];
212       DBRefEntry[] dnarefs = DBRefUtils
213               .selectRefs(dna.getDBRef(),
214                       jalview.datamodel.DBRefSource.DNACODINGDBS);
215       if (dnarefs != null)
216       {
217         // intersect with pep
218         List<DBRefEntry> mappedrefs = new ArrayList<DBRefEntry>();
219         DBRefEntry[] refs = dna.getDBRef();
220         for (int d = 0; d < refs.length; d++)
221         {
222           if (refs[d].getMap() != null && refs[d].getMap().getMap() != null
223                   && refs[d].getMap().getMap().getFromRatio() == 3
224                   && refs[d].getMap().getMap().getToRatio() == 1)
225           {
226             mappedrefs.add(refs[d]); // add translated protein maps
227           }
228         }
229         dnarefs = mappedrefs.toArray(new DBRefEntry[mappedrefs.size()]);
230         for (int d = 0; d < dnarefs.length; d++)
231         {
232           Mapping mp = dnarefs[d].getMap();
233           if (mp != null)
234           {
235             for (int vc = 0; vc < viscontigs.length; vc += 2)
236             {
237               int[] mpr = mp.locateMappedRange(viscontigs[vc],
238                       viscontigs[vc + 1]);
239               if (mpr != null)
240               {
241                 return true;
242               }
243             }
244           }
245         }
246       }
247     }
248     return false;
249   }
250
251   /**
252    * Translate nucleotide alignment annotations onto translated amino acid
253    * alignment using codon mapping codons
254    * 
255    * @param al
256    *          the translated protein alignment
257    */
258   protected void translateAlignedAnnotations(AlignmentI al,
259           AlignedCodonFrame acf)
260   {
261     // Can only do this for columns with consecutive codons, or where
262     // annotation is sequence associated.
263
264     if (annotations != null)
265     {
266       for (AlignmentAnnotation annotation : annotations)
267       {
268         /*
269          * Skip hidden or autogenerated annotation. Also (for now), RNA
270          * secondary structure annotation. If we want to show this against
271          * protein we need a smarter way to 'translate' without generating
272          * invalid (unbalanced) structure annotation.
273          */
274         if (annotation.autoCalculated || !annotation.visible
275                 || annotation.isRNA())
276         {
277           continue;
278         }
279
280         int aSize = aaWidth;
281         Annotation[] anots = (annotation.annotations == null) ? null
282                 : new Annotation[aSize];
283         if (anots != null)
284         {
285           for (int a = 0; a < aSize; a++)
286           {
287             // process through codon map.
288             if (a < alignedCodons.length && alignedCodons[a] != null
289                     && alignedCodons[a].pos1 == (alignedCodons[a].pos3 - 2))
290             {
291               anots[a] = getCodonAnnotation(alignedCodons[a],
292                       annotation.annotations);
293             }
294           }
295         }
296
297         AlignmentAnnotation aa = new AlignmentAnnotation(annotation.label,
298                 annotation.description, anots);
299         aa.graph = annotation.graph;
300         aa.graphGroup = annotation.graphGroup;
301         aa.graphHeight = annotation.graphHeight;
302         if (annotation.getThreshold() != null)
303         {
304           aa.setThreshold(new GraphLine(annotation
305                   .getThreshold()));
306         }
307         if (annotation.hasScore)
308         {
309           aa.setScore(annotation.getScore());
310         }
311
312         final SequenceI seqRef = annotation.sequenceRef;
313         if (seqRef != null)
314         {
315           SequenceI aaSeq = acf.getAaForDnaSeq(seqRef);
316           if (aaSeq != null)
317           {
318             // aa.compactAnnotationArray(); // throw away alignment annotation
319             // positioning
320             aa.setSequenceRef(aaSeq);
321             // rebuild mapping
322             aa.createSequenceMapping(aaSeq, aaSeq.getStart(), true);
323             aa.adjustForAlignment();
324             aaSeq.addAlignmentAnnotation(aa);
325           }
326         }
327         al.addAnnotation(aa);
328       }
329     }
330   }
331
332   private static Annotation getCodonAnnotation(AlignedCodon is,
333           Annotation[] annotations)
334   {
335     // Have a look at all the codon positions for annotation and put the first
336     // one found into the translated annotation pos.
337     int contrib = 0;
338     Annotation annot = null;
339     for (int p = 1; p <= 3; p++)
340     {
341       int dnaCol = is.getBaseColumn(p);
342       if (annotations[dnaCol] != null)
343       {
344         if (annot == null)
345         {
346           annot = new Annotation(annotations[dnaCol]);
347           contrib = 1;
348         }
349         else
350         {
351           // merge with last
352           Annotation cpy = new Annotation(annotations[dnaCol]);
353           if (annot.colour == null)
354           {
355             annot.colour = cpy.colour;
356           }
357           if (annot.description == null || annot.description.length() == 0)
358           {
359             annot.description = cpy.description;
360           }
361           if (annot.displayCharacter == null)
362           {
363             annot.displayCharacter = cpy.displayCharacter;
364           }
365           if (annot.secondaryStructure == 0)
366           {
367             annot.secondaryStructure = cpy.secondaryStructure;
368           }
369           annot.value += cpy.value;
370           contrib++;
371         }
372       }
373     }
374     if (contrib > 1)
375     {
376       annot.value /= contrib;
377     }
378     return annot;
379   }
380
381   /**
382    * Translate a na sequence
383    * 
384    * @param selection
385    *          sequence displayed under viscontigs visible columns
386    * @param seqstring
387    *          ORF read in some global alignment reference frame
388    * @param acf
389    *          Definition of global ORF alignment reference frame
390    * @param proteinSeqs
391    * @return sequence ready to be added to alignment.
392    */
393   protected SequenceI translateCodingRegion(SequenceI selection,
394           String seqstring, AlignedCodonFrame acf,
395           List<SequenceI> proteinSeqs)
396   {
397     List<int[]> skip = new ArrayList<int[]>();
398     int skipint[] = null;
399     ShiftList vismapping = new ShiftList(); // map from viscontigs to seqstring
400     // intervals
401     int vc;
402     int[] scontigs = new int[contigs.length];
403     int npos = 0;
404     for (vc = 0; vc < contigs.length; vc += 2)
405     {
406       if (vc == 0)
407       {
408         vismapping.addShift(npos, contigs[vc]);
409       }
410       else
411       {
412         // hidden region
413         vismapping.addShift(npos, contigs[vc] - contigs[vc - 1] + 1);
414       }
415       scontigs[vc] = contigs[vc];
416       scontigs[vc + 1] = contigs[vc + 1];
417     }
418
419     // allocate a roughly sized buffer for the protein sequence
420     StringBuilder protein = new StringBuilder(seqstring.length() / 2);
421     String seq = seqstring.replace('U', 'T').replace('u', 'T');
422     char codon[] = new char[3];
423     int cdp[] = new int[3];
424     int rf = 0;
425     int lastnpos = 0;
426     int nend;
427     int aspos = 0;
428     int resSize = 0;
429     for (npos = 0, nend = seq.length(); npos < nend; npos++)
430     {
431       if (!Comparison.isGap(seq.charAt(npos)))
432       {
433         cdp[rf] = npos; // store position
434         codon[rf++] = seq.charAt(npos); // store base
435       }
436       if (rf == 3)
437       {
438         /*
439          * Filled up a reading frame...
440          */
441         AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1], cdp[2]);
442         String aa = ResidueProperties.codonTranslate(new String(codon));
443         rf = 0;
444         final String gapString = String.valueOf(gapChar);
445         if (aa == null)
446         {
447           aa = gapString;
448           if (skipint == null)
449           {
450             skipint = new int[]
451             { alignedCodon.pos1, alignedCodon.pos3 /* cdp[0], cdp[2] */};
452           }
453           skipint[1] = alignedCodon.pos3; // cdp[2];
454         }
455         else
456         {
457           if (skipint != null)
458           {
459             // edit scontigs
460             skipint[0] = vismapping.shift(skipint[0]);
461             skipint[1] = vismapping.shift(skipint[1]);
462             for (vc = 0; vc < scontigs.length;)
463             {
464               if (scontigs[vc + 1] < skipint[0])
465               {
466                 // before skipint starts
467                 vc += 2;
468                 continue;
469               }
470               if (scontigs[vc] > skipint[1])
471               {
472                 // finished editing so
473                 break;
474               }
475               // Edit the contig list to include the skipped region which did
476               // not translate
477               int[] t;
478               // from : s1 e1 s2 e2 s3 e3
479               // to s: s1 e1 s2 k0 k1 e2 s3 e3
480               // list increases by one unless one boundary (s2==k0 or e2==k1)
481               // matches, and decreases by one if skipint intersects whole
482               // visible contig
483               if (scontigs[vc] <= skipint[0])
484               {
485                 if (skipint[0] == scontigs[vc])
486                 {
487                   // skipint at start of contig
488                   // shift the start of this contig
489                   if (scontigs[vc + 1] > skipint[1])
490                   {
491                     scontigs[vc] = skipint[1];
492                     vc += 2;
493                   }
494                   else
495                   {
496                     if (scontigs[vc + 1] == skipint[1])
497                     {
498                       // remove the contig
499                       t = new int[scontigs.length - 2];
500                       if (vc > 0)
501                       {
502                         System.arraycopy(scontigs, 0, t, 0, vc - 1);
503                       }
504                       if (vc + 2 < t.length)
505                       {
506                         System.arraycopy(scontigs, vc + 2, t, vc, t.length
507                                 - vc + 2);
508                       }
509                       scontigs = t;
510                     }
511                     else
512                     {
513                       // truncate contig to before the skipint region
514                       scontigs[vc + 1] = skipint[0] - 1;
515                       vc += 2;
516                     }
517                   }
518                 }
519                 else
520                 {
521                   // scontig starts before start of skipint
522                   if (scontigs[vc + 1] < skipint[1])
523                   {
524                     // skipint truncates end of scontig
525                     scontigs[vc + 1] = skipint[0] - 1;
526                     vc += 2;
527                   }
528                   else
529                   {
530                     // divide region to new contigs
531                     t = new int[scontigs.length + 2];
532                     System.arraycopy(scontigs, 0, t, 0, vc + 1);
533                     t[vc + 1] = skipint[0];
534                     t[vc + 2] = skipint[1];
535                     System.arraycopy(scontigs, vc + 1, t, vc + 3,
536                             scontigs.length - (vc + 1));
537                     scontigs = t;
538                     vc += 4;
539                   }
540                 }
541               }
542             }
543             skip.add(skipint);
544             skipint = null;
545           }
546           if (aa.equals("STOP"))
547           {
548             aa = STOP_X;
549           }
550           resSize++;
551         }
552         boolean findpos = true;
553         while (findpos)
554         {
555           /*
556            * Compare this codon's base positions with those currently aligned to
557            * this column in the translation.
558            */
559           final int compareCodonPos = compareCodonPos(alignedCodon,
560                   alignedCodons[aspos]);
561           switch (compareCodonPos)
562           {
563           case -1:
564
565             /*
566              * This codon should precede the mapped positions - need to insert a
567              * gap in all prior sequences.
568              */
569             insertAAGap(aspos, proteinSeqs);
570             findpos = false;
571             break;
572
573           case +1:
574
575             /*
576              * This codon belongs after the aligned codons at aspos. Prefix it
577              * with a gap and try the next position.
578              */
579             aa = gapString + aa;
580             aspos++;
581             break;
582
583           case 0:
584
585             /*
586              * Exact match - codon 'belongs' at this translated position.
587              */
588             findpos = false;
589           }
590         }
591         protein.append(aa);
592         lastnpos = npos;
593         if (alignedCodons[aspos] == null)
594         {
595           // mark this column as aligning to this aligned reading frame
596           alignedCodons[aspos] = alignedCodon;
597         }
598         else if (!alignedCodons[aspos].equals(alignedCodon))
599         {
600           throw new IllegalStateException("Tried to coalign "
601                   + alignedCodons[aspos].toString() + " with "
602                   + alignedCodon.toString());
603         }
604         if (aspos >= aaWidth)
605         {
606           // update maximum alignment width
607           aaWidth = aspos;
608         }
609         // ready for next translated reading frame alignment position (if any)
610         aspos++;
611       }
612     }
613     if (resSize > 0)
614     {
615       SequenceI newseq = new Sequence(selection.getName(),
616               protein.toString());
617       if (rf != 0)
618       {
619         final String errMsg = "trimming contigs for incomplete terminal codon.";
620         if (Cache.log != null)
621         {
622           Cache.log.debug(errMsg);
623         }
624         else
625         {
626           System.err.println(errMsg);
627         }
628         // map and trim contigs to ORF region
629         vc = scontigs.length - 1;
630         lastnpos = vismapping.shift(lastnpos); // place npos in context of
631         // whole dna alignment (rather
632         // than visible contigs)
633         // incomplete ORF could be broken over one or two visible contig
634         // intervals.
635         while (vc >= 0 && scontigs[vc] > lastnpos)
636         {
637           if (vc > 0 && scontigs[vc - 1] > lastnpos)
638           {
639             vc -= 2;
640           }
641           else
642           {
643             // correct last interval in list.
644             scontigs[vc] = lastnpos;
645           }
646         }
647
648         if (vc > 0 && (vc + 1) < scontigs.length)
649         {
650           // truncate map list to just vc elements
651           int t[] = new int[vc + 1];
652           System.arraycopy(scontigs, 0, t, 0, vc + 1);
653           scontigs = t;
654         }
655         if (vc <= 0)
656         {
657           scontigs = null;
658         }
659       }
660       if (scontigs != null)
661       {
662         npos = 0;
663         // map scontigs to actual sequence positions on selection
664         for (vc = 0; vc < scontigs.length; vc += 2)
665         {
666           scontigs[vc] = selection.findPosition(scontigs[vc]); // not from 1!
667           scontigs[vc + 1] = selection.findPosition(scontigs[vc + 1]); // exclusive
668           if (scontigs[vc + 1] == selection.getEnd())
669           {
670             break;
671           }
672         }
673         // trim trailing empty intervals.
674         if ((vc + 2) < scontigs.length)
675         {
676           int t[] = new int[vc + 2];
677           System.arraycopy(scontigs, 0, t, 0, vc + 2);
678           scontigs = t;
679         }
680         /*
681          * delete intervals in scontigs which are not translated. 1. map skip
682          * into sequence position intervals 2. truncate existing ranges and add
683          * new ranges to exclude untranslated regions. if (skip.size()>0) {
684          * Vector narange = new Vector(); for (vc=0; vc<scontigs.length; vc++) {
685          * narange.addElement(new int[] {scontigs[vc]}); } int sint=0,iv[]; vc =
686          * 0; while (sint<skip.size()) { skipint = (int[]) skip.elementAt(sint);
687          * do { iv = (int[]) narange.elementAt(vc); if (iv[0]>=skipint[0] &&
688          * iv[0]<=skipint[1]) { if (iv[0]==skipint[0]) { // delete beginning of
689          * range } else { // truncate range and create new one if necessary iv =
690          * (int[]) narange.elementAt(vc+1); if (iv[0]<=skipint[1]) { // truncate
691          * range iv[0] = skipint[1]; } else { } } } else if (iv[0]<skipint[0]) {
692          * iv = (int[]) narange.elementAt(vc+1); } } while (iv[0]) } }
693          */
694         MapList map = new MapList(scontigs, new int[]
695         { 1, resSize }, 3, 1);
696
697         transferCodedFeatures(selection, newseq, map, null, null);
698
699         /*
700          * Construct a dataset sequence for our new peptide.
701          */
702         SequenceI rseq = newseq.deriveSequence();
703
704         /*
705          * Store a mapping (between the dataset sequences for the two
706          * sequences).
707          */
708         // SIDE-EFFECT: acf stores the aligned sequence reseq; to remove!
709         acf.addMap(selection, rseq, map);
710         return rseq;
711       }
712     }
713     // register the mapping somehow
714     //
715     return null;
716   }
717
718   /**
719    * Insert a gap into the aligned proteins and the codon mapping array.
720    * 
721    * @param pos
722    * @param proteinSeqs
723    * @return
724    */
725   protected void insertAAGap(int pos,
726           List<SequenceI> proteinSeqs)
727   {
728     aaWidth++;
729     for (SequenceI seq : proteinSeqs)
730     {
731       seq.insertCharAt(pos, gapChar);
732     }
733
734     checkCodonFrameWidth();
735     if (pos < aaWidth)
736     {
737       aaWidth++;
738
739       /*
740        * Shift from [pos] to the end one to the right, and null out [pos]
741        */
742       System.arraycopy(alignedCodons, pos, alignedCodons, pos + 1,
743               alignedCodons.length - pos - 1);
744       alignedCodons[pos] = null;
745     }
746   }
747
748   /**
749    * Check the codons array can accommodate a single insertion, if not resize
750    * it.
751    */
752   protected void checkCodonFrameWidth()
753   {
754     if (alignedCodons[alignedCodons.length - 1] != null)
755     {
756       /*
757        * arraycopy insertion would bump a filled slot off the end, so expand.
758        */
759       AlignedCodon[] c = new AlignedCodon[alignedCodons.length + 10];
760       System.arraycopy(alignedCodons, 0, c, 0, alignedCodons.length);
761       alignedCodons = c;
762     }
763   }
764
765   /**
766    * Given a peptide newly translated from a dna sequence, copy over and set any
767    * features on the peptide from the DNA. If featureTypes is null, all features
768    * on the dna sequence are searched (rather than just the displayed ones), and
769    * similarly for featureGroups.
770    * 
771    * @param dna
772    * @param pep
773    * @param map
774    * @param featureTypes
775    *          hash whose keys are the displayed feature type strings
776    * @param featureGroups
777    *          hash where keys are feature groups and values are Boolean objects
778    *          indicating if they are displayed.
779    */
780   private static void transferCodedFeatures(SequenceI dna, SequenceI pep,
781           MapList map, Map<String, Object> featureTypes,
782           Map<String, Boolean> featureGroups)
783   {
784     SequenceFeature[] sfs = dna.getSequenceFeatures();
785     Boolean fgstate;
786     DBRefEntry[] dnarefs = DBRefUtils.selectRefs(dna.getDBRef(),
787             DBRefSource.DNACODINGDBS);
788     if (dnarefs != null)
789     {
790       // intersect with pep
791       for (int d = 0; d < dnarefs.length; d++)
792       {
793         Mapping mp = dnarefs[d].getMap();
794         if (mp != null)
795         {
796         }
797       }
798     }
799     if (sfs != null)
800     {
801       for (SequenceFeature sf : sfs)
802       {
803         fgstate = (featureGroups == null) ? null : featureGroups
804                 .get(sf.featureGroup);
805         if ((featureTypes == null || featureTypes.containsKey(sf.getType()))
806                 && (fgstate == null || fgstate.booleanValue()))
807         {
808           if (FeatureProperties.isCodingFeature(null, sf.getType()))
809           {
810             // if (map.intersectsFrom(sf[f].begin, sf[f].end))
811             {
812
813             }
814           }
815         }
816       }
817     }
818   }
819 }