1 /* ProteinMapPanel.java
2  *
3  * created: 2008
4  *
5  * This file is part of Artemis
6  *
7  * Copyright (C) 2008  Genome Research Limited
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  **/
24 
25 package uk.ac.sanger.artemis.components.genebuilder;
26 
27 import java.awt.Dimension;
28 import java.awt.Graphics;
29 import java.awt.Graphics2D;
30 import java.awt.Rectangle;
31 import java.util.List;
32 
33 import uk.ac.sanger.artemis.Selection;
34 import uk.ac.sanger.artemis.io.Feature;
35 import uk.ac.sanger.artemis.io.ChadoCanonicalGene;
36 import uk.ac.sanger.artemis.io.GFFStreamFeature;
37 import uk.ac.sanger.artemis.io.Qualifier;
38 import uk.ac.sanger.artemis.io.QualifierVector;
39 import uk.ac.sanger.artemis.util.DatabaseDocument;
40 
41 public class BasicProteinMapPanel extends ProteinMapPanel
42 {
43   private static final long serialVersionUID = 1L;
44   private BasicGeneBuilderFrame gbFrame;
45 
BasicProteinMapPanel(final Feature feature, final ChadoCanonicalGene chado_gene, final Selection selection, final BasicGeneBuilderFrame gbFrame)46   public BasicProteinMapPanel(final Feature feature,
47                          final ChadoCanonicalGene chado_gene,
48                          final Selection selection,
49                          final BasicGeneBuilderFrame gbFrame)
50   {
51     super(feature, chado_gene, selection);
52     this.gbFrame = gbFrame;
53     setFont(uk.ac.sanger.artemis.Options.getOptions().getFont());
54     setPreferredSize(new Dimension(getSize().width, 100));
55   }
56 
paintComponent(Graphics g)57   public void paintComponent(Graphics g)
58   {
59     super.paintComponent(g);
60     Graphics2D g2d = (Graphics2D)g;
61     toolTipPositions.clear();
62 
63     Feature embl_gene = (Feature)chado_gene.getGene();
64     uk.ac.sanger.artemis.Feature gene =
65       (uk.ac.sanger.artemis.Feature)embl_gene.getUserData();
66 
67     int ypos = border;
68     int geneStart = embl_gene.getFirstBase();
69     int geneEnd   = embl_gene.getLastBase();
70     float fraction = (float)(getSize().width - (2*border))/
71                      (float)(geneEnd-geneStart);
72 
73     uk.ac.sanger.artemis.Feature transcript = gbFrame.getSelectedTranscriptFeature();
74     if(transcript == null)
75       return;
76     String transcriptName = GeneUtils.getUniqueName(
77         transcript.getEmblFeature());
78     Feature protein_embl_feature =
79        (Feature)chado_gene.getProteinOfTranscript(transcriptName);
80 
81     if(protein_embl_feature == null)
82       return;
83 
84     uk.ac.sanger.artemis.Feature protein =
85       (uk.ac.sanger.artemis.Feature)protein_embl_feature.getUserData();
86 
87     List<Feature> exons = chado_gene.getSpliceSitesOfTranscript(transcriptName,
88                                           DatabaseDocument.EXONMODEL);
89     if(exons == null || exons.size() == 0)
90       exons = chado_gene.getSpliceSitesOfTranscript(transcriptName,
91                                                  "pseudogenic_exon");
92 
93     if(exons == null || exons.size() == 0)
94       return;
95 
96     Feature exon_embl_feature = exons.get(0);
97     uk.ac.sanger.artemis.Feature exon =
98       (uk.ac.sanger.artemis.Feature)exon_embl_feature.getUserData();
99 
100     int ppLength = exon.getTranslationBasesLength()/3;
101     int emblStart = protein_embl_feature.getFirstBase();
102     int emblEnd   = protein_embl_feature.getLastBase();
103 
104     // draw protein
105     g2d.drawString(protein.getIDString()+
106         ( GeneUtils.isObsolete((GFFStreamFeature)embl_gene) ? " (obsolete)" : "") , border, ypos);
107 
108     int ppStart = border+(int)((emblStart-geneStart)*fraction);
109     int ppEnd   = border+(int)((emblEnd-geneStart)*fraction);
110 
111     drawFeature(g2d, ppStart, ppEnd,
112                 ypos, protein.getColour(), 1,
113                 selection.contains(gene), 2.f, getFontHeight());
114 
115     //record position for tooltip
116     Rectangle r = new Rectangle(ppStart, ypos, ppEnd-ppStart, 1*getFontHeight());
117     toolTipPositions.put(r, protein.getIDString()+" length="+ppLength);
118 
119     ypos += border*2;
120     ypos = drawDomain(protein_embl_feature,
121             g2d, ypos, ppStart, ppEnd, ppLength);
122 
123     QualifierVector qualifiers = protein_embl_feature.getQualifiers();
124     if(qualifiers.getQualifierByName(TMHMM[0]) != null)
125     {
126       g2d.drawString("Transmembrane Domains:", ppStart, ypos);
127       drawPrediction(protein_embl_feature,
128                      g2d, ypos, ppStart, ppEnd, ppLength, TMHMM);
129       ypos += border * 2;
130     }
131 
132     if(qualifiers.getQualifierByName(SIGNALP[0]) != null)
133     {
134       g2d.drawString("SignalP:", ppStart, ypos);
135       drawPrediction(protein_embl_feature,
136                    g2d, ypos, ppStart, ppEnd, ppLength,
137                    new String[]{ SIGNALP[0] });
138       ypos += border * 2;
139     }
140 
141     Qualifier gpiAnchor;
142     if((gpiAnchor=qualifiers.getQualifierByName(GPI_ANCHORED)) != null)
143     {
144       g2d.drawString("GPI anchor cleavage site:", ppStart, ypos);
145       drawGPIArrow(g2d, gpiAnchor, ppStart, ppEnd, ppLength, ypos);
146     }
147   }
148 }