Merge branch 'develop' into features/JAL-4219_extended_fasta_rna_ss
[jalview.git] / test / jalview / gui / AssociatePDBFileTest.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.gui;
22
23
24 import java.awt.Color;
25 import java.io.File;
26 import java.util.Iterator;
27
28 import org.junit.Assert;
29 import org.testng.annotations.AfterMethod;
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.BeforeMethod;
32 import org.testng.annotations.Test;
33
34 import jalview.analysis.AlignmentAnnotationUtils;
35 import jalview.api.FeatureColourI;
36 import jalview.bin.Cache;
37 import jalview.bin.Jalview;
38 import jalview.datamodel.Alignment;
39 import jalview.datamodel.AlignmentI;
40 import jalview.datamodel.HiddenColumns;
41 import jalview.datamodel.PDBEntry;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceFeature;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.io.DataSourceType;
47 import jalview.io.FileLoader;
48 import jalview.project.Jalview2xmlTests;
49 import jalview.renderer.ResidueShaderI;
50 import jalview.schemes.BuriedColourScheme;
51 import jalview.schemes.FeatureColour;
52 import jalview.schemes.HelixColourScheme;
53 import jalview.schemes.JalviewColourScheme;
54 import jalview.schemes.StrandColourScheme;
55 import jalview.schemes.TurnColourScheme;
56 import jalview.util.MessageManager;
57
58 public class AssociatePDBFileTest
59 {
60   AlignFrame af;
61
62   @BeforeClass(alwaysRun = true)
63   public static void setUpBeforeClass() throws Exception
64   {
65     setUpJvOptionPane();
66     /*
67      * use read-only test properties file
68      */
69     Cache.loadProperties("test/jalview/io/testProps.jvprops");
70     Jalview.main(new String[] { "--nonews" });
71   }
72
73   @AfterMethod(alwaysRun = true)
74   public void tearDown()
75   {
76     if (Desktop.instance != null)
77       Desktop.instance.closeAll_actionPerformed(null);
78   }
79
80   /**
81    * configure (read-only) properties for test to ensure Consensus is computed
82    * for colour Above PID testing
83    */
84   @BeforeMethod(alwaysRun = true)
85   public void setUp()
86   {
87     Cache.loadProperties("test/jalview/io/testProps.jvprops");
88     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
89             Boolean.TRUE.toString());
90     af = new FileLoader().LoadFileWaitTillLoaded(">1GAQ|A/19-314\n"
91             + "ESKKQEEGVVTNLYKPKEPYVGRCLLNTKITGDDAPGETWHMVFSTEGKIPYREGQSIGVIADGVDKNGKPH\n"
92             + "KVRLYSIASSAIGDFGDSKTVSLCVKRLIYTNDAGEIVKGVCSNFLCDLQPGDNVQITGPVGKEMLMPKDPN\n"
93             + "ATIIMLATGTGIAPFRSFLWKMFFEKHDDYKFNGLGWLFLGVPTSSSLLYKEEFGKMKERAPENFRVDYAVS\n"
94             + "REQTNAAGERMYIQTRMAEYKEELWELLKKDNTYVYMCGLKGMEKGIDDIMVSLAEKDGIDWFDYKKQLKRG\n"
95             + "DQWNVEVY\n"
96             + ">1GAQ|B/1-98\n"
97             + "ATYNVKLITPEGEVELQVPDDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADG\n"
98             + "WVLTCHAYPTSDVVIETHKEEELTGA\n"
99             + ">1GAQ|C/19-314\n"
100             + "ESKKQEEGVVTNLYKPKEPYVGRCLLNTKITGDDAPGETWHMVFSTEGKIPYREGQSIGVIADGVDKNGKPH\n"
101             + "KVRLYSIASSAIGDFGDSKTVSLCVKRLIYTNDAGEIVKGVCSNFLCDLQPGDNVQITGPVGKEMLMPKDPN\n"
102             + "ATIIMLATGTGIAPFRSFLWKMFFEKHDDYKFNGLGWLFLGVPTSSSLLYKEEFGKMKERAPENFRVDYAVS\n"
103             + "REQTNAAGERMYIQTRMAEYKEELWELLKKDNTYVYMCGLKGMEKGIDDIMVSLAEKDGIDWFDYKKQLKRG\n"
104             + "DQWNVEVY\n"
105             ,
106             DataSourceType.PASTE);
107
108     /*
109      * wait for Consensus thread to complete
110      */
111     do
112     {
113       try
114       {
115         Thread.sleep(50);
116       } catch (InterruptedException x)
117       {
118       }
119     } while (af.getViewport().getCalcManager().isWorking());
120   }
121
122   public static void setUpJvOptionPane()
123   {
124     JvOptionPane.setInteractiveMode(false);
125     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
126   }
127
128   @Test(groups = "Functional")
129   public void testAssociatePDBFile()
130   {
131     String assoc_file="examples/1gaq.txt";
132     for (SequenceI toassoc:af.getViewport().getAlignment().getSequences())
133     {
134       PDBEntry pe = new AssociatePdbFileWithSeq()
135               .associatePdbWithSeq(assoc_file,
136                       DataSourceType.FILE, toassoc, false,
137                       Desktop.instance);
138       Assert.assertNotNull(pe);
139       Assert.assertNotEquals(toassoc.getDatasetSequence().getAnnotation().length,0);
140     }
141   }
142 }