<td>defaultColour</td>
<td> <em>One of: </em><br>
Clustal, Blosum62, % Identity, Hydrophobic, Zappo, Taylor, Helix
- Propensity, Strand Propensity, Turn Propensity, Buried Index, Nucleotide, T-Coffee Scores, RNA Helices</td>
+ Propensity, Strand Propensity, Turn Propensity, Buried Index, Nucleotide, Purine/Pyrimidine, T-Coffee Scores, RNA Helices</td>
<td>Default is no colour.</td>
</tr>
<tr>
ST-TURN-IIL blue|255,0,255|absolute|20.0|95.0|below|66.0
-GAMMA-TURN-CLASSIC red|0,255,255|20.0|95.0|below|66.0
+GAMMA-TURN-CLASSIC lightGray|0,255,255|20.0|95.0|below|66.0
BETA-TURN-IR 9a6a94
BETA-TURN-IL d6a6ca
BETA-BULGE 1dc451
--- /dev/null
+import java.awt.Color;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.datamodel.SequenceCollectionI;
+
+/*
+ * Example script that registers two new alignment colour schemes
+ */
+
+/*
+ * Closure that defines a colour scheme where consensus residues are pink,
+ * other residues are red in odd columns and blue in even columns, and
+ * gaps are yellow
+ */
+def candy
+candy = { ->
+ [
+ /*
+ * name shown in the colour menu
+ */
+ getSchemeName: { -> 'candy' },
+
+ /*
+ * to make a new instance for each alignment view
+ */
+ getInstance: { AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> candy() },
+
+ /*
+ * method only needed if colour scheme has to recalculate
+ * values when an alignment is modified
+ */
+ alignmentChanged: { AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> },
+
+ /*
+ * determine colour for a residue at an aligned position of a
+ * sequence, given consensus residue(s) for the column and the
+ * consensus percentage identity score for the column
+ */
+ findColour: { char res, int col, SequenceI seq, String consensus, float pid ->
+ if (res == ' ' || res == '-' || res == '.')
+ {
+ Color.yellow
+ } else if (consensus.contains(String.valueOf(res)))
+ {
+ Color.pink
+ } else if (col % 2 == 0)
+ {
+ Color.blue
+ } else
+ {
+ Color.red
+ }
+ },
+
+ /*
+ * true means applicable to nucleotide or peptide data
+ */
+ isApplicableTo: {AnnotatedCollectionI coll -> true},
+
+ /*
+ * simple colour schemes are those that depend on the residue
+ * only (these are also available to colour structure viewers)
+ */
+ isSimple: { false }
+ ] as ColourSchemeI
+}
+
+/*
+ * A closure that defines a colour scheme graduated
+ * (approximately) by amino acid weight
+ * here from lightest (G) Blue, to heaviest (W) Red
+ */
+def makeColour = { weight ->
+ minWeight = 75 // Glycine
+ maxWeight = 204 // Tryptophan
+ int i = 255 * (weight - minWeight) / (maxWeight - minWeight);
+ new Color(i, 0, 255-i);
+}
+def byWeight
+byWeight = { ->
+ [
+ getSchemeName: { 'By Weight' },
+ // this colour scheme is peptide-specific:
+ isApplicableTo: { coll -> !coll.isNucleotide() },
+ alignmentChanged: { coll, map -> },
+ getInstance: { coll, map -> byWeight() },
+ isSimple: { true },
+ findColour: {res, col, seq, consensus, pid ->
+ switch (res) {
+ case ' ':
+ case '-':
+ case '.':
+ Color.white
+ break
+ case 'A':
+ makeColour(89)
+ break
+ case 'R':
+ makeColour(174)
+ break
+ case 'N':
+ case 'D':
+ case 'B':
+ case 'I':
+ case 'L':
+ makeColour(132)
+ break
+ case 'C':
+ makeColour(121)
+ break
+ case 'Q':
+ case 'E':
+ case 'Z':
+ case 'K':
+ case 'M':
+ makeColour(146)
+ break
+ case 'G':
+ makeColour(75)
+ break
+ case 'H':
+ makeColour(155)
+ break
+ case 'F':
+ makeColour(165)
+ break
+ case 'P':
+ makeColour(115)
+ break
+ case 'S':
+ makeColour(105)
+ break
+ case 'T':
+ makeColour(119)
+ break
+ case 'W':
+ makeColour(204)
+ break
+ case 'Y':
+ makeColour(181)
+ break
+ case 'V':
+ makeColour(117)
+ break
+ default:
+ makeColour(150)
+ }
+ }
+ ] as ColourSchemeI
+}
+
+ColourSchemes.instance.registerColourScheme(candy())
+ColourSchemes.instance.registerColourScheme(byWeight())
<mapID target="uniprotfetcher" url="html/features/uniprotsequencefetcher.html" />
+ <mapID target="urllinks" url="html/webServices/urllinks.html" />
+ <mapID target="linksprefs" url="html/features/Preferences.html#links" />
+
<mapID target="backIcon" url="icons/back.png" />
<mapID target="forwardIcon" url="icons/forward.png" />
<mapID target="homeIcon" url="icons/Home.png" />
<tocitem text="Chimera Viewer" target="chimera" />
</tocitem>
<tocitem text="Viewing RNA structures" target="varna" expand="false"/>
+ <tocitem text="Opening URLs from Jalview" target="urllinks" expand="true">
+ <tocitem text="Configuring URL Links" target="urllinkspref" />
+ </tocitem>
<tocitem text="VAMSAS Data Exchange" target="vamsas">
<!-- what can Jalview share with other apps -->
<!-- what other apps exist -->
is assigned a colour if the amino acid profile of the alignment at
that position meets some minimum criteria specific for the residue
type.</p>
- <p>The table below gives these criteria as clauses: {+X%,xx,y},
- where X is the minimum percentage presence for any of the xx (or y)
- residue types.</p>
+ <p>The table below gives these criteria as clauses: {>X%,xx,y},
+ where X is the threshold percentage presence for any of the xx (or y)
+ residue types.
+ <br>For example, K or R is coloured red if the column includes more than 60% K or R (combined), or more than 80% of either K or R or Q (individually).</p>
<div align="center">
<p> </p>
<table border="1">
<tr>
<td><table border="1">
<tr>
+ <th>Category</th>
+ <th>Colour</th>
<th>Residue at position</th>
- <th>Applied Colour</th>
- <th>{ Threshhold, Residue group }</th>
+ <th>{ Threshold, Residue group }</th>
</tr>
<tr>
+ <td rowspan="2">Hydrophobic</td>
+ <td rowspan="2" bgcolor="#80a0f0">BLUE</td>
<td>A,I,L,M,F,W,V</td>
- <td bgcolor="#80a0f0">BLUE</td>
- <td>{+60%, WLVIMAFCHP}</td>
+ <td>{>60%, WLVIMAFCHP}</td>
</tr>
<tr>
- <td>R,K</td>
+ <td>C</td>
+ <td>{>60%, WLVIMAFCHP}</td>
+ </tr>
+ <tr>
+ <td>Positive charge</td>
<td bgcolor="#f01505">RED</td>
- <td>{+60%,KR},{+80%, K,R,Q}</td>
+ <td>K,R</td>
+ <td>{>60%,KR},{>80%, K,R,Q}</td>
</tr>
<tr>
- <td>N</td>
- <td bgcolor="#15c015">GREEN</td>
- <td>{+50%, N}, {+85%, N,Y}</td>
+ <td rowspan="2">Negative charge</td>
+ <td rowspan="2" bgcolor="#c048c0">MAGENTA</td>
+ <td>E</td>
+ <td>{>60%,KR},{>50%,QE},{>85%,E,Q,D}</td>
</tr>
<tr>
- <td>C</td>
- <td bgcolor="#80a0f0">BLUE</td>
- <td>{+60%, WLVIMAFCHP}</td>
+ <td>D</td>
+ <td>{>60%,KR}, {>85%, K,R,Q}, {>50%,ED}</td>
</tr>
<tr>
- <td>C</td>
- <td bgcolor="#f08080">PINK</td>
- <td>{100%, C}</td>
+ <td rowspan="3">Polar</td>
+ <td rowspan="3" bgcolor="#15c015">GREEN</td>
+ <td>N</td>
+ <td>{>50%, N}, {>85%, N,Y}</td>
</tr>
<tr>
<td>Q</td>
- <td bgcolor="#15c015">GREEN</td>
- <td>{+60%,KR},{+50%,QE},{+85%,Q,E,K,R}</td>
+ <td>{>60%,KR},{>50%,QE},{>85%,Q,E,K,R}</td>
</tr>
<tr>
- <td>E</td>
- <td bgcolor="#c048c0">MAGENTA</td>
- <td>{+60%,KR},{+50%,QE},{+85%,E,Q,D}</td>
+ <td>S,T</td>
+ <td>{>60%, WLVIMAFCHP}, {>50%, TS}, {>85%,S,T}</td>
</tr>
<tr>
- <td>D</td>
- <td bgcolor="#c048c0">MAGENTA</td>
- <td>{+60%,KR}, {+85%, K,R,Q}, {+50%,ED}</td>
+ <td>Cysteines</td>
+ <td bgcolor="#f08080">PINK</td>
+ <td>C</td>
+ <td>{>85%, C}</td>
</tr>
<tr>
- <td>G</td>
+ <td>Glycines</td>
<td bgcolor="#f09048">ORANGE</td>
- <td>{+0%, G}</td>
+ <td>G</td>
+ <td>{>0%, G}</td>
</tr>
<tr>
- <td>H,Y</td>
- <td bgcolor="#15a4a4">CYAN</td>
- <td>{+60%, WLVIMAFCHP}, {+85%,
- W,Y,A,C,P,Q,F,H,I,L,M,V}</td>
+ <td>Prolines</td>
+ <td bgcolor="#c0c000">YELLOW</td>
+ <td>P</td>
+ <td>{>0%, P}</td>
</tr>
<tr>
- <td>P</td>
- <td bgcolor="#c0c000">YELLOW</td>
- <td>{+0%, P}</td>
+ <td>Aromatic</td>
+ <td bgcolor="#15a4a4">CYAN</td>
+ <td>H,Y</td>
+ <td>{>60%, WLVIMAFCHP}, {>85%,
+ W,Y,A,C,P,Q,F,H,I,L,M,V}</td>
</tr>
<tr>
- <td>S,T</td>
- <td bgcolor="#15c015">GREEN</td>
- <td>{+60%, WLVIMAFCHP}, {+50%, TS}, {+85%,S,T}</td>
+ <td>Unconserved</td>
+ <td>WHITE</td>
+ <td>any / gap</td>
+ <td>If none of the above criteria are met</td>
</tr>
</table></td>
</tr>
The <strong>Case Sensitive</strong> option allows you to choose
distinct colours for upper and lower case residue codes.
<p>
+ The <strong>Lower Case Colour</strong> option allows you to apply a selected colour
+ to all lower case residues.
+ <p>
Click <strong>Apply</strong> or <strong>OK</strong> to set your new
colours on the active alignment window.<br /> Click <strong>Cancel</strong>
to undo your changes if you pressed the <strong>Apply</strong>
and displaying structure information.
</li>
<li>The <a href="#connections"><strong>"Connections"</strong>
- Preferences</a> tab allows you to change the links made from Jalview
- to your default web browser.
+ Preferences</a> tab allows you to configure Jalview's internet
+ settings and specify your default web browser.
+ </li>
+ <li>The <a href="#links"><strong>"Links"</strong>
+ Preferences</a> tab shows the currently configured <em>URL
+ Links</em> shown in the <strong>Link</strong> submenu in the Sequence
+ ID popup menu.
</li>
<li>The <a href="#output"><strong>"Output"</strong>
Preferences</a> tab contains settings affecting the export of
Preferences tab</strong></a>
</p>
<p>
- <em>URL Link From Sequence ID</em><br> These definitions are
- used to generate URLs from a sequence's ID or database cross
- references. Read more about <a
- href="../webServices/urllinks.html#urllinks">configuring
- URL links here</a>.
- </p>
- <p>
<em>Default Browser (Unix)</em><br> Its difficult in Java to
detect the default web browser for Unix users. If Jalview can't find
your default web browser, enter the name or full path to your web
statement</a> for more information.
</p>
<p>
+ <a name="links"><strong>The "Links" Preferences
+ tab</strong></a>
+ </p>
+ <p>
+ This panel shows a table, and two sections - <em>Edit</em> and <em>Filter</em>.
+ The table shows the available URL link definitions (consisting of a
+ database, Name, and URL template string), a checkbox <em>In
+ Menu</em> which indicates if the link is enabled, and <em>Double
+ Click</em> which marks the link that will be opened if a sequence's ID
+ is double clicked. The table can be sorted by clicking on the column headers.
+ </p>
+ <p><em>Edit Links</em><br /> This section contains three buttons,
+ <em>New</em>, <em>Edit</em> and <em>Delete</em>, which allow you to
+ create, modify and remove user-defined URL links from the Sequence
+ ID's links submenu.
+ </p>
+ <p>
+ <em>Filter</em><br /> The <em>Filter text</em> box allows you to
+ quickly show rows in the table containing a particular text string.
+ The <em>Custom only</em> button limits the entries in the table to
+ just those you have configured yourself <em>via</em> the <em>Edit
+ Links</em> buttons. Press <em>Show all</em> to clear any filters.
+ <p>
+ <a href="../webServices/urllinks.html#urllinks">Read more about configuring
+ URL links.</a>
+ </p>
+ <p>
<a name="output"><strong>Output Preferences tab</strong></a>
</p>
<p>
and PDB file association (if available). The Jalview id/start-end
option is ignored if Modeller output is selected.
<p>
- <a name="editing"><strong>Editing Preferences tab</strong></a>
+ <a name="editing"><strong>e"Editinge" Preferences tab</strong></a>
</p>
<p>There are currently three options available which can be
selected / deselected.</p>
1QCF ----------6878742356789999999999889
cons 00100000006877641356789999999999889
</pre>
-
+<table border="1">
+<tr><th>Score</th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th></tr>
+<tr>
+<td>RGB colour</td>
+<td bgcolor="#6666FF">102, 102, 255</td>
+<td bgcolor="#00FF00">0, 255, 0</td>
+<td bgcolor="#66FF00">102, 255, 0</td>
+<td bgcolor="#CCFF00">204, 255, 0</td>
+<td bgcolor="#FFFF00">255, 255, 0</td>
+<td bgcolor="#FFCC00">255, 204, 0</td>
+<td bgcolor="#FF9900">255, 153, 0</td>
+<td bgcolor="#FF6600">255, 102, 0</td>
+<td bgcolor="#FF3300">255, 51, 0</td>
+<td bgcolor="#FF2000">255, 34, 0</td></tr>
+</table>
</body>
</html>
</head>
<body>
<p>
- <p>
<strong>Opening URLs from Jalview</strong><br> Both the applet
and the desktop application are able to open URLs as 'popups' in
- your web browser. <br> Double-clicking on the ID of a sequence
- will open the first URL that can be generated from its sequence ID.
+ your web browser.</p>
+ <p> Double-clicking on the ID of a sequence
+ will open whichever URL is selected for 'popups' in the <strong>"Links"</strong> tab of the <a
+ href="../features/preferences.html#links">Jalview desktop
+ preferences</a>.
This is by default the EMBL-EBI site, but you can easily configure your own <a
href="#urllinks">sequence URL links</a>.
</p>
<p>
- Other links for a sequence either derived from any other configured
+ Other links for a sequence, either derived from any other configured
URL links, or imported from the sequence's annotation, are accessed
by right clicking to open the sequence pop-up menu, and selecting
from the <em>Links</em> submenu.
</p>
<p>
<strong><a name="urllinks">Configuring URL Links</a></strong> <br>URL
- links are defined in the "Connections" tab of the <a
- href="../features/preferences.html">Jalview desktop
+ links are defined in the "Links" tab of the <a
+ href="../features/preferences.html#links">Jalview desktop
preferences</a>, or specified as <a
href="http://www.jalview.org/examples/appletParameters.html#parameters">applet
- parameters</a>. <br> By default the item "EMBL-EBI Search" is added
- to this link menu. This link will show a web page in your default
- browser with the selected sequence id as part of the URL.<br>
- In the preferences dialog box, click <strong>new</strong> to add a
- new link, and <strong>edit</strong> to modify an existing link, or <strong>delete</strong>
- to remove it.<br> You can name the link, this will be displayed
- on a new menu item under the "Link" menu when you right
- click on a sequence id. <br> The URL string must contain a
- token that can be replaced with a sequence ID or DB accession ID. The simplest token is
- "$SEQUENCE_ID$", which will be replaced by the chosen
- sequence id when you click on it.
+ parameters</a>.</p>
+ <p>
+ <em>Default Link Settings</em><br /> The "EMBL-EBI Search"
+ link is the default link shown in the "Link" submenu, and
+ opened when double-clicking on a sequence ID. When clicked, this
+ link will show a web page in your default browser with the selected
+ sequence ID as part of the URL.
+ </p>
+ <p>
+ <em>Adding additional links</em><br /> You can configure your own
+ links via the Jalview <a href="../features/preferences.html#links"><strong>Preferences</strong></a>
+ dialog. Jalview also provides persistent URLs for many common
+ bioinformatics databases. These links are downloaded by Jalview from
+ the <em>identifiers.org</em> website, and the names and URLs are not
+ user editable.
</p>
<p>
- eg.<br> UniRef100 =
- http://www.ebi.uniprot.org/uniprot-srv/uniRefView.do?proteinAc=$SEQUENCE_ID$&library=uniref100<br>
- Swissprot = http://www.expasy.org/uniprot/$SEQUENCE_ID$ <br> <br>
+ <em>Creating your own URL link</em> URL links are specified as a
+ template containing special tokens that Jalview will replace with
+ the Sequence ID or Database Accession of the sequence when you
+ double click on its ID or open it's <strong>Link</strong> submenu.
+ Link URL templates must contain at least one token.
+ </p>
+ <em>eg.</em><pre> UniRef100 =
+ http://www.ebi.uniprot.org/uniprot-srv/uniRefView.do?proteinAc=$SEQUENCE_ID$&library=uniref100<br/>
+ Swissprot = http://www.expasy.org/uniprot/$SEQUENCE_ID$ <br> </pre>
+ <p>
Links will also be made for any database cross references associated
with the sequence where the database name exactly matches a URL link
name. In this case, the $DB_ACCESSION$ string will be replaced with
<p>
<strong>Regular Expression Substitution</strong><br> A url may
contain a string of the form $SEQUENCE_ID=/<em>regular
- expression</em>/=$ or $DB_ACCESSION=/<em>regular expression</em>/=$.
- In this case, the regular expression will be
- applied to the full sequence ID or DB accession ID string and the resulting match will
+ expression</em>/=$ or $DB_ACCESSION=/<em>regular expression</em>/=$. In
+ this case, the regular expression will be applied to the full
+ sequence ID or DB accession ID string and the resulting match will
be inserted into the URL. Groups of parentheses can be used to
specify which regions of the regular expression will be used to
generate the URL:
+
<ul>
<li>Each top level parenthesis will yield a URL containing the
text matched within that parenthesis.</li>
<li>Regions matching sub-parentheses within a top-level
parenthesis will be concatenated to form the text inserted into
the URL for the top-level parenthesis.</li>
- <em>Please Note:
- <ul>
- <li>The regular expressions supported by Jalview are those
- provided by the <a href="http://www.javaregex.com">Stevesoft
- javaregex package</a>.
- </li>
- <li>Some characters must be escaped when specifying them as
- a match within a regular expression.</li>
- </ul> <br> Many Thanks to Bernd Brandt of the Free University of
- Amsterdam for testing this new regular-expression expansion
- feature!
- </em>
- <em>
</ul>
- </p>
- </p>
+ <em>Please Note:</em>
+ <ul>
+ <li>The regular expressions supported by Jalview are those
+ provided by the <a href="http://www.javaregex.com">Stevesoft
+ javaregex package</a>.
+ </li>
+ <li>Some characters must be escaped when specifying them as a
+ match within a regular expression.</li>
+ </ul> <br> Many Thanks to Bernd Brandt of the Free University of
+ Amsterdam for testing the regular-expression expansion feature!
</body>
</html>
action.remove = Remove
action.remove_redundancy = Remove Redundancy...
action.pairwise_alignment = Pairwise Alignment
-action.by_rna_helixes = By RNA Helices
action.user_defined = User Defined...
action.by_conservation = By Conservation
action.wrap = Wrap
label.view_flanking_regions = Show sequence data either side of the subsequences involved in this alignment
label.structures_manager = Structures Manager
label.nickname = Nickname:
-label.url = URL:
+label.url = URL
+label.url\: = URL:
label.input_file_url = Enter URL or Input File
label.select_feature = Select feature
label.name = Name
label.score_model_enhconservation = Physicochemical property conservation
label.status_bar = Status bar
label.out_to_textbox = Output to Textbox
-label.clustalx = Clustalx
+# delete Clustal - use FileFormat name instead
label.clustal = Clustal
-label.zappo = Zappo
-label.taylor = Taylor
+# label.colourScheme_<schemeName> as in JalviewColourScheme
+label.colourScheme_clustal = Clustalx
+label.colourScheme_blosum62 = BLOSUM62 Score
+label.colourScheme_%_identity = Percentage Identity
+label.colourScheme_zappo = Zappo
+label.colourScheme_taylor = Taylor
+label.colourScheme_hydrophobic = Hydrophobicity
+label.colourScheme_helix_propensity = Helix Propensity
+label.colourScheme_strand_propensity = Strand Propensity
+label.colourScheme_turn_propensity = Turn Propensity
+label.colourScheme_buried_index = Buried Index
+label.colourScheme_purine/pyrimidine = Purine/Pyrimidine
+label.colourScheme_nucleotide = Nucleotide
+label.colourScheme_t-coffee_scores = T-Coffee Scores
+label.colourScheme_rna_helices = By RNA Helices
label.blc = BLC
label.fasta = Fasta
label.msf = MSF
label.pfam = PFAM
label.pileup = Pileup
label.pir = PIR
-label.hydrophobicity = Hydrophobicity
-label.helix_propensity = Helix Propensity
-label.strand_propensity = Strand Propensity
-label.turn_propensity = Turn Propensity
-label.buried_index = Buried Index
-label.purine_pyrimidine = Purine/Pyrimidine
-label.percentage_identity = Percentage Identity
-label.blosum62 = BLOSUM62
-label.blosum62_score = BLOSUM62 Score
-label.tcoffee_scores = T-Coffee Scores
-label.average_distance_bloslum62 = Average Distance Using BLOSUM62
+label.average_distance_blosum62 = Average Distance Using BLOSUM62
label.neighbour_blosum62 = Neighbour Joining Using BLOSUM62
label.show_annotations = Show annotations
label.hide_annotations = Hide annotations
label.add_reference_annotations = Add reference annotations
label.find_tip = Search alignment, selection or sequence ids for a subsequence (ignoring gaps).<br>Accepts regular expressions - search Help for 'regex' for details.
label.colour_text = Colour Text
-label.show_non_conversed = Show nonconserved
+label.show_non_conserved = Show nonconserved
label.overview_window = Overview Window
label.none = None
label.above_identity_threshold = Above Identity Threshold
label.style = Style:
label.calculating = Calculating....
label.modify_conservation_visibility = Modify conservation visibility
-label.colour_residues_above_occurence = Colour residues above % occurence
+label.colour_residues_above_occurrence = Colour residues above % occurrence
label.set_this_label_text = set this label text
label.sequences_from = Sequences from {0}
label.successfully_loaded_file = Successfully loaded file {0}
label.vamsas_document_import_failed = Vamsas Document Import Failed
label.couldnt_locate = Couldn't locate {0}
label.url_not_found = URL not found
-label.no_link_selected = No link selected
label.new_sequence_url_link = New sequence URL link
label.cannot_edit_annotations_in_wrapped_view = Cannot edit annotations in wrapped view
label.wrapped_view_no_edit = Wrapped view - no edit
label.right_click_to_edit_currently_selected_parameter = Right click to edit currently selected parameter.
label.let_jmol_manage_structure_colours = Let Jmol manage structure colours
label.let_chimera_manage_structure_colours = Let Chimera manage structure colours
+label.fetch_chimera_attributes = Fetch Chimera attributes
+label.fetch_chimera_attributes_tip = Copy Chimera attribute to Jalview feature
label.marks_leaves_tree_not_associated_with_sequence = Marks leaves of tree not associated with a sequence
label.index_web_services_menu_by_host_site = Index web services in menu by the host site
label.option_want_informed_web_service_URL_cannot_be_accessed_jalview_when_starts_up = Check this option if you want to be informed<br>when a web service URL cannot be accessed by Jalview<br>when it starts up
label.structure = Structure
label.show_pdbstruct_dialog = 3D Structure Data...
label.view_rna_structure = VARNA 2D Structure
-label.clustalx_colours = Clustalx colours
-label.above_identity_percentage = Above % Identity
label.create_sequence_details_report_annotation_for = Annotation for {0}
label.sequence_details_for = Sequence Details for {0}
label.sequence_name = Sequence Name
label.associate_leaves_with = Associate Leaves With
label.save_colour_scheme_with_unique_name_added_to_colour_menu = Save your colour scheme with a unique name and it will be added to the Colour menu
label.case_sensitive = Case Sensitive
-label.lower_case_colour = Lower Case Colour
+label.lower_case_colour = Colour All Lower Case
+label.lower_case_tip = Chosen colour applies to all lower case symbols
label.index_by_host = Index by Host
label.index_by_type = Index by Type
label.enable_jabaws_services = Enable JABAWS Services
label.points_for_params = Points for {0}
label.transformed_points_for_params = Transformed points for {0}
label.graduated_color_for_params = Graduated Feature Colour for {0}
-label.select_backgroud_colour = Select Background Colour
+label.select_background_colour = Select Background Colour
label.invalid_font = Invalid Font
label.separate_multiple_accession_ids = Enter one or more accession IDs separated by a semi-colon ";"
label.separate_multiple_query_values = Enter one or more {0}s separated by a semi-colon ";"
error.implementation_error_cannot_have_null_alignment = Implementation error: Cannot have null alignment property key
error.implementation_error_null_fileparse = Implementation error. Null FileParse in copy constructor
error.implementation_error_cannot_map_alignment_sequences = IMPLEMENTATION ERROR: Cannot map an alignment of sequences from different datasets into a single alignment in the vamsas document.
-error.implementation_error_cannot_duplicate_colour_scheme = Serious implementation error: cannot duplicate colourscheme {0}
error.implementation_error_structure_selection_manager_null = Implementation error. Structure selection manager's context is 'null'
exception.ssm_context_is_null = SSM context is null
error.idstring_seqstrings_only_one_per_sequence = idstrings and seqstrings contain one string each per sequence
exception.bad_pattern_to_regex_perl_code = bad pattern to Regex.perlCode: {0}
exception.no_stub_implementation_for_interface = There is no stub implementation for the interface: {0}
exception.cannot_set_endpoint_address_unknown_port = Cannot set Endpoint Address for Unknown Port {0}
-exception.querying_matching_opening_parenthesis_for_non_closing_parenthesis = Querying matching opening parenthesis for non-closing parenthesis character {0}
exception.mismatched_unseen_closing_char = Mismatched (unseen) closing character {0}
exception.mismatched_closing_char = Mismatched closing character {0}
exception.mismatched_opening_char = Mismatched opening character {0} at {1}
exception.application_test_npe = Application test: throwing an NullPointerException It should arrive at the console
exception.overwriting_vamsas_id_binding = Overwriting vamsas id binding
exception.overwriting_jalview_id_binding = Overwriting jalview id binding
-error.implementation_error_unknown_file_format_string = Implementation error: Unknown file format string
exception.failed_to_resolve_gzip_stream = Failed to resolve GZIP stream
exception.problem_opening_file_also_tried = Problem opening {0} (also tried {1}) : {2}
exception.problem_opening_file = Problem opening {0} : {1}
action.export_hidden_sequences = Export Hidden Sequences
action.export_features = Export Features
label.export_settings = Export Settings
-label.save_as_biojs_html = Save as BioJs HTML
label.pdb_web-service_error = PDB Web-service Error
label.structure_chooser_manual_association = Structure Chooser - Manual association
label.structure_chooser_filter_time = Structure Chooser - Filter time ({0})
label.SEQUENCE_ID_for_DB_ACCESSION1 = Please review your URL links in the 'Connections' tab of the Preferences window:
label.SEQUENCE_ID_for_DB_ACCESSION2 = URL links using '$SEQUENCE_ID$' for DB accessions now use '$DB_ACCESSION$'.
label.do_not_display_again = Do not display this message again
+exception.url_cannot_have_miriam_id = {0} is a MIRIAM id and cannot be used as a custom url name
+exception.url_cannot_have_duplicate_id = {0} cannot be used as a label for more than one line
+label.filter = Filter text:
+action.customfilter = Custom only
+action.showall = Show All
+label.insert = Insert:
+action.seq_id = $SEQUENCE_ID$
+action.db_acc = $DB_ACCESSION$
+label.primary = Double Click
+label.inmenu = In Menu
+label.id = ID
+label.database = Database
+label.urltooltip = Only one url, which must use a sequence id, can be selected for the 'On Click' option
+label.edit_sequence_url_link = Edit sequence URL link
+warn.name_cannot_be_duplicate = User-defined URL names must be unique and cannot be MIRIAM ids
+label.invalid_name = Invalid Name !
label.output_seq_details = Output Sequence Details to list all database references
+label.urllinks = Links
action.remove = Eliminar
action.remove_redundancy = Eliminar redundancia...
action.pairwise_alignment = Alineamiento de pares...
-action.by_rna_helixes = Por hélices de RNA
action.user_defined = Definido por el usuario...
action.by_conservation = Por conservación
action.wrap = Envolver
label.view_flanking_regions = Mostrar los datos de la secuencia a ambos lados de las subsecuencias implicadas en este alineamiento
label.structures_manager = Administrar estructuras
label.nickname = Sobrenombre:
-label.url = URL:
+label.url\: = URL:
+label.url = URL
label.input_file_url = Introducir URL en el fichero de entrada
label.select_feature = Seleccionar característica
label.name = Nombre
label.score_model_enhconservation = Conservación de las propiedades físico-químicas
label.status_bar = Barra de estado
label.out_to_textbox = Generar cuadro de texto
-label.clustalx = Clustalx
label.clustal = Clustal
-label.zappo = Zappo
-label.taylor = Taylor
+# label.colourScheme_<schemeName> as in JalviewColourScheme
+label.colourScheme_clustal = Clustalx
+label.colourScheme_blosum62 = Puntuación del BLOSUM62
+label.colourScheme_%_identity = Porcentaje de identidad
+label.colourScheme_zappo = Zappo
+label.colourScheme_taylor = Taylor
+label.colourScheme_hydrophobic = Hidrofobicidad
+label.colourScheme_helix_propensity = Tendencia de la hélice
+label.colourScheme_strand_propensity = Tendencia de la hebra
+label.colourScheme_turn_propensity = Tendencia de giro
+label.colourScheme_buried_index = Índice de encubrimiento
+label.colourScheme_purine/pyrimidine = Purina/Pirimidina
+label.colourScheme_nucleotide = Nucleótido
+label.colourScheme_t-coffee_scores = Puntuación del T-Coffee
+label.colourScheme_rna_helices = Por hélices de RNA
label.blc = BLC
label.fasta = Fasta
label.msf = MSF
label.pfam = PFAM
label.pileup = Pileup
label.pir = PIR
-label.hydrophobicity = Hidrofobicidad
-label.helix_propensity = Tendencia de la hélice
-label.strand_propensity = Tendencia de la hebra
-label.turn_propensity = Tendencia de giro
-label.buried_index = Índice de encubrimiento
-label.purine_pyrimidine = Purina/Pirimidina
-label.percentage_identity = Porcentaje de identidad
-label.blosum62 = BLOSUM62
-label.blosum62_score = Puntuación del BLOSUM62
-label.tcoffee_scores = Puntuación del T-Coffee
-label.average_distance_bloslum62 = Distancia Media Usando BLOSUM62
+label.average_distance_blosum62 = Distancia Media Usando BLOSUM62
label.neighbour_blosum62 = Neighbour Joining usando BLOSUM62
label.show_annotations = Mostrar anotaciones
label.colour_text = Color del texto
-label.show_non_conversed = Mostrar no conservadas
+label.show_non_conserved = Mostrar no conservadas
label.overview_window = Ventana resumen
label.none = Ninguno
label.above_identity_threshold = Por encima del umbral de identidad
label.style = Estilo:
label.calculating = Calculando....
label.modify_conservation_visibility = Modificar la visibilidad de conservación
-label.colour_residues_above_occurence = Residuos de color por encima del % de aparición
+label.colour_residues_above_occurrence = Residuos de color por encima del % de aparición
label.set_this_label_text = fijar como etiqueta
label.sequences_from = Secuencias de {0}
label.successfully_loaded_file = Fichero cargado exitosamente {0}
label.vamsas_document_import_failed = Fallo en la importación del documento Vamsas
label.couldnt_locate = No se pudo localizar {0}
label.url_not_found = URL no encontrada
-label.no_link_selected = Enlace no seleccionado
label.new_sequence_url_link = Enlace a una nueva secuencia URL
label.cannot_edit_annotations_in_wrapped_view = No se pueden editar anotaciones en vista envolvente
label.wrapped_view_no_edit = Vista envolvente - no editar
label.enter_pdb_id = Introducir PDB Id
label.text_colour = Color del texto
label.structure = Estructura
-label.clustalx_colours = Colores de Clustalx
-label.above_identity_percentage = Sobre % identidad
label.create_sequence_details_report_annotation_for = Anotación para {0}
label.sequence_details_for = Detalles de la secuencia para {0}
label.sequence_name = Nombre de la secuencia
label.associate_leaves_with = Asociar hojas con
label.save_colour_scheme_with_unique_name_added_to_colour_menu = Guarde el esquema cromáticos con un nombre único y se añadirá al menú de colores
label.case_sensitive = Sensible a mayúsculas
-label.lower_case_colour = Color para las minúsculas
+label.lower_case_colour = Colorear todas las minúsculas
+label.lower_case_tip = El color elegido se aplicará a todas las minúsculas
label.index_by_host = Indizar por host
label.index_by_type = Indizar por tipo
label.enable_jabaws_services = Habilitar servicios JABAWS
label.points_for_params = Puntos de {0}
label.transformed_points_for_params = Puntos transformados de {0}
label.graduated_color_for_params = Color graduado para la característica de {0}
-label.select_backgroud_colour = Seleccionar color de fondo
+label.select_background_colour = Seleccionar color de fondo
label.invalid_font = Fuente no válida
label.separate_multiple_accession_ids = Separar los accession id con un punto y coma ";"
label.replace_commas_semicolons = Cambiar comas por puntos y comas
error.implementation_error_cannot_have_null_alignment = Error de implementación: no es posible tener una clave nula en el alineamiento
error.implementation_error_null_fileparse = Error de implementación. FileParse nulo en el construictor de copia
error.implementation_error_cannot_map_alignment_sequences = Error de implementación: no es posible maper un alineamiento de secuencias desde distintos conjuntos de datos en un único alineamiento en el documento VAMSAS.
-error.implementation_error_cannot_duplicate_colour_scheme = Error grave de implementación: no es posible duplicar el esquema cromático {0}
error.implementation_error_structure_selection_manager_null = Error de implementación. El contexto structure selection manager's es nulo
exception.ssm_context_is_null = El contexto SSM es nulo
error.idstring_seqstrings_only_one_per_sequence = idstrings y seqstrings contienen una cadena por cada secuencia
exception.bad_pattern_to_regex_perl_code = patrón erróneo en Regex.perlCode: {0}
exception.no_stub_implementation_for_interface = No existe una implementación del stub para la interfaz: {0}
exception.cannot_set_endpoint_address_unknown_port = No es posible estabelcer la dirección de punto final para el puerto desconocido {0}
-exception.querying_matching_opening_parenthesis_for_non_closing_parenthesis = Consultando la coincidencia de apertura de paréntesis para paréntesis sin cerrar (?)
exception.mismatched_unseen_closing_char = Discordancia (no vista) en el carácter de cierre {0}
exception.mismatched_closing_char = Carácter de cierre discordante {0}
exception.mismatched_opening_char = Carácter de apertura discordante {0} en {1}
exception.application_test_npe = Prueba de aplicación: lanzando un NullPointerException que debe aparecer en la consola
exception.overwriting_vamsas_id_binding = Sobreescribiendo la asociación al VAMSAS id
exception.overwriting_jalview_id_binding = Sobreescribiendo la asociación al Jalview id
-error.implementation_error_unknown_file_format_string = Error de implementación: cadena de formato de fichero desconocido
exception.failed_to_resolve_gzip_stream = Fallo al resolver el flujo GZIP
exception.problem_opening_file_also_tried = Problema abriendo {0} (también se intentó {1}) : {2}
exception.problem_opening_file = Problema abriendo {0} : {1}
info.select_filter_option=Escoger Opción de Filtro / Entrada Manual
info.invalid_msa_input_mininfo=Necesita por lo menos dos secuencias con al menos 3 residuos cada una, sin regiones ocultas entre ellas.
label.chimera_missing=Visualizador de estructura Chimera no encontrado.<br/>Por favor, introduzca la ruta de Chimera,<br/>o descargar e instalar la UCSF Chimera.
-label.save_as_biojs_html=Guardar como HTML BioJs
exception.fts_server_unreachable=Jalview no puede conectar con el servidor {0}. \nPor favor asegúrese de que está conectado a Internet y vuelva a intentarlo.
exception.outofmemory_loading_mmcif_file=Sin memoria al cargar el fichero mmCIF
label.hide_columns_not_containing=Ocultar las columnas que no contengan
label.SEQUENCE_ID_for_DB_ACCESSION1 = Por favor, revise sus URLs en la pestaña 'Conexiones' de la ventana de Preferencias:
label.SEQUENCE_ID_for_DB_ACCESSION2 = URL enlaza usando '$SEQUENCE_ID$' para accesiones DB ahora usar '$DB_ACCESSION$'.
label.do_not_display_again = No mostrar este mensaje de nuevo
+exception.url_cannot_have_miriam_id = {0} es una id MIRIAM y no puede ser usada como nombre url personalizado
+exception.url_cannot_have_duplicate_id = {0} no puede ser usada como etiqueta en más de un enlace
+label.filter = Filtrar texto:
+action.customfilter = Sólo personalizado
+action.showall = Mostrar todo
+label.insert = Insertar:
+action.seq_id = $SEQUENCE_ID$
+action.db_acc = $DB_ACCESSION$
+label.primary = Doble clic
+label.inmenu = En Menú
+label.id = ID
+label.database = Base de datos
+label.urltooltip = Sólo una url, que debe usar una id de secuencia, puede ser seleccionada en la opción 'On Click'
+label.edit_sequence_url_link = Editar link de secuencia URL
+warn.name_cannot_be_duplicate = Los nombres URL definidos por el usuario deben ser únicos y no pueden ser ids de MIRIAM
+label.invalid_name = Nombre inválido !
label.output_seq_details = Seleccionar Detalles de la secuencia para ver todas
+label.urllinks = Enlaces
\ No newline at end of file
zbuffer.addItemListener(this);
charge.setLabel(MessageManager.getString("label.charge_cysteine"));
charge.addActionListener(this);
- hydro.setLabel(MessageManager.getString("label.hydrophobicity"));
+ hydro.setLabel(MessageManager
+ .getString("label.colourScheme_hydrophobic"));
hydro.addActionListener(this);
chain.setLabel(MessageManager.getString("action.by_chain"));
chain.addActionListener(this);
.setLabel(MessageManager.getString("label.all_chains_visible"));
allchains.addItemListener(this);
viewMenu.setLabel(MessageManager.getString("action.view"));
- zappo.setLabel(MessageManager.getString("label.zappo"));
+ zappo.setLabel(MessageManager.getString("label.colourScheme_zappo"));
zappo.addActionListener(this);
- taylor.setLabel(MessageManager.getString("label.taylor"));
+ taylor.setLabel(MessageManager.getString("label.colourScheme_taylor"));
taylor.addActionListener(this);
- helix.setLabel(MessageManager.getString("label.helix_propensity"));
+ helix.setLabel(MessageManager
+ .getString("label.colourScheme_helix_propensity"));
helix.addActionListener(this);
- strand.setLabel(MessageManager.getString("label.strand_propensity"));
+ strand.setLabel(MessageManager
+ .getString("label.colourScheme_strand_propensity"));
strand.addActionListener(this);
- turn.setLabel(MessageManager.getString("label.turn_propensity"));
+ turn.setLabel(MessageManager
+ .getString("label.colourScheme_turn_propensity"));
turn.addActionListener(this);
- buried.setLabel(MessageManager.getString("label.buried_index"));
+ buried.setLabel(MessageManager
+ .getString("label.colourScheme_buried_index"));
buried.addActionListener(this);
user.setLabel(MessageManager.getString("action.user_defined"));
user.addActionListener(this);
try
{
index = ResidueProperties.aa3Hash.get(b.at1.resName).intValue();
- b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
+ b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0),
+ 0, null, null, 0f);
index = ResidueProperties.aa3Hash.get(b.at2.resName).intValue();
- b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
+ b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0), 0,
+ null, null, 0f);
} catch (Exception e)
{
+++ /dev/null
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package MCview;
-
-import jalview.datamodel.PDBEntry;
-import jalview.datamodel.SequenceI;
-import jalview.gui.AlignmentPanel;
-import jalview.gui.Desktop;
-import jalview.gui.JvOptionPane;
-import jalview.gui.OOMWarning;
-import jalview.gui.UserDefinedColours;
-import jalview.io.DataSourceType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
-import jalview.util.MessageManager;
-import jalview.ws.ebi.EBIFetchClient;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.PrintWriter;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
-import javax.swing.JInternalFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.JRadioButtonMenuItem;
-
-public class PDBViewer extends JInternalFrame implements Runnable
-{
-
- /**
- * The associated sequence in an alignment
- */
- PDBCanvas pdbcanvas;
-
- PDBEntry pdbentry;
-
- SequenceI[] seq;
-
- String[] chains;
-
- AlignmentPanel ap;
-
- DataSourceType protocol;
-
- String tmpPDBFile;
-
- public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
- AlignmentPanel ap, DataSourceType protocol)
- {
- this.pdbentry = pdbentry;
- this.seq = seq;
- this.chains = chains;
- this.ap = ap;
- this.protocol = protocol;
-
- try
- {
- jbInit();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
-
- StringBuffer title = new StringBuffer(seq[0].getName() + ":"
- + pdbentry.getFile());
-
- pdbcanvas = new PDBCanvas();
-
- setContentPane(pdbcanvas);
-
- if (pdbentry.getFile() != null)
- {
- try
- {
- tmpPDBFile = pdbentry.getFile();
- PDBfile pdbfile = new PDBfile(false, false, false, tmpPDBFile,
- DataSourceType.FILE);
-
- pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
-
- } catch (java.io.IOException ex)
- {
- ex.printStackTrace();
- }
- }
- else
- {
- Thread worker = new Thread(this);
- worker.start();
- }
-
- String method = (String) pdbentry.getProperty("method");
- if (method != null)
- {
- title.append(" Method: ");
- title.append(method);
- }
- String ch = (String) pdbentry.getProperty("chains");
- if (ch != null)
- {
- title.append(" Chain:");
- title.append(ch);
- }
- Desktop.addInternalFrame(this, title.toString(), 400, 400);
- }
-
- @Override
- public void run()
- {
- try
- {
- EBIFetchClient ebi = new EBIFetchClient();
- String query = "pdb:" + pdbentry.getId();
- pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "xml")
- .getAbsolutePath());
-
- if (pdbentry.getFile() != null)
- {
- pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
- }
- } catch (Exception ex)
- {
- pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
- ex.printStackTrace();
- }
- }
-
- private void jbInit() throws Exception
- {
- this.addKeyListener(new KeyAdapter()
- {
- @Override
- public void keyPressed(KeyEvent evt)
- {
- pdbcanvas.keyPressed(evt);
- }
- });
-
- this.setJMenuBar(jMenuBar1);
- fileMenu.setText(MessageManager.getString("action.file"));
- coloursMenu.setText(MessageManager.getString("label.colours"));
- saveMenu.setActionCommand(MessageManager.getString("action.save_image"));
- saveMenu.setText(MessageManager.getString("action.save_as"));
- png.setText("PNG");
- png.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- png_actionPerformed(e);
- }
- });
- eps.setText("EPS");
- eps.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- eps_actionPerformed(e);
- }
- });
- mapping.setText(MessageManager.getString("label.view_mapping"));
- mapping.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- mapping_actionPerformed(e);
- }
- });
- wire.setText(MessageManager.getString("label.wireframe"));
- wire.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- wire_actionPerformed(e);
- }
- });
- depth.setSelected(true);
- depth.setText(MessageManager.getString("label.depthcue"));
- depth.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- depth_actionPerformed(e);
- }
- });
- zbuffer.setSelected(true);
- zbuffer.setText(MessageManager.getString("label.z_buffering"));
- zbuffer.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- zbuffer_actionPerformed(e);
- }
- });
- charge.setText(MessageManager.getString("label.charge_cysteine"));
- charge.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- charge_actionPerformed(e);
- }
- });
- chain.setText(MessageManager.getString("action.by_chain"));
- chain.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- chain_actionPerformed(e);
- }
- });
- seqButton.setSelected(true);
- seqButton.setText(MessageManager.getString("action.by_sequence"));
- seqButton.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- seqButton_actionPerformed(e);
- }
- });
- allchains.setSelected(true);
- allchains.setText(MessageManager.getString("label.show_all_chains"));
- allchains.addItemListener(new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- allchains_itemStateChanged(e);
- }
- });
- zappo.setText(MessageManager.getString("label.zappo"));
- zappo.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- zappo_actionPerformed(e);
- }
- });
- taylor.setText(MessageManager.getString("label.taylor"));
- taylor.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- taylor_actionPerformed(e);
- }
- });
- hydro.setText(MessageManager.getString("label.hydrophobicity"));
- hydro.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hydro_actionPerformed(e);
- }
- });
- helix.setText(MessageManager.getString("label.helix_propensity"));
- helix.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- helix_actionPerformed(e);
- }
- });
- strand.setText(MessageManager.getString("label.strand_propensity"));
- strand.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- strand_actionPerformed(e);
- }
- });
- turn.setText(MessageManager.getString("label.turn_propensity"));
- turn.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- turn_actionPerformed(e);
- }
- });
- buried.setText(MessageManager.getString("label.buried_index"));
- buried.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- buried_actionPerformed(e);
- }
- });
- user.setText(MessageManager.getString("action.user_defined"));
- user.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- user_actionPerformed(e);
- }
- });
- viewMenu.setText(MessageManager.getString("action.view"));
- background
- .setText(MessageManager.getString("action.background_colour"));
- background.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- background_actionPerformed(e);
- }
- });
- savePDB.setText(MessageManager.getString("label.pdb_file"));
- savePDB.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- savePDB_actionPerformed(e);
- }
- });
- jMenuBar1.add(fileMenu);
- jMenuBar1.add(coloursMenu);
- jMenuBar1.add(viewMenu);
- fileMenu.add(saveMenu);
- fileMenu.add(mapping);
- saveMenu.add(savePDB);
- saveMenu.add(png);
- saveMenu.add(eps);
- coloursMenu.add(seqButton);
- coloursMenu.add(chain);
- coloursMenu.add(charge);
- coloursMenu.add(zappo);
- coloursMenu.add(taylor);
- coloursMenu.add(hydro);
- coloursMenu.add(helix);
- coloursMenu.add(strand);
- coloursMenu.add(turn);
- coloursMenu.add(buried);
- coloursMenu.add(user);
- coloursMenu.add(background);
- ButtonGroup bg = new ButtonGroup();
- bg.add(seqButton);
- bg.add(chain);
- bg.add(charge);
- bg.add(zappo);
- bg.add(taylor);
- bg.add(hydro);
- bg.add(helix);
- bg.add(strand);
- bg.add(turn);
- bg.add(buried);
- bg.add(user);
-
- if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
- {
- java.util.Enumeration userColours = jalview.gui.UserDefinedColours
- .getUserColourSchemes().keys();
-
- while (userColours.hasMoreElements())
- {
- final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
- userColours.nextElement().toString());
- radioItem.setName("USER_DEFINED");
- radioItem.addMouseListener(new MouseAdapter()
- {
- @Override
- public void mousePressed(MouseEvent evt)
- {
- if (evt.isPopupTrigger()) // Mac
- {
- offerRemoval(radioItem);
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent evt)
- {
- if (evt.isPopupTrigger()) // Windows
- {
- offerRemoval(radioItem);
- }
- }
-
- /**
- * @param radioItem
- */
- void offerRemoval(final JRadioButtonMenuItem radioItem)
- {
- radioItem.removeActionListener(radioItem.getActionListeners()[0]);
-
- int option = JvOptionPane.showInternalConfirmDialog(
- jalview.gui.Desktop.desktop, MessageManager
- .getString("label.remove_from_default_list"),
- MessageManager
- .getString("label.remove_user_defined_colour"),
- JvOptionPane.YES_NO_OPTION);
- if (option == JvOptionPane.YES_OPTION)
- {
- jalview.gui.UserDefinedColours
- .removeColourFromDefaults(radioItem.getText());
- coloursMenu.remove(radioItem);
- }
- else
- {
- radioItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- user_actionPerformed(evt);
- }
- });
- }
- }
- });
- radioItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- user_actionPerformed(evt);
- }
- });
- coloursMenu.add(radioItem);
- bg.add(radioItem);
- }
- }
-
- viewMenu.add(wire);
- viewMenu.add(depth);
- viewMenu.add(zbuffer);
- viewMenu.add(allchains);
- }
-
- JMenuBar jMenuBar1 = new JMenuBar();
-
- JMenu fileMenu = new JMenu();
-
- JMenu coloursMenu = new JMenu();
-
- JMenu saveMenu = new JMenu();
-
- JMenuItem png = new JMenuItem();
-
- JMenuItem eps = new JMenuItem();
-
- JMenuItem mapping = new JMenuItem();
-
- JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
-
- JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
-
- JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
-
- JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
-
- JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem user = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
-
- JMenu viewMenu = new JMenu();
-
- JMenuItem background = new JMenuItem();
-
- JMenuItem savePDB = new JMenuItem();
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- public void eps_actionPerformed(ActionEvent e)
- {
- makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- public void png_actionPerformed(ActionEvent e)
- {
- makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
- }
-
- void makePDBImage(jalview.util.ImageMaker.TYPE type)
- {
- int width = pdbcanvas.getWidth();
- int height = pdbcanvas.getHeight();
-
- jalview.util.ImageMaker im;
-
- if (type == jalview.util.ImageMaker.TYPE.PNG)
- {
- im = new jalview.util.ImageMaker(this,
- jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from view",
- width, height, null, null, null, 0, false);
- }
- else if (type == jalview.util.ImageMaker.TYPE.EPS)
- {
- im = new jalview.util.ImageMaker(this,
- jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from view",
- width, height, null, this.getTitle(), null, 0, false);
- }
- else
- {
-
- im = new jalview.util.ImageMaker(this,
- jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
- width, height, null, this.getTitle(), null, 0, false);
- }
-
- if (im.getGraphics() != null)
- {
- pdbcanvas.drawAll(im.getGraphics(), width, height);
- im.writeImage();
- }
- }
-
- public void charge_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setChargeColours();
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void hydro_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void chain_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setChainColours();
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void zbuffer_actionPerformed(ActionEvent e)
- {
- pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void molecule_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void depth_actionPerformed(ActionEvent e)
- {
- pdbcanvas.depthcue = !pdbcanvas.depthcue;
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void wire_actionPerformed(ActionEvent e)
- {
- pdbcanvas.wire = !pdbcanvas.wire;
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void seqButton_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = true;
- pdbcanvas.updateSeqColours();
- }
-
- public void mapping_actionPerformed(ActionEvent e)
- {
- jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
- try
- {
- cap.setText(pdbcanvas.mappingDetails.toString());
- Desktop.addInternalFrame(cap,
- MessageManager.getString("label.pdb_sequence_mapping"), 550,
- 600);
- } catch (OutOfMemoryError oom)
- {
- new OOMWarning("Opening sequence to structure mapping report", oom);
- cap.dispose();
- }
- }
-
- public void allchains_itemStateChanged(ItemEvent e)
- {
- pdbcanvas.setAllchainsVisible(allchains.getState());
- }
-
- public void zappo_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setColours(new ZappoColourScheme());
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void taylor_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setColours(new TaylorColourScheme());
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void helix_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setColours(new HelixColourScheme());
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void strand_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setColours(new StrandColourScheme());
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void turn_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setColours(new TurnColourScheme());
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void buried_actionPerformed(ActionEvent e)
- {
- pdbcanvas.bysequence = false;
- pdbcanvas.pdb.setColours(new BuriedColourScheme());
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
-
- public void user_actionPerformed(ActionEvent e)
- {
- if (e.getActionCommand().equals(
- MessageManager.getString("action.user_defined")))
- {
- // new UserDefinedColours(pdbcanvas, null);
- }
- else
- {
- UserColourScheme udc = (UserColourScheme) UserDefinedColours
- .getUserColourSchemes().get(e.getActionCommand());
-
- pdbcanvas.pdb.setColours(udc);
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
- }
-
- public void background_actionPerformed(ActionEvent e)
- {
- java.awt.Color col = JColorChooser.showDialog(this,
- MessageManager.getString("label.select_backgroud_colour"),
- pdbcanvas.backgroundColour);
-
- if (col != null)
- {
- pdbcanvas.backgroundColour = col;
- pdbcanvas.redrawneeded = true;
- pdbcanvas.repaint();
- }
- }
-
- public void savePDB_actionPerformed(ActionEvent e)
- {
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
- chooser.setToolTipText(MessageManager.getString("action.save"));
-
- int value = chooser.showSaveDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- try
- {
- BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
- File outFile = chooser.getSelectedFile();
-
- PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
- String data;
- while ((data = in.readLine()) != null)
- {
- if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
- {
- out.println(data);
- }
- }
- out.close();
- in.close();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- }
-}
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.SortedMap;
import java.util.TreeMap;
/**
* @param unmapped
* @return
*/
- static Map<Integer, Map<SequenceI, Character>> buildMappedColumnsMap(
+ static SortedMap<Integer, Map<SequenceI, Character>> buildMappedColumnsMap(
AlignmentI unaligned, AlignmentI aligned, List<SequenceI> unmapped)
{
/*
* {unalignedSequence, characterPerSequence} at that position.
* TreeMap keeps the entries in ascending column order.
*/
- Map<Integer, Map<SequenceI, Character>> map = new TreeMap<Integer, Map<SequenceI, Character>>();
+ SortedMap<Integer, Map<SequenceI, Character>> map = new TreeMap<Integer, Map<SequenceI, Character>>();
/*
* record any sequences that have no mapping so can't be realigned
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
* or not conserved (-1)
* Using TreeMap means properties are displayed in alphabetical order
*/
- Map<String, Integer> resultHash = new TreeMap<String, Integer>();
+ SortedMap<String, Integer> resultHash = new TreeMap<String, Integer>();
SymbolCounts symbolCounts = values.getSymbolCounts();
char[] symbols = symbolCounts.symbols;
int[] counts = symbolCounts.values;
*
* @return Conservation sequence
*/
- public Sequence getConsSequence()
+ public SequenceI getConsSequence()
{
return consSequence;
}
*/
package jalview.analysis;
-import jalview.datamodel.BinarySequence;
-import jalview.datamodel.BinarySequence.InvalidSequenceTypeException;
-import jalview.math.Matrix;
+import jalview.math.MatrixI;
import jalview.schemes.ResidueProperties;
import jalview.schemes.ScoreMatrix;
/**
* Performs Principal Component Analysis on given sequences
- *
- * @author $author$
- * @version $Revision$
*/
public class PCA implements Runnable
{
- Matrix m;
-
- Matrix symm;
+ boolean jvCalcMode = true;
- Matrix m2;
+ MatrixI symm;
double[] eigenvalue;
- Matrix eigenvector;
+ MatrixI eigenvector;
- StringBuffer details = new StringBuffer();
+ StringBuilder details = new StringBuilder(1024);
+
+ private String[] seqs;
+
+ private ScoreMatrix scoreMatrix;
/**
* Creates a new PCA object. By default, uses blosum62 matrix to generate
public PCA(String[] s, boolean nucleotides, String s_m)
{
+ this.seqs = s;
- BinarySequence[] bs = new BinarySequence[s.length];
- int ii = 0;
-
- while ((ii < s.length) && (s[ii] != null))
- {
- bs[ii] = new BinarySequence(s[ii], nucleotides);
- bs[ii].encode();
- ii++;
- }
-
- BinarySequence[] bs2 = new BinarySequence[s.length];
- ii = 0;
- ScoreMatrix smtrx = null;
+ scoreMatrix = null;
String sm = s_m;
if (sm != null)
{
- smtrx = ResidueProperties.getScoreMatrix(sm);
+ scoreMatrix = ResidueProperties.getScoreMatrix(sm);
}
- if (smtrx == null)
+ if (scoreMatrix == null)
{
// either we were given a non-existent score matrix or a scoremodel that
// isn't based on a pairwise symbol score matrix
- smtrx = ResidueProperties.getScoreMatrix(sm = (nucleotides ? "DNA"
- : "BLOSUM62"));
+ scoreMatrix = ResidueProperties
+ .getScoreMatrix(sm = (nucleotides ? "DNA" : "BLOSUM62"));
}
details.append("PCA calculation using " + sm
+ " sequence similarity matrix\n========\n\n");
- while ((ii < s.length) && (s[ii] != null))
- {
- bs2[ii] = new BinarySequence(s[ii], nucleotides);
- if (smtrx != null)
- {
- try
- {
- bs2[ii].matrixEncode(smtrx);
- } catch (InvalidSequenceTypeException x)
- {
- details.append("Unexpected mismatch of sequence type and score matrix. Calculation will not be valid!\n\n");
- }
- }
- ii++;
- }
-
- // System.out.println("Created binary encoding");
- // printMemory(rt);
- int count = 0;
-
- while ((count < bs.length) && (bs[count] != null))
- {
- count++;
- }
-
- double[][] seqmat = new double[count][bs[0].getDBinary().length];
- double[][] seqmat2 = new double[count][bs2[0].getDBinary().length];
- int i = 0;
-
- while (i < count)
- {
- seqmat[i] = bs[i].getDBinary();
- seqmat2[i] = bs2[i].getDBinary();
- i++;
- }
-
- // System.out.println("Created array");
- // printMemory(rt);
- // System.out.println(" --- Original matrix ---- ");
- m = new Matrix(seqmat, count, bs[0].getDBinary().length);
- m2 = new Matrix(seqmat2, count, bs2[0].getDBinary().length);
-
- }
-
- /**
- * Returns the matrix used in PCA calculation
- *
- * @return java.math.Matrix object
- */
-
- public Matrix getM()
- {
- return m;
}
/**
*/
public double getEigenvalue(int i)
{
- return eigenvector.d[i];
+ return eigenvector.getD()[i];
}
/**
*/
public float[][] getComponents(int l, int n, int mm, float factor)
{
- float[][] out = new float[m.rows][3];
+ float[][] out = new float[getHeight()][3];
- for (int i = 0; i < m.rows; i++)
+ for (int i = 0; i < getHeight(); i++)
{
out[i][0] = (float) component(i, l) * factor;
out[i][1] = (float) component(i, n) * factor;
public double[] component(int n)
{
// n = index of eigenvector
- double[] out = new double[m.rows];
+ double[] out = new double[getHeight()];
- for (int i = 0; i < m.rows; i++)
+ for (int i = 0; i < out.length; i++)
{
out[i] = component(i, n);
}
{
double out = 0.0;
- for (int i = 0; i < symm.cols; i++)
+ for (int i = 0; i < symm.width(); i++)
{
- out += (symm.value[row][i] * eigenvector.value[i][n]);
+ out += (symm.getValue(row, i) * eigenvector.getValue(i, n));
}
- return out / eigenvector.d[n];
+ return out / eigenvector.getD()[n];
}
public String getDetails()
/**
* DOCUMENT ME!
*/
+ @Override
public void run()
{
PrintStream ps = new PrintStream(System.out)
{
+ @Override
public void print(String x)
{
details.append(x);
}
+ @Override
public void println()
{
details.append("\n");
}
};
+ // long now = System.currentTimeMillis();
try
{
details.append("PCA Calculation Mode is "
+ (jvCalcMode ? "Jalview variant" : "Original SeqSpace")
+ "\n");
- Matrix mt = m.transpose();
- details.append(" --- OrigT * Orig ---- \n");
- if (!jvCalcMode)
- {
- eigenvector = mt.preMultiply(m); // standard seqspace comparison matrix
- }
- else
- {
- eigenvector = mt.preMultiply(m2); // jalview variation on seqsmace
- // method
- }
+ eigenvector = scoreMatrix.computePairwiseScores(seqs);
- eigenvector.print(ps);
+ details.append(" --- OrigT * Orig ---- \n");
+ eigenvector.print(ps, "%8.2f");
symm = eigenvector.copy();
details.append(" ---Tridiag transform matrix ---\n");
details.append(" --- D vector ---\n");
- eigenvector.printD(ps);
+ eigenvector.printD(ps, "%15.4e");
ps.println();
details.append("--- E vector ---\n");
- eigenvector.printE(ps);
+ eigenvector.printE(ps, "%15.4e");
ps.println();
// Now produce the diagonalization matrix
}
details.append(" --- New diagonalization matrix ---\n");
- eigenvector.print(ps);
+ eigenvector.print(ps, "%8.2f");
details.append(" --- Eigenvalues ---\n");
- eigenvector.printD(ps);
+ eigenvector.printD(ps, "%15.4e");
ps.println();
/*
* for (int seq=0;seq<symm.rows;seq++) { ps.print("\"Seq"+seq+"\""); for
*
* ps.print(","+component(seq, ev)); } ps.println(); }
*/
+ // System.out.println(("PCA.run() took "
+ // + (System.currentTimeMillis() - now) + "ms"));
}
- boolean jvCalcMode = true;
-
public void setJvCalcMode(boolean calcMode)
{
this.jvCalcMode = calcMode;
}
+
+ /**
+ * Answers the N dimensions of the NxN PCA matrix. This is the number of
+ * sequences involved in the pairwise score calculation.
+ *
+ * @return
+ */
+ public int getHeight()
+ {
+ // TODO can any of seqs[] be null?
+ return seqs.length;
+ }
}
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.renderer.ResidueShaderI;
import jalview.schemes.ColourSchemeI;
import java.awt.Color;
ColourSchemeI getGlobalColourScheme();
+ /**
+ * Returns an object that describes colouring (including any thresholding or
+ * fading) of the alignment
+ *
+ * @return
+ */
+ ResidueShaderI getResidueShading();
+
AlignmentI getAlignment();
ColumnSelection getColumnSelection();
/**
*
- * @return the alignment annotatino row for the structure consensus
+ * @return the alignment annotation row for the structure consensus
* calculation
*/
AlignmentAnnotation getAlignmentStrucConsensusAnnotation();
void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus);
/**
- * set global colourscheme
+ * Sets the colour scheme for the background alignment (as distinct from
+ * sub-groups, which may have their own colour schemes). A null value is used
+ * for no residue colour (white).
*
- * @param rhc
+ * @param cs
*/
- void setGlobalColourScheme(ColourSchemeI rhc);
+ void setGlobalColourScheme(ColourSchemeI cs);
Map<SequenceI, SequenceCollectionI> getHiddenRepSequences();
import jalview.io.FileFormatI;
import jalview.io.FileFormats;
import jalview.io.SequenceAnnotationReport;
+import jalview.renderer.ResidueShader;
+import jalview.renderer.ResidueShaderI;
import jalview.schemes.Blosum62ColourScheme;
import jalview.schemes.BuriedColourScheme;
import jalview.schemes.ClustalxColourScheme;
import jalview.schemes.HelixColourScheme;
import jalview.schemes.HydrophobicColourScheme;
+import jalview.schemes.JalviewColourScheme;
import jalview.schemes.NucleotideColourScheme;
import jalview.schemes.PIDColourScheme;
+import jalview.schemes.PurinePyrimidineColourScheme;
import jalview.schemes.StrandColourScheme;
import jalview.schemes.TaylorColourScheme;
import jalview.schemes.TurnColourScheme;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
MenuItem editGroupName = new MenuItem();
- protected MenuItem clustalColour = new MenuItem();
+ CheckboxMenuItem noColour = new CheckboxMenuItem();
- protected MenuItem zappoColour = new MenuItem();
+ protected CheckboxMenuItem clustalColour = new CheckboxMenuItem();
- protected MenuItem taylorColour = new MenuItem();
+ protected CheckboxMenuItem zappoColour = new CheckboxMenuItem();
- protected MenuItem hydrophobicityColour = new MenuItem();
+ protected CheckboxMenuItem taylorColour = new CheckboxMenuItem();
- protected MenuItem helixColour = new MenuItem();
+ protected CheckboxMenuItem hydrophobicityColour = new CheckboxMenuItem();
- protected MenuItem strandColour = new MenuItem();
+ protected CheckboxMenuItem helixColour = new CheckboxMenuItem();
- protected MenuItem turnColour = new MenuItem();
+ protected CheckboxMenuItem strandColour = new CheckboxMenuItem();
- protected MenuItem buriedColour = new MenuItem();
+ protected CheckboxMenuItem turnColour = new CheckboxMenuItem();
- protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
+ protected CheckboxMenuItem buriedColour = new CheckboxMenuItem();
+
+ protected CheckboxMenuItem PIDColour = new CheckboxMenuItem();
+
+ protected CheckboxMenuItem BLOSUM62Colour = new CheckboxMenuItem();
+
+ CheckboxMenuItem nucleotideColour = new CheckboxMenuItem();
+
+ CheckboxMenuItem purinePyrimidineColour = new CheckboxMenuItem();
protected MenuItem userDefinedColour = new MenuItem();
- protected MenuItem PIDColour = new MenuItem();
+ protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
- protected MenuItem BLOSUM62Colour = new MenuItem();
+ MenuItem modifyPID = new MenuItem();
- MenuItem noColourmenuItem = new MenuItem();
+ protected CheckboxMenuItem conservationColour = new CheckboxMenuItem();
- protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
+ MenuItem modifyConservation = new MenuItem();
+
+ MenuItem noColourmenuItem = new MenuItem();
final AlignmentPanel ap;
MenuItem createGroupMenuItem = new MenuItem();
- MenuItem nucleotideMenuItem = new MenuItem();
-
Menu colourMenu = new Menu();
CheckboxMenuItem showBoxes = new CheckboxMenuItem();
Menu menu1 = new Menu();
public APopupMenu(AlignmentPanel apanel, final SequenceI seq,
- Vector<String> links)
+ List<String> links)
{
// /////////////////////////////////////////////////////////
// If this is activated from the sequence panel, the user may want to
SequenceGroup sg = ap.av.getSelectionGroup();
if (sg != null && sg.getSize() > 0)
{
+ if (sg.isNucleotide())
+ {
+ conservationColour.setEnabled(false);
+ clustalColour.setEnabled(false);
+ BLOSUM62Colour.setEnabled(false);
+ zappoColour.setEnabled(false);
+ taylorColour.setEnabled(false);
+ hydrophobicityColour.setEnabled(false);
+ helixColour.setEnabled(false);
+ strandColour.setEnabled(false);
+ turnColour.setEnabled(false);
+ buriedColour.setEnabled(false);
+ }
+ else
+ {
+ purinePyrimidineColour.setEnabled(false);
+ nucleotideColour.setEnabled(false);
+ }
editGroupName.setLabel(MessageManager.formatMessage(
"label.name_param", new Object[] { sg.getName() }));
showText.setState(sg.getDisplayText());
if (sg.cs != null)
{
abovePIDColour.setState(sg.cs.getThreshold() > 0);
- conservationMenuItem.setState(sg.cs.conservationApplied());
+ conservationColour.setState(sg.cs.conservationApplied());
+ modifyPID.setEnabled(abovePIDColour.getState());
+ modifyConservation.setEnabled(conservationColour.getState());
}
}
+ setSelectedColour(sg.cs);
}
else
{
}
/**
+ * Select the menu item (if any) matching the current colour scheme. This
+ * works by matching the menu item name (not display text) to the canonical
+ * name of the colour scheme.
+ *
+ * @param cs
+ */
+ protected void setSelectedColour(ResidueShaderI cs)
+ {
+ if (cs == null || cs.getColourScheme() == null)
+ {
+ noColour.setState(true);
+ }
+ else
+ {
+ String name = cs.getColourScheme().getSchemeName();
+ for (int i = 0; i < colourMenu.getItemCount(); i++)
+ {
+ MenuItem item = colourMenu.getItem(i);
+ if (item instanceof CheckboxMenuItem)
+ {
+ if (name.equals(item.getName()))
+ {
+ ((CheckboxMenuItem) item).setState(true);
+ }
+ }
+ }
+ }
+ }
+
+ /**
* Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
*
* @param seq
* Temporary store to hold distinct calcId / type pairs for the tooltip.
* Using TreeMap means calcIds are shown in alphabetical order.
*/
- Map<String, String> tipEntries = new TreeMap<String, String>();
+ SortedMap<String, String> tipEntries = new TreeMap<String, String>();
final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
AlignmentI al = this.ap.av.getAlignment();
AlignmentUtils.findAddableReferenceAnnotations(forSequences,
linkMenu.add(item);
}
+ /**
+ * Actions on selecting / unselecting a checkbox menu item
+ */
@Override
public void itemStateChanged(ItemEvent evt)
{
Object source = evt.getSource();
- if (source == abovePIDColour)
- {
- abovePIDColour_itemStateChanged();
- }
- else if (source == conservationMenuItem)
+ if (source == noColour)
{
- conservationMenuItem_itemStateChanged();
- }
- else if (source == showColourText)
- {
- showColourText_itemStateChanged();
- }
- else if (source == showText)
- {
- showText_itemStateChanged();
+ noColourmenuItem_actionPerformed();
}
- else if (source == showBoxes)
+ else if (source == clustalColour)
{
- showBoxes_itemStateChanged();
+ clustalColour_actionPerformed();
}
- else if (source == displayNonconserved)
+ else if (source == BLOSUM62Colour)
{
- this.showNonconserved_itemStateChanged();
+ BLOSUM62Colour_actionPerformed();
}
- }
-
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- Object source = evt.getSource();
- if (source == clustalColour)
+ else if (evt.getSource() == PIDColour)
{
- clustalColour_actionPerformed();
+ PIDColour_actionPerformed();
}
else if (source == zappoColour)
{
{
buriedColour_actionPerformed();
}
- else if (source == nucleotideMenuItem)
+ else if (source == nucleotideColour)
{
nucleotideMenuItem_actionPerformed();
}
-
- else if (source == userDefinedColour)
+ else if (source == purinePyrimidineColour)
{
- userDefinedColour_actionPerformed();
+ purinePyrimidineColour_actionPerformed();
}
- else if (source == PIDColour)
+ else if (source == abovePIDColour)
{
- PIDColour_actionPerformed();
+ abovePIDColour_itemStateChanged();
}
- else if (source == BLOSUM62Colour)
+ else if (source == conservationColour)
{
- BLOSUM62Colour_actionPerformed();
+ conservationMenuItem_itemStateChanged();
}
- else if (source == noColourmenuItem)
+ else if (source == showColourText)
{
- noColourmenuItem_actionPerformed();
+ showColourText_itemStateChanged();
+ }
+ else if (source == showText)
+ {
+ showText_itemStateChanged();
+ }
+ else if (source == showBoxes)
+ {
+ showBoxes_itemStateChanged();
+ }
+ else if (source == displayNonconserved)
+ {
+ this.showNonconserved_itemStateChanged();
+ }
+ }
+
+ /**
+ * Actions on clicking a menu item
+ */
+ @Override
+ public void actionPerformed(ActionEvent evt)
+ {
+ Object source = evt.getSource();
+ if (source == userDefinedColour)
+ {
+ userDefinedColour_actionPerformed();
+ }
+ else if (source == modifyConservation)
+ {
+ conservationMenuItem_itemStateChanged();
+ }
+ else if (source == modifyPID)
+ {
+ abovePIDColour_itemStateChanged();
}
else if (source == unGroupMenuItem)
{
void addPDB()
{
Vector<PDBEntry> pdbs = seq.getAllPDBEntries();
- if (pdbs != null&& !pdbs.isEmpty())
+ if (pdbs != null && !pdbs.isEmpty())
{
PDBEntry entry = pdbs.firstElement();
if (ap.av.applet.jmolAvailable)
{
- new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq },
- null, ap, DataSourceType.URL);
+ new AppletJmol(entry, new SequenceI[] { seq }, null, ap,
+ DataSourceType.URL);
}
else
{
cap.setPDBImport(seq);
Frame frame = new Frame();
frame.add(cap);
- jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
+ JalviewLite.addFrame(frame, MessageManager.formatMessage(
"label.paste_pdb_file_for_sequence",
new Object[] { seq.getName() }), 400, 300);
}
.getString("action.create_group"));
createGroupMenuItem.addActionListener(this);
- nucleotideMenuItem.setLabel(MessageManager
- .getString("label.nucleotide"));
- nucleotideMenuItem.addActionListener(this);
- conservationMenuItem.addItemListener(this);
- abovePIDColour.addItemListener(this);
+ modifyPID.setEnabled(abovePIDColour.getState());
+ modifyConservation.setEnabled(conservationColour.getState());
colourMenu.setLabel(MessageManager.getString("label.group_colour"));
showBoxes.setLabel(MessageManager.getString("action.boxes"));
showBoxes.setState(true);
sequenceDetails.addActionListener(this);
selSeqDetails.addActionListener(this);
displayNonconserved.setLabel(MessageManager
- .getString("label.show_non_conversed"));
+ .getString("label.show_non_conserved"));
displayNonconserved.setState(false);
displayNonconserved.addItemListener(this);
showText.setLabel(MessageManager.getString("action.text"));
groupMenu.add(unGroupMenuItem);
groupMenu.add(menu1);
- colourMenu.add(noColourmenuItem);
+ colourMenu.add(noColour);
colourMenu.add(clustalColour);
colourMenu.add(BLOSUM62Colour);
colourMenu.add(PIDColour);
colourMenu.add(strandColour);
colourMenu.add(turnColour);
colourMenu.add(buriedColour);
- colourMenu.add(nucleotideMenuItem);
+ colourMenu.add(nucleotideColour);
+ colourMenu.add(purinePyrimidineColour);
colourMenu.add(userDefinedColour);
colourMenu.addSeparator();
+ colourMenu.add(conservationColour);
+ colourMenu.add(modifyConservation);
colourMenu.add(abovePIDColour);
- colourMenu.add(conservationMenuItem);
+ colourMenu.add(modifyPID);
- noColourmenuItem.setLabel(MessageManager.getString("label.none"));
- noColourmenuItem.addActionListener(this);
+ noColour.setLabel(MessageManager.getString("label.none"));
+ noColour.addItemListener(this);
+ /*
+ * setName allows setSelectedColour to do its thing
+ */
clustalColour.setLabel(MessageManager
- .getString("label.clustalx_colours"));
- clustalColour.addActionListener(this);
- zappoColour.setLabel(MessageManager.getString("label.zappo"));
- zappoColour.addActionListener(this);
- taylorColour.setLabel(MessageManager.getString("label.taylor"));
- taylorColour.addActionListener(this);
+ .getString("label.colourScheme_clustal"));
+ clustalColour.setName(JalviewColourScheme.Clustal.toString());
+ clustalColour.addItemListener(this);
+ BLOSUM62Colour.setLabel(MessageManager
+ .getString("label.colourScheme_blosum62"));
+ BLOSUM62Colour.setName(JalviewColourScheme.Blosum62.toString());
+ BLOSUM62Colour.addItemListener(this);
+ PIDColour.setLabel(MessageManager
+ .getString("label.colourScheme_%_identity"));
+ PIDColour.setName(JalviewColourScheme.PID.toString());
+ PIDColour.addItemListener(this);
+ zappoColour.setLabel(MessageManager
+ .getString("label.colourScheme_zappo"));
+ zappoColour.setName(JalviewColourScheme.Zappo.toString());
+ zappoColour.addItemListener(this);
+ taylorColour.setLabel(MessageManager
+ .getString("label.colourScheme_taylor"));
+ taylorColour.setName(JalviewColourScheme.Taylor.toString());
+ taylorColour.addItemListener(this);
hydrophobicityColour.setLabel(MessageManager
- .getString("label.hydrophobicity"));
- hydrophobicityColour.addActionListener(this);
- helixColour
- .setLabel(MessageManager.getString("label.helix_propensity"));
- helixColour.addActionListener(this);
+ .getString("label.colourScheme_hydrophobic"));
+ hydrophobicityColour
+ .setName(JalviewColourScheme.Hydrophobic.toString());
+ hydrophobicityColour.addItemListener(this);
+ helixColour.setLabel(MessageManager
+ .getString("label.colourScheme_helix_propensity"));
+ helixColour.setName(JalviewColourScheme.Helix.toString());
+ helixColour.addItemListener(this);
strandColour.setLabel(MessageManager
- .getString("label.strand_propensity"));
- strandColour.addActionListener(this);
- turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
- turnColour.addActionListener(this);
- buriedColour.setLabel(MessageManager.getString("label.buried_index"));
- buriedColour.addActionListener(this);
- abovePIDColour.setLabel(MessageManager
- .getString("label.above_identity_percentage"));
+ .getString("label.colourScheme_strand_propensity"));
+ strandColour.setName(JalviewColourScheme.Strand.toString());
+ strandColour.addItemListener(this);
+ turnColour.setLabel(MessageManager
+ .getString("label.colourScheme_turn_propensity"));
+ turnColour.setName(JalviewColourScheme.Turn.toString());
+ turnColour.addItemListener(this);
+ buriedColour.setLabel(MessageManager
+ .getString("label.colourScheme_buried_index"));
+ buriedColour.setName(JalviewColourScheme.Buried.toString());
+ buriedColour.addItemListener(this);
+ nucleotideColour.setLabel(MessageManager
+ .getString("label.colourScheme_nucleotide"));
+ nucleotideColour.setName(JalviewColourScheme.Nucleotide.toString());
+ nucleotideColour.addItemListener(this);
+ purinePyrimidineColour.setLabel(MessageManager
+ .getString("label.colourScheme_purine/pyrimidine"));
+ purinePyrimidineColour.setName(JalviewColourScheme.PurinePyrimidine
+ .toString());
+ purinePyrimidineColour.addItemListener(this);
userDefinedColour.setLabel(MessageManager
.getString("action.user_defined"));
userDefinedColour.addActionListener(this);
- PIDColour.setLabel(MessageManager
- .getString("label.percentage_identity"));
+
+ abovePIDColour.setLabel(MessageManager
+ .getString("label.above_identity_threshold"));
+ abovePIDColour.addItemListener(this);
+ modifyPID.setLabel(MessageManager
+ .getString("label.modify_identity_threshold"));
+ modifyPID.addActionListener(this);
+ conservationColour.setLabel(MessageManager
+ .getString("action.by_conservation"));
+ conservationColour.addItemListener(this);
+ modifyConservation.setLabel(MessageManager
+ .getString("label.modify_conservation_threshold"));
+ modifyConservation.addActionListener(this);
+
PIDColour.addActionListener(this);
- BLOSUM62Colour.setLabel("BLOSUM62");
BLOSUM62Colour.addActionListener(this);
- conservationMenuItem.setLabel(MessageManager
- .getString("label.conservation"));
editMenu.add(copy);
copy.addActionListener(this);
protected void clustalColour_actionPerformed()
{
SequenceGroup sg = getGroup();
- sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
+ sg.cs = new ResidueShader(new ClustalxColourScheme(sg,
+ ap.av.getHiddenRepSequences()));
refresh();
}
protected void zappoColour_actionPerformed()
{
- getGroup().cs = new ZappoColourScheme();
+ getGroup().cs = new ResidueShader(new ZappoColourScheme());
refresh();
}
protected void taylorColour_actionPerformed()
{
- getGroup().cs = new TaylorColourScheme();
+ getGroup().cs = new ResidueShader(new TaylorColourScheme());
refresh();
}
protected void hydrophobicityColour_actionPerformed()
{
- getGroup().cs = new HydrophobicColourScheme();
+ getGroup().cs = new ResidueShader(new HydrophobicColourScheme());
refresh();
}
protected void helixColour_actionPerformed()
{
- getGroup().cs = new HelixColourScheme();
+ getGroup().cs = new ResidueShader(new HelixColourScheme());
refresh();
}
protected void strandColour_actionPerformed()
{
- getGroup().cs = new StrandColourScheme();
+ getGroup().cs = new ResidueShader(new StrandColourScheme());
refresh();
}
protected void turnColour_actionPerformed()
{
- getGroup().cs = new TurnColourScheme();
+ getGroup().cs = new ResidueShader(new TurnColourScheme());
refresh();
}
protected void buriedColour_actionPerformed()
{
- getGroup().cs = new BuriedColourScheme();
+ getGroup().cs = new ResidueShader(new BuriedColourScheme());
refresh();
}
public void nucleotideMenuItem_actionPerformed()
{
- getGroup().cs = new NucleotideColourScheme();
+ getGroup().cs = new ResidueShader(new NucleotideColourScheme());
+ refresh();
+ }
+
+ public void purinePyrimidineColour_actionPerformed()
+ {
+ getGroup().cs = new ResidueShader(
+ new PurinePyrimidineColourScheme());
refresh();
}
else
// remove PIDColouring
{
+ SliderPanel.hidePIDSlider();
sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
}
-
+ modifyPID.setEnabled(abovePIDColour.getState());
refresh();
-
}
protected void userDefinedColour_actionPerformed()
protected void PIDColour_actionPerformed()
{
SequenceGroup sg = getGroup();
- sg.cs = new PIDColourScheme();
+ sg.cs = new ResidueShader(new PIDColourScheme());
sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
.getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
refresh();
{
SequenceGroup sg = getGroup();
- sg.cs = new Blosum62ColourScheme();
+ sg.cs = new ResidueShader(new Blosum62ColourScheme());
sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
.getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
return;
}
- if (conservationMenuItem.getState())
+ if (conservationColour.getState())
{
- sg.cs.setConservation(Conservation.calculateConservation("Group", sg
+ Conservation conservation = Conservation.calculateConservation(
+ "Group", sg
.getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
.getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
- false));
+ false);
+ sg.getGroupColourScheme().setConservation(conservation);
SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
SliderPanel.showConservationSlider();
}
else
// remove ConservationColouring
{
+ SliderPanel.hideConservationSlider();
sg.cs.setConservation(null);
}
-
+ modifyConservation.setEnabled(conservationColour.getState());
refresh();
}
import jalview.schemes.NucleotideColourScheme;
import jalview.schemes.PIDColourScheme;
import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.RNAHelicesColourChooser;
+import jalview.schemes.RNAHelicesColour;
import jalview.schemes.StrandColourScheme;
import jalview.schemes.TCoffeeColourScheme;
import jalview.schemes.TaylorColourScheme;
}
if (viewport.getAlignment().isNucleotide())
{
+ conservationMenuItem.setEnabled(false);
+ clustalColour.setEnabled(false);
+ BLOSUM62Colour.setEnabled(false);
+ zappoColour.setEnabled(false);
+ taylorColour.setEnabled(false);
+ hydrophobicityColour.setEnabled(false);
+ helixColour.setEnabled(false);
+ strandColour.setEnabled(false);
+ turnColour.setEnabled(false);
+ buriedColour.setEnabled(false);
viewport.updateStrucConsensus(alignPanel);
if (viewport.getAlignment().hasRNAStructure())
{
{
RNAHelixColour.setEnabled(false);
purinePyrimidineColour.setEnabled(false);
+ nucleotideColour.setEnabled(false);
}
// Some JVMS send keyevents to Top frame or lowest panel,
// Havent worked out why yet. So add to both this frame and seqCanvas for
// }
else if (source == RNAHelixColour)
{
- new RNAHelicesColourChooser(viewport, alignPanel);
+ changeColour(new RNAHelicesColour(viewport.getAlignment()));
+ // new RNAHelicesColourChooser(viewport, alignPanel);
}
else if (source == modifyPID)
{
@Override
public void changeColour(ColourSchemeI cs)
{
-
- if (cs != null)
- {
- if (viewport.getAbovePIDThreshold())
- {
- viewport.setThreshold(SliderPanel.setPIDSliderSource(alignPanel,
- cs, "Background"));
- }
-
- if (viewport.getConservationSelected())
- {
- cs.setConservationApplied(true);
- viewport.setIncrement(SliderPanel.setConservationSlider(alignPanel,
- cs, "Background"));
- }
- else
- {
- cs.setConservationApplied(false);
- }
- }
viewport.setGlobalColourScheme(cs);
alignPanel.paintAlignment(true);
&& viewport.getGlobalColourScheme() != null)
{
SliderPanel.setPIDSliderSource(alignPanel,
- viewport.getGlobalColourScheme(), "Background");
+ viewport.getResidueShading(), alignPanel.getViewName());
SliderPanel.showPIDSlider();
}
}
&& viewport.getGlobalColourScheme() != null)
{
SliderPanel.setConservationSlider(alignPanel,
- viewport.getGlobalColourScheme(), "Background");
+ viewport.getResidueShading(), alignPanel.getViewName());
SliderPanel.showConservationSlider();
}
}
protected void conservationMenuItem_actionPerformed()
{
- viewport.setConservationSelected(conservationMenuItem.getState());
+ boolean selected = conservationMenuItem.getState();
+ modifyConservation.setEnabled(selected);
+ viewport.setConservationSelected(selected);
- viewport.setAbovePIDThreshold(false);
- abovePIDThreshold.setState(false);
+ // viewport.setAbovePIDThreshold(false);
+ // abovePIDThreshold.setState(false);
changeColour(viewport.getGlobalColourScheme());
- modifyConservation_actionPerformed();
+ if (selected)
+ {
+ modifyConservation_actionPerformed();
+ }
+ else
+ {
+ SliderPanel.hideConservationSlider();
+ }
}
public void abovePIDThreshold_actionPerformed()
{
- viewport.setAbovePIDThreshold(abovePIDThreshold.getState());
-
- conservationMenuItem.setState(false);
- viewport.setConservationSelected(false);
+ boolean selected = abovePIDThreshold.getState();
+ modifyPID.setEnabled(selected);
+ viewport.setAbovePIDThreshold(selected);
+ // conservationMenuItem.setState(false);
+ // viewport.setConservationSelected(false);
changeColour(viewport.getGlobalColourScheme());
- modifyPID_actionPerformed();
+ if (selected)
+ {
+ modifyPID_actionPerformed();
+ }
+ else
+ {
+ SliderPanel.hidePIDSlider();
+ }
}
public void sortPairwiseMenuItem_actionPerformed()
.getString("label.colour_text"));
colourTextMenuItem.addItemListener(this);
displayNonconservedMenuItem.setLabel(MessageManager
- .getString("label.show_non_conversed"));
+ .getString("label.show_non_conserved"));
displayNonconservedMenuItem.addItemListener(this);
wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
wrapMenuItem.addItemListener(this);
.getString("label.apply_colour_to_all_groups"));
applyToAllGroups.setState(true);
applyToAllGroups.addItemListener(this);
- clustalColour.setLabel(MessageManager.getString("label.clustalx"));
+ clustalColour.setLabel(MessageManager
+ .getString("label.colourScheme_clustal"));
clustalColour.addActionListener(this);
- zappoColour.setLabel(MessageManager.getString("label.zappo"));
+ zappoColour.setLabel(MessageManager
+ .getString("label.colourScheme_zappo"));
zappoColour.addActionListener(this);
- taylorColour.setLabel(MessageManager.getString("label.taylor"));
+ taylorColour.setLabel(MessageManager
+ .getString("label.colourScheme_taylor"));
taylorColour.addActionListener(this);
hydrophobicityColour.setLabel(MessageManager
- .getString("label.hydrophobicity"));
+ .getString("label.colourScheme_hydrophobic"));
hydrophobicityColour.addActionListener(this);
- helixColour
- .setLabel(MessageManager.getString("label.helix_propensity"));
+ helixColour.setLabel(MessageManager
+ .getString("label.colourScheme_helix_propensity"));
helixColour.addActionListener(this);
strandColour.setLabel(MessageManager
- .getString("label.strand_propensity"));
+ .getString("label.colourScheme_strand_propensity"));
strandColour.addActionListener(this);
- turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
+ turnColour.setLabel(MessageManager
+ .getString("label.colourScheme_turn_propensity"));
turnColour.addActionListener(this);
- buriedColour.setLabel(MessageManager.getString("label.buried_index"));
+ buriedColour.setLabel(MessageManager
+ .getString("label.colourScheme_buried_index"));
buriedColour.addActionListener(this);
purinePyrimidineColour.setLabel(MessageManager
- .getString("label.purine_pyrimidine"));
+ .getString("label.colourScheme_purine/pyrimidine"));
purinePyrimidineColour.addActionListener(this);
// RNAInteractionColour.setLabel(MessageManager
// .getString("label.rna_interaction"));
// RNAInteractionColour.addActionListener(this);
RNAHelixColour.setLabel(MessageManager
- .getString("action.by_rna_helixes"));
+ .getString("label.colourScheme_rna_helices"));
RNAHelixColour.addActionListener(this);
userDefinedColour.setLabel(MessageManager
.getString("action.user_defined"));
userDefinedColour.addActionListener(this);
PIDColour.setLabel(MessageManager
- .getString("label.percentage_identity"));
+ .getString("label.colourScheme_%_identity"));
PIDColour.addActionListener(this);
BLOSUM62Colour.setLabel(MessageManager
- .getString("label.blosum62_score"));
+ .getString("label.colourScheme_blosum62"));
BLOSUM62Colour.addActionListener(this);
- tcoffeeColour
- .setLabel(MessageManager.getString("label.tcoffee_scores"));
+ tcoffeeColour.setLabel(MessageManager
+ .getString("label.colourScheme_t-coffee_scores"));
// it will be enabled only if a score file is provided
tcoffeeColour.setEnabled(false);
tcoffeeColour.addActionListener(this);
abovePIDThreshold.setLabel(MessageManager
.getString("label.above_identity_threshold"));
abovePIDThreshold.addItemListener(this);
- nucleotideColour.setLabel(MessageManager.getString("label.nucleotide"));
+ nucleotideColour.setLabel(MessageManager
+ .getString("label.colourScheme_nucleotide"));
nucleotideColour.addActionListener(this);
modifyPID.setLabel(MessageManager
.getString("label.modify_identity_threshold"));
+ modifyPID.setEnabled(abovePIDThreshold.getState());
modifyPID.addActionListener(this);
modifyConservation.setLabel(MessageManager
.getString("label.modify_conservation_threshold"));
+ modifyConservation.setEnabled(conservationMenuItem.getState());
modifyConservation.addActionListener(this);
annotationColour.setLabel(MessageManager
.getString("action.by_annotation"));
.getString("label.neighbour_joining_identity"));
neighbourTreeMenuItem.addActionListener(this);
avDistanceTreeBlosumMenuItem.setLabel(MessageManager
- .getString("label.average_distance_bloslum62"));
+ .getString("label.average_distance_blosum62"));
avDistanceTreeBlosumMenuItem.addActionListener(this);
njTreeBlosumMenuItem.setLabel(MessageManager
.getString("label.neighbour_blosum62"));
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.renderer.ResidueShader;
import jalview.schemes.ColourSchemeProperty;
import jalview.schemes.UserColourScheme;
import jalview.structure.CommandListener;
if (colour != null)
{
- globalColourScheme = ColourSchemeProperty.getColour(alignment,
- colour);
- if (globalColourScheme != null)
+ residueShading = new ResidueShader(
+ ColourSchemeProperty.getColourScheme(alignment, colour));
+ if (residueShading != null)
{
- globalColourScheme.setConsensus(hconsensus);
+ residueShading.setConsensus(hconsensus);
}
}
if (applet.getParameter("userDefinedColour") != null)
{
- ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
- .getParameter("userDefinedColour"));
+ residueShading = new ResidueShader(
+ new UserColourScheme(
+ applet.getParameter("userDefinedColour")));
}
}
initAutoAnnotation();
oldgroupColours = new Hashtable();
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- if (sg.cs != null)
+ if (sg.getColourScheme() != null)
{
- oldgroupColours.put(sg, sg.cs);
+ oldgroupColours.put(sg, sg.getColourScheme());
}
else
{
AnnotationColourGradient acg = null;
if (currentColours.getState())
{
- acg = new AnnotationColourGradient(currentAnnotation,
- av.getGlobalColourScheme(), aboveThreshold);
}
else
{
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- if (sg.cs == null)
+ if (sg.getColourScheme() == null)
{
continue;
}
if (currentColours.getState())
{
- sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
- aboveThreshold);
+ sg.setColourScheme(new AnnotationColourGradient(
+ currentAnnotation, sg.getColourScheme(), aboveThreshold));
}
else
{
- sg.cs = new AnnotationColourGradient(currentAnnotation,
- minColour.getBackground(), maxColour.getBackground(),
- aboveThreshold);
+ sg.setColourScheme(new AnnotationColourGradient(
+ currentAnnotation, minColour.getBackground(), maxColour
+ .getBackground(), aboveThreshold));
}
}
Object cs = oldgroupColours.get(sg);
if (cs instanceof ColourSchemeI)
{
- sg.cs = (ColourSchemeI) cs;
+ sg.setColourScheme((ColourSchemeI) cs);
}
else
{
// probably the "null" string we set it to if it was null originally.
- sg.cs = null;
+ sg.setColourScheme(null);
}
}
}
import jalview.datamodel.AlignmentI;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
-import jalview.io.FileParse;
import jalview.io.DataSourceType;
+import jalview.io.FileParse;
import jalview.io.StructureFile;
import jalview.schemes.BuriedColourScheme;
import jalview.schemes.HelixColourScheme;
MenuItem charge = new MenuItem(
MessageManager.getString("label.charge_cysteine"));
- MenuItem zappo = new MenuItem(MessageManager.getString("label.zappo"));
+ MenuItem zappo = new MenuItem(
+ MessageManager.getString("label.colourScheme_zappo"));
- MenuItem taylor = new MenuItem(MessageManager.getString("label.taylor"));
+ MenuItem taylor = new MenuItem(
+ MessageManager.getString("label.colourScheme_taylor"));
MenuItem hydro = new MenuItem(
- MessageManager.getString("label.hydrophobicity"));
+ MessageManager.getString("label.colourScheme_hydrophobic"));
MenuItem helix = new MenuItem(
- MessageManager.getString("label.helix_propensity"));
+ MessageManager.getString("label.colourScheme_helix_propensity"));
MenuItem strand = new MenuItem(
- MessageManager.getString("label.strand_propensity"));
+ MessageManager.getString("label.colourScheme_strand_propensity"));
MenuItem turn = new MenuItem(
- MessageManager.getString("label.turn_propensity"));
+ MessageManager.getString("label.colourScheme_turn_propensity"));
MenuItem buried = new MenuItem(
- MessageManager.getString("label.buried_index"));
+ MessageManager.getString("label.colourScheme_buried_index"));
MenuItem purinepyrimidine = new MenuItem(
- MessageManager.getString("label.purine_pyrimidine"));
+ MessageManager.getString("label.colourScheme_purine/pyrimidine"));
MenuItem user = new MenuItem(
MessageManager.getString("label.user_defined_colours"));
public void updateTitleAndMenus()
{
- if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
+ if (jmb.hasFileLoadingError())
{
repaint();
return;
import jalview.datamodel.SequenceI;
import jalview.io.FeaturesFile;
import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
FeatureColourI col = getFeatureStyle(name.getText());
if (col == null)
{
- Color generatedColour = UserColourScheme
+ Color generatedColour = ColorUtils
.createColourFromName(name.getText());
col = new FeatureColour(generatedColour);
}
*/
package jalview.appletgui;
-import static jalview.util.UrlConstants.EMBLEBI_STRING;
-import static jalview.util.UrlConstants.SRS_STRING;
-
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.util.UrlLink;
+import jalview.urls.api.UrlProviderFactoryI;
+import jalview.urls.api.UrlProviderI;
+import jalview.urls.applet.AppletUrlProviderFactory;
import jalview.viewmodel.AlignmentViewport;
import java.awt.BorderLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
+import java.util.HashMap;
import java.util.List;
-import java.util.Vector;
public class IdPanel extends Panel implements MouseListener,
MouseMotionListener
boolean mouseDragging = false;
- java.util.Vector links = new java.util.Vector();
+ UrlProviderI urlProvider = null;
public IdPanel(AlignViewport av, AlignmentPanel parent)
{
String label, url;
// TODO: add in group link parameter
+
+ // make a list of label,url pairs
+ HashMap<String, String> urlList = new HashMap<String, String>();
if (av.applet != null)
{
for (int i = 1; i < 10; i++)
label = av.applet.getParameter("linkLabel_" + i);
url = av.applet.getParameter("linkURL_" + i);
- if (label != null && url != null)
+ // only add non-null parameters
+ if (label != null)
{
- links.addElement(label + "|" + url);
+ urlList.put(label, url);
}
-
}
- }
- {
- // upgrade old SRS link
- int srsPos = links.indexOf(SRS_STRING);
- if (srsPos > -1)
+
+ if (!urlList.isEmpty())
{
- links.setElementAt(EMBLEBI_STRING, srsPos);
+ // set default as first entry in list
+ String defaultUrl = av.applet.getParameter("linkLabel_1");
+ UrlProviderFactoryI factory = new AppletUrlProviderFactory(
+ defaultUrl, urlList);
+ urlProvider = factory.createUrlProvider();
}
}
- if (links.size() < 1)
- {
- links = new java.util.Vector();
- links.addElement(EMBLEBI_STRING);
- }
}
Tooltip tooltip;
return;
}
- // DEFAULT LINK IS FIRST IN THE LINK LIST
+ // get the sequence details
int seq = alignPanel.seqPanel.findSeq(e);
SequenceI sq = av.getAlignment().getSequenceAt(seq);
if (sq == null)
}
String id = sq.getName();
- String target = null;
- String url = null;
- int i = 0;
- while (url == null && i < links.size())
- {
- // DEFAULT LINK IS FIRST IN THE LINK LIST
- // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
- url = links.elementAt(i++).toString();
- jalview.util.UrlLink urlLink = null;
- try
- {
- urlLink = new UrlLink(url);
- target = urlLink.getTarget();
- } catch (Exception foo)
- {
- System.err.println("Exception for URLLink '" + url + "'");
- foo.printStackTrace();
- url = null;
- continue;
- }
-
- if (urlLink.usesDBAccession())
- {
- // this URL requires an accession id, not the name of a sequence
- url = null;
- continue;
- }
-
- if (!urlLink.isValid())
- {
- System.err.println(urlLink.getInvalidMessage());
- url = null;
- continue;
- }
-
- String urls[] = urlLink.makeUrls(id, true);
- if (urls == null || urls[0] == null || urls[0].length() < 1)
- {
- url = null;
- continue;
- }
- // just take first URL made from regex
- url = urls[1];
- }
+ // get the default url with the sequence details filled in
+ String url = urlProvider.getPrimaryUrl(id);
+ String target = urlProvider.getPrimaryTarget(id);
try
{
-
alignPanel.alignFrame.showURL(url, target);
} catch (Exception ex)
{
// build a new links menu based on the current links + any non-positional
// features
- Vector nlinks = new Vector();
- for (int l = 0, lSize = links.size(); l < lSize; l++)
- {
- nlinks.addElement(links.elementAt(l));
- }
+ List<String> nlinks = urlProvider.getLinksForMenu();
+
SequenceFeature sf[] = sq == null ? null : sq.getSequenceFeatures();
for (int sl = 0; sf != null && sl < sf.length; sl++)
{
{
for (int l = 0, lSize = sf[sl].links.size(); l < lSize; l++)
{
- nlinks.addElement(sf[sl].links.elementAt(l));
+ nlinks.add(sf[sl].links.elementAt(l));
}
}
}
slider.addAdjustmentListener(new AdjustmentListener()
{
+ @Override
public void adjustmentValueChanged(AdjustmentEvent evt)
{
- valueField.setText(slider.getValue() + "");
+ valueField.setText(String.valueOf(slider.getValue()));
sliderValueChanged();
}
});
*
* @return DOCUMENT ME!
*/
+ @Override
public void run()
{
label.setText(MessageManager.getString("label.calculating"));
}
+ @Override
public void applyButton_actionPerformed()
{
Vector del = new Vector();
}
+ @Override
public void undoButton_actionPerformed()
{
CommandI command = (CommandI) historyList.pop();
}
}
+ @Override
public void windowOpened(WindowEvent evt)
{
}
+ @Override
public void windowClosing(WindowEvent evt)
{
ap.idPanel.idCanvas.setHighlighted(null);
}
+ @Override
public void windowClosed(WindowEvent evt)
{
}
+ @Override
public void windowActivated(WindowEvent evt)
{
}
+ @Override
public void windowDeactivated(WindowEvent evt)
{
}
+ @Override
public void windowIconified(WindowEvent evt)
{
}
+ @Override
public void windowDeiconified(WindowEvent evt)
{
}
av.sendSelection();
}
+ /**
+ * Action on dragging the mouse in the scale panel is to expand or shrink the
+ * selection group range (including any hidden columns that it spans)
+ *
+ * @param evt
+ */
@Override
public void mouseDragged(MouseEvent evt)
{
mouseDragging = true;
+ ColumnSelection cs = av.getColumnSelection();
int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
- if (res < 0)
- {
- res = 0;
- }
-
- if (av.hasHiddenColumns())
- {
- res = av.getColumnSelection().adjustForHiddenColumns(res);
- }
-
- if (res > av.getAlignment().getWidth())
- {
- res = av.getAlignment().getWidth() - 1;
- }
-
- if (res < min)
- {
- min = res;
- }
-
- if (res > max)
- {
- max = res;
- }
+ res = Math.max(0, res);
+ res = cs.adjustForHiddenColumns(res);
+ res = Math.min(res, av.getAlignment().getWidth() - 1);
+ min = Math.min(res, min);
+ max = Math.max(res, max);
SequenceGroup sg = av.getSelectionGroup();
-
if (sg != null)
{
stretchingGroup = true;
-
- if (!av.getColumnSelection().contains(res))
- {
- av.getColumnSelection().addElement(res);
- }
-
- if (res > sg.getStartRes())
- {
- sg.setEndRes(res);
- }
- if (res < sg.getStartRes())
- {
- sg.setStartRes(res);
- }
-
- int col;
- for (int i = min; i <= max; i++)
- {
- col = av.getColumnSelection().adjustForHiddenColumns(i);
-
- if ((col < sg.getStartRes()) || (col > sg.getEndRes()))
- {
- av.getColumnSelection().removeElement(col);
- }
- else
- {
- av.getColumnSelection().addElement(col);
- }
- }
-
+ cs.stretchGroup(res, sg, min, max);
ap.paintAlignment(false);
}
}
stretchGroup = av.getSelectionGroup();
- if (stretchGroup == null)
+ if (stretchGroup == null || !stretchGroup.contains(sequence, res))
{
stretchGroup = av.getAlignment().findGroup(sequence, res);
- av.setSelectionGroup(stretchGroup);
- }
-
- if (stretchGroup == null
- || !stretchGroup.getSequences(null).contains(sequence)
- || stretchGroup.getStartRes() > res
- || stretchGroup.getEndRes() < res)
- {
- stretchGroup = null;
-
- SequenceGroup[] allGroups = av.getAlignment().findAllGroups(sequence);
-
- if (allGroups != null)
+ if (stretchGroup != null)
{
- for (int i = 0; i < allGroups.length; i++)
- {
- if (allGroups[i].getStartRes() <= res
- && allGroups[i].getEndRes() >= res)
- {
- stretchGroup = allGroups[i];
- break;
- }
- }
+ // only update the current selection if the popup menu has a group to
+ // focus on
+ av.setSelectionGroup(stretchGroup);
}
- av.setSelectionGroup(stretchGroup);
}
// DETECT RIGHT MOUSE BUTTON IN AWT
if (av.getConservationSelected())
{
- SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
- "Background");
+ SliderPanel.setConservationSlider(ap, av.getResidueShading(),
+ ap.getViewName());
}
if (av.getAbovePIDThreshold())
{
- SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
- "Background");
+ SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
+ ap.getViewName());
}
}
SliderPanel.setConservationSlider(ap, stretchGroup.cs,
stretchGroup.getName());
}
- else
+ if (stretchGroup.cs.getThreshold() > 0)
{
SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
stretchGroup.getName());
import jalview.api.FeatureRenderer;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.schemes.ColourSchemeI;
+import jalview.renderer.ResidueShaderI;
import java.awt.Color;
import java.awt.Font;
{
if (currentSequenceGroup.getDisplayBoxes())
{
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, i);
}
}
else if (av.getShowBoxes())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getResidueShading(), seq, i);
}
return resBoxColour;
return col;
}
- void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
+ void getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
{
- if (cs != null)
+ if (shader != null)
{
- resBoxColour = cs.findColour(seq.getCharAt(i), i, seq);
+ resBoxColour = shader.findColour(seq.getCharAt(i), i, seq);
}
else if (forOverview
&& !jalview.util.Comparison.isGap(seq.getCharAt(i)))
{
if (currentSequenceGroup.getDisplayBoxes())
{
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq,
+ i);
}
}
else if (av.getShowBoxes())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getResidueShading(), seq, i);
}
}
if (currentSequenceGroup.getColourText())
{
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, i);
graphics.setColor(resBoxColour.darker());
}
if (currentSequenceGroup.getShowNonconserved())
if (av.getColourText())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getResidueShading(), seq, i);
if (av.getShowBoxes())
{
graphics.setColor(resBoxColour.darker());
package jalview.appletgui;
import jalview.datamodel.SequenceGroup;
-import jalview.schemes.ColourSchemeI;
+import jalview.renderer.ResidueShaderI;
import jalview.util.MessageManager;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
public class SliderPanel extends Panel implements ActionListener,
AdjustmentListener, MouseListener
{
+ private static final String BACKGROUND = "Background";
+
AlignmentPanel ap;
boolean forConservation = true;
- ColourSchemeI cs;
+ ResidueShaderI cs;
static Frame conservationSlider;
static Frame PIDSlider;
public static int setConservationSlider(AlignmentPanel ap,
- ColourSchemeI cs, String source)
+ ResidueShaderI ccs, String source)
{
SliderPanel sp = null;
if (conservationSlider == null)
{
- sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
+ sp = new SliderPanel(ap, ccs.getConservationInc(), true, ccs);
conservationSlider = new Frame();
conservationSlider.add(sp);
}
else
{
sp = (SliderPanel) conservationSlider.getComponent(0);
- sp.cs = cs;
+ sp.cs = ccs;
+ sp.valueField.setText(String.valueOf(ccs.getConservationInc()));
}
- conservationSlider
- .setTitle(MessageManager.formatMessage(
- "label.conservation_colour_increment",
- new String[] { source }));
+ conservationSlider.setTitle(MessageManager.formatMessage(
+ "label.conservation_colour_increment",
+ new String[] { source == null ? BACKGROUND : source }));
if (ap.av.getAlignment().getGroups() != null)
{
sp.setAllGroupsCheckEnabled(true);
conservationSlider.getTitle(), 420, 100);
conservationSlider.addWindowListener(new WindowAdapter()
{
+ @Override
public void windowClosing(WindowEvent e)
{
conservationSlider = null;
}
- public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
- String source)
+ public static int setPIDSliderSource(AlignmentPanel ap,
+ ResidueShaderI ccs, String source)
{
SliderPanel pid = null;
if (PIDSlider == null)
{
- pid = new SliderPanel(ap, 50, false, cs);
+ pid = new SliderPanel(ap, ccs.getThreshold(), false, ccs);
PIDSlider = new Frame();
PIDSlider.add(pid);
}
else
{
pid = (SliderPanel) PIDSlider.getComponent(0);
- pid.cs = cs;
+ pid.cs = ccs;
+ pid.valueField.setText(String.valueOf(ccs.getThreshold()));
}
- PIDSlider
- .setTitle(MessageManager.formatMessage(
- "label.percentage_identity_threshold",
- new String[] { source }));
+ PIDSlider.setTitle(MessageManager.formatMessage(
+ "label.percentage_identity_threshold",
+ new String[] { source == null ? BACKGROUND : source }));
if (ap.av.getAlignment().getGroups() != null)
{
420, 100);
PIDSlider.addWindowListener(new WindowAdapter()
{
+ @Override
public void windowClosing(WindowEvent e)
{
PIDSlider = null;
}
+ /**
+ * Hides the PID slider panel if it is shown
+ */
+ public static void hidePIDSlider()
+ {
+ if (PIDSlider != null)
+ {
+ PIDSlider.setVisible(false);
+ PIDSlider = null;
+ }
+ }
+
+ /**
+ * Hides the Conservation slider panel if it is shown
+ */
+ public static void hideConservationSlider()
+ {
+ if (conservationSlider != null)
+ {
+ conservationSlider.setVisible(false);
+ conservationSlider = null;
+ }
+ }
public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
- ColourSchemeI cs)
+ ResidueShaderI shader)
{
try
{
e.printStackTrace();
}
this.ap = ap;
- this.cs = cs;
+ this.cs = shader;
forConservation = forConserve;
undoButton.setVisible(false);
applyButton.setVisible(false);
else
{
label.setText(MessageManager
- .getString("label.colour_residues_above_occurence"));
+ .getString("label.colour_residues_above_occurrence"));
slider.setMinimum(0);
slider.setMaximum(100 + slider.getVisibleAmount());
slider.setBlockIncrement(1);
return;
}
- ColourSchemeI toChange = cs;
+ ResidueShaderI toChange = cs;
Iterator<SequenceGroup> allGroups = null;
if (allGroupsCheck.getState())
allGroupsCheck.setEnabled(b);
}
+ @Override
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == applyButton)
}
}
+ @Override
public void adjustmentValueChanged(AdjustmentEvent evt)
{
valueField.setText(slider.getValue() + "");
{
try
{
- int i = Integer.parseInt(valueField.getText());
+ int i = Integer.valueOf(valueField.getText());
slider.setValue(i);
- } catch (Exception ex)
+ } catch (NumberFormatException ex)
{
- valueField.setText(slider.getValue() + "");
+ valueField.setText(String.valueOf(slider.getValue()));
}
}
valueField.setText(" ");
valueField.addActionListener(this);
valueField.setColumns(3);
+ valueField.addFocusListener(new FocusAdapter()
+ {
+ @Override
+ public void focusLost(FocusEvent e)
+ {
+ valueField_actionPerformed();
+ valueChanged(slider.getValue());
+ }
+ });
+
label.setFont(new java.awt.Font("Verdana", 0, 11));
label.setText(MessageManager.getString("label.set_this_label_text"));
jPanel1.setLayout(borderLayout1);
{
}
+ @Override
public void mousePressed(MouseEvent evt)
{
}
+ @Override
public void mouseReleased(MouseEvent evt)
{
ap.paintAlignment(true);
}
+ @Override
public void mouseClicked(MouseEvent evt)
{
}
+ @Override
public void mouseEntered(MouseEvent evt)
{
}
+ @Override
public void mouseExited(MouseEvent evt)
{
}
}
else
{
- cs = ColourSchemeProperty.getColour(sg, ColourSchemeProperty
- .getColourName(av.getGlobalColourScheme()));
+ cs = ColourSchemeProperty.getColourScheme(sg,
+ ColourSchemeProperty.getColourName(av
+ .getGlobalColourScheme()));
}
// cs is null if shading is an annotationColourGradient
- if (cs != null)
- {
- cs.setThreshold(av.getGlobalColourScheme().getThreshold(),
- av.isIgnoreGapsConsensus());
- }
+ // if (cs != null)
+ // {
+ // cs.setThreshold(av.getViewportColourScheme().getThreshold(),
+ // av.isIgnoreGapsConsensus());
+ // }
}
// TODO: cs used to be initialized with a sequence collection and
// recalcConservation called automatically
// instead we set it manually - recalc called after updateAnnotation
- sg.cs = cs;
+ sg.setColourScheme(cs);
+ sg.getGroupColourScheme().setThreshold(
+ av.getResidueShading().getThreshold(),
+ av.isIgnoreGapsConsensus());
sg.setName("JTreeGroup:" + sg.hashCode());
sg.setIdColour(col);
if (av.getGlobalColourScheme() != null
- && av.getGlobalColourScheme().conservationApplied())
+ && av.getResidueShading().conservationApplied())
{
Conservation c = new Conservation("Group", sg.getSequences(null),
sg.getStartRes(), sg.getEndRes());
c.calculate();
c.verdict(false, av.getConsPercGaps());
- cs.setConservation(c);
-
- sg.cs = cs;
+ sg.setColourScheme(cs);
+ sg.getGroupColourScheme().setConservation(c);
}
av.getAlignment().addGroup(sg);
import jalview.api.FeatureColourI;
import jalview.datamodel.SequenceGroup;
+import jalview.renderer.ResidueShader;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.FeatureColour;
import jalview.schemes.ResidueProperties;
if (seqGroup != null)
{
- oldColourScheme = seqGroup.cs;
+ oldColourScheme = seqGroup.getColourScheme();
}
else
{
{
final Button button = new Button();
Color col = Color.white;
- if (oldColourScheme != null)
+ if (oldColourScheme != null && oldColourScheme.isSimple())
{
- try
- {
- col = oldColourScheme.findColour(aa.charAt(0), -1, null);
- } catch (Exception ex)
- {
- }
+ col = oldColourScheme.findColour(aa.charAt(0), 0, null, null, 0f);
}
button.setBackground(col);
oldColours.addElement(col);
}
UserColourScheme ucs = new UserColourScheme(newColours);
- if (ap != null)
- {
- ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
- }
+ // if (ap != null)
+ // {
+ // ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
+ // }
if (ap != null)
{
if (seqGroup != null)
{
- seqGroup.cs = ucs;
+ seqGroup.cs = new ResidueShader(ucs);
+ seqGroup.getGroupColourScheme().setThreshold(0,
+ ap.av.isIgnoreGapsConsensus());
}
else
{
ap.av.setGlobalColourScheme(ucs);
+ ap.av.getResidueShading().setThreshold(0,
+ ap.av.isIgnoreGapsConsensus());
}
ap.seqPanel.seqCanvas.img = null;
ap.paintAlignment(true);
{
if (seqGroup != null)
{
- seqGroup.cs = ucs;
+ seqGroup.cs = new ResidueShader(ucs);
}
else
{
package jalview.bin;
import jalview.datamodel.PDBEntry;
+import jalview.gui.UserDefinedColours;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.UserColourScheme;
import jalview.structure.StructureImportSettings;
+import jalview.urls.IdOrgSettings;
+import jalview.util.ColorUtils;
import jalview.ws.dbsources.das.api.DasSourceRegistryI;
import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
import jalview.ws.sifts.SiftsSettings;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Properties;
+import java.util.StringTokenizer;
import java.util.TreeSet;
import org.apache.log4j.ConsoleAppender;
* <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
* <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
* $SEQUENCE_ID$</li>
+ * <li>STORED_LINKS list of name|url pairs which user has entered but are not
+ * currently used
+ * <li>DEFAULT_LINK name of single url to be used when user double clicks a
+ * sequence id (must be in SEQUENCE_LINKS or STORED_LINKS)
* <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
* jalview.utils.GroupURLLink for more info</li>
* <li>DAS_REGISTRY_URL the registry to query</li>
* <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
* display</li>
* <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
+ * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
+ * </li>
*
* </ul>
* Deprecated settings:
public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
+ /**
+ * Sifts settings
+ */
public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
.getProperty("user.home")
+ File.separatorChar
private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
/**
+ * Identifiers.org download settings
+ */
+ private static final String ID_ORG_FILE = System.getProperty("user.home")
+ + File.separatorChar + ".identifiers.org.ids.json";
+
+ /**
* Allowed values are PDB or mmCIF
*/
private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF
"sifts_cache_threshold_in_days",
DEFAULT_CACHE_THRESHOLD_IN_DAYS));
+ IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
+ "http://www.jalview.org/services/identifiers"));
+ IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
+
System.out
.println("Jalview Version: " + codeVersion + codeInstallation);
setProperty("VERSION", codeVersion);
// LOAD USERDEFINED COLOURS
- jalview.gui.UserDefinedColours
+ jalview.bin.Cache
.initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
false);
{
return defcolour;
}
- Color col = jalview.schemes.ColourSchemeProperty
- .getAWTColorFromName(colprop);
+ Color col = ColorUtils.parseColourString(colprop);
if (col == null)
{
- try
- {
- col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
- } catch (Exception ex)
- {
- log.warn("Couldn't parse '" + colprop + "' as a colour for "
- + property);
- col = null;
- }
+ log.warn("Couldn't parse '" + colprop + "' as a colour for "
+ + property);
}
return (col == null) ? defcolour : col;
}
Cache.applicationProperties.setProperty(propName, value);
}
}
+
+ /**
+ * Loads in user colour schemes from files.
+ *
+ * @param files
+ * a '|'-delimited list of file paths
+ */
+ public static void initUserColourSchemes(String files)
+ {
+ if (files == null || files.length() == 0)
+ {
+ return;
+ }
+
+ // In case colours can't be loaded, we'll remove them
+ // from the default list here.
+ StringBuffer coloursFound = new StringBuffer();
+ StringTokenizer st = new StringTokenizer(files, "|");
+ while (st.hasMoreElements())
+ {
+ String file = st.nextToken();
+ try
+ {
+ UserColourScheme ucs = ColourSchemes.loadColourScheme(file);
+ if (ucs != null)
+ {
+ if (coloursFound.length() > 0)
+ {
+ coloursFound.append("|");
+ }
+ coloursFound.append(file);
+ ColourSchemes.getInstance().registerColourScheme(ucs);
+ }
+ } catch (Exception ex)
+ {
+ System.out.println("Error loading User ColourFile\n" + ex);
+ }
+ }
+ if (!files.equals(coloursFound.toString()))
+ {
+ if (coloursFound.toString().length() > 1)
+ {
+ setProperty(UserDefinedColours.USER_DEFINED_COLOURS, coloursFound.toString());
+ }
+ else
+ {
+ applicationProperties.remove(UserDefinedColours.USER_DEFINED_COLOURS);
+ }
+ }
+ }
}
import jalview.io.gff.SequenceOntologyFactory;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.ws.jws2.Jws2Discoverer;
{
data.replaceAll("%20", " ");
- ColourSchemeI cs = ColourSchemeProperty.getColour(af
+ ColourSchemeI cs = ColourSchemeProperty.getColourScheme(af
.getViewport().getAlignment(), data);
- if (cs == null)
- {
- UserColourScheme ucs = new UserColourScheme("white");
- ucs.parseAppletParameter(data);
- cs = ucs;
- }
- else
+ if (cs != null)
{
System.out.println("CMD [-color " + data
+ "] executed successfully!");
import jalview.javascript.MouseOverStructureListener;
import jalview.structure.SelectionListener;
import jalview.structure.StructureSelectionManager;
+import jalview.util.ColorUtils;
import jalview.util.HttpUtils;
import jalview.util.MessageManager;
{
return defcolour;
}
- Color col = jalview.schemes.ColourSchemeProperty
- .getAWTColorFromName(colprop);
+ Color col = ColorUtils.parseColourString(colprop);
if (col == null)
{
- try
- {
- col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
- } catch (Exception ex)
- {
- System.err.println("Couldn't parse '" + colprop
- + "' as a colour for " + colparam);
- col = null;
- }
+ System.err.println("Couldn't parse '" + colprop
+ + "' as a colour for " + colparam);
}
return (col == null) ? defcolour : col;
-
}
public void openJalviewHelpUrl()
protected char gapCharacter = '-';
- protected int type = NUCLEOTIDE;
-
- public static final int PROTEIN = 0;
-
- public static final int NUCLEOTIDE = 1;
+ private boolean nucleotide = true;
public boolean hasRNAStructure = false;
hiddenSequences = new HiddenSequences(this);
codonFrameList = new ArrayList<AlignedCodonFrame>();
- if (Comparison.isNucleotide(seqs))
- {
- type = NUCLEOTIDE;
- }
- else
- {
- type = PROTEIN;
- }
+ nucleotide = Comparison.isNucleotide(seqs);
sequences = Collections.synchronizedList(new ArrayList<SequenceI>());
}
/**
- * Adds a sequence to the alignment. Recalculates maxLength and size.
+ * Adds a sequence to the alignment. Recalculates maxLength and size. Note
+ * this currently does not recalculate whether or not the alignment is
+ * nucleotide, so mixed alignments may have undefined behaviour.
*
* @param snew
*/
}
@Override
- public void setNucleotide(boolean b)
- {
- if (b)
- {
- type = NUCLEOTIDE;
- }
- else
- {
- type = PROTEIN;
- }
- }
-
- @Override
public boolean isNucleotide()
{
- if (type == NUCLEOTIDE)
- {
- return true;
- }
- else
- {
- return false;
- }
+ return nucleotide;
}
@Override
String calcId, boolean autoCalc, SequenceI seqRef,
SequenceGroup groupRef)
{
- assert (name != null);
if (annotations != null)
{
for (AlignmentAnnotation annot : getAlignmentAnnotation())
@Override
public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
{
- ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
- for (AlignmentAnnotation a : getAlignmentAnnotation())
+ List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ AlignmentAnnotation[] alignmentAnnotation = getAlignmentAnnotation();
+ if (alignmentAnnotation != null)
{
- if (a.getCalcId() == calcId
- || (a.getCalcId() != null && calcId != null && a.getCalcId()
- .equals(calcId)))
+ for (AlignmentAnnotation a : alignmentAnnotation)
{
- aa.add(a);
+ if (a.getCalcId() == calcId
+ || (a.getCalcId() != null && calcId != null && a
+ .getCalcId().equals(calcId)))
+ {
+ aa.add(a);
+ }
}
}
return aa;
/**
* Returns the first group (in the order in which groups were added) that
- * includes the given sequence and aligned position (base 0), or null if none
- * found
+ * includes the given sequence instance and aligned position (base 0), or null
+ * if none found
*
* @param seq
+ * - must be contained in the alignment (not a dataset sequence)
* @param position
*
* @return
char getGapCharacter();
/**
- * Test for all nucleotide alignment
- *
- * @return true if alignment is nucleotide sequence
- */
- boolean isNucleotide();
-
- /**
* Test if alignment contains RNA structure
*
* @return true if RNA structure AligmnentAnnotation was added to alignment
boolean hasRNAStructure();
/**
- * Set alignment to be a nucleotide sequence
- *
- */
- void setNucleotide(boolean b);
-
- /**
* Get the associated dataset for the alignment.
*
* @return Alignment containing dataset sequences or null of this is a
*/
AlignmentAnnotation[] getAlignmentAnnotation();
+ /**
+ * Returns a list of annotations matching the given calc id, or an empty list
+ * if calcId is null
+ *
+ * @param calcId
+ * @return
+ */
Iterable<AlignmentAnnotation> findAnnotation(String calcId);
Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
{
int nores = (isNa) ? ResidueProperties.maxNucleotideIndex
: ResidueProperties.maxProteinIndex;
- // Set all matrix to 0
+
dbinary = new double[getSequence().length * nores];
- for (int i = 0; i < dbinary.length; i++)
- {
- dbinary[i] = 0.0;
- }
return nores;
}
private void matrixEncode(final int[] aaIndex, final int[][] matrix)
{
- // Set all matrix to 0
- // dbinary = new double[getSequence().length * 21];
-
int nores = initMatrixGetNoRes();
- // for (int i = 0; i < dbinary.length; i++) {
- // dbinary[i] = 0.0;
- // }
for (int i = 0, iSize = getSequence().length; i < iSize; i++)
{
int aanum = nores - 1;
return changed;
}
+ /**
+ * Adjusts column selections, and the given selection group, to match the
+ * range of a stretch (e.g. mouse drag) operation
+ * <p>
+ * Method refactored from ScalePanel.mouseDragged
+ *
+ * @param res
+ * current column position, adjusted for hidden columns
+ * @param sg
+ * current selection group
+ * @param min
+ * start position of the stretch group
+ * @param max
+ * end position of the stretch group
+ */
+ public void stretchGroup(int res, SequenceGroup sg, int min, int max)
+ {
+ if (!contains(res))
+ {
+ addElement(res);
+ }
+
+ if (res > sg.getStartRes())
+ {
+ // expand selection group to the right
+ sg.setEndRes(res);
+ }
+ if (res < sg.getStartRes())
+ {
+ // expand selection group to the left
+ sg.setStartRes(res);
+ }
+
+ /*
+ * expand or shrink column selection to match the
+ * range of the drag operation
+ */
+ for (int col = min; col <= max; col++)
+ {
+ if (col < sg.getStartRes() || col > sg.getEndRes())
+ {
+ // shrinking drag - remove from selection
+ removeElement(col);
+ }
+ else
+ {
+ // expanding drag - add to selection
+ addElement(col);
+ }
+ }
+ }
}
*/
int getEndRes();
+ /**
+ * Answers true if sequence data is nucleotide (according to some heuristic)
+ *
+ * @return
+ */
+ boolean isNucleotide();
}
import jalview.analysis.AAFrequency;
import jalview.analysis.Conservation;
+import jalview.renderer.ResidueShader;
+import jalview.renderer.ResidueShaderI;
import jalview.schemes.ColourSchemeI;
import java.awt.Color;
/**
* Colourscheme applied to group if any
*/
- public ColourSchemeI cs;
+ public ResidueShaderI cs;
// start column (base 0)
int startRes = 0;
public SequenceGroup()
{
groupName = "JGroup:" + this.hashCode();
+ cs = new ResidueShader();
}
/**
ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
boolean colourText, int start, int end)
{
+ this();
this.sequences = sequences;
this.groupName = groupName;
this.displayBoxes = displayBoxes;
this.displayText = displayText;
this.colourText = colourText;
- this.cs = scheme;
+ this.cs = new ResidueShader(scheme);
startRes = start;
endRes = end;
recalcConservation();
*/
public SequenceGroup(SequenceGroup seqsel)
{
+ this();
if (seqsel != null)
{
sequences = new ArrayList<SequenceI>();
@Override
public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
{
- ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+ if (calcId == null)
+ {
+ return aa;
+ }
for (AlignmentAnnotation a : getAlignmentAnnotation())
{
- if (a.getCalcId() == calcId)
+ if (calcId.equals(a.getCalcId()))
{
aa.add(a);
}
private AnnotatedCollectionI context;
/**
- * set the alignment or group context for this group
+ * Sets the alignment or group context for this group
*
- * @param context
+ * @param ctx
+ * @throws IllegalArgumentException
+ * if setting the context would result in a circular reference chain
*/
- public void setContext(AnnotatedCollectionI context)
+ public void setContext(AnnotatedCollectionI ctx)
{
- this.context = context;
+ AnnotatedCollectionI ref = ctx;
+ while (ref != null)
+ {
+ if (ref == this)
+ {
+ throw new IllegalArgumentException(
+ "Circular reference in SequenceGroup.context");
+ }
+ ref = ref.getContext();
+ }
+ this.context = ctx;
}
/*
{
return context;
}
+
+ public void setColourScheme(ColourSchemeI scheme)
+ {
+ if (cs == null)
+ {
+ cs = new ResidueShader();
+ }
+ cs.setColourScheme(scheme);
+ }
+
+ public void setGroupColourScheme(ResidueShaderI scheme)
+ {
+ cs = scheme;
+ }
+
+ public ColourSchemeI getColourScheme()
+ {
+ return cs == null ? null : cs.getColourScheme();
+ }
+
+ public ResidueShaderI getGroupColourScheme()
+ {
+ return cs;
+ }
+
+ @Override
+ public boolean isNucleotide()
+ {
+ if (context != null) {
+ return context.isNucleotide();
+ }
+ return false;
+ }
+
+ /**
+ * @param seq
+ * @return true if seq is a member of the group
+ */
+
+ public boolean contains(SequenceI seq1)
+ {
+ return sequences.contains(seq1);
+ }
+
+ /**
+ * @param seq
+ * @param apos
+ * @return true if startRes<=apos and endRes>=apos and seq is in the group
+ */
+ public boolean contains(SequenceI seq, int apos)
+ {
+ return (startRes <= apos && endRes >= apos) && sequences.contains(seq);
+ }
}
/*
* Copied to Jalview September 2016.
* Only the members of this class required for SparseIntArray were copied.
- * Method binarySearch(short[] array, int size, short value) added to support
+ * Change Log:
+ * Sep 2016: Method binarySearch(short[] array, int size, short value) added to support
* SparseShortArray.
+ * Jan 2017: EMPTY_DOUBLES added
*/
class ContainerHelpers
{
static final int[] EMPTY_INTS = new int[0];
+ static final double[] EMPTY_DOUBLES = new double[0];
+
static final long[] EMPTY_LONGS = new long[0];
static final Object[] EMPTY_OBJECTS = new Object[0];
--- /dev/null
+package jalview.ext.android;
+
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * SparseDoubleArray map integers to doubles. Unlike a normal array of integers,
+ * there can be gaps in the indices. It is intended to be more memory efficient
+ * than using a HashMap to map Integer to Double, both because it avoids
+ * auto-boxing keys and values and its data structure doesn't rely on an extra
+ * entry object for each mapping.
+ *
+ * <p>
+ * Note that this container keeps its mappings in an array data structure, using
+ * a binary search to find keys. The implementation is not intended to be
+ * appropriate for data structures that may contain large numbers of items. It
+ * is generally slower than a traditional HashMap, since lookups require a
+ * binary search and adds and removes require inserting and deleting entries in
+ * the array. For containers holding up to hundreds of items, the performance
+ * difference is not significant, less than 50%.
+ * </p>
+ *
+ * <p>
+ * It is possible to iterate over the items in this container using
+ * {@link #keyAt(int)} and {@link #valueAt(int)}. Iterating over the keys using
+ * <code>keyAt(int)</code> with ascending values of the index will return the
+ * keys in ascending order, or the values corresponding to the keys in ascending
+ * order in the case of <code>valueAt(int)<code>.
+ * </p>
+ */
+
+/*
+ * Change log:
+ * Jan 2017 cloned from SparseIntArray for Jalview to support SparseMatrix
+ * - SparseDoubleArray(double[]) constructor added
+ * - multiply() added for more efficient multiply (or divide) of a value
+ */
+public class SparseDoubleArray implements Cloneable
+{
+ private int[] mKeys;
+
+ private double[] mValues;
+
+ private int mSize;
+
+ /**
+ * Creates a new SparseDoubleArray containing no mappings.
+ */
+ public SparseDoubleArray()
+ {
+ this(10);
+ }
+
+ /**
+ * Creates a new SparseDoubleArray containing no mappings that will not
+ * require any additional memory allocation to store the specified number of
+ * mappings. If you supply an initial capacity of 0, the sparse array will be
+ * initialized with a light-weight representation not requiring any additional
+ * array allocations.
+ */
+ public SparseDoubleArray(int initialCapacity)
+ {
+ if (initialCapacity == 0)
+ {
+ mKeys = ContainerHelpers.EMPTY_INTS;
+ mValues = ContainerHelpers.EMPTY_DOUBLES;
+ }
+ else
+ {
+ initialCapacity = idealDoubleArraySize(initialCapacity);
+ mKeys = new int[initialCapacity];
+ mValues = new double[initialCapacity];
+ }
+ mSize = 0;
+ }
+
+ /**
+ * Constructor given an array of double values; stores the non-zero values
+ *
+ * @param row
+ */
+ public SparseDoubleArray(double[] row)
+ {
+ this();
+ for (int i = 0; i < row.length; i++)
+ {
+ if (row[i] != 0d)
+ {
+ put(i, row[i]);
+ }
+ }
+ }
+
+ @Override
+ public SparseDoubleArray clone()
+ {
+ SparseDoubleArray clone = null;
+ try
+ {
+ clone = (SparseDoubleArray) super.clone();
+ clone.mKeys = mKeys.clone();
+ clone.mValues = mValues.clone();
+ } catch (CloneNotSupportedException cnse)
+ {
+ /* ignore */
+ }
+ return clone;
+ }
+
+ /**
+ * Gets the value mapped from the specified key, or <code>0</code> if no such
+ * mapping has been made.
+ */
+ public double get(int key)
+ {
+ return get(key, 0d);
+ }
+
+ /**
+ * Gets the int mapped from the specified key, or the specified value if no
+ * such mapping has been made.
+ */
+ public double get(int key, double valueIfKeyNotFound)
+ {
+ int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
+ if (i < 0)
+ {
+ return valueIfKeyNotFound;
+ }
+ else
+ {
+ return mValues[i];
+ }
+ }
+
+ /**
+ * Removes the mapping from the specified key, if there was any.
+ */
+ public void delete(int key)
+ {
+ int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
+ if (i >= 0)
+ {
+ removeAt(i);
+ }
+ }
+
+ /**
+ * Removes the mapping at the given index.
+ */
+ public void removeAt(int index)
+ {
+ System.arraycopy(mKeys, index + 1, mKeys, index, mSize - (index + 1));
+ System.arraycopy(mValues, index + 1, mValues, index, mSize
+ - (index + 1));
+ mSize--;
+ }
+
+ /**
+ * Adds a mapping from the specified key to the specified value, replacing the
+ * previous mapping from the specified key if there was one.
+ */
+ public void put(int key, double value)
+ {
+ int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
+ if (i >= 0)
+ {
+ mValues[i] = value;
+ }
+ else
+ {
+ i = ~i;
+ if (mSize >= mKeys.length)
+ {
+ int n = idealDoubleArraySize(mSize + 1);
+ int[] nkeys = new int[n];
+ double[] nvalues = new double[n];
+ // Log.e("SparseDoubleArray", "grow " + mKeys.length + " to " + n);
+ System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
+ System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
+ mKeys = nkeys;
+ mValues = nvalues;
+ }
+ if (mSize - i != 0)
+ {
+ // Log.e("SparseDoubleArray", "move " + (mSize - i));
+ System.arraycopy(mKeys, i, mKeys, i + 1, mSize - i);
+ System.arraycopy(mValues, i, mValues, i + 1, mSize - i);
+ }
+ mKeys[i] = key;
+ mValues[i] = value;
+ mSize++;
+ }
+ }
+
+ /**
+ * Returns the number of key-value mappings that this SparseDoubleArray
+ * currently stores.
+ */
+ public int size()
+ {
+ return mSize;
+ }
+
+ /**
+ * Given an index in the range <code>0...size()-1</code>, returns the key from
+ * the <code>index</code>th key-value mapping that this SparseDoubleArray
+ * stores.
+ *
+ * <p>
+ * The keys corresponding to indices in ascending order are guaranteed to be
+ * in ascending order, e.g., <code>keyAt(0)</code> will return the smallest
+ * key and <code>keyAt(size()-1)</code> will return the largest key.
+ * </p>
+ */
+ public int keyAt(int index)
+ {
+ return mKeys[index];
+ }
+
+ /**
+ * Given an index in the range <code>0...size()-1</code>, returns the value
+ * from the <code>index</code>th key-value mapping that this SparseDoubleArray
+ * stores.
+ *
+ * <p>
+ * The values corresponding to indices in ascending order are guaranteed to be
+ * associated with keys in ascending order, e.g., <code>valueAt(0)</code> will
+ * return the value associated with the smallest key and
+ * <code>valueAt(size()-1)</code> will return the value associated with the
+ * largest key.
+ * </p>
+ */
+ public double valueAt(int index)
+ {
+ return mValues[index];
+ }
+
+ /**
+ * Returns the index for which {@link #keyAt} would return the specified key,
+ * or a negative number if the specified key is not mapped.
+ */
+ public int indexOfKey(int key)
+ {
+ return ContainerHelpers.binarySearch(mKeys, mSize, key);
+ }
+
+ /**
+ * Returns an index for which {@link #valueAt} would return the specified key,
+ * or a negative number if no keys map to the specified value. Beware that
+ * this is a linear search, unlike lookups by key, and that multiple keys can
+ * map to the same value and this will find only one of them.
+ */
+ public int indexOfValue(double value)
+ {
+ for (int i = 0; i < mSize; i++)
+ {
+ if (mValues[i] == value)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Removes all key-value mappings from this SparseDoubleArray.
+ */
+ public void clear()
+ {
+ mSize = 0;
+ }
+
+ /**
+ * Puts a key/value pair into the array, optimizing for the case where the key
+ * is greater than all existing keys in the array.
+ */
+ public void append(int key, double value)
+ {
+ if (mSize != 0 && key <= mKeys[mSize - 1])
+ {
+ put(key, value);
+ return;
+ }
+ int pos = mSize;
+ if (pos >= mKeys.length)
+ {
+ int n = idealDoubleArraySize(pos + 1);
+ int[] nkeys = new int[n];
+ double[] nvalues = new double[n];
+ // Log.e("SparseDoubleArray", "grow " + mKeys.length + " to " + n);
+ System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
+ System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
+ mKeys = nkeys;
+ mValues = nvalues;
+ }
+ mKeys[pos] = key;
+ mValues[pos] = value;
+ mSize = pos + 1;
+ }
+
+ /**
+ * Created by analogy with
+ * com.android.internal.util.ArrayUtils#idealLongArraySize
+ *
+ * @param i
+ * @return
+ */
+ public static int idealDoubleArraySize(int need)
+ {
+ return idealByteArraySize(need * 8) / 8;
+ }
+
+ /**
+ * Inlined here by copying from com.android.internal.util.ArrayUtils
+ *
+ * @param i
+ * @return
+ */
+ public static int idealByteArraySize(int need)
+ {
+ for (int i = 4; i < 32; i++)
+ {
+ if (need <= (1 << i) - 12)
+ {
+ return (1 << i) - 12;
+ }
+ }
+
+ return need;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * <p>
+ * This implementation composes a string by iterating over its mappings.
+ */
+ @Override
+ public String toString()
+ {
+ if (size() <= 0)
+ {
+ return "{}";
+ }
+ StringBuilder buffer = new StringBuilder(mSize * 28);
+ buffer.append('{');
+ for (int i = 0; i < mSize; i++)
+ {
+ if (i > 0)
+ {
+ buffer.append(", ");
+ }
+ int key = keyAt(i);
+ buffer.append(key);
+ buffer.append('=');
+ double value = valueAt(i);
+ buffer.append(value);
+ }
+ buffer.append('}');
+ return buffer.toString();
+ }
+
+ /**
+ * Method (copied from put) added for Jalview to efficiently increment a key's
+ * value if present, else add it with the given value. This avoids a double
+ * binary search (once to get the value, again to put the updated value).
+ *
+ * @param key
+ * @oparam toAdd
+ * @return the new value for the key
+ */
+ public double add(int key, double toAdd)
+ {
+ double newValue = toAdd;
+ int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
+ if (i >= 0)
+ {
+ mValues[i] += toAdd;
+ newValue = mValues[i];
+ }
+ else
+ {
+ i = ~i;
+ if (mSize >= mKeys.length)
+ {
+ int n = idealDoubleArraySize(mSize + 1);
+ int[] nkeys = new int[n];
+ double[] nvalues = new double[n];
+ System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
+ System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
+ mKeys = nkeys;
+ mValues = nvalues;
+ }
+ if (mSize - i != 0)
+ {
+ System.arraycopy(mKeys, i, mKeys, i + 1, mSize - i);
+ System.arraycopy(mValues, i, mValues, i + 1, mSize - i);
+ }
+ mKeys[i] = key;
+ mValues[i] = toAdd;
+ mSize++;
+ }
+ return newValue;
+ }
+
+ /**
+ * Method added for Jalview to efficiently multiply a key's value if present,
+ * else do nothing. This avoids a double binary search (once to get the value,
+ * again to put the updated value).
+ *
+ * @param key
+ * @oparam toAdd
+ * @return the new value for the key
+ */
+ public double divide(int key, double divisor)
+ {
+ double newValue = 0d;
+ if (divisor == 0d)
+ {
+ return newValue;
+ }
+ int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
+ if (i >= 0)
+ {
+ mValues[i] /= divisor;
+ newValue = mValues[i];
+ }
+ return newValue;
+ }
+}
*/
package jalview.ext.jmol;
-import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
import jalview.datamodel.AlignmentI;
Hashtable<String, String> chainFile;
- public String fileLoadingError;
-
/*
* the default or current model displayed if the model cannot be identified
* from the selection message
releaseUIResources();
}
+ @Override
public void colourByChain()
{
colourBySequence = false;
evalStateCommand("select *;color chain");
}
+ @Override
public void colourByCharge()
{
colourBySequence = false;
* @param _hiddenCols
* an array of corresponding hidden columns for each alignment
*/
+ @Override
public void superposeStructures(AlignmentI[] _alignment,
int[] _refStructure, ColumnSelection[] _hiddenCols)
{
}
/**
- * colour any structures associated with sequences in the given alignment
- * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
- * if colourBySequence is enabled.
+ * Sends a set of colour commands to the structure viewer
+ *
+ * @param colourBySequenceCommands
*/
- public void colourBySequence(AlignmentViewPanel alignmentv)
+ @Override
+ protected void colourBySequence(
+ StructureMappingcommandSet[] colourBySequenceCommands)
{
- boolean showFeatures = alignmentv.getAlignViewport()
- .isShowSequenceFeatures();
- if (!colourBySequence || !isLoadingFinished())
- {
- return;
- }
- if (getSsm() == null)
- {
- return;
- }
- String[] files = getPdbFile();
-
- SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
- FeatureRenderer fr = null;
- if (showFeatures)
- {
- fr = getFeatureRenderer(alignmentv);
- }
- AlignmentI alignment = alignmentv.getAlignment();
-
- for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
- files, sr, fr, alignment))
+ for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
{
for (String cbyseq : cpdbbyseq.commands)
{
* @param alignment
* @return
*/
+ @Override
protected StructureMappingcommandSet[] getColourBySequenceCommands(
String[] files, SequenceRenderer sr, FeatureRenderer fr,
AlignmentI alignment)
}
/**
- * returns the current featureRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract FeatureRenderer getFeatureRenderer(
- AlignmentViewPanel alignment);
-
- /**
* instruct the Jalview binding to update the pdbentries vector if necessary
* prior to matching the jmol view's contents to the list of structure files
* Jalview knows about.
return null;
}
- /**
- * returns the current sequenceRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract SequenceRenderer getSequenceRenderer(
- AlignmentViewPanel alignment);
+
// ///////////////////////////////
// JmolStatusListener
}
+ @Override
public void setJalviewColourScheme(ColourSchemeI cs)
{
colourBySequence = false;
command.append("select *;color white;");
List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
false);
- for (String res : residueSet)
+ for (String resName : residueSet)
{
- Color col = cs.findColour(res.charAt(0));
- command.append("select " + res + ";color[" + col.getRed() + ","
+ char res = resName.length() == 3 ? ResidueProperties
+ .getSingleCharacterCode(resName) : resName.charAt(0);
+ Color col = cs.findColour(res, 0, null, null, 0f);
+ command.append("select " + resName + ";color[" + col.getRed() + ","
+ col.getGreen() + "," + col.getBlue() + "];");
}
protected org.jmol.api.JmolAppConsoleInterface console = null;
+ @Override
public void setBackgroundColour(java.awt.Color col)
{
jmolHistory(false);
* @param alignment
* @return
*/
- public static StructureMappingcommandSet getColourBySequenceCommand(
+ public static StructureMappingcommandSet[] getColourBySequenceCommand(
StructureSelectionManager ssm, String[] files,
SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
AlignmentI alignment)
{
- Map<Object, AtomSpecModel> colourMap = buildColoursMap(
- ssm, files, sequence, sr, fr, alignment);
+ Map<Object, AtomSpecModel> colourMap = buildColoursMap(ssm, files,
+ sequence, sr, fr, alignment);
List<String> colourCommands = buildColourCommands(colourMap);
ChimeraCommands.class, null,
colourCommands.toArray(new String[colourCommands.size()]));
- return cs;
+ return new StructureMappingcommandSet[] { cs };
}
/**
}
sb.append("color ").append(colourCode).append(" ");
firstColour = false;
- final AtomSpecModel colourData = colourMap
- .get(colour);
+ final AtomSpecModel colourData = colourMap.get(colour);
sb.append(colourData.getAtomSpec());
}
commands.add(sb.toString());
{
if (startPos != -1)
{
- addRange(colourMap, lastColour, pdbfnum, startPos,
+ addColourRange(colourMap, lastColour, pdbfnum, startPos,
lastPos, lastChain);
}
startPos = pos;
// final colour range
if (lastColour != null)
{
- addRange(colourMap, lastColour, pdbfnum, startPos,
- lastPos, lastChain);
+ addColourRange(colourMap, lastColour, pdbfnum, startPos, lastPos,
+ lastChain);
}
// break;
}
* @param endPos
* @param chain
*/
- protected static void addRange(Map<Object, AtomSpecModel> map,
+ protected static void addColourRange(Map<Object, AtomSpecModel> map,
Object key, int model, int startPos, int endPos, String chain)
{
/*
{
return theMap;
}
-
+
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
}
for (int[] range : mappedRanges)
{
- addRange(featureValues, value, modelNumber, range[0], range[1],
+ addColourRange(featureValues, value, modelNumber, range[0], range[1],
mapping.getChain());
}
}
*/
private boolean loadingFinished = true;
- public String fileLoadingError;
-
/*
* Map of ChimeraModel objects keyed by PDB full local file name
*/
}
/**
- * Construct a title string for the viewer window based on the data Jalview
- * knows about
- *
- * @param verbose
- * @return
- */
- public String getViewerTitle(boolean verbose)
- {
- return getViewerTitle("Chimera", verbose);
- }
-
- /**
* Tells Chimera to display only the specified chains
*
* @param toshow
releaseUIResources();
}
+ @Override
public void colourByChain()
{
colourBySequence = false;
* <li>all others - white</li>
* </ul>
*/
+ @Override
public void colourByCharge()
{
colourBySequence = false;
* @param _hiddenCols
* an array of corresponding hidden columns for each alignment
*/
+ @Override
public void superposeStructures(AlignmentI[] _alignment,
int[] _refStructure, ColumnSelection[] _hiddenCols)
{
String progressMsg);
/**
- * colour any structures associated with sequences in the given alignment
- * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
- * if colourBySequence is enabled.
+ * Sends a set of colour commands to the structure viewer
+ *
+ * @param colourBySequenceCommands
*/
- public void colourBySequence(boolean showFeatures,
- jalview.api.AlignmentViewPanel alignmentv)
+ @Override
+ protected void colourBySequence(
+ StructureMappingcommandSet[] colourBySequenceCommands)
{
- if (!colourBySequence || !loadingFinished)
+ for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
{
- return;
- }
- if (getSsm() == null)
- {
- return;
- }
- String[] files = getPdbFile();
-
- SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
- FeatureRenderer fr = null;
- if (showFeatures)
- {
- fr = getFeatureRenderer(alignmentv);
+ for (String command : cpdbbyseq.commands)
+ {
+ sendAsynchronousCommand(command, COLOURING_CHIMERA);
+ }
}
- AlignmentI alignment = alignmentv.getAlignment();
+ }
- StructureMappingcommandSet colourBySequenceCommands = ChimeraCommands
- .getColourBySequenceCommand(getSsm(), files, getSequence(), sr,
- fr, alignment);
- for (String command : colourBySequenceCommands.commands)
- {
- sendAsynchronousCommand(command, COLOURING_CHIMERA);
- }
+ /**
+ * @param files
+ * @param sr
+ * @param fr
+ * @param alignment
+ * @return
+ */
+ @Override
+ protected StructureMappingcommandSet[] getColourBySequenceCommands(
+ String[] files, SequenceRenderer sr, FeatureRenderer fr,
+ AlignmentI alignment)
+ {
+ return ChimeraCommands.getColourBySequenceCommand(getSsm(), files,
+ getSequence(), sr, fr, alignment);
}
/**
// //////////////////////////
/**
- * returns the current featureRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract FeatureRenderer getFeatureRenderer(
- AlignmentViewPanel alignment);
-
- /**
* instruct the Jalview binding to update the pdbentries vector if necessary
* prior to matching the viewer's contents to the list of structure files
* Jalview knows about.
*/
public abstract void refreshPdbEntries();
+ /**
+ * map between index of model filename returned from getPdbFile and the first
+ * index of models from this file in the viewer. Note - this is not trimmed -
+ * use getPdbFile to get number of unique models.
+ */
+ private int _modelFileNameMap[];
+
+
// ////////////////////////////////
// /StructureListener
@Override
}
/**
- * returns the current sequenceRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract SequenceRenderer getSequenceRenderer(
- AlignmentViewPanel alignment);
-
- /**
* Construct and send a command to highlight zero, one or more atoms. We do
* this by sending an "rlabel" command to show the residue label at that
* position.
return loadNotifiesHandled;
}
+ @Override
public void setJalviewColourScheme(ColourSchemeI cs)
{
colourBySequence = false;
List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
false);
- for (String res : residueSet)
+ for (String resName : residueSet)
{
- Color col = cs.findColour(res.charAt(0));
+ char res = resName.length() == 3 ? ResidueProperties
+ .getSingleCharacterCode(resName) : resName.charAt(0);
+ Color col = cs.findColour(res, 0, null, null, 0f);
command.append("color " + col.getRed() / normalise + ","
+ col.getGreen() / normalise + "," + col.getBlue()
- / normalise + " ::" + res + ";");
+ / normalise + " ::" + resName + ";");
}
sendAsynchronousCommand(command.toString(), COLOURING_CHIMERA);
* .html
* @param col
*/
+ @Override
public void setBackgroundColour(Color col)
{
viewerCommandHistory(false);
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.gui.ColourMenuHelper.ColourChangeListener;
import jalview.gui.ViewSelectionMenu.ViewSetProvider;
import jalview.io.AlignmentProperties;
import jalview.io.AnnotationFile;
import jalview.io.NewickFile;
import jalview.io.TCoffeeScoreFile;
import jalview.jbgui.GAlignFrame;
-import jalview.schemes.Blosum62ColourScheme;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ClustalxColourScheme;
import jalview.schemes.ColourSchemeI;
-import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.NucleotideColourScheme;
-import jalview.schemes.PIDColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.RNAHelicesColourChooser;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.ResidueColourScheme;
import jalview.schemes.ResidueProperties;
-import jalview.schemes.StrandColourScheme;
import jalview.schemes.TCoffeeColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
import jalview.ws.DBRefFetcher;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
-import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
* @version $Revision$
*/
public class AlignFrame extends GAlignFrame implements DropTargetListener,
- IProgressIndicator, AlignViewControllerGuiI
+ IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
{
public static final int DEFAULT_WIDTH = 700;
alignPanel);
if (viewport.getAlignmentConservationAnnotation() == null)
{
- BLOSUM62Colour.setEnabled(false);
+ // BLOSUM62Colour.setEnabled(false);
conservationMenuItem.setEnabled(false);
modifyConservation.setEnabled(false);
// PIDColour.setEnabled(false);
sortPairwiseMenuItem_actionPerformed(null);
}
- if (Desktop.desktop != null)
- {
- this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
- addServiceListeners();
- setGUINucleotide(viewport.getAlignment().isNucleotide());
- }
-
this.alignPanel.av
.setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
setMenusFromViewport(viewport);
buildSortByAnnotationScoresMenu();
buildTreeMenu();
+ buildColourMenu();
+
+ if (Desktop.desktop != null)
+ {
+ this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
+ addServiceListeners();
+ setGUINucleotide();
+ }
if (viewport.getWrapAlignment())
{
/**
* Configure menu items that vary according to whether the alignment is
* nucleotide or protein
- *
- * @param nucleotide
*/
- public void setGUINucleotide(boolean nucleotide)
+ public void setGUINucleotide()
{
+ AlignmentI al = getViewport().getAlignment();
+ boolean nucleotide = al.isNucleotide();
+
showTranslation.setVisible(nucleotide);
showReverse.setVisible(nucleotide);
showReverseComplement.setVisible(nucleotide);
conservationMenuItem.setEnabled(!nucleotide);
- modifyConservation.setEnabled(!nucleotide);
+ modifyConservation.setEnabled(!nucleotide
+ && conservationMenuItem.isSelected());
showGroupConservation.setEnabled(!nucleotide);
- rnahelicesColour.setEnabled(nucleotide);
- nucleotideColour.setEnabled(nucleotide);
- purinePyrimidineColour.setEnabled(nucleotide);
- RNAInteractionColour.setEnabled(nucleotide);
+
showComplementMenuItem.setText(nucleotide ? MessageManager
.getString("label.protein") : MessageManager
.getString("label.nucleotide"));
- setColourSelected(jalview.bin.Cache.getDefault(
- nucleotide ? Preferences.DEFAULT_COLOUR_NUC
- : Preferences.DEFAULT_COLOUR_PROT, "None"));
}
/**
padGapsMenuitem.setSelected(av.isPadGaps());
colourTextMenuItem.setSelected(av.isShowColourText());
abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
+ modifyPID.setEnabled(abovePIDThreshold.isSelected());
conservationMenuItem.setSelected(av.getConservationSelected());
+ modifyConservation.setEnabled(conservationMenuItem.isSelected());
seqLimits.setSelected(av.getShowJVSuffix());
idRightAlign.setSelected(av.isRightAlignIds());
centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
showSequenceLogo.setSelected(av.isShowSequenceLogo());
normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
- setColourSelected(ColourSchemeProperty.getColourName(av
- .getGlobalColourScheme()));
+ ColourMenuHelper.setColourSelected(colourMenu,
+ av.getGlobalColourScheme());
showSeqFeatures.setSelected(av.isShowSequenceFeatures());
hiddenMarkers.setState(av.getShowHiddenMarkers());
autoCalculate.setSelected(av.autoCalculateConsensus);
sortByTree.setSelected(av.sortByTree);
listenToViewSelections.setSelected(av.followSelection);
- rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
- rnahelicesColour
- .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
showProducts.setEnabled(canShowProducts());
setGroovyEnabled(Desktop.getGroovyConsole() != null);
{
FileFormatI format = fileFormat;
cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
- .formatSequences(format,
- exportData.getAlignment(),
+ .formatSequences(format, exportData.getAlignment(),
exportData.getOmitHidden(),
exportData.getStartEndPostions(),
viewport.getColumnSelection()));
}
String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
- seqs,
- omitHidden, null);
+ seqs, omitHidden, null);
StringSelection ss = new StringSelection(output);
}
@Override
- public void textColour_actionPerformed(ActionEvent e)
+ public void textColour_actionPerformed()
{
new TextColourChooser().chooseColour(alignPanel, null);
}
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- protected void noColourmenuItem_actionPerformed(ActionEvent e)
- {
- changeColour(null);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void clustalColour_actionPerformed(ActionEvent e)
- {
- changeColour(new ClustalxColourScheme(viewport.getAlignment(),
- viewport.getHiddenRepSequences()));
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void zappoColour_actionPerformed(ActionEvent e)
- {
- changeColour(new ZappoColourScheme());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void taylorColour_actionPerformed(ActionEvent e)
- {
- changeColour(new TaylorColourScheme());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void hydrophobicityColour_actionPerformed(ActionEvent e)
- {
- changeColour(new HydrophobicColourScheme());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void helixColour_actionPerformed(ActionEvent e)
- {
- changeColour(new HelixColourScheme());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void strandColour_actionPerformed(ActionEvent e)
- {
- changeColour(new StrandColourScheme());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void turnColour_actionPerformed(ActionEvent e)
- {
- changeColour(new TurnColourScheme());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void buriedColour_actionPerformed(ActionEvent e)
- {
- changeColour(new BuriedColourScheme());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void nucleotideColour_actionPerformed(ActionEvent e)
- {
- changeColour(new NucleotideColourScheme());
- }
-
- @Override
- public void purinePyrimidineColour_actionPerformed(ActionEvent e)
- {
- changeColour(new PurinePyrimidineColourScheme());
- }
-
/*
- * public void covariationColour_actionPerformed(ActionEvent e) {
+ * public void covariationColour_actionPerformed() {
* changeColour(new
* CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
* ()[0])); }
*/
@Override
- public void annotationColour_actionPerformed(ActionEvent e)
+ public void annotationColour_actionPerformed()
{
new AnnotationColourChooser(viewport, alignPanel);
}
new AnnotationColumnChooser(viewport, alignPanel);
}
+ /**
+ * Action on the user checking or unchecking the option to apply the selected
+ * colour scheme to all groups. If unchecked, groups may have their own
+ * independent colour schemes.
+ *
+ * @param selected
+ */
@Override
- public void rnahelicesColour_actionPerformed(ActionEvent e)
+ public void applyToAllGroups_actionPerformed(boolean selected)
{
- new RNAHelicesColourChooser(viewport, alignPanel);
+ viewport.setColourAppliesToAllGroups(selected);
}
/**
- * DOCUMENT ME!
+ * Action on user selecting a colour from the colour menu
*
- * @param e
- * DOCUMENT ME!
+ * @param name
+ * the name (not the menu item label!) of the colour scheme
*/
@Override
- protected void applyToAllGroups_actionPerformed(ActionEvent e)
+ public void changeColour_actionPerformed(String name)
{
- viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
+ /*
+ * 'User Defined' opens a panel to configure or load a
+ * user-defined colour scheme
+ */
+ if (ResidueColourScheme.USER_DEFINED.equals(name))
+ {
+ new UserDefinedColours(alignPanel, null);
+ return;
+ }
+
+ /*
+ * otherwise set the chosen colour scheme (or null for 'None')
+ */
+ ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
+ viewport.getAlignment(), viewport.getHiddenRepSequences());
+ changeColour(cs);
}
/**
- * DOCUMENT ME!
+ * Actions on setting or changing the alignment colour scheme
*
* @param cs
- * DOCUMENT ME!
*/
@Override
public void changeColour(ColourSchemeI cs)
{
// TODO: pull up to controller method
-
if (cs != null)
{
- // Make sure viewport is up to date w.r.t. any sliders
- if (viewport.getAbovePIDThreshold())
- {
- int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
- "Background");
- viewport.setThreshold(threshold);
- }
-
- if (viewport.getConservationSelected())
- {
- cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
- cs, "Background"));
- }
- if (cs instanceof TCoffeeColourScheme)
- {
- tcoffeeColour.setEnabled(true);
- tcoffeeColour.setSelected(true);
- }
+ ColourMenuHelper.setColourSelected(colourMenu, cs.getSchemeName());
}
viewport.setGlobalColourScheme(cs);
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Show the PID threshold slider panel
*/
@Override
- protected void modifyPID_actionPerformed(ActionEvent e)
+ protected void modifyPID_actionPerformed()
{
- if (viewport.getAbovePIDThreshold()
- && viewport.getGlobalColourScheme() != null)
- {
- SliderPanel.setPIDSliderSource(alignPanel,
- viewport.getGlobalColourScheme(), "Background");
- SliderPanel.showPIDSlider();
- }
+ SliderPanel.setPIDSliderSource(alignPanel,
+ viewport.getResidueShading(), alignPanel.getViewName());
+ SliderPanel.showPIDSlider();
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Show the Conservation slider panel
*/
@Override
- protected void modifyConservation_actionPerformed(ActionEvent e)
+ protected void modifyConservation_actionPerformed()
{
- if (viewport.getConservationSelected()
- && viewport.getGlobalColourScheme() != null)
- {
- SliderPanel.setConservationSlider(alignPanel,
- viewport.getGlobalColourScheme(), "Background");
- SliderPanel.showConservationSlider();
- }
+ SliderPanel.setConservationSlider(alignPanel,
+ viewport.getResidueShading(), alignPanel.getViewName());
+ SliderPanel.showConservationSlider();
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Action on selecting or deselecting (Colour) By Conservation
*/
@Override
- protected void conservationMenuItem_actionPerformed(ActionEvent e)
+ public void conservationMenuItem_actionPerformed(boolean selected)
{
- viewport.setConservationSelected(conservationMenuItem.isSelected());
-
- viewport.setAbovePIDThreshold(false);
- abovePIDThreshold.setSelected(false);
+ modifyConservation.setEnabled(selected);
+ viewport.setConservationSelected(selected);
+ viewport.getResidueShading().setConservationApplied(selected);
changeColour(viewport.getGlobalColourScheme());
-
- modifyConservation_actionPerformed(null);
+ if (selected)
+ {
+ modifyConservation_actionPerformed();
+ }
+ else
+ {
+ SliderPanel.hideConservationSlider();
+ }
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Action on selecting or deselecting (Colour) Above PID Threshold
*/
@Override
- public void abovePIDThreshold_actionPerformed(ActionEvent e)
+ public void abovePIDThreshold_actionPerformed(boolean selected)
{
- viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
-
- conservationMenuItem.setSelected(false);
- viewport.setConservationSelected(false);
+ modifyPID.setEnabled(selected);
+ viewport.setAbovePIDThreshold(selected);
+ if (!selected)
+ {
+ viewport.getResidueShading().setThreshold(0,
+ viewport.isIgnoreGapsConsensus());
+ }
changeColour(viewport.getGlobalColourScheme());
-
- modifyPID_actionPerformed(null);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void userDefinedColour_actionPerformed(ActionEvent e)
- {
- if (e.getActionCommand().equals(
- MessageManager.getString("action.user_defined")))
+ if (selected)
{
- new UserDefinedColours(alignPanel, null);
+ modifyPID_actionPerformed();
}
else
{
- UserColourScheme udc = (UserColourScheme) UserDefinedColours
- .getUserColourSchemes().get(e.getActionCommand());
-
- changeColour(udc);
+ SliderPanel.hidePIDSlider();
}
}
- public void updateUserColourMenu()
- {
-
- Component[] menuItems = colourMenu.getMenuComponents();
- int iSize = menuItems.length;
- for (int i = 0; i < iSize; i++)
- {
- if (menuItems[i].getName() != null
- && menuItems[i].getName().equals("USER_DEFINED"))
- {
- colourMenu.remove(menuItems[i]);
- iSize--;
- }
- }
- if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
- {
- java.util.Enumeration userColours = jalview.gui.UserDefinedColours
- .getUserColourSchemes().keys();
-
- while (userColours.hasMoreElements())
- {
- final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
- userColours.nextElement().toString());
- radioItem.setName("USER_DEFINED");
- radioItem.addMouseListener(new MouseAdapter()
- {
- @Override
- public void mousePressed(MouseEvent evt)
- {
- if (evt.isPopupTrigger()) // Mac
- {
- offerRemoval(radioItem);
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent evt)
- {
- if (evt.isPopupTrigger()) // Windows
- {
- offerRemoval(radioItem);
- }
- }
-
- /**
- * @param radioItem
- */
- void offerRemoval(final JRadioButtonMenuItem radioItem)
- {
- radioItem.removeActionListener(radioItem.getActionListeners()[0]);
-
- int option = JvOptionPane.showInternalConfirmDialog(
- jalview.gui.Desktop.desktop, MessageManager
- .getString("label.remove_from_default_list"),
- MessageManager
- .getString("label.remove_user_defined_colour"),
- JvOptionPane.YES_NO_OPTION);
- if (option == JvOptionPane.YES_OPTION)
- {
- jalview.gui.UserDefinedColours
- .removeColourFromDefaults(radioItem.getText());
- colourMenu.remove(radioItem);
- }
- else
- {
- radioItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- userDefinedColour_actionPerformed(evt);
- }
- });
- }
- }
- });
- radioItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- userDefinedColour_actionPerformed(evt);
- }
- });
-
- colourMenu.insert(radioItem, 15);
- colours.add(radioItem);
- }
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void PIDColour_actionPerformed(ActionEvent e)
- {
- changeColour(new PIDColourScheme());
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- @Override
- public void BLOSUM62Colour_actionPerformed(ActionEvent e)
- {
- changeColour(new Blosum62ColourScheme());
- }
-
/**
* DOCUMENT ME!
*
}
}
- @Override
- protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
- {
- changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
- }
-
public TreePanel ShowNewickTree(NewickFile nf, String title)
{
return ShowNewickTree(nf, title, 600, 500, 4, 5);
{
if (tcf.annotateAlignment(viewport.getAlignment(), true))
{
- tcoffeeColour.setEnabled(true);
- tcoffeeColour.setSelected(true);
+ buildColourMenu();
changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
isAnnotation = true;
statusBar
}
if (FileFormat.Jnet.equals(format))
{
- JPredFile predictions = new JPredFile(
- file, sourceType);
+ JPredFile predictions = new JPredFile(file, sourceType);
new JnetAnnotationMaker();
JnetAnnotationMaker.add_annotation(predictions,
viewport.getAlignment(), 0, false);
}
/*
+ * 'focus' any colour slider that is open to the selected viewport
+ */
+ if (viewport.getConservationSelected())
+ {
+ SliderPanel.setConservationSlider(alignPanel,
+ viewport.getResidueShading(), alignPanel.getViewName());
+ }
+ else
+ {
+ SliderPanel.hideConservationSlider();
+ }
+ if (viewport.getAbovePIDThreshold())
+ {
+ SliderPanel.setPIDSliderSource(alignPanel,
+ viewport.getResidueShading(), alignPanel.getViewName());
+ }
+ else
+ {
+ SliderPanel.hidePIDSlider();
+ }
+
+ /*
* If there is a frame linked to this one in a SplitPane, switch it to the
* same view tab index. No infinite recursion of calls should happen, since
* tabSelectionChanged() should not get invoked on setting the selected
}
AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
.size()]));
- AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
+ GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
AlignFrame.DEFAULT_HEIGHT);
cdna.alignAs(alignment);
String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
true,
(actionEvent.getModifiers() & (ActionEvent.META_MASK | ActionEvent.CTRL_MASK)) != 0);
}
+
+ /**
+ * Rebuilds the Colour menu, including any user-defined colours which have
+ * been loaded either on startup or during the session
+ */
+ public void buildColourMenu()
+ {
+ colourMenu.removeAll();
+
+ colourMenu.add(applyToAllGroups);
+ colourMenu.add(textColour);
+ colourMenu.addSeparator();
+
+ ColourMenuHelper.addMenuItems(colourMenu, this,
+ viewport.getAlignment(), false);
+
+ colourMenu.addSeparator();
+ colourMenu.add(conservationMenuItem);
+ colourMenu.add(modifyConservation);
+ colourMenu.add(abovePIDThreshold);
+ colourMenu.add(modifyPID);
+ colourMenu.add(annotationColour);
+
+ ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
+ String schemeName = colourScheme == null ? null : colourScheme
+ .getSchemeName();
+
+ ColourMenuHelper.setColourSelected(colourMenu, schemeName);
+ }
}
class PrintThread extends Thread
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.renderer.ResidueShader;
+import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.ResidueColourScheme;
import jalview.schemes.UserColourScheme;
import jalview.structure.CommandListener;
import jalview.structure.SelectionSource;
import java.util.Vector;
import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
/**
* DOCUMENT ME!
initAutoAnnotation();
String colourProperty = alignment.isNucleotide() ? Preferences.DEFAULT_COLOUR_NUC
: Preferences.DEFAULT_COLOUR_PROT;
- String propertyValue = Cache.getProperty(colourProperty);
- if (propertyValue == null)
+ String schemeName = Cache.getProperty(colourProperty);
+ if (schemeName == null)
{
- // fall back on this property for backwards compatibility
- propertyValue = Cache.getProperty(Preferences.DEFAULT_COLOUR);
+ // only DEFAULT_COLOUR available in Jalview before 2.9
+ schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
+ ResidueColourScheme.NONE);
}
- if (propertyValue != null)
- {
- globalColourScheme = ColourSchemeProperty.getColour(alignment,
- propertyValue);
+ ColourSchemeI colourScheme = ColourSchemeProperty.getColourScheme(
+ alignment, schemeName);
+ residueShading = new ResidueShader(colourScheme);
- if (globalColourScheme instanceof UserColourScheme)
- {
- globalColourScheme = UserDefinedColours.loadDefaultColours();
- ((UserColourScheme) globalColourScheme).setThreshold(0,
- isIgnoreGapsConsensus());
- }
+ if (colourScheme instanceof UserColourScheme)
+ {
+ residueShading = new ResidueShader(
+ UserDefinedColours.loadDefaultColours());
+ residueShading.setThreshold(0, isIgnoreGapsConsensus());
+ }
- if (globalColourScheme != null)
- {
- globalColourScheme.setConsensus(hconsensus);
- }
+ if (residueShading != null)
+ {
+ residueShading.setConsensus(hconsensus);
}
}
super.setViewStyle(settingsForView);
setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
viewStyle.getFontSize()), false);
-
}
/**
oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- if (sg.cs != null)
+ if (sg.getColourScheme() != null)
{
- oldgroupColours.put(sg, sg.cs);
+ oldgroupColours.put(sg, sg.getColourScheme());
}
}
}
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- sg.cs = oldgroupColours.get(sg);
+ sg.setColourScheme(oldgroupColours.get(sg));
}
}
}
continue;
}
+ AnnotationColourGradient scheme = null;
if (currentColours.isSelected())
{
- sg.cs = new AnnotationColourGradient(currentAnn, sg.cs,
- selectedThresholdOption);
- ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
- .isSelected());
-
+ scheme = new AnnotationColourGradient(currentAnn,
+ sg.getColourScheme(), selectedThresholdOption);
}
else
{
- sg.cs = new AnnotationColourGradient(currentAnn,
+ scheme = new AnnotationColourGradient(currentAnn,
minColour.getBackground(), maxColour.getBackground(),
selectedThresholdOption);
- ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
- .isSelected());
}
-
+ scheme.setSeqAssociated(seqAssociated.isSelected());
+ sg.setColourScheme(scheme);
}
}
return false;
package jalview.gui;
import jalview.bin.Cache;
-import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.ZappoColourScheme;
import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.BrowserLauncher;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.ws.dbsources.Pdb;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
-import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
public class AppJmol extends StructureViewerBase
{
RenderPanel renderPanel;
- ViewSelectionMenu seqColourBy;
-
/**
*
* @param files
{
useAlignmentPanelForSuperposition(ap);
}
+ initMenus();
if (leaveColouringToJmol || !usetoColour)
{
jmb.setColourBySequence(false);
viewerColour.setSelected(false);
}
this.setBounds(bounds);
- initMenus();
setViewId(viewid);
// jalview.gui.Desktop.addInternalFrame(this, "Loading File",
// bounds.width,bounds.height);
}
});
initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
-
}
- private void initMenus()
+ @Override
+ protected void initMenus()
{
- seqColour.setSelected(jmb.isColourBySequence());
- viewerColour.setSelected(!jmb.isColourBySequence());
- if (_colourwith == null)
- {
- _colourwith = new Vector<AlignmentPanel>();
- }
- if (_alignwith == null)
- {
- _alignwith = new Vector<AlignmentPanel>();
- }
-
- seqColourBy = new ViewSelectionMenu(
- MessageManager.getString("label.colour_by"), this, _colourwith,
- new ItemListener()
- {
-
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- if (!seqColour.isSelected())
- {
- seqColour.doClick();
- }
- else
- {
- // update the jmol display now.
- seqColour_actionPerformed(null);
- }
- }
- });
- viewMenu.add(seqColourBy);
- final ItemListener handler;
- JMenu alpanels = new ViewSelectionMenu(
- MessageManager.getString("label.superpose_with"), this,
- _alignwith, handler = new ItemListener()
- {
-
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- alignStructs.setEnabled(_alignwith.size() > 0);
- alignStructs.setToolTipText(MessageManager
- .formatMessage(
- "label.align_structures_using_linked_alignment_views",
- new String[] { new Integer(_alignwith
- .size()).toString() }));
- }
- });
- handler.itemStateChanged(null);
- viewerActionMenu.add(alpanels);
- viewerActionMenu.addMenuListener(new MenuListener()
- {
-
- @Override
- public void menuSelected(MenuEvent e)
- {
- handler.itemStateChanged(null);
- }
-
- @Override
- public void menuDeselected(MenuEvent e)
- {
- // TODO Auto-generated method stub
+ super.initMenus();
- }
+ viewerActionMenu = new JMenu(MessageManager.getString("label.jmol"));
- @Override
- public void menuCanceled(MenuEvent e)
- {
- // TODO Auto-generated method stub
-
- }
- });
+ viewerColour
+ .setText(MessageManager.getString("label.colour_with_jmol"));
+ viewerColour.setToolTipText(MessageManager
+ .getString("label.let_jmol_manage_structure_colours"));
}
IProgressIndicator progressBar = null;
openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq });
}
- /**
- * Answers true if this viewer already involves the given PDB ID
- */
- @Override
- protected boolean hasPdbId(String pdbId)
- {
- return jmb.hasPdbId(pdbId);
- }
-
private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys,
SequenceI[][] seqs)
{
pdbentrys, seqs, null);
addAlignmentPanel(ap);
useAlignmentPanelForColourbyseq(ap);
+
if (pdbentrys.length > 1)
{
alignAddedStructures = true;
}
@Override
- public void pdbFile_actionPerformed(ActionEvent actionEvent)
- {
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
- chooser.setToolTipText(MessageManager.getString("action.save"));
-
- int value = chooser.showSaveDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- BufferedReader in = null;
- try
- {
- // TODO: cope with multiple PDB files in view
- in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
- File outFile = chooser.getSelectedFile();
-
- PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
- String data;
- while ((data = in.readLine()) != null)
- {
- if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
- {
- out.println(data);
- }
- }
- out.close();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- } finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- } catch (IOException e)
- {
- // ignore
- }
- }
- }
- }
- }
-
- @Override
- public void viewMapping_actionPerformed(ActionEvent actionEvent)
- {
- jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
- try
- {
- cap.appendText(jmb.printMappings());
- } catch (OutOfMemoryError e)
- {
- new OOMWarning(
- "composing sequence-structure alignments for display in text box.",
- e);
- cap.dispose();
- return;
- }
- jalview.gui.Desktop.addInternalFrame(cap,
- MessageManager.getString("label.pdb_sequence_mapping"), 550,
- 600);
- }
-
- @Override
public void eps_actionPerformed(ActionEvent e)
{
makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
}
@Override
- public void viewerColour_actionPerformed(ActionEvent actionEvent)
- {
- if (viewerColour.isSelected())
- {
- // disable automatic sequence colouring.
- jmb.setColourBySequence(false);
- }
- }
-
- @Override
- public void seqColour_actionPerformed(ActionEvent actionEvent)
- {
- jmb.setColourBySequence(seqColour.isSelected());
- if (_colourwith == null)
- {
- _colourwith = new Vector<AlignmentPanel>();
- }
- if (jmb.isColourBySequence())
- {
- if (!jmb.isLoadingFromArchive())
- {
- if (_colourwith.size() == 0 && getAlignmentPanel() != null)
- {
- // Make the currently displayed alignment panel the associated view
- _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
- }
- }
- // Set the colour using the current view for the associated alignframe
- for (AlignmentPanel ap : _colourwith)
- {
- jmb.colourBySequence(ap);
- }
- }
- }
-
- @Override
- public void chainColour_actionPerformed(ActionEvent actionEvent)
- {
- chainColour.setSelected(true);
- jmb.colourByChain();
- }
-
- @Override
- public void chargeColour_actionPerformed(ActionEvent actionEvent)
- {
- chargeColour.setSelected(true);
- jmb.colourByCharge();
- }
-
- @Override
- public void zappoColour_actionPerformed(ActionEvent actionEvent)
- {
- zappoColour.setSelected(true);
- jmb.setJalviewColourScheme(new ZappoColourScheme());
- }
-
- @Override
- public void taylorColour_actionPerformed(ActionEvent actionEvent)
- {
- taylorColour.setSelected(true);
- jmb.setJalviewColourScheme(new TaylorColourScheme());
- }
-
- @Override
- public void hydroColour_actionPerformed(ActionEvent actionEvent)
- {
- hydroColour.setSelected(true);
- jmb.setJalviewColourScheme(new HydrophobicColourScheme());
- }
-
- @Override
- public void helixColour_actionPerformed(ActionEvent actionEvent)
- {
- helixColour.setSelected(true);
- jmb.setJalviewColourScheme(new HelixColourScheme());
- }
-
- @Override
- public void strandColour_actionPerformed(ActionEvent actionEvent)
- {
- strandColour.setSelected(true);
- jmb.setJalviewColourScheme(new StrandColourScheme());
- }
-
- @Override
- public void turnColour_actionPerformed(ActionEvent actionEvent)
- {
- turnColour.setSelected(true);
- jmb.setJalviewColourScheme(new TurnColourScheme());
- }
-
- @Override
- public void buriedColour_actionPerformed(ActionEvent actionEvent)
- {
- buriedColour.setSelected(true);
- jmb.setJalviewColourScheme(new BuriedColourScheme());
- }
-
- @Override
- public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
- {
- setJalviewColourScheme(new PurinePyrimidineColourScheme());
- }
-
- @Override
- public void userColour_actionPerformed(ActionEvent actionEvent)
- {
- userColour.setSelected(true);
- new UserDefinedColours(this, null);
- }
-
- @Override
- public void backGround_actionPerformed(ActionEvent actionEvent)
- {
- java.awt.Color col = JColorChooser
- .showDialog(this, MessageManager
- .getString("label.select_backgroud_colour"), null);
- if (col != null)
- {
- jmb.setBackgroundColour(col);
- }
- }
-
- @Override
public void showHelp_actionPerformed(ActionEvent actionEvent)
{
try
{
- jalview.util.BrowserLauncher
+ BrowserLauncher
.openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
} catch (Exception ex)
{
{
getSize(currentSize);
- if (jmb != null && jmb.fileLoadingError != null)
+ if (jmb != null && jmb.hasFileLoadingError())
{
g.setColor(Color.black);
g.fillRect(0, 0, currentSize.width, currentSize.height);
}
}
- public void updateTitleAndMenus()
- {
- if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
- {
- repaint();
- return;
- }
- setChainMenuItems(jmb.getChainNames());
-
- this.setTitle(jmb.getViewerTitle());
- if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
- {
- viewerActionMenu.setVisible(true);
- }
- if (!jmb.isLoadingFromArchive())
- {
- seqColour_actionPerformed(null);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
- * .ActionEvent)
- */
- @Override
- protected void alignStructs_actionPerformed(ActionEvent actionEvent)
- {
- alignStructs_withAllAlignPanels();
- }
-
- private void alignStructs_withAllAlignPanels()
- {
- if (getAlignmentPanel() == null)
- {
- return;
- }
- ;
- if (_alignwith.size() == 0)
- {
- _alignwith.add(getAlignmentPanel());
- }
- ;
- try
- {
- AlignmentI[] als = new Alignment[_alignwith.size()];
- ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
- int[] alm = new int[_alignwith.size()];
- int a = 0;
-
- for (AlignmentPanel ap : _alignwith)
- {
- als[a] = ap.av.getAlignment();
- alm[a] = -1;
- alc[a++] = ap.av.getColumnSelection();
- }
- jmb.superposeStructures(als, alm, alc);
- } catch (Exception e)
- {
- StringBuffer sp = new StringBuffer();
- for (AlignmentPanel ap : _alignwith)
- {
- sp.append("'" + ap.alignFrame.getTitle() + "' ");
- }
- Cache.log.info("Couldn't align structures with the " + sp.toString()
- + "associated alignment panels.", e);
-
- }
-
- }
-
- @Override
- public void setJalviewColourScheme(ColourSchemeI ucs)
- {
- jmb.setJalviewColourScheme(ucs);
-
- }
-
- /**
- *
- * @param alignment
- * @return first alignment panel displaying given alignment, or the default
- * alignment panel
- */
- public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
- {
- for (AlignmentPanel ap : getAllAlignmentPanels())
- {
- if (ap.av.getAlignment() == alignment)
- {
- return ap;
- }
- }
- return getAlignmentPanel();
- }
-
@Override
public AAStructureBindingModel getBinding()
{
}
@Override
- protected AAStructureBindingModel getBindingModel()
+ protected String getViewerName()
{
- return jmb;
+ return "Jmol";
}
-
}
package jalview.gui;
import jalview.bin.Cache;
-import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.ext.rbvi.chimera.ChimeraCommands;
import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
import jalview.gui.StructureViewer.ViewerType;
import jalview.io.DataSourceType;
-import jalview.io.JalviewFileChooser;
-import jalview.io.JalviewFileView;
import jalview.io.StructureFile;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.ZappoColourScheme;
import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.BrowserLauncher;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.ws.dbsources.Pdb;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
-import java.util.Vector;
import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
-import javax.swing.event.MenuEvent;
-import javax.swing.event.MenuListener;
/**
* GUI elements for handling an external chimera display
{
private JalviewChimeraBinding jmb;
- private boolean allChainsSelected = false;
-
private IProgressIndicator progressBar = null;
/*
/**
* Initialise menu options.
*/
- private void initMenus()
+ @Override
+ protected void initMenus()
{
+ super.initMenus();
+
viewerActionMenu.setText(MessageManager.getString("label.chimera"));
+
viewerColour.setText(MessageManager
.getString("label.colour_with_chimera"));
viewerColour.setToolTipText(MessageManager
.getString("label.let_chimera_manage_structure_colours"));
- helpItem.setText(MessageManager.getString("label.chimera_help"));
- seqColour.setSelected(jmb.isColourBySequence());
- viewerColour.setSelected(!jmb.isColourBySequence());
- if (_colourwith == null)
- {
- _colourwith = new Vector<AlignmentPanel>();
- }
- if (_alignwith == null)
- {
- _alignwith = new Vector<AlignmentPanel>();
- }
-
- // save As not yet implemented
- savemenu.setVisible(false);
- ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
- MessageManager.getString("label.colour_by"), this, _colourwith,
- new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- if (!seqColour.isSelected())
- {
- seqColour.doClick();
- }
- else
- {
- // update the Chimera display now.
- seqColour_actionPerformed(null);
- }
- }
- });
- viewMenu.add(seqColourBy);
+ helpItem.setText(MessageManager.getString("label.chimera_help"));
+ savemenu.setVisible(false); // not yet implemented
viewMenu.add(fitToWindow);
- final ItemListener handler;
- JMenu alpanels = new ViewSelectionMenu(
- MessageManager.getString("label.superpose_with"), this,
- _alignwith, handler = new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- alignStructs.setEnabled(_alignwith.size() > 0);
- alignStructs.setToolTipText(MessageManager
- .formatMessage(
- "label.align_structures_using_linked_alignment_views",
- new Object[] { new Integer(_alignwith
- .size()).toString() }));
- }
- });
- handler.itemStateChanged(null);
- viewerActionMenu.add(alpanels);
- viewerActionMenu.addMenuListener(new MenuListener()
- {
-
- @Override
- public void menuSelected(MenuEvent e)
- {
- handler.itemStateChanged(null);
- }
-
- @Override
- public void menuDeselected(MenuEvent e)
- {
- // TODO Auto-generated method stub
- }
-
- @Override
- public void menuCanceled(MenuEvent e)
- {
- // TODO Auto-generated method stub
- }
- });
-
JMenuItem writeFeatures = new JMenuItem(
MessageManager.getString("label.create_chimera_attributes"));
writeFeatures.setToolTipText(MessageManager
});
viewerActionMenu.add(writeFeatures);
- final JMenu fetchAttributes = new JMenu("Fetch Chimera attributes");
- fetchAttributes
- .setToolTipText("Copy Chimera attribute to Jalview feature");
+ final JMenu fetchAttributes = new JMenu(
+ MessageManager.getString("label.fetch_chimera_attributes"));
+ fetchAttributes.setToolTipText(MessageManager
+ .getString("label.fetch_chimera_attributes_tip"));
fetchAttributes.addMouseListener(new MouseAdapter()
{
}
}
- /**
- * Answers true if this viewer already involves the given PDB ID
- */
- @Override
- protected boolean hasPdbId(String pdbId)
- {
- return jmb.hasPdbId(pdbId);
- }
-
private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
SequenceI[][] seqs)
{
ap.getStructureSelectionManager(), pdbentrys, seqs, null);
addAlignmentPanel(ap);
useAlignmentPanelForColourbyseq(ap);
+
if (pdbentrys.length > 1)
{
alignAddedStructures = true;
*/
void initChimera()
{
- Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true),
- getBounds().width, getBounds().height);
+ jmb.setFinishedInit(false);
+ Desktop.addInternalFrame(this,
+ jmb.getViewerTitle(getViewerName(), true), getBounds().width,
+ getBounds().height);
if (!jmb.launchChimera())
{
}
/**
- * If the list is not empty, add menu items for 'All' and each individual
- * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
- *
- * @param chainNames
- */
- @Override
- void setChainMenuItems(List<String> chainNames)
- {
- chainMenu.removeAll();
- if (chainNames == null || chainNames.isEmpty())
- {
- return;
- }
- JMenuItem menuItem = new JMenuItem(
- MessageManager.getString("label.all"));
- menuItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- allChainsSelected = true;
- for (int i = 0; i < chainMenu.getItemCount(); i++)
- {
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
- {
- ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
- }
- }
- showSelectedChains();
- allChainsSelected = false;
- }
- });
-
- chainMenu.add(menuItem);
-
- for (String chainName : chainNames)
- {
- menuItem = new JCheckBoxMenuItem(chainName, true);
- menuItem.addItemListener(new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent evt)
- {
- if (!allChainsSelected)
- {
- showSelectedChains();
- }
- }
- });
-
- chainMenu.add(menuItem);
- }
- }
-
- /**
* Show only the selected chain(s) in the viewer
*/
@Override
{
String prompt = MessageManager.formatMessage(
"label.confirm_close_chimera",
- new Object[] { jmb.getViewerTitle("Chimera", false) });
+ new Object[] { jmb.getViewerTitle(getViewerName(),
+ false) });
prompt = JvSwingUtils.wrapTooltip(true, prompt);
int confirm = JvOptionPane.showConfirmDialog(this, prompt,
MessageManager.getString("label.close_viewer"),
try
{
int pos = filePDBpos.get(num).intValue();
- long startTime = startProgressBar("Chimera "
+ long startTime = startProgressBar(getViewerName() + " "
+ MessageManager.getString("status.opening_file_for")
+ " " + pe.getId());
jmb.openFile(pe);
}
@Override
- public void pdbFile_actionPerformed(ActionEvent actionEvent)
- {
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
- chooser.setToolTipText(MessageManager.getString("action.save"));
-
- int value = chooser.showSaveDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- BufferedReader in = null;
- try
- {
- // TODO: cope with multiple PDB files in view
- in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
- File outFile = chooser.getSelectedFile();
-
- PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
- String data;
- while ((data = in.readLine()) != null)
- {
- if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
- {
- out.println(data);
- }
- }
- out.close();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- } finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- } catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
- }
-
- @Override
- public void viewMapping_actionPerformed(ActionEvent actionEvent)
- {
- jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
- try
- {
- cap.appendText(jmb.printMappings());
- } catch (OutOfMemoryError e)
- {
- new OOMWarning(
- "composing sequence-structure alignments for display in text box.",
- e);
- cap.dispose();
- return;
- }
- jalview.gui.Desktop.addInternalFrame(cap,
- MessageManager.getString("label.pdb_sequence_mapping"), 550,
- 600);
- }
-
- @Override
public void eps_actionPerformed(ActionEvent e)
{
throw new Error(
}
@Override
- public void viewerColour_actionPerformed(ActionEvent actionEvent)
- {
- if (viewerColour.isSelected())
- {
- // disable automatic sequence colouring.
- jmb.setColourBySequence(false);
- }
- }
-
- @Override
- public void seqColour_actionPerformed(ActionEvent actionEvent)
- {
- jmb.setColourBySequence(seqColour.isSelected());
- if (_colourwith == null)
- {
- _colourwith = new Vector<AlignmentPanel>();
- }
- if (jmb.isColourBySequence())
- {
- if (!jmb.isLoadingFromArchive())
- {
- if (_colourwith.size() == 0 && getAlignmentPanel() != null)
- {
- // Make the currently displayed alignment panel the associated view
- _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
- }
- }
- // Set the colour using the current view for the associated alignframe
- for (AlignmentPanel ap : _colourwith)
- {
- jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
- }
- }
- }
-
- @Override
- public void chainColour_actionPerformed(ActionEvent actionEvent)
- {
- chainColour.setSelected(true);
- jmb.colourByChain();
- }
-
- @Override
- public void chargeColour_actionPerformed(ActionEvent actionEvent)
- {
- chargeColour.setSelected(true);
- jmb.colourByCharge();
- }
-
- @Override
- public void zappoColour_actionPerformed(ActionEvent actionEvent)
- {
- zappoColour.setSelected(true);
- jmb.setJalviewColourScheme(new ZappoColourScheme());
- }
-
- @Override
- public void taylorColour_actionPerformed(ActionEvent actionEvent)
- {
- taylorColour.setSelected(true);
- jmb.setJalviewColourScheme(new TaylorColourScheme());
- }
-
- @Override
- public void hydroColour_actionPerformed(ActionEvent actionEvent)
- {
- hydroColour.setSelected(true);
- jmb.setJalviewColourScheme(new HydrophobicColourScheme());
- }
-
- @Override
- public void helixColour_actionPerformed(ActionEvent actionEvent)
- {
- helixColour.setSelected(true);
- jmb.setJalviewColourScheme(new HelixColourScheme());
- }
-
- @Override
- public void strandColour_actionPerformed(ActionEvent actionEvent)
- {
- strandColour.setSelected(true);
- jmb.setJalviewColourScheme(new StrandColourScheme());
- }
-
- @Override
- public void turnColour_actionPerformed(ActionEvent actionEvent)
- {
- turnColour.setSelected(true);
- jmb.setJalviewColourScheme(new TurnColourScheme());
- }
-
- @Override
- public void buriedColour_actionPerformed(ActionEvent actionEvent)
- {
- buriedColour.setSelected(true);
- jmb.setJalviewColourScheme(new BuriedColourScheme());
- }
-
- @Override
- public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
- {
- setJalviewColourScheme(new PurinePyrimidineColourScheme());
- }
-
- @Override
- public void userColour_actionPerformed(ActionEvent actionEvent)
- {
- userColour.setSelected(true);
- new UserDefinedColours(this, null);
- }
-
- @Override
- public void backGround_actionPerformed(ActionEvent actionEvent)
- {
- java.awt.Color col = JColorChooser
- .showDialog(this, MessageManager
- .getString("label.select_backgroud_colour"), null);
- if (col != null)
- {
- jmb.setBackgroundColour(col);
- }
- }
-
- @Override
public void showHelp_actionPerformed(ActionEvent actionEvent)
{
try
{
- jalview.util.BrowserLauncher
+ BrowserLauncher
.openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
- } catch (Exception ex)
+ } catch (IOException ex)
{
}
}
- public void updateTitleAndMenus()
- {
- if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
- {
- repaint();
- return;
- }
- setChainMenuItems(jmb.getChainNames());
-
- this.setTitle(jmb.getViewerTitle("Chimera", true));
- // if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
- // {
- viewerActionMenu.setVisible(true);
- // }
- if (!jmb.isLoadingFromArchive())
- {
- seqColour_actionPerformed(null);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
- * .ActionEvent)
- */
- @Override
- protected void alignStructs_actionPerformed(ActionEvent actionEvent)
- {
- alignStructs_withAllAlignPanels();
- }
-
- private void alignStructs_withAllAlignPanels()
- {
- if (getAlignmentPanel() == null)
- {
- return;
- }
-
- if (_alignwith.size() == 0)
- {
- _alignwith.add(getAlignmentPanel());
- }
-
- try
- {
- AlignmentI[] als = new Alignment[_alignwith.size()];
- ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
- int[] alm = new int[_alignwith.size()];
- int a = 0;
-
- for (AlignmentPanel ap : _alignwith)
- {
- als[a] = ap.av.getAlignment();
- alm[a] = -1;
- alc[a++] = ap.av.getColumnSelection();
- }
- jmb.superposeStructures(als, alm, alc);
- } catch (Exception e)
- {
- StringBuffer sp = new StringBuffer();
- for (AlignmentPanel ap : _alignwith)
- {
- sp.append("'" + ap.alignFrame.getTitle() + "' ");
- }
- Cache.log.info("Couldn't align structures with the " + sp.toString()
- + "associated alignment panels.", e);
- }
- }
-
- @Override
- public void setJalviewColourScheme(ColourSchemeI ucs)
- {
- jmb.setJalviewColourScheme(ucs);
-
- }
-
- /**
- *
- * @param alignment
- * @return first alignment panel displaying given alignment, or the default
- * alignment panel
- */
- public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
- {
- for (AlignmentPanel ap : getAllAlignmentPanels())
- {
- if (ap.av.getAlignment() == alignment)
- {
- return ap;
- }
- }
- return getAlignmentPanel();
- }
-
@Override
public AAStructureBindingModel getBinding()
{
}
@Override
- protected AAStructureBindingModel getBindingModel()
+ protected String getViewerName()
{
- return jmb;
+ return "Chimera";
+ }
+
+ @Override
+ public void updateTitleAndMenus()
+ {
+ super.updateTitleAndMenus();
+ viewerActionMenu.setVisible(true);
}
}
--- /dev/null
+package jalview.gui;
+
+import jalview.bin.Cache;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.ResidueColourScheme;
+import jalview.schemes.UserColourScheme;
+import jalview.util.MessageManager;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JMenu;
+import javax.swing.JRadioButtonMenuItem;
+
+public class ColourMenuHelper
+{
+ public interface ColourChangeListener
+ {
+ void changeColour_actionPerformed(String name);
+ }
+
+ /**
+ * Adds items to the colour menu, as mutually exclusive members of a button
+ * group. The callback handler is responsible for the action on selecting any
+ * of these options. The callback method receives the name of the selected
+ * colour, or "None" or "User Defined". This method returns the ButtonGroup to
+ * which items were added.
+ * <ul>
+ * <li>None</li>
+ * <li>Clustal</li>
+ * <li>...other 'built-in' colours</li>
+ * <li>...any user-defined colours</li>
+ * <li>User Defined..</li>
+ * </ul>
+ *
+ * @param colourMenu
+ * the menu to attach items to
+ * @param client
+ * a callback to handle menu selection
+ * @param coll
+ * the data the menu is being built for
+ * @param simpleOnly
+ * if true, only simple per-residue colour schemes are included
+ */
+ public static ButtonGroup addMenuItems(final JMenu colourMenu,
+ final ColourChangeListener client, AnnotatedCollectionI coll,
+ boolean simpleOnly)
+ {
+ /*
+ * ButtonGroup groups those items whose
+ * selection is mutually exclusive
+ */
+ ButtonGroup colours = new ButtonGroup();
+
+ if (!simpleOnly)
+ {
+ JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(
+ MessageManager.getString("label.none"));
+ noColourmenuItem.setName(ResidueColourScheme.NONE);
+ noColourmenuItem.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ client.changeColour_actionPerformed(ResidueColourScheme.NONE);
+ }
+ });
+ colourMenu.add(noColourmenuItem);
+ colours.add(noColourmenuItem);
+ }
+
+ /*
+ * scan registered colour schemes (built-in or user-defined
+ * and add them to the menu (in the order they were registered)
+ */
+ Iterable<ColourSchemeI> colourSchemes = ColourSchemes.getInstance()
+ .getColourSchemes();
+ for (ColourSchemeI scheme : colourSchemes)
+ {
+ if (simpleOnly && !scheme.isSimple())
+ {
+ continue;
+ }
+
+ /*
+ * button text is i18n'd but the name is the canonical name of
+ * the colour scheme (inspected in setColourSelected())
+ */
+ final String name = scheme.getSchemeName();
+ String label = MessageManager.getStringOrReturn("label.colourScheme_"
+ + name.toLowerCase().replace(" ", "_"), name);
+ final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(label);
+ radioItem.setName(name);
+ radioItem.setEnabled(scheme.isApplicableTo(coll));
+ if (scheme instanceof UserColourScheme)
+ {
+ /*
+ * user-defined colour scheme loaded on startup or during the
+ * Jalview session; right-click on this offers the option to
+ * remove it as a colour choice
+ */
+ radioItem.addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mousePressed(MouseEvent evt)
+ {
+ if (evt.isPopupTrigger()) // Mac
+ {
+ offerRemoval();
+ }
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent evt)
+ {
+ if (evt.isPopupTrigger()) // Windows
+ {
+ offerRemoval();
+ }
+ }
+
+ void offerRemoval()
+ {
+ ActionListener al = radioItem.getActionListeners()[0];
+ radioItem.removeActionListener(al);
+ int option = JvOptionPane.showInternalConfirmDialog(
+ Desktop.desktop, MessageManager
+ .getString("label.remove_from_default_list"),
+ MessageManager
+ .getString("label.remove_user_defined_colour"),
+ JvOptionPane.YES_NO_OPTION);
+ if (option == JvOptionPane.YES_OPTION)
+ {
+ ColourSchemes.getInstance().removeColourScheme(
+ radioItem.getName());
+ colourMenu.remove(radioItem);
+ updatePreferences();
+ }
+ else
+ {
+ radioItem.addActionListener(al);
+ }
+ }
+ });
+ }
+ radioItem.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent evt)
+ {
+ client.changeColour_actionPerformed(name);
+ }
+ });
+ colourMenu.add(radioItem);
+ colours.add(radioItem);
+ }
+
+ /*
+ * only add the option to load/configure a user-defined colour
+ * to the AlignFrame colour menu
+ */
+ if (client instanceof AlignFrame)
+ {
+ final String label = MessageManager.getString("action.user_defined");
+ JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(
+ label);
+ userDefinedColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ client.changeColour_actionPerformed(ResidueColourScheme.USER_DEFINED);
+ }
+ });
+ colourMenu.add(userDefinedColour);
+ colours.add(userDefinedColour);
+ }
+
+ return colours;
+ }
+
+ /**
+ * Marks as selected the colour menu item matching the given name, or the
+ * first item ('None') if no match is found
+ *
+ * @param colourMenu
+ * @param colourName
+ */
+ public static void setColourSelected(JMenu colourMenu, String colourName)
+ {
+ if (colourName == null)
+ {
+ return;
+ }
+
+ JRadioButtonMenuItem none = null;
+
+ /*
+ * select the radio button whose name matches the colour name
+ * (not the button text, as it may be internationalised)
+ */
+ for (Component menuItem : colourMenu.getMenuComponents())
+ {
+ if (menuItem instanceof JRadioButtonMenuItem)
+ {
+ String buttonName = ((JRadioButtonMenuItem) menuItem).getName();
+ if (colourName.equals(buttonName))
+ {
+ ((JRadioButtonMenuItem) menuItem).setSelected(true);
+ return;
+ }
+ if (ResidueColourScheme.NONE.equals(buttonName))
+ {
+ none = (JRadioButtonMenuItem) menuItem;
+ }
+ }
+ }
+ if (none != null)
+ {
+ none.setSelected(true);
+ }
+ }
+
+ /**
+ * Marks as selected the colour menu item matching the given colour scheme, or
+ * the first item ('None') if no match is found
+ *
+ * @param colourMenu
+ * @param cs
+ */
+ public static void setColourSelected(JMenu colourMenu, ColourSchemeI cs)
+ {
+ setColourSelected(colourMenu, cs == null ? ResidueColourScheme.NONE
+ : cs.getSchemeName());
+ }
+
+ /**
+ * Updates the USER_DEFINE_COLOURS preference to remove any de-registered
+ * colour scheme
+ */
+ static void updatePreferences()
+ {
+ StringBuilder coloursFound = new StringBuilder();
+ String[] files = Cache.getProperty("USER_DEFINED_COLOURS").split("\\|");
+
+ /*
+ * the property does not include the scheme name, it is in the file;
+ * so just load the colour schemes and discard any whose name is not
+ * registered
+ */
+ for (String file : files)
+ {
+ try
+ {
+ UserColourScheme ucs = ColourSchemes.loadColourScheme(file);
+ if (ucs != null
+ && ColourSchemes.getInstance().nameExists(ucs.getName()))
+ {
+ if (coloursFound.length() > 0)
+ {
+ coloursFound.append("|");
+ }
+ coloursFound.append(file);
+ }
+ } catch (Exception ex)
+ {
+ System.out.println("Error loading User ColourFile\n" + ex);
+ }
+ }
+
+ if (coloursFound.toString().length() > 1)
+ {
+ Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString());
+ }
+ else
+ {
+ Cache.applicationProperties.remove("USER_DEFINED_COLOURS");
+ }
+ }
+}
pane12.add(nametf, BorderLayout.EAST);
panel.add(pane12, BorderLayout.NORTH);
pane12 = new JPanel(new BorderLayout());
- pane12.add(new JLabel(MessageManager.getString("label.url")),
+ pane12.add(new JLabel(MessageManager.getString("label.url:")),
BorderLayout.NORTH);
pane12.add(seqs, BorderLayout.SOUTH);
pane12.add(urltf, BorderLayout.EAST);
*/
package jalview.gui;
-import static jalview.util.UrlConstants.EMBLEBI_STRING;
import static jalview.util.UrlConstants.SEQUENCE_ID;
import jalview.api.AlignViewportI;
import jalview.jbgui.GSplitFrame;
import jalview.jbgui.GStructureViewer;
import jalview.structure.StructureSelectionManager;
+import jalview.urls.IdOrgSettings;
import jalview.util.ImageMaker;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.UrlConstants;
import jalview.viewmodel.AlignmentViewport;
import jalview.ws.params.ParamManager;
+import jalview.ws.utils.UrlDownloadClient;
import java.awt.BorderLayout;
import java.awt.Color;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
showNews.setVisible(false);
+ getIdentifiersOrgData();
+
checkURLLinks();
this.addWindowListener(new WindowAdapter()
});
}
+ public void getIdentifiersOrgData()
+ {
+ // Thread off the identifiers fetcher
+ addDialogThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Cache.log.debug("Downloading data from identifiers.org");
+ UrlDownloadClient client = new UrlDownloadClient();
+ try
+ {
+ client.download(IdOrgSettings.getUrl(),
+ IdOrgSettings.getDownloadLocation());
+ } catch (IOException e)
+ {
+ Cache.log.debug("Exception downloading identifiers.org data"
+ + e.getMessage());
+ }
+ }
+ });
+ }
+
@Override
protected void showNews_actionPerformed(ActionEvent e)
{
@Override
public void saveState_actionPerformed(ActionEvent e)
{
- JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project");
+ JalviewFileChooser chooser = new JalviewFileChooser("jvp",
+ "Jalview Project");
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager.getString("label.save_state"));
{
if (v_client != null)
{
- JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"), "vdj",// TODO: VAMSAS DOCUMENT EXTENSION is VDJ
+ // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
+ JalviewFileChooser chooser = new JalviewFileChooser("vdj",
"Vamsas Document");
chooser.setFileView(new JalviewFileView());
{
// check what the actual links are - if it's just the default don't
// bother with the warning
- Vector<String> links = Preferences.sequenceURLLinks;
+ List<String> links = Preferences.sequenceUrlLinks
+ .getLinksForMenu();
// only need to check links if there is one with a
// SEQUENCE_ID which is not the default EMBL_EBI link
while (li.hasNext())
{
String link = li.next();
- if (link.contains(SEQUENCE_ID) && !link.equals(EMBLEBI_STRING))
+ if (link.contains(SEQUENCE_ID)
+ && !link.equals(UrlConstants.DEFAULT_STRING))
{
check = true;
int barPos = link.indexOf("|");
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
import jalview.util.MessageManager;
import java.awt.BorderLayout;
FeatureColourI col = getFeatureStyle(name.getText());
if (col == null)
{
- col = new FeatureColour(UserColourScheme
+ col = new FeatureColour(ColorUtils
.createColourFromName(name.getText()));
}
oldcol = fcol = col;
void load()
{
- JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"), "fc",
+ JalviewFileChooser chooser = new JalviewFileChooser("fc",
"Sequence Feature Colours");
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
void save()
{
- JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"), "fc",
+ JalviewFileChooser chooser = new JalviewFileChooser("fc",
"Sequence Feature Colours");
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
import jalview.io.SequenceAnnotationReport;
import jalview.util.MessageManager;
import jalview.util.Platform;
-import jalview.util.UrlLink;
import jalview.viewmodel.AlignmentViewport;
import java.awt.BorderLayout;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.util.List;
-import java.util.Vector;
-import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
return;
}
- Vector links = Preferences.sequenceURLLinks;
- if (links == null || links.size() < 1)
- {
- return;
- }
-
int seq = alignPanel.getSeqPanel().findSeq(e);
- String url = null;
- int i = 0;
String id = av.getAlignment().getSequenceAt(seq).getName();
- while (url == null && i < links.size())
- {
- // DEFAULT LINK IS FIRST IN THE LINK LIST
- // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
- url = links.elementAt(i++).toString();
- jalview.util.UrlLink urlLink = null;
- try
- {
- urlLink = new UrlLink(url);
- } catch (Exception foo)
- {
- jalview.bin.Cache.log.error("Exception for URLLink '" + url + "'",
- foo);
- url = null;
- continue;
- }
+ String url = Preferences.sequenceUrlLinks.getPrimaryUrl(id);
- if (urlLink.usesDBAccession())
- {
- // this URL requires an accession id, not the name of a sequence
- url = null;
- continue;
- }
-
- if (!urlLink.isValid())
- {
- jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
- url = null;
- continue;
- }
-
- String urls[] = urlLink.makeUrls(id, true);
- if (urls == null || urls[0] == null || urls[0].length() < 4)
- {
- url = null;
- continue;
- }
- // just take first URL made from regex
- url = urls[1];
- }
try
{
jalview.util.BrowserLauncher.openURL(url);
Sequence sq = (Sequence) av.getAlignment().getSequenceAt(seq2);
// build a new links menu based on the current links + any non-positional
// features
- Vector<String> nlinks = new Vector<String>(Preferences.sequenceURLLinks);
+ List<String> nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
SequenceFeature sfs[] = sq == null ? null : sq.getSequenceFeatures();
if (sfs != null)
{
{
for (int l = 0, lSize = sf.links.size(); l < lSize; l++)
{
- nlinks.addElement(sf.links.elementAt(l));
+ nlinks.add(sf.links.elementAt(l));
}
}
}
import jalview.gui.StructureViewer.ViewerType;
import jalview.io.DataSourceType;
import jalview.io.FileFormat;
+import jalview.renderer.ResidueShaderI;
import jalview.schemabinding.version2.AlcodMap;
import jalview.schemabinding.version2.AlcodonFrame;
import jalview.schemabinding.version2.Annotation;
import java.util.jar.JarOutputStream;
import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.exolab.castor.xml.Marshaller;
// group has references so set its ID field
jGroup.setId(groupRefs.get(sg));
}
- if (sg.cs != null)
+ ColourSchemeI colourScheme = sg.getColourScheme();
+ if (colourScheme != null)
{
- if (sg.cs.conservationApplied())
+ ResidueShaderI groupColourScheme = sg
+ .getGroupColourScheme();
+ if (groupColourScheme.conservationApplied())
{
- jGroup.setConsThreshold(sg.cs.getConservationInc());
+ jGroup.setConsThreshold(groupColourScheme.getConservationInc());
- if (sg.cs instanceof jalview.schemes.UserColourScheme)
+ if (colourScheme instanceof jalview.schemes.UserColourScheme)
{
- jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
+ jGroup.setColour(setUserColourScheme(colourScheme,
+ userColours, jms));
}
else
{
- jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
+ jGroup.setColour(colourScheme.getSchemeName());
}
}
- else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient)
+ else if (colourScheme instanceof jalview.schemes.AnnotationColourGradient)
{
jGroup.setColour("AnnotationColourGradient");
jGroup.setAnnotationColours(constructAnnotationColours(
- (jalview.schemes.AnnotationColourGradient) sg.cs,
+ (jalview.schemes.AnnotationColourGradient) colourScheme,
userColours, jms));
}
- else if (sg.cs instanceof jalview.schemes.UserColourScheme)
+ else if (colourScheme instanceof jalview.schemes.UserColourScheme)
{
- jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
+ jGroup.setColour(setUserColourScheme(colourScheme,
+ userColours, jms));
}
else
{
- jGroup.setColour(ColourSchemeProperty.getColourName(sg.cs));
+ jGroup.setColour(colourScheme.getSchemeName());
}
- jGroup.setPidThreshold(sg.cs.getThreshold());
+ jGroup.setPidThreshold(groupColourScheme.getThreshold());
}
jGroup.setOutlineColour(sg.getOutlineColour().getRGB());
.getGlobalColourScheme()));
}
+ ResidueShaderI vcs = av.getResidueShading();
ColourSchemeI cs = av.getGlobalColourScheme();
if (cs != null)
{
- if (cs.conservationApplied())
+ if (vcs.conservationApplied())
{
- view.setConsThreshold(cs.getConservationInc());
+ view.setConsThreshold(vcs.getConservationInc());
if (cs instanceof jalview.schemes.UserColourScheme)
{
view.setBgColour(setUserColourScheme(cs, userColours, jms));
}
}
-
- if (cs instanceof ResidueColourScheme)
- {
- view.setPidThreshold(cs.getThreshold());
- }
+ view.setPidThreshold(vcs.getThreshold());
}
view.setConservationSelected(av.getConservationSelected());
}
else
{
- ac.setColourScheme(ColourSchemeProperty.getColourName(acg
- .getBaseColour()));
+ ac.setColourScheme(ColourSchemeProperty.getColourName(acg.getBaseColour()));
}
ac.setMaxColour(acg.getMaxColour().getRGB());
&& jGroup.getAnnotationColours() != null)
{
addAnnotSchemeGroup = true;
- cs = null;
}
else
{
- cs = ColourSchemeProperty.getColour(al, jGroup.getColour());
- }
-
- if (cs != null)
- {
- cs.setThreshold(jGroup.getPidThreshold(), true);
+ cs = ColourSchemeProperty.getColourScheme(al, jGroup.getColour());
}
}
+ int pidThreshold = jGroup.getPidThreshold();
Vector<SequenceI> seqs = new Vector<SequenceI>();
SequenceGroup sg = new SequenceGroup(seqs, jGroup.getName(), cs,
jGroup.getDisplayBoxes(), jGroup.getDisplayText(),
jGroup.getColourText(), jGroup.getStart(), jGroup.getEnd());
-
+ sg.getGroupColourScheme().setThreshold(pidThreshold, true);
+ sg.getGroupColourScheme().setConservationInc(jGroup.getConsThreshold());
sg.setOutlineColour(new java.awt.Color(jGroup.getOutlineColour()));
sg.textColour = new java.awt.Color(jGroup.getTextCol1());
if (addAnnotSchemeGroup)
{
// reconstruct the annotation colourscheme
- sg.cs = constructAnnotationColour(jGroup.getAnnotationColours(),
- null, al, jms, false);
+ sg.setColourScheme(constructAnnotationColour(
+ jGroup.getAnnotationColours(), null, al, jms, false));
}
}
}
af.viewport.setShowAnnotation(view.getShowAnnotation());
af.viewport.setAbovePIDThreshold(view.getPidSelected());
+ af.viewport.setThreshold(view.getPidThreshold());
af.viewport.setColourText(view.getShowColourText());
af.viewport.setConservationSelected(view.getConservationSelected());
+ af.viewport.setIncrement(view.getConsThreshold());
af.viewport.setShowJVSuffix(view.getShowFullId());
af.viewport.setRightAlignIds(view.getRightAlignIds());
af.viewport.setFont(
}
else
{
- cs = ColourSchemeProperty.getColour(al, view.getBgColour());
- }
-
- if (cs != null)
- {
- cs.setThreshold(view.getPidThreshold(), true);
- cs.setConsensus(af.viewport.getSequenceConsensusHash());
+ cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour());
}
}
af.viewport.setGlobalColourScheme(cs);
+ af.viewport.getResidueShading().setThreshold(
+ view.getPidThreshold(), true);
+ af.viewport.getResidueShading().setConsensus(
+ af.viewport.getSequenceConsensusHash());
af.viewport.setColourAppliesToAllGroups(false);
if (view.getConservationSelected() && cs != null)
{
- cs.setConservationInc(view.getConsThreshold());
+ af.viewport.getResidueShading().setConservationInc(
+ view.getConsThreshold());
}
af.changeColour(cs);
propagateAnnColour = true;
for (jalview.datamodel.SequenceGroup sg : al.getGroups())
{
- if (sg.cs instanceof AnnotationColourGradient)
+ if (sg.getColourScheme() instanceof AnnotationColourGradient)
{
propagateAnnColour = false;
}
);
}
- if (viewAnnColour.getColourScheme().equals("None"))
+ if (viewAnnColour.getColourScheme().equals(
+ ResidueColourScheme.NONE))
{
cs = new AnnotationColourGradient(
annAlignment.getAlignmentAnnotation()[i],
{
cs = new AnnotationColourGradient(
annAlignment.getAlignmentAnnotation()[i],
- ColourSchemeProperty.getColour(al,
+ ColourSchemeProperty.getColourScheme(al,
viewAnnColour.getColourScheme()),
viewAnnColour.getAboveThreshold());
}
}
/*
- * if (viewAnnColour.getColourScheme().equals("None" )) { sg.cs =
+ * if (viewAnnColour.getColourScheme().equals(ResidueColourScheme.NONE)) { sg.cs =
* new AnnotationColourGradient(
* annAlignment.getAlignmentAnnotation()[i], new
* java.awt.Color(viewAnnColour. getMinColour()), new
* viewAnnColour.getAboveThreshold()); } else
*/
{
- sg.cs = new AnnotationColourGradient(
- annAlignment.getAlignmentAnnotation()[i], sg.cs,
- viewAnnColour.getAboveThreshold());
+ sg.setColourScheme(new AnnotationColourGradient(
+ annAlignment.getAlignmentAnnotation()[i], sg
+ .getColourScheme(), viewAnnColour
+ .getAboveThreshold()));
if (cs instanceof AnnotationColourGradient)
{
if (viewAnnColour.hasPerSequence())
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
-import javax.swing.JOptionPane;
-
/**
* DOCUMENT ME!
*
}
else
{
- cs = ColourSchemeProperty.getColour(al, groups[i].getColour());
- }
-
- if (cs != null)
- {
- cs.setThreshold(groups[i].getPidThreshold(), true);
+ cs = ColourSchemeProperty.getColourScheme(al, groups[i].getColour());
}
-
}
+ int pidThreshold = groups[i].getPidThreshold();
Vector seqs = new Vector();
int[] ids = groups[i].getSeq();
seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
groups[i].getDisplayText(), groups[i].getColourText(),
groups[i].getStart(), groups[i].getEnd());
+ sg.getGroupColourScheme().setThreshold(pidThreshold, true);
sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
}
else
{
- cs = ColourSchemeProperty.getColour(al, view.getBgColour());
+ cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour());
}
- if (cs != null)
- {
- cs.setThreshold(view.getPidThreshold(), true);
- cs.setConsensus(af.viewport.getSequenceConsensusHash());
- }
+ // if (cs != null)
+ // {
+ // cs.setThreshold(view.getPidThreshold(), true);
+ // cs.setConsensus(af.viewport.getSequenceConsensusHash());
+ // }
}
- af.viewport.setGlobalColourScheme(cs);
+ af.viewport.getResidueShading().setThreshold(
+ view.getPidThreshold(), true);
+ af.viewport.getResidueShading().setConsensus(
+ af.viewport.getSequenceConsensusHash());
af.viewport.setColourAppliesToAllGroups(false);
af.alignPanel.updateLayout();
af.changeColour(cs);
if (view.getConservationSelected() && cs != null)
{
- cs.setConservationInc(view.getConsThreshold());
+ af.viewport.getResidueShading().setConservationInc(
+ view.getConsThreshold());
}
af.viewport.setColourAppliesToAllGroups(true);
}
if (!isLoadingFromArchive())
{
- colourBySequence(ap.av.isShowSequenceFeatures(), ap);
+ colourBySequence(ap);
}
}
public void bgcolour_actionPerformed(ActionEvent e)
{
Color col = JColorChooser.showDialog(this,
- MessageManager.getString("label.select_backgroud_colour"),
+ MessageManager.getString("label.select_background_colour"),
rc.bgColour);
if (col != null)
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.gui.ColourMenuHelper.ColourChangeListener;
import jalview.io.FileFormatI;
import jalview.io.FileFormats;
import jalview.io.FormatAdapter;
import jalview.io.SequenceAnnotationReport;
import jalview.schemes.AnnotationColourGradient;
import jalview.schemes.Blosum62ColourScheme;
-import jalview.schemes.BuriedColourScheme;
-import jalview.schemes.ClustalxColourScheme;
-import jalview.schemes.HelixColourScheme;
-import jalview.schemes.HydrophobicColourScheme;
-import jalview.schemes.NucleotideColourScheme;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
import jalview.schemes.PIDColourScheme;
-import jalview.schemes.PurinePyrimidineColourScheme;
-import jalview.schemes.StrandColourScheme;
-import jalview.schemes.TaylorColourScheme;
-import jalview.schemes.TurnColourScheme;
-import jalview.schemes.UserColourScheme;
-import jalview.schemes.ZappoColourScheme;
+import jalview.schemes.ResidueColourScheme;
import jalview.util.GroupUrlLink;
import jalview.util.GroupUrlLink.UrlStringTooLongException;
import jalview.util.MessageManager;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
-import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JColorChooser;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
-import javax.swing.JRadioButtonMenuItem;
/**
* DOCUMENT ME!
* @author $author$
* @version $Revision: 1.118 $
*/
-public class PopupMenu extends JPopupMenu
+public class PopupMenu extends JPopupMenu implements ColourChangeListener
{
JMenu groupMenu = new JMenu();
JMenuItem groupName = new JMenuItem();
- protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
-
protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
- protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
-
- JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
+ protected JMenuItem modifyPID = new JMenuItem();
protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
+ protected JMenuItem modifyConservation = new JMenuItem();
+
AlignmentPanel ap;
JMenu sequenceMenu = new JMenu();
JMenuItem outline = new JMenuItem();
- JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
-
JMenu colourMenu = new JMenu();
JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
this.ap = ap;
sequence = seq;
- ButtonGroup colours = new ButtonGroup();
- colours.add(noColourmenuItem);
- colours.add(clustalColour);
- colours.add(zappoColour);
- colours.add(taylorColour);
- colours.add(hydrophobicityColour);
- colours.add(helixColour);
- colours.add(strandColour);
- colours.add(turnColour);
- colours.add(buriedColour);
- colours.add(userDefinedColour);
- colours.add(PIDColour);
- colours.add(BLOSUM62Colour);
- colours.add(purinePyrimidineColour);
- colours.add(RNAInteractionColour);
-
for (String ff : FileFormats.getInstance().getWritableFormats(true))
{
JMenuItem item = new JMenuItem(ff);
- item.addActionListener(new java.awt.event.ActionListener()
+ item.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
menuItem.setText(MessageManager.formatMessage(
"label.2d_rna_structure_line",
new Object[] { aa.label }));
- menuItem.addActionListener(new java.awt.event.ActionListener()
+ menuItem.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
menuItem.setText(MessageManager.formatMessage(
"label.2d_rna_sequence_name",
new Object[] { seq.getName() }));
- menuItem.addActionListener(new java.awt.event.ActionListener()
+ menuItem.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
menuItem = new JMenuItem(
MessageManager.getString("action.hide_sequences"));
- menuItem.addActionListener(new java.awt.event.ActionListener()
+ menuItem.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
menuItem = new JMenuItem(MessageManager.formatMessage(
"label.represent_group_with",
new Object[] { seq.getName() }));
- menuItem.addActionListener(new java.awt.event.ActionListener()
+ menuItem.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
add(menuItem);
}
-
}
SequenceGroup sg = ap.av.getSelectionGroup();
groupName.setText(MessageManager
.getString("label.edit_name_and_description_current_group"));
- if (sg.cs instanceof ZappoColourScheme)
- {
- zappoColour.setSelected(true);
- }
- else if (sg.cs instanceof TaylorColourScheme)
- {
- taylorColour.setSelected(true);
- }
- else if (sg.cs instanceof PIDColourScheme)
- {
- PIDColour.setSelected(true);
- }
- else if (sg.cs instanceof Blosum62ColourScheme)
- {
- BLOSUM62Colour.setSelected(true);
- }
- else if (sg.cs instanceof UserColourScheme)
- {
- userDefinedColour.setSelected(true);
- }
- else if (sg.cs instanceof HydrophobicColourScheme)
- {
- hydrophobicityColour.setSelected(true);
- }
- else if (sg.cs instanceof HelixColourScheme)
- {
- helixColour.setSelected(true);
- }
- else if (sg.cs instanceof StrandColourScheme)
- {
- strandColour.setSelected(true);
- }
- else if (sg.cs instanceof TurnColourScheme)
- {
- turnColour.setSelected(true);
- }
- else if (sg.cs instanceof BuriedColourScheme)
- {
- buriedColour.setSelected(true);
- }
- else if (sg.cs instanceof ClustalxColourScheme)
- {
- clustalColour.setSelected(true);
- }
- else if (sg.cs instanceof PurinePyrimidineColourScheme)
- {
- purinePyrimidineColour.setSelected(true);
- }
+ ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
- /*
- * else if (sg.cs instanceof CovariationColourScheme) {
- * covariationColour.setSelected(true); }
- */
- else
- {
- noColourmenuItem.setSelected(true);
- }
+ conservationMenuItem.setEnabled(!sg.isNucleotide());
if (sg.cs != null)
{
if (sg.cs.conservationApplied())
{
- conservationMenuItem.setSelected(true);
+ conservationMenuItem.setSelected(true);
}
if (sg.cs.getThreshold() > 0)
{
abovePIDColour.setSelected(true);
}
}
+ modifyConservation.setEnabled(conservationMenuItem.isSelected());
+ modifyPID.setEnabled(abovePIDColour.isSelected());
displayNonconserved.setSelected(sg.getShowNonconserved());
showText.setSelected(sg.getDisplayText());
showColourText.setSelected(sg.getColourText());
}
-
-
/**
* Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
* "All" is added first, followed by a separator. Then add any annotation
label = label.substring(1, label.length() - 1); // a, b, c
final JMenuItem item = new JMenuItem(label);
item.setToolTipText(calcId);
- item.addActionListener(new java.awt.event.ActionListener()
+ item.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
JMenuItem item = new JMenuItem(label);
item.setToolTipText(MessageManager.formatMessage(
"label.open_url_param", new Object[] { url }));
- item.addActionListener(new java.awt.event.ActionListener()
+ item.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
groupMenu.setText(MessageManager.getString("label.selection"));
groupName.setText(MessageManager.getString("label.name"));
- groupName.addActionListener(new java.awt.event.ActionListener()
+ groupName.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
sequenceMenu.setText(MessageManager.getString("label.sequence"));
sequenceName.setText(MessageManager
.getString("label.edit_name_description"));
- sequenceName.addActionListener(new java.awt.event.ActionListener()
+ sequenceName.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
});
chooseAnnotations.setText(MessageManager
.getString("action.choose_annotations"));
- chooseAnnotations.addActionListener(new java.awt.event.ActionListener()
+ chooseAnnotations.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
});
sequenceDetails.setText(MessageManager
.getString("label.sequence_details"));
- sequenceDetails.addActionListener(new java.awt.event.ActionListener()
+ sequenceDetails.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
});
sequenceSelDetails.setText(MessageManager
.getString("label.sequence_details"));
- sequenceSelDetails
- .addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- sequenceSelectionDetails_actionPerformed();
- }
- });
- PIDColour.setFocusPainted(false);
+ sequenceSelDetails.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ sequenceSelectionDetails_actionPerformed();
+ }
+ });
+
unGroupMenuItem
.setText(MessageManager.getString("action.remove_group"));
- unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
+ unGroupMenuItem.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
});
createGroupMenuItem.setText(MessageManager
.getString("action.create_group"));
- createGroupMenuItem
- .addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- createGroupMenuItem_actionPerformed();
- }
- });
-
- outline.setText(MessageManager.getString("action.border_colour"));
- outline.addActionListener(new java.awt.event.ActionListener()
+ createGroupMenuItem.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- outline_actionPerformed();
+ createGroupMenuItem_actionPerformed();
}
});
- nucleotideMenuItem
- .setText(MessageManager.getString("label.nucleotide"));
- nucleotideMenuItem.addActionListener(new ActionListener()
+
+ outline.setText(MessageManager.getString("action.border_colour"));
+ outline.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- nucleotideMenuItem_actionPerformed();
+ outline_actionPerformed();
}
});
- colourMenu.setText(MessageManager.getString("label.group_colour"));
showBoxes.setText(MessageManager.getString("action.boxes"));
showBoxes.setState(true);
showBoxes.addActionListener(new ActionListener()
}
});
displayNonconserved.setText(MessageManager
- .getString("label.show_non_conversed"));
+ .getString("label.show_non_conserved"));
displayNonconserved.setState(true);
displayNonconserved.addActionListener(new ActionListener()
{
sequenceFeature_actionPerformed();
}
});
- textColour.setText(MessageManager.getString("label.text_colour"));
- textColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- textColour_actionPerformed();
- }
- });
jMenu1.setText(MessageManager.getString("label.group"));
pdbStructureDialog.setText(MessageManager
.getString("label.show_pdbstruct_dialog"));
sequenceMenu.add(sequenceName);
sequenceMenu.add(sequenceDetails);
sequenceMenu.add(makeReferenceSeq);
- colourMenu.add(textColour);
- colourMenu.add(noColourmenuItem);
- colourMenu.add(clustalColour);
- colourMenu.add(BLOSUM62Colour);
- colourMenu.add(PIDColour);
- colourMenu.add(zappoColour);
- colourMenu.add(taylorColour);
- colourMenu.add(hydrophobicityColour);
- colourMenu.add(helixColour);
- colourMenu.add(strandColour);
- colourMenu.add(turnColour);
- colourMenu.add(buriedColour);
- colourMenu.add(nucleotideMenuItem);
- if (ap.getAlignment().isNucleotide())
- {
- // JBPNote - commented since the colourscheme isn't functional
- colourMenu.add(purinePyrimidineColour);
- }
- colourMenu.add(userDefinedColour);
-
- if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
- {
- java.util.Enumeration userColours = jalview.gui.UserDefinedColours
- .getUserColourSchemes().keys();
- while (userColours.hasMoreElements())
- {
- JMenuItem item = new JMenuItem(userColours.nextElement().toString());
- item.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- userDefinedColour_actionPerformed(evt);
- }
- });
- colourMenu.add(item);
- }
- }
+ initColourMenu();
+ buildColourMenu();
- colourMenu.addSeparator();
- colourMenu.add(abovePIDColour);
- colourMenu.add(conservationMenuItem);
editMenu.add(copy);
editMenu.add(cut);
editMenu.add(editSequence);
jMenu1.add(showColourText);
jMenu1.add(outline);
jMenu1.add(displayNonconserved);
- noColourmenuItem.setText(MessageManager.getString("label.none"));
- noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
+ }
+
+ /**
+ * Constructs the entries for the colour menu
+ */
+ protected void initColourMenu()
+ {
+ colourMenu.setText(MessageManager.getString("label.group_colour"));
+ textColour.setText(MessageManager.getString("label.text_colour"));
+ textColour.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- noColourmenuItem_actionPerformed();
+ textColour_actionPerformed();
}
});
- clustalColour.setText(MessageManager
- .getString("label.clustalx_colours"));
- clustalColour.addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- clustalColour_actionPerformed();
- }
- });
- zappoColour.setText(MessageManager.getString("label.zappo"));
- zappoColour.addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- zappoColour_actionPerformed();
- }
- });
- taylorColour.setText(MessageManager.getString("label.taylor"));
- taylorColour.addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- taylorColour_actionPerformed();
- }
- });
- hydrophobicityColour.setText(MessageManager
- .getString("label.hydrophobicity"));
- hydrophobicityColour
- .addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hydrophobicityColour_actionPerformed();
- }
- });
- helixColour.setText(MessageManager.getString("label.helix_propensity"));
- helixColour.addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- helixColour_actionPerformed();
- }
- });
- strandColour.setText(MessageManager
- .getString("label.strand_propensity"));
- strandColour.addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- strandColour_actionPerformed();
- }
- });
- turnColour.setText(MessageManager.getString("label.turn_propensity"));
- turnColour.addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- turnColour_actionPerformed();
- }
- });
- buriedColour.setText(MessageManager.getString("label.buried_index"));
- buriedColour.addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- buriedColour_actionPerformed();
- }
- });
abovePIDColour.setText(MessageManager
- .getString("label.above_identity_percentage"));
- abovePIDColour.addActionListener(new java.awt.event.ActionListener()
+ .getString("label.above_identity_threshold"));
+ abovePIDColour.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- abovePIDColour_actionPerformed();
+ abovePIDColour_actionPerformed(abovePIDColour.isSelected());
}
});
- userDefinedColour.setText(MessageManager
- .getString("action.user_defined"));
- userDefinedColour.addActionListener(new java.awt.event.ActionListener()
+
+ modifyPID.setText(MessageManager
+ .getString("label.modify_identity_threshold"));
+ modifyPID.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- userDefinedColour_actionPerformed(e);
+ modifyPID_actionPerformed();
}
});
- PIDColour
- .setText(MessageManager.getString("label.percentage_identity"));
- PIDColour.addActionListener(new java.awt.event.ActionListener()
+
+ conservationMenuItem.setText(MessageManager
+ .getString("action.by_conservation"));
+ conservationMenuItem.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- PIDColour_actionPerformed();
+ conservationMenuItem_actionPerformed(conservationMenuItem
+ .isSelected());
}
});
- BLOSUM62Colour.setText(MessageManager.getString("label.blosum62"));
- BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
+
+ modifyConservation.setText(MessageManager
+ .getString("label.modify_conservation_threshold"));
+ modifyConservation.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
- BLOSUM62Colour_actionPerformed();
+ modifyConservation_actionPerformed();
}
});
- purinePyrimidineColour.setText(MessageManager
- .getString("label.purine_pyrimidine"));
- purinePyrimidineColour
- .addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- purinePyrimidineColour_actionPerformed();
- }
- });
+ }
- /*
- * covariationColour.addActionListener(new java.awt.event.ActionListener() {
- * public void actionPerformed(ActionEvent e) {
- * covariationColour_actionPerformed(); } });
- */
+ /**
+ * Builds the group colour sub-menu, including any user-defined colours which
+ * were loaded at startup or during the Jalview session
+ */
+ protected void buildColourMenu()
+ {
+ SequenceGroup sg = ap.av.getSelectionGroup();
+ if (sg == null)
+ {
+ /*
+ * popup menu with no sequence group scope
+ */
+ return;
+ }
+ colourMenu.removeAll();
+ colourMenu.add(textColour);
+ colourMenu.addSeparator();
- conservationMenuItem.setText(MessageManager
- .getString("label.conservation"));
- conservationMenuItem
- .addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- conservationMenuItem_actionPerformed();
- }
- });
+ ColourMenuHelper.addMenuItems(colourMenu, this, sg, false);
+
+ colourMenu.addSeparator();
+ colourMenu.add(conservationMenuItem);
+ colourMenu.add(modifyConservation);
+ colourMenu.add(abovePIDColour);
+ colourMenu.add(modifyPID);
+ }
+
+ protected void modifyConservation_actionPerformed()
+ {
+ SequenceGroup sg = getGroup();
+ if (sg.cs != null)
+ {
+ SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
+ SliderPanel.showConservationSlider();
+ }
+ }
+
+ protected void modifyPID_actionPerformed()
+ {
+ SequenceGroup sg = getGroup();
+ if (sg.cs != null)
+ {
+ // int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
+ // .getName());
+ // sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
+ SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
+ .getName());
+ SliderPanel.showPIDSlider();
+ }
}
/**
* Temporary store to hold distinct calcId / type pairs for the tooltip.
* Using TreeMap means calcIds are shown in alphabetical order.
*/
- Map<String, String> tipEntries = new TreeMap<String, String>();
+ SortedMap<String, String> tipEntries = new TreeMap<String, String>();
final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<SequenceI, List<AlignmentAnnotation>>();
AlignmentI al = this.ap.av.getAlignment();
AlignmentUtils.findAddableReferenceAnnotations(forSequences,
PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
}
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void clustalColour_actionPerformed()
- {
- SequenceGroup sg = getGroup();
- sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void zappoColour_actionPerformed()
- {
- getGroup().cs = new ZappoColourScheme();
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void taylorColour_actionPerformed()
- {
- getGroup().cs = new TaylorColourScheme();
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void hydrophobicityColour_actionPerformed()
- {
- getGroup().cs = new HydrophobicColourScheme();
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void helixColour_actionPerformed()
- {
- getGroup().cs = new HelixColourScheme();
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void strandColour_actionPerformed()
- {
- getGroup().cs = new StrandColourScheme();
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void turnColour_actionPerformed()
- {
- getGroup().cs = new TurnColourScheme();
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void buriedColour_actionPerformed()
- {
- getGroup().cs = new BuriedColourScheme();
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- public void nucleotideMenuItem_actionPerformed()
- {
- getGroup().cs = new NucleotideColourScheme();
- refresh();
- }
-
- protected void purinePyrimidineColour_actionPerformed()
- {
- getGroup().cs = new PurinePyrimidineColourScheme();
- refresh();
- }
-
/*
* protected void covariationColour_actionPerformed() { getGroup().cs = new
* CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
/**
* DOCUMENT ME!
*
+ * @param selected
+ *
* @param e
* DOCUMENT ME!
*/
- protected void abovePIDColour_actionPerformed()
+ public void abovePIDColour_actionPerformed(boolean selected)
{
SequenceGroup sg = getGroup();
if (sg.cs == null)
return;
}
- if (abovePIDColour.isSelected())
+ if (selected)
{
sg.cs.setConsensus(AAFrequency.calculate(
sg.getSequences(ap.av.getHiddenRepSequences()),
sg.getStartRes(), sg.getEndRes() + 1));
- int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
+ int threshold = SliderPanel.setPIDSliderSource(ap,
+ sg.getGroupColourScheme(), getGroup()
.getName());
sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
// remove PIDColouring
{
sg.cs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
+ SliderPanel.hidePIDSlider();
}
+ modifyPID.setEnabled(selected);
refresh();
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void userDefinedColour_actionPerformed(ActionEvent e)
- {
- SequenceGroup sg = getGroup();
-
- if (e.getSource().equals(userDefinedColour))
- {
- new UserDefinedColours(ap, sg);
- }
- else
- {
- UserColourScheme udc = (UserColourScheme) UserDefinedColours
- .getUserColourSchemes().get(e.getActionCommand());
-
- sg.cs = udc;
- }
- refresh();
- }
-
- /**
* Open a panel where the user can choose which types of sequence annotation
* to show or hide.
*
* @param e
* DOCUMENT ME!
*/
- protected void PIDColour_actionPerformed()
- {
- SequenceGroup sg = getGroup();
- sg.cs = new PIDColourScheme();
- sg.cs.setConsensus(AAFrequency.calculate(
- sg.getSequences(ap.av.getHiddenRepSequences()),
- sg.getStartRes(), sg.getEndRes() + 1));
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void BLOSUM62Colour_actionPerformed()
- {
- SequenceGroup sg = getGroup();
-
- sg.cs = new Blosum62ColourScheme();
-
- sg.cs.setConsensus(AAFrequency.calculate(
- sg.getSequences(ap.av.getHiddenRepSequences()),
- sg.getStartRes(), sg.getEndRes() + 1));
-
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void noColourmenuItem_actionPerformed()
- {
- getGroup().cs = null;
- refresh();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- protected void conservationMenuItem_actionPerformed()
+ public void conservationMenuItem_actionPerformed(boolean selected)
{
SequenceGroup sg = getGroup();
if (sg.cs == null)
return;
}
- if (conservationMenuItem.isSelected())
+ if (selected)
{
// JBPNote: Conservation name shouldn't be i18n translated
Conservation c = new Conservation("Group", sg.getSequences(ap.av
c.calculate();
c.verdict(false, ap.av.getConsPercGaps());
-
sg.cs.setConservation(c);
- SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
+ SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
+ sg.getName());
SliderPanel.showConservationSlider();
}
else
// remove ConservationColouring
{
sg.cs.setConservation(null);
+ SliderPanel.hideConservationSlider();
}
+ modifyConservation.setEnabled(selected);
refresh();
}
AnnotationColourGradient.NO_THRESHOLD);
acg.setPredefinedColours(true);
- sg.cs = acg;
+ sg.setColourScheme(acg);
refresh();
}
// or we simply trust the user wants
// wysiwig behaviour
- FileFormatI fileFormat = FileFormats.getInstance().forName(
- e.getActionCommand());
+ FileFormatI fileFormat = FileFormats.getInstance().forName(e.getActionCommand());
cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true));
}
}
}
+ /**
+ * Action on user selecting an item from the colour menu (that does not have
+ * its bespoke action handler)
+ *
+ * @return
+ */
+ @Override
+ public void changeColour_actionPerformed(String colourSchemeName)
+ {
+ SequenceGroup sg = getGroup();
+ if (ResidueColourScheme.USER_DEFINED.equals(colourSchemeName))
+ {
+ /*
+ * open a panel to load or configure a user-defined colour scheme
+ */
+ new UserDefinedColours(ap, sg);
+ }
+ else
+ {
+ /*
+ * switch to the chosen colour scheme (or null for None)
+ */
+ ColourSchemeI colourScheme = ColourSchemes.getInstance().getColourScheme(
+ colourSchemeName, sg, ap.av.getHiddenRepSequences());
+ sg.setColourScheme(colourScheme);
+ if (colourScheme instanceof Blosum62ColourScheme
+ || colourScheme instanceof PIDColourScheme)
+ {
+ sg.cs.setConsensus(AAFrequency.calculate(
+ sg.getSequences(ap.av.getHiddenRepSequences()),
+ sg.getStartRes(), sg.getEndRes() + 1));
+ }
+ }
+
+ refresh();
+ }
+
}
*/
package jalview.gui;
-import static jalview.util.UrlConstants.DB_ACCESSION;
-import static jalview.util.UrlConstants.EMBLEBI_STRING;
-import static jalview.util.UrlConstants.SEQUENCE_ID;
-import static jalview.util.UrlConstants.SRS_STRING;
-
import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
import jalview.bin.Cache;
import jalview.gui.Help.HelpId;
import jalview.io.JalviewFileView;
import jalview.jbgui.GPreferences;
import jalview.jbgui.GSequenceLink;
-import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
+import jalview.schemes.ResidueColourScheme;
+import jalview.urls.UrlLinkTableModel;
+import jalview.urls.api.UrlProviderFactoryI;
+import jalview.urls.api.UrlProviderI;
+import jalview.urls.desktop.DesktopUrlProviderFactory;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.UrlConstants;
import jalview.ws.sifts.SiftsSettings;
import java.awt.BorderLayout;
import java.awt.Color;
+import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
-import java.util.StringTokenizer;
-import java.util.Vector;
import javax.help.HelpSetException;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
+import javax.swing.ListSelectionModel;
+import javax.swing.RowFilter;
+import javax.swing.RowSorter;
+import javax.swing.SortOrder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableModel;
+import javax.swing.table.TableRowSorter;
import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
* Holds name and link separated with | character. Sequence ID must be
* $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
*/
- public static Vector<String> sequenceURLLinks;
+ public static UrlProviderI sequenceUrlLinks;
+
+ public static UrlLinkTableModel dataModel;
/**
* Holds name and link separated with | character. Sequence IDS and Sequences
public static List<String> groupURLLinks;
static
{
- String string = Cache.getDefault("SEQUENCE_LINKS", EMBLEBI_STRING);
- sequenceURLLinks = new Vector<String>();
-
- try
+ // get links selected to be in the menu (SEQUENCE_LINKS)
+ // and links entered by the user but not selected (STORED_LINKS)
+ String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
+ String notInMenuString = Cache.getDefault("STORED_LINKS", "");
+ String defaultUrl = Cache.getDefault("DEFAULT_URL",
+ UrlConstants.DEFAULT_LABEL);
+
+ // if both links lists are empty, add the DEFAULT_URL link
+ // otherwise we assume the default link is in one of the lists
+ if (inMenuString.isEmpty() && notInMenuString.isEmpty())
{
- StringTokenizer st = new StringTokenizer(string, "|");
- while (st.hasMoreElements())
- {
- String name = st.nextToken();
- String url = st.nextToken();
- // check for '|' within a regex
- int rxstart = url.indexOf("$" + DB_ACCESSION + "$");
- if (rxstart == -1)
- {
- rxstart = url.indexOf("$" + SEQUENCE_ID + "$");
- }
- while (rxstart == -1 && url.indexOf("/=$") == -1)
- {
- url = url + "|" + st.nextToken();
- }
- sequenceURLLinks.addElement(name + "|" + url);
- }
- } catch (Exception ex)
- {
- System.out.println(ex + "\nError parsing sequence links");
- }
- {
- // upgrade old SRS link
- int srsPos = sequenceURLLinks.indexOf(SRS_STRING);
- if (srsPos > -1)
- {
- sequenceURLLinks.setElementAt(EMBLEBI_STRING, srsPos);
- }
+ inMenuString = UrlConstants.DEFAULT_STRING;
}
+ UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
+ inMenuString, notInMenuString);
+ sequenceUrlLinks = factory.createUrlProvider();
+ dataModel = new UrlLinkTableModel(sequenceUrlLinks);
/**
* TODO: reformulate groupURL encoding so two or more can be stored in the
groupURLLinks = new ArrayList<String>();
}
- Vector<String> nameLinks, urlLinks;
-
JInternalFrame frame;
DasSourceBrowser dasSource;
/*
* Set Colours tab defaults
*/
- for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
+ protColour.addItem(ResidueColourScheme.NONE);
+ nucColour.addItem(ResidueColourScheme.NONE);
+ for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
{
- protColour.addItem(ColourSchemeProperty.getColourName(i));
- nucColour.addItem(ColourSchemeProperty.getColourName(i));
+ String name = cs.getSchemeName();
+ protColour.addItem(name);
+ nucColour.addItem(name);
}
- String oldProp = Cache.getDefault(DEFAULT_COLOUR, "None");
+ String oldProp = Cache.getDefault(DEFAULT_COLOUR,
+ ResidueColourScheme.NONE);
String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
protColour.setSelectedItem(newProp != null ? newProp : oldProp);
newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
/*
* Set Connections tab defaults
*/
- nameLinks = new Vector<String>();
- urlLinks = new Vector<String>();
- for (int i = 0; i < sequenceURLLinks.size(); i++)
+
+ // set up sorting
+ linkUrlTable.setModel(dataModel);
+ final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
+ linkUrlTable.getModel());
+ linkUrlTable.setRowSorter(sorter);
+ List<RowSorter.SortKey> sortKeys = new ArrayList<>();
+
+ UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
+ sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
+ SortOrder.DESCENDING));
+ sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
+ SortOrder.DESCENDING));
+ sortKeys.add(new RowSorter.SortKey(m.getNameColumn(),
+ SortOrder.ASCENDING));
+
+ sorter.setSortKeys(sortKeys);
+ sorter.sort();
+
+ // set up filtering
+ ActionListener onReset;
+ onReset = new ActionListener()
{
- String link = sequenceURLLinks.elementAt(i).toString();
- nameLinks.addElement(link.substring(0, link.indexOf("|")));
- urlLinks.addElement(link.substring(link.indexOf("|") + 1));
- }
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ filterTB.setText("");
+ sorter.setRowFilter(RowFilter.regexFilter(""));
+ }
+
+ };
+ doReset.addActionListener(onReset);
+
+ // filter to display only custom urls
+ final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
+ {
+ @Override
+ public boolean include(
+ Entry<? extends TableModel, ? extends Object> entry)
+ {
+ return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
+ }
+ };
+
+ final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
+ linkUrlTable.getModel());
+ customSorter.setRowFilter(customUrlFilter);
+
+ ActionListener onCustomOnly;
+ onCustomOnly = new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ filterTB.setText("");
+ sorter.setRowFilter(customUrlFilter);
+ }
+ };
+ userOnly.addActionListener(onCustomOnly);
+
+ filterTB.getDocument().addDocumentListener(new DocumentListener()
+ {
+ String caseInsensitiveFlag = "(?i)";
- updateLinkData();
+ @Override
+ public void changedUpdate(DocumentEvent e)
+ {
+ sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
+ + filterTB.getText()));
+ }
+
+ @Override
+ public void removeUpdate(DocumentEvent e)
+ {
+ sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
+ + filterTB.getText()));
+ }
+
+ @Override
+ public void insertUpdate(DocumentEvent e)
+ {
+ sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
+ + filterTB.getText()));
+ }
+ });
+
+ // set up list selection functionality
+ linkUrlTable.getSelectionModel().addListSelectionListener(
+ new UrlListSelectionHandler());
+
+ // set up radio buttons
+ int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
+ .getPrimaryColumn();
+ String onClickName = linkUrlTable.getColumnName(onClickCol);
+ linkUrlTable.getColumn(onClickName).setCellRenderer(
+ new RadioButtonRenderer());
+ linkUrlTable.getColumn(onClickName)
+ .setCellEditor(new RadioButtonEditor());
+
+ // get boolean columns and resize those to min possible
+ for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
+ {
+ if (linkUrlTable.getModel().getColumnClass(column)
+ .equals(Boolean.class))
+ {
+ TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn(
+ column);
+ int preferredWidth = tableColumn.getMinWidth();
+
+ TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
+ column);
+ Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
+ int cwidth = c.getPreferredSize().width
+ + linkUrlTable.getIntercellSpacing().width;
+ preferredWidth = Math.max(preferredWidth, cwidth);
+
+ tableColumn.setPreferredWidth(preferredWidth);
+ }
+ }
useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
- proxyServerTB.setEnabled(useProxy.isSelected());
- proxyPortTB.setEnabled(useProxy.isSelected());
+ useProxy_actionPerformed(); // make sure useProxy is correctly initialised
proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
jalview.util.BrowserLauncher.resetBrowser();
- if (nameLinks.size() > 0)
+ // save user-defined and selected links
+ String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
+ if (menuLinks.isEmpty())
+ {
+ Cache.applicationProperties.remove("SEQUENCE_LINKS");
+ }
+ else
{
- StringBuffer links = new StringBuffer();
- sequenceURLLinks = new Vector<String>();
- for (int i = 0; i < nameLinks.size(); i++)
- {
- sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
- + urlLinks.elementAt(i));
- links.append(sequenceURLLinks.elementAt(i).toString());
- links.append("|");
- }
- // remove last "|"
- links.setLength(links.length() - 1);
Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
- links.toString());
+ menuLinks.toString());
+ }
+
+ String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
+ if (nonMenuLinks.isEmpty())
+ {
+ Cache.applicationProperties.remove("STORED_LINKS");
}
else
{
- Cache.applicationProperties.remove("SEQUENCE_LINKS");
- sequenceURLLinks.clear();
+ Cache.applicationProperties.setProperty("STORED_LINKS",
+ nonMenuLinks.toString());
}
+ Cache.applicationProperties.setProperty("DEFAULT_URL",
+ sequenceUrlLinks.getPrimaryUrlId());
+
Cache.applicationProperties.setProperty("USE_PROXY",
Boolean.toString(useProxy.isSelected()));
@Override
public void newLink_actionPerformed(ActionEvent e)
{
-
GSequenceLink link = new GSequenceLink();
boolean valid = false;
while (!valid)
{
if (link.checkValid())
{
- nameLinks.addElement(link.getName());
- urlLinks.addElement(link.getURL());
- updateLinkData();
- valid = true;
+ if (((UrlLinkTableModel) linkUrlTable.getModel())
+ .isUniqueName(link.getName()))
+ {
+ ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow(
+ link.getName(), link.getURL());
+ valid = true;
+ }
+ else
+ {
+ link.notifyDuplicate();
+ continue;
+ }
}
}
else
{
GSequenceLink link = new GSequenceLink();
- int index = linkNameList.getSelectedIndex();
+ int index = linkUrlTable.getSelectedRow();
if (index == -1)
{
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
- MessageManager.getString("label.no_link_selected"),
- MessageManager.getString("label.no_link_selected"),
- JvOptionPane.WARNING_MESSAGE);
+ // button no longer enabled if row is not selected
+ Cache.log.debug("Edit with no row selected in linkUrlTable");
return;
}
- link.setName(nameLinks.elementAt(index).toString());
- link.setURL(urlLinks.elementAt(index).toString());
+ int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
+ .getNameColumn();
+ int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
+ .getUrlColumn();
+ String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
+ link.setName(oldName);
+ link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
boolean valid = false;
while (!valid)
{
-
if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
- MessageManager.getString("label.new_sequence_url_link"),
+ MessageManager.getString("label.edit_sequence_url_link"),
JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
{
if (link.checkValid())
{
- nameLinks.setElementAt(link.getName(), index);
- urlLinks.setElementAt(link.getURL(), index);
- updateLinkData();
- valid = true;
+ if ((oldName.equals(link.getName()))
+ || (((UrlLinkTableModel) linkUrlTable.getModel())
+ .isUniqueName(link.getName())))
+ {
+ linkUrlTable.setValueAt(link.getName(), index, nameCol);
+ linkUrlTable.setValueAt(link.getURL(), index, urlCol);
+ valid = true;
+ }
+ else
+ {
+ link.notifyDuplicate();
+ continue;
+ }
}
}
-
else
{
break;
@Override
public void deleteLink_actionPerformed(ActionEvent e)
{
- int index = linkNameList.getSelectedIndex();
+ int index = linkUrlTable.getSelectedRow();
+ int modelIndex = -1;
if (index == -1)
{
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
- MessageManager.getString("label.no_link_selected"),
- MessageManager.getString("label.no_link_selected"),
- JvOptionPane.WARNING_MESSAGE);
+ // button no longer enabled if row is not selected
+ Cache.log.debug("Delete with no row selected in linkUrlTable");
return;
}
- nameLinks.removeElementAt(index);
- urlLinks.removeElementAt(index);
- updateLinkData();
- }
+ else
+ {
+ modelIndex = linkUrlTable.convertRowIndexToModel(index);
+ }
- void updateLinkData()
- {
- linkNameList.setListData(nameLinks);
- linkURLList.setListData(urlLinks);
+ // make sure we use the model index to delete, and not the table index
+ ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
}
+
@Override
public void defaultBrowser_mouseClicked(MouseEvent e)
{
return name.hashCode() + code.hashCode();
}
}
+
+ private class UrlListSelectionHandler implements ListSelectionListener
+ {
+
+ @Override
+ public void valueChanged(ListSelectionEvent e)
+ {
+ ListSelectionModel lsm = (ListSelectionModel) e.getSource();
+
+ int index = lsm.getMinSelectionIndex();
+ if (index == -1)
+ {
+ // no selection, so disable delete/edit buttons
+ editLink.setEnabled(false);
+ deleteLink.setEnabled(false);
+ return;
+ }
+ int modelIndex = linkUrlTable.convertRowIndexToModel(index);
+
+ // enable/disable edit and delete link buttons
+ if (((UrlLinkTableModel) linkUrlTable.getModel())
+ .isRowDeletable(modelIndex))
+ {
+ deleteLink.setEnabled(true);
+ }
+ else
+ {
+ deleteLink.setEnabled(false);
+ }
+
+ if (((UrlLinkTableModel) linkUrlTable.getModel())
+ .isRowEditable(modelIndex))
+ {
+ editLink.setEnabled(true);
+ }
+ else
+ {
+ editLink.setEnabled(false);
+ }
+ }
+}
}
slider.addChangeListener(new ChangeListener()
{
+ @Override
public void stateChanged(ChangeEvent evt)
{
valueField.setText(slider.getValue() + "");
false);
frame.addInternalFrameListener(new InternalFrameAdapter()
{
+ @Override
public void internalFrameClosing(InternalFrameEvent evt)
{
ap.getIdPanel().getIdCanvas().setHighlighted(null);
*
* @return DOCUMENT ME!
*/
+ @Override
public void run()
{
JProgressBar progress = new JProgressBar();
* @param e
* DOCUMENT ME!
*/
+ @Override
public void applyButton_actionPerformed(ActionEvent e)
{
Vector del = new Vector();
* @param e
* DOCUMENT ME!
*/
+ @Override
public void undoButton_actionPerformed(ActionEvent e)
{
if (historyList == null || historyList.isEmpty())
}
}
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- public void valueField_actionPerformed(ActionEvent e)
- {
- try
- {
- int i = Integer.parseInt(valueField.getText());
- slider.setValue(i);
- } catch (Exception ex)
- {
- valueField.setText(slider.getValue() + "");
- }
- }
-
}
}
/**
- * DOCUMENT ME!
+ * Action on dragging the mouse in the scale panel is to expand or shrink the
+ * selection group range (including any hidden columns that it spans)
*
* @param evt
- * DOCUMENT ME!
*/
@Override
public void mouseDragged(MouseEvent evt)
{
mouseDragging = true;
+ ColumnSelection cs = av.getColumnSelection();
int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
- if (res < 0)
- {
- res = 0;
- }
-
- if (av.hasHiddenColumns())
- {
- res = av.getColumnSelection().adjustForHiddenColumns(res);
- }
-
- if (res >= av.getAlignment().getWidth())
- {
- res = av.getAlignment().getWidth() - 1;
- }
-
- if (res < min)
- {
- min = res;
- }
-
- if (res > max)
- {
- max = res;
- }
+ res = Math.max(0, res);
+ res = cs.adjustForHiddenColumns(res);
+ res = Math.min(res, av.getAlignment().getWidth() - 1);
+ min = Math.min(res, min);
+ max = Math.max(res, max);
SequenceGroup sg = av.getSelectionGroup();
-
if (sg != null)
{
stretchingGroup = true;
-
- if (!av.getColumnSelection().contains(res))
- {
- av.getColumnSelection().addElement(res);
- }
-
- if (res > sg.getStartRes())
- {
- sg.setEndRes(res);
- }
- if (res < sg.getStartRes())
- {
- sg.setStartRes(res);
- }
-
- int col;
- for (int i = min; i <= max; i++)
- {
- col = i; // av.getColumnSelection().adjustForHiddenColumns(i);
-
- if ((col < sg.getStartRes()) || (col > sg.getEndRes()))
- {
- av.getColumnSelection().removeElement(col);
- }
- else
- {
- av.getColumnSelection().addElement(col);
- }
- }
-
+ cs.stretchGroup(res, sg, min, max);
ap.paintAlignment(false);
}
}
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.io.SequenceAnnotationReport;
+import jalview.renderer.ResidueShaderI;
import jalview.schemes.ResidueProperties;
import jalview.structure.SelectionListener;
import jalview.structure.SelectionSource;
stretchGroup = av.getSelectionGroup();
- if (stretchGroup == null)
+ if (stretchGroup == null || !stretchGroup.contains(sequence, res))
{
stretchGroup = av.getAlignment().findGroup(sequence, res);
- av.setSelectionGroup(stretchGroup);
- }
- if (stretchGroup == null
- || !stretchGroup.getSequences(null).contains(sequence)
- || (stretchGroup.getStartRes() > res)
- || (stretchGroup.getEndRes() < res))
- {
- stretchGroup = null;
-
- SequenceGroup[] allGroups = av.getAlignment().findAllGroups(sequence);
-
- if (allGroups != null)
+ if (stretchGroup != null)
{
- for (int i = 0; i < allGroups.length; i++)
- {
- if ((allGroups[i].getStartRes() <= res)
- && (allGroups[i].getEndRes() >= res))
- {
- stretchGroup = allGroups[i];
- break;
- }
- }
+ // only update the current selection if the popup menu has a group to
+ // focus on
+ av.setSelectionGroup(stretchGroup);
}
-
- av.setSelectionGroup(stretchGroup);
}
if (evt.isPopupTrigger()) // Mac: mousePressed
if (av.getConservationSelected())
{
- SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
- "Background");
+ SliderPanel.setConservationSlider(ap, av.getResidueShading(),
+ ap.getViewName());
}
if (av.getAbovePIDThreshold())
{
- SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
- "Background");
+ SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
+ ap.getViewName());
}
+ // TODO: stretchGroup will always be not null. Is this a merge error ?
if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
{
// Edit end res position of selected group
stretchGroup.cs.alignmentChanged(stretchGroup,
av.getHiddenRepSequences());
+ ResidueShaderI groupColourScheme = stretchGroup.getGroupColourScheme();
+ String name = stretchGroup.getName();
if (stretchGroup.cs.conservationApplied())
{
- SliderPanel.setConservationSlider(ap, stretchGroup.cs,
- stretchGroup.getName());
+ SliderPanel.setConservationSlider(ap, groupColourScheme, name);
}
- else
+ if (stretchGroup.cs.getThreshold() > 0)
{
- SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
- stretchGroup.getName());
+ SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
}
}
PaintRefresher.Refresh(this, av.getSequenceSetId());
import jalview.api.FeatureRenderer;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.schemes.ColourSchemeI;
+import jalview.renderer.ResidueShaderI;
+import jalview.util.Comparison;
import java.awt.Color;
import java.awt.FontMetrics;
{
if (currentSequenceGroup.getDisplayBoxes())
{
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, i);
}
}
else if (av.getShowBoxes())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getResidueShading(), seq, i);
}
return resBoxColour;
/**
* DOCUMENT ME!
*
- * @param cs
+ * @param shader
* DOCUMENT ME!
* @param seq
* DOCUMENT ME!
* @param i
* DOCUMENT ME!
*/
- void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
+ void getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
{
- if (cs != null)
+ if (shader != null)
{
- resBoxColour = cs.findColour(seq.getCharAt(i), i, seq);
+ resBoxColour = shader.findColour(seq.getCharAt(i),
+ i, seq);
}
- else if (forOverview
- && !jalview.util.Comparison.isGap(seq.getCharAt(i)))
+ else if (forOverview && !Comparison.isGap(seq.getCharAt(i)))
{
resBoxColour = Color.lightGray;
}
{
if (currentSequenceGroup.getDisplayBoxes())
{
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq,
+ i);
}
}
else if (av.getShowBoxes())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getResidueShading(), seq, i);
}
-
}
if (resBoxColour != tempColour)
|| currentSequenceGroup.getColourText())
{
getboxColour = true;
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq,
+ i);
if (currentSequenceGroup.getColourText())
{
if (av.getColourText())
{
getboxColour = true;
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getResidueShading(), seq, i);
if (av.getShowBoxes())
{
{
if (!getboxColour)
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getResidueShading(), seq, i);
}
if (resBoxColour.getRed() + resBoxColour.getBlue()
import jalview.datamodel.SequenceGroup;
import jalview.jbgui.GSliderPanel;
-import jalview.schemes.ColourSchemeI;
+import jalview.renderer.ResidueShaderI;
import jalview.util.MessageManager;
-import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
-import java.util.Iterator;
+import java.beans.PropertyVetoException;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
/**
* DOCUMENT ME!
*/
public class SliderPanel extends GSliderPanel
{
+ private static final String BACKGROUND = "Background";
+
static JInternalFrame conservationSlider;
static JInternalFrame PIDSlider;
boolean forConservation = true;
- ColourSchemeI cs;
+ ResidueShaderI cs;
+
+ /**
+ * Returns the currently displayed slider panel (or null if none).
+ *
+ * @return
+ */
+ public static SliderPanel getSliderPanel()
+ {
+ if (conservationSlider != null && conservationSlider.isVisible())
+ {
+ return (SliderPanel) conservationSlider.getContentPane();
+ }
+ if (PIDSlider != null && PIDSlider.isVisible())
+ {
+ return (SliderPanel) PIDSlider.getContentPane();
+ }
+ return null;
+ }
/**
* Creates a new SliderPanel object.
* DOCUMENT ME!
* @param forConserve
* DOCUMENT ME!
- * @param cs
+ * @param scheme
* DOCUMENT ME!
*/
public SliderPanel(final AlignmentPanel ap, int value,
- boolean forConserve, ColourSchemeI cs)
+ boolean forConserve, ResidueShaderI scheme)
{
this.ap = ap;
- this.cs = cs;
+ this.cs = scheme;
forConservation = forConserve;
undoButton.setVisible(false);
applyButton.setVisible(false);
slider.addChangeListener(new ChangeListener()
{
+ @Override
public void stateChanged(ChangeEvent evt)
{
valueField.setText(slider.getValue() + "");
slider.addMouseListener(new MouseAdapter()
{
+ @Override
public void mouseReleased(MouseEvent evt)
{
ap.paintAlignment(true);
}
/**
- * DOCUMENT ME!
+ * Method to 'set focus' of the Conservation slider panel
*
* @param ap
- * DOCUMENT ME!
- * @param cs
- * DOCUMENT ME!
+ * the panel to repaint on change of slider
+ * @param rs
+ * the colour scheme to update on change of slider
* @param source
- * DOCUMENT ME!
+ * a text description for the panel's title
*
- * @return DOCUMENT ME!
+ * @return
*/
public static int setConservationSlider(AlignmentPanel ap,
- ColourSchemeI cs, String source)
+ ResidueShaderI rs, String source)
{
- SliderPanel sp = null;
+ SliderPanel sliderPanel = null;
if (conservationSlider == null)
{
- sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
+ sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs);
conservationSlider = new JInternalFrame();
- conservationSlider.setContentPane(sp);
+ conservationSlider.setContentPane(sliderPanel);
conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
}
else
{
- sp = (SliderPanel) conservationSlider.getContentPane();
- sp.cs = cs;
+ sliderPanel = (SliderPanel) conservationSlider.getContentPane();
+ sliderPanel.valueField.setText(String.valueOf(rs.getConservationInc()));
+ sliderPanel.cs = rs;
+ sliderPanel.ap = ap;
+ sliderPanel.slider.setValue(rs.getConservationInc());
}
- conservationSlider
- .setTitle(MessageManager.formatMessage(
- "label.conservation_colour_increment",
- new String[] { source }));
+ conservationSlider.setTitle(MessageManager.formatMessage(
+ "label.conservation_colour_increment",
+ new String[] { source == null ? BACKGROUND : source }));
if (ap.av.getAlignment().getGroups() != null)
{
- sp.setAllGroupsCheckEnabled(true);
+ sliderPanel.setAllGroupsCheckEnabled(true);
}
else
{
- sp.setAllGroupsCheckEnabled(false);
+ sliderPanel.setAllGroupsCheckEnabled(false);
}
- return sp.getValue();
+ return sliderPanel.getValue();
}
/**
- * DOCUMENT ME!
+ * Hides the PID slider panel if it is shown
*/
- public static void showConservationSlider()
+ public static void hidePIDSlider()
{
- try
+ if (PIDSlider != null)
{
- PIDSlider.setClosed(true);
- PIDSlider = null;
- } catch (Exception ex)
+ try
+ {
+ PIDSlider.setClosed(true);
+ PIDSlider = null;
+ } catch (PropertyVetoException ex)
+ {
+ }
+ }
+ }
+
+ /**
+ * Hides the conservation slider panel if it is shown
+ */
+ public static void hideConservationSlider()
+ {
+ if (conservationSlider != null)
{
+ try
+ {
+ conservationSlider.setClosed(true);
+ conservationSlider = null;
+ } catch (PropertyVetoException ex)
+ {
+ }
}
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static void showConservationSlider()
+ {
+ hidePIDSlider();
if (!conservationSlider.isVisible())
{
Desktop.addInternalFrame(conservationSlider,
conservationSlider.getTitle(), 420, 90, false);
conservationSlider
- .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+ .addInternalFrameListener(new InternalFrameAdapter()
{
- public void internalFrameClosed(
- javax.swing.event.InternalFrameEvent e)
+ @Override
+ public void internalFrameClosed(InternalFrameEvent e)
{
conservationSlider = null;
}
}
/**
- * DOCUMENT ME!
+ * Method to 'set focus' of the PID slider panel
*
* @param ap
- * DOCUMENT ME!
- * @param cs
- * DOCUMENT ME!
+ * the panel to repaint on change of slider
+ * @param rs
+ * the colour scheme to update on change of slider
* @param source
- * DOCUMENT ME!
+ * a text description for the panel's title
*
- * @return DOCUMENT ME!
+ * @return
*/
- public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
- String source)
+ public static int setPIDSliderSource(AlignmentPanel ap,
+ ResidueShaderI rs, String source)
{
- SliderPanel pid = null;
+ int threshold = rs.getThreshold();
- int threshold = cs.getThreshold();
+ SliderPanel sliderPanel = null;
if (PIDSlider == null)
{
- pid = new SliderPanel(ap, threshold, false, cs);
+ sliderPanel = new SliderPanel(ap, threshold, false, rs);
PIDSlider = new JInternalFrame();
- PIDSlider.setContentPane(pid);
+ PIDSlider.setContentPane(sliderPanel);
PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
}
else
{
- pid = (SliderPanel) PIDSlider.getContentPane();
- pid.cs = cs;
+ sliderPanel = (SliderPanel) PIDSlider.getContentPane();
+ sliderPanel.cs = rs;
+ sliderPanel.ap = ap;
+ sliderPanel.valueField.setText(String.valueOf(rs.getThreshold()));
+ sliderPanel.slider.setValue(rs.getThreshold());
}
- PIDSlider
- .setTitle(MessageManager.formatMessage(
- "label.percentage_identity_threshold",
- new String[] { source }));
+ PIDSlider.setTitle(MessageManager.formatMessage(
+ "label.percentage_identity_threshold",
+ new String[] { source == null ? BACKGROUND : source }));
if (ap.av.getAlignment().getGroups() != null)
{
- pid.setAllGroupsCheckEnabled(true);
+ sliderPanel.setAllGroupsCheckEnabled(true);
}
else
{
- pid.setAllGroupsCheckEnabled(false);
+ sliderPanel.setAllGroupsCheckEnabled(false);
}
- return pid.getValue();
+ return sliderPanel.getValue();
}
/**
* DOCUMENT ME!
+ *
+ * @return
*/
- public static void showPIDSlider()
+ public static JInternalFrame showPIDSlider()
{
- try
- {
- conservationSlider.setClosed(true);
- conservationSlider = null;
- } catch (Exception ex)
- {
- }
+ hideConservationSlider();
if (!PIDSlider.isVisible())
{
Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), 420, 90,
false);
PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
- PIDSlider
- .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
- {
- public void internalFrameClosed(
- javax.swing.event.InternalFrameEvent e)
- {
- PIDSlider = null;
- }
- });
+ PIDSlider.addInternalFrameListener(new InternalFrameAdapter()
+ {
+ @Override
+ public void internalFrameClosed(InternalFrameEvent e)
+ {
+ PIDSlider = null;
+ }
+ });
PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
}
+ return PIDSlider;
}
/**
- * DOCUMENT ME!
+ * Updates the colour scheme with the current (identity threshold or
+ * conservation) percentage value. Also updates all groups if 'apply to all
+ * groups' is selected.
*
- * @param i
- * DOCUMENT ME!
+ * @param percent
*/
- public void valueChanged(int i)
+ public void valueChanged(int percent)
{
- if (cs == null)
+ if (!forConservation)
{
- return;
+ ap.av.setThreshold(percent);
}
-
- ColourSchemeI toChange = cs;
- Iterator<SequenceGroup> allGroups = null;
+ updateColourScheme(percent, cs);
if (allGroupsCheck.isSelected())
{
- allGroups = ap.av.getAlignment().getGroups().listIterator();
- }
-
- while (toChange != null)
- {
- if (forConservation)
- {
- toChange.setConservationInc(i);
- }
- else
- {
- toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
- }
- if (allGroups != null && allGroups.hasNext())
- {
- while ((toChange = allGroups.next().cs) == null
- && allGroups.hasNext())
- {
- ;
- }
- }
- else
+ for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- toChange = null;
+ updateColourScheme(percent, sg.getGroupColourScheme());
}
}
}
/**
+ * Updates the colour scheme (if not null) with the current (identity
+ * threshold or conservation) percentage value
+ *
+ * @param percent
+ * @param scheme
+ */
+ protected void updateColourScheme(int percent, ResidueShaderI scheme)
+ {
+ if (scheme == null)
+ {
+ return;
+ }
+ if (forConservation)
+ {
+ scheme.setConservationInc(percent);
+ }
+ else
+ {
+ scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
+ }
+ }
+
+ /**
* DOCUMENT ME!
*
* @param b
* @param e
* DOCUMENT ME!
*/
- public void valueField_actionPerformed(ActionEvent e)
+ @Override
+ public void valueField_actionPerformed()
{
try
{
return Integer.parseInt(valueField.getText());
}
+ @Override
public void slider_mouseReleased(MouseEvent e)
{
if (ap.overviewPanel != null)
}
}
+ public static int getConservationValue()
+ {
+ return getValue(conservationSlider);
+ }
+
+ static int getValue(JInternalFrame slider)
+ {
+ return slider == null ? 0 : ((SliderPanel) slider.getContentPane())
+ .getValue();
+ }
+
+ public static int getPIDValue()
+ {
+ return getValue(PIDSlider);
+ }
+
+ /**
+ * Answers true if the SliderPanel is for Conservation, false if it is for PID
+ * threshold
+ *
+ * @return
+ */
+ public boolean isForConservation()
+ {
+ return forConservation;
+ }
+
+ /**
+ * Answers the title for the slider panel; this may include 'Background' if
+ * for the alignment, or the group id if for a group
+ *
+ * @return
+ */
+ public String getTitle()
+ {
+ String title = null;
+ if (isForConservation())
+ {
+ if (conservationSlider != null)
+ {
+ title = conservationSlider.getTitle();
+ }
+ }
+ else if (PIDSlider != null)
+ {
+ title = PIDSlider.getTitle();
+ }
+ return title;
+ }
}
*/
package jalview.gui;
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.gui.StructureViewer.ViewerType;
import jalview.gui.ViewSelectionMenu.ViewSetProvider;
import jalview.io.DataSourceType;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
import jalview.jbgui.GStructureViewer;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
import jalview.structures.models.AAStructureBindingModel;
import jalview.util.MessageManager;
+import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
+import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JMenu;
import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
/**
* Base class with common functionality for JMol, Chimera or other structure
public abstract class StructureViewerBase extends GStructureViewer
implements Runnable, ViewSetProvider
{
+ /*
+ * names for colour options (additional to Jalview colour schemes)
+ */
+ enum ViewerColour
+ {
+ BySequence, ByChain, ChargeCysteine, ByViewer
+ }
/**
* list of sequenceSet ids associated with the view
protected boolean allChainsSelected = false;
/**
+ * Default constructor
+ */
+ public StructureViewerBase()
+ {
+ super();
+ }
+ /**
*
* @param ap2
* @return true if this Jmol instance is linked with the given alignPanel
public abstract ViewerType getViewerType();
- protected abstract AAStructureBindingModel getBindingModel();
-
/**
* add a new structure (with associated sequences and chains) to this viewer,
* retrieving it if necessary first.
}
}
// otherwise, start adding the structure.
- getBindingModel().addSequenceAndChain(new PDBEntry[] { pdbentry },
+ getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
new SequenceI[][] { seqs }, new String[][] { chains });
addingStructures = true;
_started = false;
return option;
}
- protected abstract boolean hasPdbId(String pdbId);
+ protected boolean hasPdbId(String pdbId)
+ {
+ return getBinding().hasPdbId(pdbId);
+ }
protected abstract List<StructureViewerBase> getViewersFor(
AlignmentPanel alp);
// JBPNOTE: this looks like a binding routine, rather than a gui routine
for (StructureViewerBase viewer : getViewersFor(null))
{
- AAStructureBindingModel bindingModel = viewer.getBindingModel();
+ AAStructureBindingModel bindingModel = viewer.getBinding();
for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
{
if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
abstract void showSelectedChains();
+ /**
+ * Action on selecting one of Jalview's registered colour schemes
+ */
+ @Override
+ public void changeColour_actionPerformed(String colourSchemeName)
+ {
+ AlignmentI al = getAlignmentPanel().av.getAlignment();
+ ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(
+ colourSchemeName, al, null);
+ getBinding().setJalviewColourScheme(cs);
+ }
+
+ /**
+ * Builds the colour menu
+ */
+ protected void buildColourMenu()
+ {
+ colourMenu.removeAll();
+ AlignmentI al = getAlignmentPanel().av.getAlignment();
+
+ /*
+ * add colour by sequence, by chain, by charge and cysteine
+ */
+ colourMenu.add(seqColour);
+ colourMenu.add(chainColour);
+ colourMenu.add(chargeColour);
+ chargeColour.setEnabled(!al.isNucleotide());
+
+ /*
+ * add all 'simple' (per-residue) colour schemes registered to Jalview
+ */
+ ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
+ al, true);
+
+ /*
+ * add 'colour by viewer' (menu item text is set in subclasses)
+ */
+ viewerColour.setSelected(false);
+ viewerColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ viewerColour_actionPerformed(actionEvent);
+ }
+ });
+ colourMenu.add(viewerColour);
+
+ /*
+ * add 'set background colour'
+ */
+ JMenuItem backGround = new JMenuItem();
+ backGround
+ .setText(MessageManager.getString("action.background_colour"));
+ backGround.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ background_actionPerformed(actionEvent);
+ }
+ });
+ colourMenu.add(backGround);
+
+ /*
+ * add colour buttons to a group so their selection is
+ * mutually exclusive (background colour is a separate option)
+ */
+ itemGroup.add(seqColour);
+ itemGroup.add(chainColour);
+ itemGroup.add(chargeColour);
+ itemGroup.add(viewerColour);
+ }
+
+ /**
+ * Construct menu items
+ */
+ protected void initMenus()
+ {
+ AAStructureBindingModel binding = getBinding();
+
+ seqColour = new JRadioButtonMenuItem();
+ seqColour.setText(MessageManager.getString("action.by_sequence"));
+ seqColour.setName(ViewerColour.BySequence.name());
+ seqColour.setSelected(binding.isColourBySequence());
+ seqColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ seqColour_actionPerformed(actionEvent);
+ }
+ });
+
+ chainColour = new JRadioButtonMenuItem();
+ chainColour.setText(MessageManager.getString("action.by_chain"));
+ chainColour.setName(ViewerColour.ByChain.name());
+ chainColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ chainColour_actionPerformed(actionEvent);
+ }
+ });
+
+ chargeColour = new JRadioButtonMenuItem();
+ chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
+ chargeColour.setName(ViewerColour.ChargeCysteine.name());
+ chargeColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ chargeColour_actionPerformed(actionEvent);
+ }
+ });
+
+ viewerColour = new JRadioButtonMenuItem();
+ // text is set in overrides of this method
+ viewerColour.setName(ViewerColour.ByViewer.name());
+ viewerColour.setSelected(!binding.isColourBySequence());
+
+ if (_colourwith == null)
+ {
+ _colourwith = new Vector<AlignmentPanel>();
+ }
+ if (_alignwith == null)
+ {
+ _alignwith = new Vector<AlignmentPanel>();
+ }
+
+ ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
+ MessageManager.getString("label.colour_by"), this, _colourwith,
+ new ItemListener()
+ {
+ @Override
+ public void itemStateChanged(ItemEvent e)
+ {
+ if (!seqColour.isSelected())
+ {
+ seqColour.doClick();
+ }
+ else
+ {
+ // update the Chimera display now.
+ seqColour_actionPerformed(null);
+ }
+ }
+ });
+ viewMenu.add(seqColourBy);
+
+ final ItemListener handler = new ItemListener()
+ {
+ @Override
+ public void itemStateChanged(ItemEvent e)
+ {
+ alignStructs.setEnabled(_alignwith.size() > 0);
+ alignStructs.setToolTipText(MessageManager.formatMessage(
+ "label.align_structures_using_linked_alignment_views",
+ new String[] { String.valueOf(_alignwith.size()) }));
+ }
+ };
+ JMenu alpanels = new ViewSelectionMenu(
+ MessageManager.getString("label.superpose_with"), this,
+ _alignwith, handler);
+ handler.itemStateChanged(null);
+ viewerActionMenu.add(alpanels);
+ viewerActionMenu.addMenuListener(new MenuListener()
+ {
+ @Override
+ public void menuSelected(MenuEvent e)
+ {
+ handler.itemStateChanged(null);
+ }
+
+ @Override
+ public void menuDeselected(MenuEvent e)
+ {
+ }
+
+ @Override
+ public void menuCanceled(MenuEvent e)
+ {
+ }
+ });
+
+ buildColourMenu();
+ }
+
+ @Override
+ public void setJalviewColourScheme(ColourSchemeI cs) {
+ getBinding().setJalviewColourScheme(cs);
+ }
+ @Override
+ protected void alignStructs_actionPerformed(ActionEvent actionEvent)
+ {
+ alignStructs_withAllAlignPanels();
+ }
+ protected void alignStructs_withAllAlignPanels()
+ {
+ if (getAlignmentPanel() == null)
+ {
+ return;
+ }
+
+ if (_alignwith.size() == 0)
+ {
+ _alignwith.add(getAlignmentPanel());
+ }
+
+ try
+ {
+ AlignmentI[] als = new Alignment[_alignwith.size()];
+ ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
+ int[] alm = new int[_alignwith.size()];
+ int a = 0;
+
+ for (AlignmentPanel ap : _alignwith)
+ {
+ als[a] = ap.av.getAlignment();
+ alm[a] = -1;
+ alc[a++] = ap.av.getColumnSelection();
+ }
+ getBinding().superposeStructures(als, alm, alc);
+ } catch (Exception e)
+ {
+ StringBuffer sp = new StringBuffer();
+ for (AlignmentPanel ap : _alignwith)
+ {
+ sp.append("'" + ap.alignFrame.getTitle() + "' ");
+ }
+ Cache.log.info("Couldn't align structures with the " + sp.toString()
+ + "associated alignment panels.", e);
+ }
+ }
+ @Override
+ public void background_actionPerformed(ActionEvent actionEvent)
+ {
+ Color col = JColorChooser.showDialog(this,
+ MessageManager.getString("label.select_background_colour"),
+ null);
+ if (col != null)
+ {
+ getBinding().setBackgroundColour(col);
+ }
+ }
+ @Override
+ public void viewerColour_actionPerformed(ActionEvent actionEvent)
+ {
+ if (viewerColour.isSelected())
+ {
+ // disable automatic sequence colouring.
+ getBinding().setColourBySequence(false);
+ }
+ }
+ @Override
+ public void chainColour_actionPerformed(ActionEvent actionEvent)
+ {
+ chainColour.setSelected(true);
+ getBinding().colourByChain();
+ }
+ @Override
+ public void chargeColour_actionPerformed(ActionEvent actionEvent)
+ {
+ chargeColour.setSelected(true);
+ getBinding().colourByCharge();
+ }
+ @Override
+ public void seqColour_actionPerformed(ActionEvent actionEvent)
+ {
+ AAStructureBindingModel binding = getBinding();
+ binding.setColourBySequence(seqColour.isSelected());
+ if (_colourwith == null)
+ {
+ _colourwith = new Vector<AlignmentPanel>();
+ }
+ if (binding.isColourBySequence())
+ {
+ if (!binding.isLoadingFromArchive())
+ {
+ if (_colourwith.size() == 0 && getAlignmentPanel() != null)
+ {
+ // Make the currently displayed alignment panel the associated view
+ _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
+ }
+ }
+ // Set the colour using the current view for the associated alignframe
+ for (AlignmentPanel ap : _colourwith)
+ {
+ binding.colourBySequence(ap);
+ }
+ }
+ }
+ @Override
+ public void pdbFile_actionPerformed(ActionEvent actionEvent)
+ {
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ Cache.getProperty("LAST_DIRECTORY"));
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
+ chooser.setToolTipText(MessageManager.getString("action.save"));
+
+ int value = chooser.showSaveDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ BufferedReader in = null;
+ try
+ {
+ // TODO: cope with multiple PDB files in view
+ in = new BufferedReader(
+ new FileReader(getBinding().getPdbFile()[0]));
+ File outFile = chooser.getSelectedFile();
+
+ PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
+ String data;
+ while ((data = in.readLine()) != null)
+ {
+ if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
+ {
+ out.println(data);
+ }
+ }
+ out.close();
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ } finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ } catch (IOException e)
+ {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+ @Override
+ public void viewMapping_actionPerformed(ActionEvent actionEvent)
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();
+ try
+ {
+ cap.appendText(getBinding().printMappings());
+ } catch (OutOfMemoryError e)
+ {
+ new OOMWarning(
+ "composing sequence-structure alignments for display in text box.",
+ e);
+ cap.dispose();
+ return;
+ }
+ Desktop.addInternalFrame(cap,
+ MessageManager.getString("label.pdb_sequence_mapping"), 550,
+ 600);
+ }
+
+ protected abstract String getViewerName();
+ public void updateTitleAndMenus()
+ {
+ AAStructureBindingModel binding = getBinding();
+ if (binding.hasFileLoadingError())
+ {
+ repaint();
+ return;
+ }
+ setChainMenuItems(binding.getChainNames());
+
+ this.setTitle(binding.getViewerTitle(getViewerName(), true));
+ if (binding.getPdbFile().length > 1 && binding.getSequence().length > 1)
+ {
+ viewerActionMenu.setVisible(true);
+ }
+ if (!binding.isLoadingFromArchive())
+ {
+ seqColour_actionPerformed(null);
+ }
+ }
}
}
else
{
- cs = ColourSchemeProperty.getColour(sg, ColourSchemeProperty
- .getColourName(av.getGlobalColourScheme()));
+ cs = ColourSchemeProperty.getColourScheme(sg,
+ ColourSchemeProperty.getColourName(av
+ .getGlobalColourScheme()));
}
// cs is null if shading is an annotationColourGradient
- if (cs != null)
- {
- cs.setThreshold(av.getGlobalColourScheme().getThreshold(),
- av.isIgnoreGapsConsensus());
- }
+ // if (cs != null)
+ // {
+ // cs.setThreshold(av.getViewportColourScheme().getThreshold(),
+ // av.isIgnoreGapsConsensus());
+ // }
}
- sg.cs = cs;
+ sg.setColourScheme(cs);
+ sg.getGroupColourScheme().setThreshold(
+ av.getResidueShading().getThreshold(),
+ av.isIgnoreGapsConsensus());
// sg.recalcConservation();
sg.setName("JTreeGroup:" + sg.hashCode());
sg.setIdColour(col);
for (int a = 0; a < aps.length; a++)
{
if (aps[a].av.getGlobalColourScheme() != null
- && aps[a].av.getGlobalColourScheme().conservationApplied())
+ && aps[a].av.getResidueShading()
+ .conservationApplied())
{
Conservation c = new Conservation("Group", sg.getSequences(null),
sg.getStartRes(), sg.getEndRes());
try
{
JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"),
ImageMaker.EPS_EXTENSION, ImageMaker.EPS_EXTENSION);
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
try
{
JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"),
ImageMaker.PNG_EXTENSION, ImageMaker.PNG_DESCRIPTION);
chooser.setFileView(new jalview.io.JalviewFileView());
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
import jalview.jbgui.GUserDefinedColours;
+import jalview.schemabinding.version2.Colour;
+import jalview.schemabinding.version2.JalviewUserColours;
import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ColourSchemes;
import jalview.schemes.ResidueProperties;
import jalview.schemes.UserColourScheme;
import jalview.util.ColorUtils;
+import jalview.util.Format;
import jalview.util.MessageManager;
import java.awt.Color;
import java.awt.Font;
+import java.awt.Insets;
import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.StringTokenizer;
+import java.util.List;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
public class UserDefinedColours extends GUserDefinedColours implements
ChangeListener
{
+ private static final Font VERDANA_BOLD_10 = new Font("Verdana",
+ Font.BOLD, 10);
+
+ public static final String USER_DEFINED_COLOURS = "USER_DEFINED_COLOURS";
+
+ private static final String LAST_DIRECTORY = "LAST_DIRECTORY";
+
private static final int MY_FRAME_HEIGHT = 420;
private static final int MY_FRAME_WIDTH = 810;
SequenceGroup seqGroup;
- ArrayList<JButton> selectedButtons;
+ List<JButton> selectedButtons;
ColourSchemeI oldColourScheme;
JInternalFrame frame;
- JalviewStructureDisplayI jmol;
+ JalviewStructureDisplayI structureViewer;
- ArrayList<JButton> upperCaseButtons;
+ List<JButton> upperCaseButtons;
- ArrayList<JButton> lowerCaseButtons;
+ List<JButton> lowerCaseButtons;
/**
* Creates a new UserDefinedColours object.
*
* @param ap
- * DOCUMENT ME!
* @param sg
- * DOCUMENT ME!
*/
public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
{
- super();
+ this();
lcaseColour.setEnabled(false);
if (seqGroup != null)
{
- oldColourScheme = seqGroup.cs;
+ oldColourScheme = seqGroup.getColourScheme();
}
else
{
if (oldColourScheme instanceof UserColourScheme)
{
- schemeName.setText(((UserColourScheme) oldColourScheme).getName());
+ schemeName.setText(oldColourScheme.getSchemeName());
if (((UserColourScheme) oldColourScheme).getLowerCaseColours() != null)
{
caseSensitive.setSelected(true);
showFrame();
}
- public UserDefinedColours(JalviewStructureDisplayI jmol,
+ public UserDefinedColours(JalviewStructureDisplayI viewer,
ColourSchemeI oldcs)
{
- super();
- this.jmol = jmol;
+ this();
+ this.structureViewer = viewer;
colorChooser.getSelectionModel().addChangeListener(this);
if (oldColourScheme instanceof UserColourScheme)
{
- schemeName.setText(((UserColourScheme) oldColourScheme).getName());
+ schemeName.setText(((UserColourScheme) oldColourScheme)
+ .getSchemeName());
}
resetButtonPanel(false);
}
+ public UserDefinedColours()
+ {
+ super();
+ selectedButtons = new ArrayList<JButton>();
+ }
+
void showFrame()
{
colorChooser.getSelectionModel().addChangeListener(this);
}
}
- void resetButtonPanel(boolean caseSensitive)
+ /**
+ * Rebuilds the panel with coloured buttons for residues. If not case
+ * sensitive colours, show 3-letter amino acid code as button text. If case
+ * sensitive, just show the single letter code, in order to make space for the
+ * additional buttons.
+ *
+ * @param isCaseSensitive
+ */
+ void resetButtonPanel(boolean isCaseSensitive)
{
buttonPanel.removeAll();
upperCaseButtons = new ArrayList<JButton>();
}
- JButton button;
- String label;
for (int i = 0; i < 20; i++)
{
- if (caseSensitive)
- {
- label = ResidueProperties.aa[i];
- }
- else
- {
- label = ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
- .toString();
- }
-
- button = makeButton(label, ResidueProperties.aa[i], upperCaseButtons,
- i);
-
+ String label = isCaseSensitive ? ResidueProperties.aa[i]
+ : ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
+ .toString();
+ JButton button = makeButton(label, ResidueProperties.aa[i],
+ upperCaseButtons, i);
buttonPanel.add(button);
}
buttonPanel.add(makeButton("X", "X", upperCaseButtons, 22));
buttonPanel.add(makeButton("Gap", "-", upperCaseButtons, 23));
- if (!caseSensitive)
+ if (!isCaseSensitive)
{
gridLayout.setRows(6);
gridLayout.setColumns(4);
{
int row = i / cols + 1;
int index = (row * cols) + i;
- button = makeButton(ResidueProperties.aa[i].toLowerCase(),
+ JButton button = makeButton(ResidueProperties.aa[i].toLowerCase(),
ResidueProperties.aa[i].toLowerCase(), lowerCaseButtons, i);
buttonPanel.add(button, index);
}
}
- if (caseSensitive)
+ if (isCaseSensitive)
{
buttonPanel.add(makeButton("b", "b", lowerCaseButtons, 20));
buttonPanel.add(makeButton("z", "z", lowerCaseButtons, 21));
// codes
if (this.frame != null)
{
- int newWidth = caseSensitive ? MY_FRAME_WIDTH_CASE_SENSITIVE
+ int newWidth = isCaseSensitive ? MY_FRAME_WIDTH_CASE_SENSITIVE
: MY_FRAME_WIDTH;
this.frame.setSize(newWidth, this.frame.getHeight());
}
}
/**
- * DOCUMENT ME!
+ * ChangeListener handler for when a colour is picked in the colour chooser.
+ * The action is to apply the colour to all selected buttons as their
+ * background colour. Foreground colour (text) is set to a lighter shade in
+ * order to highlight which buttons are selected. If 'Lower Case Colour' is
+ * active, then the colour is applied to all lower case buttons (as well as
+ * the Lower Case Colour button itself).
*
* @param evt
- * DOCUMENT ME!
*/
@Override
public void stateChanged(ChangeEvent evt)
{
- if (selectedButtons != null)
+ JButton button = null;
+ final Color newColour = colorChooser.getColor();
+ for (int i = 0; i < selectedButtons.size(); i++)
{
- JButton button = null;
- final Color newColour = colorChooser.getColor();
- for (int i = 0; i < selectedButtons.size(); i++)
+ button = selectedButtons.get(i);
+ button.setBackground(newColour);
+ button.setForeground(ColorUtils.brighterThan(newColour));
+ }
+ if (lcaseColour.isSelected())
+ {
+ for (int i = 0; i < lowerCaseButtons.size(); i++)
{
- button = selectedButtons.get(i);
+ button = lowerCaseButtons.get(i);
button.setBackground(newColour);
- button.setForeground(ColorUtils.brighterThan(newColour));
- }
- if (button == lcaseColour)
- {
- for (int i = 0; i < lowerCaseButtons.size(); i++)
- {
- button = lowerCaseButtons.get(i);
- button.setBackground(newColour);
- button.setForeground(ColorUtils.brighterThan(button
- .getBackground()));
- }
+ button.setForeground(ColorUtils.brighterThan(button.getBackground()));
}
}
}
*/
public void colourButtonPressed(MouseEvent e)
{
- if (selectedButtons == null)
- {
- selectedButtons = new ArrayList<JButton>();
- }
-
JButton pressed = (JButton) e.getSource();
if (e.isShiftDown())
}
/**
- * DOCUMENT ME!
+ * A helper method to update or make a colour button, whose background colour
+ * is the associated colour, and text colour a darker shade of the same. If
+ * the button is already in the list, then its text and margins are updated,
+ * if not then it is created and added. This method supports toggling between
+ * case-sensitive and case-insensitive button panels. The case-sensitive
+ * version has abbreviated button text in order to fit in more buttons.
*
* @param label
- * DOCUMENT ME!
- * @param aa
- * DOCUMENT ME!
+ * @param residue
+ * @param the
+ * list of buttons
+ * @param buttonIndex
+ * the button's position in the list
*/
- JButton makeButton(String label, String aa,
- ArrayList<JButton> caseSensitiveButtons, int buttonIndex)
+ JButton makeButton(String label, String residue, List<JButton> buttons,
+ int buttonIndex)
{
final JButton button;
Color col;
- if (buttonIndex < caseSensitiveButtons.size())
+ if (buttonIndex < buttons.size())
{
- button = caseSensitiveButtons.get(buttonIndex);
+ button = buttons.get(buttonIndex);
col = button.getBackground();
}
else
{
button = new JButton();
- button.addMouseListener(new java.awt.event.MouseAdapter()
+ button.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
}
});
- caseSensitiveButtons.add(button);
+ buttons.add(button);
+ /*
+ * make initial button colour that of the current colour scheme,
+ * if it is a simple per-residue colouring, else white
+ */
col = Color.white;
- if (oldColourScheme != null)
+ if (oldColourScheme != null && oldColourScheme.isSimple())
{
- try
- {
- col = oldColourScheme.findColour(aa.charAt(0), -1, null);
- } catch (Exception ex)
- {
- }
+ col = oldColourScheme.findColour(residue.charAt(0), 0, null, null,
+ 0f);
}
}
if (caseSensitive.isSelected())
{
- button.setMargin(new java.awt.Insets(2, 2, 2, 2));
+ button.setMargin(new Insets(2, 2, 2, 2));
}
else
{
- button.setMargin(new java.awt.Insets(2, 14, 2, 14));
+ button.setMargin(new Insets(2, 14, 2, 14));
}
button.setOpaque(true); // required for the next line to have effect
button.setBackground(col);
button.setText(label);
button.setForeground(ColorUtils.darkerThan(col));
- button.setFont(new java.awt.Font("Verdana", Font.BOLD, 10));
+ button.setFont(VERDANA_BOLD_10);
return button;
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * On 'OK', check that at least one colour has been assigned to a residue (and
+ * if not issue a warning), and apply the chosen colour scheme and close the
+ * panel.
*/
@Override
- protected void okButton_actionPerformed(ActionEvent e)
+ protected void okButton_actionPerformed()
{
if (isNoSelectionMade())
{
}
else
{
- applyButton_actionPerformed(null);
+ applyButton_actionPerformed();
try
{
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Applies the current colour scheme to the alignment, sequence group or
+ * structure view.
*/
@Override
- protected void applyButton_actionPerformed(ActionEvent e)
+ protected void applyButton_actionPerformed()
{
if (isNoSelectionMade())
{
}
UserColourScheme ucs = getSchemeFromButtons();
- ucs.setName(schemeName.getText());
if (seqGroup != null)
{
- seqGroup.cs = ucs;
+ seqGroup.setColourScheme(ucs);
ap.paintAlignment(true);
}
else if (ap != null)
{
ap.alignFrame.changeColour(ucs);
}
- else if (jmol != null)
+ else if (structureViewer != null)
{
- jmol.setJalviewColourScheme(ucs);
+ structureViewer.setJalviewColourScheme(ucs);
}
}
}
UserColourScheme ucs = new UserColourScheme(newColours);
+ ucs.setName(schemeName.getText());
if (caseSensitive.isSelected())
{
ucs.setLowerCaseColours(newColours);
}
- if (ap != null)
- {
- ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
- }
+ // if (ap != null)
+ // {
+ // ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
+ // }
return ucs;
}
upperCaseButtons = new ArrayList<JButton>();
lowerCaseButtons = new ArrayList<JButton>();
- JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"), "jc",
+ JalviewFileChooser chooser = new JalviewFileChooser("jc",
"Jalview User Colours");
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
int value = chooser.showOpenDialog(this);
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ if (value != JalviewFileChooser.APPROVE_OPTION)
{
- File choice = chooser.getSelectedFile();
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
- String defaultColours = jalview.bin.Cache.getDefault(
- "USER_DEFINED_COLOURS", choice.getPath());
- if (defaultColours.indexOf(choice.getPath()) == -1)
- {
- defaultColours = defaultColours.concat("|")
- .concat(choice.getPath());
- }
-
- jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);
-
- UserColourScheme ucs = loadColours(choice.getAbsolutePath());
- Color[] colors = ucs.getColours();
- schemeName.setText(ucs.getName());
-
- if (ucs.getLowerCaseColours() != null)
- {
- caseSensitive.setSelected(true);
- lcaseColour.setEnabled(true);
- resetButtonPanel(true);
- for (int i = 0; i < lowerCaseButtons.size(); i++)
- {
- JButton button = lowerCaseButtons.get(i);
- button.setBackground(ucs.getLowerCaseColours()[i]);
- }
+ return;
+ }
+ File choice = chooser.getSelectedFile();
+ Cache.setProperty(LAST_DIRECTORY, choice.getParent());
- }
- else
- {
- caseSensitive.setSelected(false);
- lcaseColour.setEnabled(false);
- resetButtonPanel(false);
- }
+ UserColourScheme ucs = ColourSchemes.loadColourScheme(choice
+ .getAbsolutePath());
+ Color[] colors = ucs.getColours();
+ schemeName.setText(ucs.getSchemeName());
- for (int i = 0; i < upperCaseButtons.size(); i++)
+ if (ucs.getLowerCaseColours() != null)
+ {
+ caseSensitive.setSelected(true);
+ lcaseColour.setEnabled(true);
+ resetButtonPanel(true);
+ for (int i = 0; i < lowerCaseButtons.size(); i++)
{
- JButton button = upperCaseButtons.get(i);
- button.setBackground(colors[i]);
+ JButton button = lowerCaseButtons.get(i);
+ button.setBackground(ucs.getLowerCaseColours()[i]);
}
+ }
+ else
+ {
+ caseSensitive.setSelected(false);
+ lcaseColour.setEnabled(false);
+ resetButtonPanel(false);
+ }
+ for (int i = 0; i < upperCaseButtons.size(); i++)
+ {
+ JButton button = upperCaseButtons.get(i);
+ button.setBackground(colors[i]);
}
+
+ addNewColourScheme(choice.getPath());
}
/**
- * DOCUMENT ME!
+ * Loads the user-defined colour scheme from the first file listed in property
+ * "USER_DEFINED_COLOURS". If this fails, returns an all-white colour scheme.
*
- * @return DOCUMENT ME!
+ * @return
*/
public static UserColourScheme loadDefaultColours()
{
UserColourScheme ret = null;
- String colours = jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS");
+ String colours = Cache.getProperty(USER_DEFINED_COLOURS);
if (colours != null)
{
if (colours.indexOf("|") > -1)
{
colours = colours.substring(0, colours.indexOf("|"));
}
-
- ret = loadColours(colours);
+ ret = ColourSchemes.loadColourScheme(colours);
}
if (ret == null)
{
- Color[] newColours = new Color[24];
- for (int i = 0; i < 24; i++)
- {
- newColours[i] = Color.white;
- }
- ret = new UserColourScheme(newColours);
+ ret = new UserColourScheme("white");
}
return ret;
/**
* DOCUMENT ME!
*
- * @param file
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- static UserColourScheme loadColours(String file)
- {
- UserColourScheme ucs = null;
- Color[] newColours = null;
- try
- {
- InputStreamReader in = new InputStreamReader(
- new FileInputStream(file), "UTF-8");
-
- jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
-
- org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller(
- jucs);
- jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar
- .unmarshal(in);
-
- newColours = new Color[24];
-
- Color[] lowerCase = null;
- boolean caseSensitive = false;
-
- String name;
- int index;
- for (int i = 0; i < jucs.getColourCount(); i++)
- {
- name = jucs.getColour(i).getName();
- if (ResidueProperties.aa3Hash.containsKey(name))
- {
- index = ResidueProperties.aa3Hash.get(name).intValue();
- }
- else
- {
- index = ResidueProperties.aaIndex[name.charAt(0)];
- }
- if (index == -1)
- {
- continue;
- }
-
- if (name.toLowerCase().equals(name))
- {
- if (lowerCase == null)
- {
- lowerCase = new Color[23];
- }
- caseSensitive = true;
- lowerCase[index] = new Color(Integer.parseInt(jucs.getColour(i)
- .getRGB(), 16));
- }
- else
- {
- newColours[index] = new Color(Integer.parseInt(jucs.getColour(i)
- .getRGB(), 16));
- }
- }
-
- if (newColours != null)
- {
- ucs = new UserColourScheme(newColours);
- ucs.setName(jucs.getSchemeName());
- if (caseSensitive)
- {
- ucs.setLowerCaseColours(lowerCase);
- }
- }
-
- } catch (Exception ex)
- {
- // Could be Archive Jalview format
- try
- {
- InputStreamReader in = new InputStreamReader(new FileInputStream(
- file), "UTF-8");
-
- jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
-
- jucs = jucs.unmarshal(in);
-
- newColours = new Color[jucs.getColourCount()];
-
- for (int i = 0; i < 24; i++)
- {
- newColours[i] = new Color(Integer.parseInt(jucs.getColour(i)
- .getRGB(), 16));
- }
- if (newColours != null)
- {
- ucs = new UserColourScheme(newColours);
- ucs.setName(jucs.getSchemeName());
- }
- } catch (Exception ex2)
- {
- ex2.printStackTrace();
- }
-
- if (newColours == null)
- {
- System.out.println("Error loading User ColourFile\n" + ex);
- }
- }
-
- return ucs;
- }
-
- /**
- * DOCUMENT ME!
- *
* @param e
* DOCUMENT ME!
*/
@Override
protected void savebutton_actionPerformed(ActionEvent e)
{
- if (schemeName.getText().trim().length() < 1)
+ String name = schemeName.getText().trim();
+ if (name.length() < 1)
{
JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
.getString("label.user_colour_scheme_must_have_name"),
return;
}
- if (userColourSchemes != null
- && userColourSchemes.containsKey(schemeName.getText()))
+ if (ColourSchemes.getInstance().nameExists(name))
{
int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
MessageManager.formatMessage(
"label.colour_scheme_exists_overwrite", new Object[] {
- schemeName.getText(), schemeName.getText() }),
+ name, name }),
MessageManager.getString("label.duplicate_scheme_name"),
JvOptionPane.YES_NO_OPTION);
if (reply != JvOptionPane.YES_OPTION)
{
return;
}
-
- userColourSchemes.remove(schemeName.getText());
+ ColourSchemes.getInstance().removeColourScheme(name);
}
- JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"), "jc",
+ JalviewFileChooser chooser = new JalviewFileChooser("jc",
"Jalview User Colours");
- chooser.setFileView(new JalviewFileView());
+ JalviewFileView fileView = new JalviewFileView();
+ chooser.setFileView(fileView);
chooser.setDialogTitle(MessageManager
.getString("label.save_colour_scheme"));
chooser.setToolTipText(MessageManager.getString("action.save"));
if (value == JalviewFileChooser.APPROVE_OPTION)
{
- String choice = chooser.getSelectedFile().getPath();
- String defaultColours = jalview.bin.Cache.getDefault(
- "USER_DEFINED_COLOURS", choice);
- if (defaultColours.indexOf(choice) == -1)
- {
- if (defaultColours.length() > 0)
- {
- defaultColours = defaultColours.concat("|");
- }
- defaultColours = defaultColours.concat(choice);
- }
-
- userColourSchemes.put(schemeName.getText(), getSchemeFromButtons());
-
- ap.alignFrame.updateUserColourMenu();
-
- jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);
-
- jalview.schemabinding.version2.JalviewUserColours ucs = new jalview.schemabinding.version2.JalviewUserColours();
-
- ucs.setSchemeName(schemeName.getText());
- try
- {
- PrintWriter out = new PrintWriter(new OutputStreamWriter(
- new FileOutputStream(choice), "UTF-8"));
-
- for (int i = 0; i < buttonPanel.getComponentCount(); i++)
- {
- JButton button = (JButton) buttonPanel.getComponent(i);
- jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
- col.setName(button.getText());
- col.setRGB(jalview.util.Format.getHexString(button
- .getBackground()));
- ucs.addColour(col);
- }
-
- ucs.marshal(out);
- out.close();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
+ File file = chooser.getSelectedFile();
+ addNewColourScheme(file.getPath());
+ saveToFile(file);
}
}
/**
- * DOCUMENT ME!
+ * Adds the current colour scheme to the Jalview properties file so it is
+ * loaded on next startup, and updates the Colour menu in the parent
+ * AlignFrame (if there is one). Note this action does not including applying
+ * the colour scheme.
*
- * @param e
- * DOCUMENT ME!
+ * @param filePath
*/
- @Override
- protected void cancelButton_actionPerformed(ActionEvent e)
+ protected void addNewColourScheme(String filePath)
{
- if (ap != null)
+ /*
+ * update the delimited list of user defined colour files in
+ * Jalview property USER_DEFINED_COLOURS
+ */
+ String defaultColours = Cache
+ .getDefault(USER_DEFINED_COLOURS, filePath);
+ if (defaultColours.indexOf(filePath) == -1)
{
- if (seqGroup != null)
- {
- seqGroup.cs = oldColourScheme;
- }
- else if (ap != null)
+ if (defaultColours.length() > 0)
{
- ap.av.setGlobalColourScheme(oldColourScheme);
+ defaultColours = defaultColours.concat("|");
}
- ap.paintAlignment(true);
+ defaultColours = defaultColours.concat(filePath);
}
+ Cache.setProperty(USER_DEFINED_COLOURS, defaultColours);
- if (jmol != null)
- {
- jmol.setJalviewColourScheme(oldColourScheme);
- }
+ /*
+ * construct and register the colour scheme
+ */
+ UserColourScheme ucs = getSchemeFromButtons();
+ ColourSchemes.getInstance().registerColourScheme(ucs);
- try
- {
- frame.setClosed(true);
- } catch (Exception ex)
+ /*
+ * update the Colour menu items
+ */
+ if (ap != null)
{
+ ap.alignFrame.buildColourMenu();
}
}
- static Hashtable userColourSchemes;
-
- public static Hashtable getUserColourSchemes()
- {
- return userColourSchemes;
- }
-
- public static void initUserColourSchemes(String files)
+ /**
+ * Saves the colour scheme to file in XML format
+ *
+ * @param path
+ */
+ protected void saveToFile(File toFile)
{
- userColourSchemes = new Hashtable();
-
- if (files == null || files.length() == 0)
+ /*
+ * build a Java model of colour scheme as XML, and
+ * marshal to file
+ */
+ JalviewUserColours ucs = new JalviewUserColours();
+ ucs.setSchemeName(schemeName.getText());
+ try
{
- return;
- }
+ PrintWriter out = new PrintWriter(new OutputStreamWriter(
+ new FileOutputStream(toFile), "UTF-8"));
- // In case colours can't be loaded, we'll remove them
- // from the default list here.
- StringBuffer coloursFound = new StringBuffer();
- StringTokenizer st = new StringTokenizer(files, "|");
- while (st.hasMoreElements())
- {
- String file = st.nextToken();
- try
- {
- UserColourScheme ucs = loadColours(file);
- if (ucs != null)
- {
- if (coloursFound.length() > 0)
- {
- coloursFound.append("|");
- }
- coloursFound.append(file);
- userColourSchemes.put(ucs.getName(), ucs);
- }
- } catch (Exception ex)
+ for (int i = 0; i < buttonPanel.getComponentCount(); i++)
{
- System.out.println("Error loading User ColourFile\n" + ex);
+ JButton button = (JButton) buttonPanel.getComponent(i);
+ Colour col = new Colour();
+ col.setName(button.getText());
+ col.setRGB(Format.getHexString(button.getBackground()));
+ ucs.addColour(col);
}
- }
- if (!files.equals(coloursFound.toString()))
+ ucs.marshal(out);
+ out.close();
+ } catch (Exception ex)
{
- if (coloursFound.toString().length() > 1)
- {
- jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS",
- coloursFound.toString());
- }
- else
- {
- jalview.bin.Cache.applicationProperties
- .remove("USER_DEFINED_COLOURS");
- }
+ ex.printStackTrace();
}
}
- public static void removeColourFromDefaults(String target)
+ /**
+ * On cancel, restores the colour scheme before the dialogue was opened
+ *
+ * @param e
+ */
+ @Override
+ protected void cancelButton_actionPerformed(ActionEvent e)
{
- // The only way to find colours by name is to load them in
- // In case colours can't be loaded, we'll remove them
- // from the default list here.
-
- userColourSchemes = new Hashtable();
-
- StringBuffer coloursFound = new StringBuffer();
- StringTokenizer st = new StringTokenizer(
- jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS"), "|");
-
- while (st.hasMoreElements())
+ if (ap != null)
{
- String file = st.nextToken();
- try
+ if (seqGroup != null)
{
- UserColourScheme ucs = loadColours(file);
- if (ucs != null && !ucs.getName().equals(target))
- {
- if (coloursFound.length() > 0)
- {
- coloursFound.append("|");
- }
- coloursFound.append(file);
- userColourSchemes.put(ucs.getName(), ucs);
- }
- } catch (Exception ex)
+ seqGroup.setColourScheme(oldColourScheme);
+ }
+ else
{
- System.out.println("Error loading User ColourFile\n" + ex);
+ ap.alignFrame.changeColour(oldColourScheme);
}
+ ap.paintAlignment(true);
}
- if (coloursFound.toString().length() > 1)
+ if (structureViewer != null)
{
- jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS",
- coloursFound.toString());
+ structureViewer.setJalviewColourScheme(oldColourScheme);
}
- else
+
+ try
+ {
+ frame.setClosed(true);
+ } catch (Exception ex)
{
- jalview.bin.Cache.applicationProperties
- .remove("USER_DEFINED_COLOURS");
}
-
}
@Override
public void caseSensitive_actionPerformed(ActionEvent e)
{
- resetButtonPanel(caseSensitive.isSelected());
- lcaseColour.setEnabled(caseSensitive.isSelected());
- }
-
- @Override
- public void lcaseColour_actionPerformed(ActionEvent e)
- {
- if (selectedButtons == null)
- {
- selectedButtons = new ArrayList<JButton>();
- }
- else
- {
- selectedButtons.clear();
- }
- selectedButtons.add(lcaseColour);
+ boolean selected = caseSensitive.isSelected();
+ resetButtonPanel(selected);
+ lcaseColour.setEnabled(selected);
}
}
}
if (filename == null)
{
- JalviewFileChooser chooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"), "wsparams",
+ JalviewFileChooser chooser = new JalviewFileChooser("wsparams",
"Web Service Parameter File");
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
JTextField urltf = new JTextField(url, 40);
JPanel panel = new JPanel(new BorderLayout());
JPanel pane12 = new JPanel(new BorderLayout());
- pane12.add(new JLabel(MessageManager.getString("label.url")),
+ pane12.add(new JLabel(MessageManager.getString("label.url:")),
BorderLayout.CENTER);
pane12.add(urltf, BorderLayout.EAST);
panel.add(pane12, BorderLayout.NORTH);
new Thread(new Runnable()
{
+ @Override
public void run()
{
// force a refresh.
new Thread(new Runnable()
{
+ @Override
public void run()
{
progressBar.setVisible(true);
new Thread(new Runnable()
{
+ @Override
public void run()
{
long ct = System.currentTimeMillis();
new Thread(new Runnable()
{
+ @Override
public void run()
{
updateWsMenuConfig(false);
import jalview.datamodel.SequenceI;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
+import java.awt.Color;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
if (sg.cs != null)
{
text.append("colour=");
- text.append(ColourSchemeProperty.getColourName(sg.cs));
+ text.append(sg.cs.toString());
text.append("\t");
if (sg.cs.getThreshold() != 0)
{
Annotation parseAnnotation(String string, int graphStyle)
{
- boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH); // don't
- // do the
- // glyph
- // test
- // if we
- // don't
- // want
- // secondary
- // structure
+ // don't do the glyph test if we don't want secondary structure
+ boolean hasSymbols = (graphStyle == AlignmentAnnotation.NO_GRAPH);
String desc = null, displayChar = null;
char ss = ' '; // secondaryStructure
float value = 0;
boolean parsedValue = false, dcset = false;
// find colour here
- java.awt.Color colour = null;
+ Color colour = null;
int i = string.indexOf("[");
int j = string.indexOf("]");
if (i > -1 && j > -1)
{
- UserColourScheme ucs = new UserColourScheme();
-
- colour = ucs.getColourFromString(string.substring(i + 1, j));
+ colour = ColorUtils.parseColourString(string.substring(i + 1,
+ j));
if (i > 0 && string.charAt(i - 1) == ',')
{
// clip the preceding comma as well
void colourAnnotations(AlignmentI al, String label, String colour)
{
- UserColourScheme ucs = new UserColourScheme(colour);
+ Color awtColour = ColorUtils.parseColourString(colour);
Annotation[] annotations;
for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
{
{
if (annotations[j] != null)
{
- annotations[j].colour = ucs.findColour('A');
+ annotations[j].colour = awtColour;
}
}
}
SequenceGroup groupRef)
{
String group = st.nextToken();
- AlignmentAnnotation annotation = null, alannot[] = al
- .getAlignmentAnnotation();
- float value = new Float(st.nextToken()).floatValue();
+ AlignmentAnnotation[] alannot = al.getAlignmentAnnotation();
+ String nextToken = st.nextToken();
+ float value = 0f;
+ try
+ {
+ value = Float.valueOf(nextToken);
+ } catch (NumberFormatException e)
+ {
+ System.err.println("line " + nlinesread + ": Threshold '" + nextToken
+ + "' invalid, setting to zero");
+ }
String label = st.hasMoreTokens() ? st.nextToken() : null;
- java.awt.Color colour = null;
+ Color colour = null;
if (st.hasMoreTokens())
{
- UserColourScheme ucs = new UserColourScheme(st.nextToken());
- colour = ucs.findColour('A');
+ colour = ColorUtils.parseColourString(st.nextToken());
}
if (alannot != null)
{
}
}
}
- if (annotation == null)
- {
- return;
- }
}
void addGroup(AlignmentI al, StringTokenizer st)
if (sg != null)
{
String keyValue, key, value;
- ColourSchemeI def = sg.cs;
- sg.cs = null;
+ ColourSchemeI def = sg.getColourScheme();
while (st.hasMoreTokens())
{
keyValue = st.nextToken();
}
else if (key.equalsIgnoreCase("colour"))
{
- sg.cs = ColourSchemeProperty.getColour(al, value);
+ sg.cs.setColourScheme(ColourSchemeProperty
+ .getColourScheme(al, value));
}
else if (key.equalsIgnoreCase("pidThreshold"))
{
}
else if (key.equalsIgnoreCase("outlineColour"))
{
- sg.setOutlineColour(new UserColourScheme(value).findColour('A'));
+ sg.setOutlineColour(ColorUtils.parseColourString(value));
}
else if (key.equalsIgnoreCase("displayBoxes"))
{
}
else if (key.equalsIgnoreCase("textCol1"))
{
- sg.textColour = new UserColourScheme(value).findColour('A');
+ sg.textColour = ColorUtils.parseColourString(value);
}
else if (key.equalsIgnoreCase("textCol2"))
{
- sg.textColour2 = new UserColourScheme(value).findColour('A');
+ sg.textColour2 = ColorUtils.parseColourString(value);
}
else if (key.equalsIgnoreCase("textColThreshold"))
{
}
else if (key.equalsIgnoreCase("idColour"))
{
- // consider warning if colour doesn't resolve to a real colour
- sg.setIdColour((def = new UserColourScheme(value))
- .findColour('A'));
+ Color idColour = ColorUtils.parseColourString(value);
+ sg.setIdColour(idColour == null ? Color.black : idColour);
}
else if (key.equalsIgnoreCase("hide"))
{
}
sg.recalcConservation();
}
- if (sg.cs == null)
+ if (sg.getColourScheme() == null)
{
- sg.cs = def;
+ sg.setColourScheme(def);
}
}
}
import jalview.io.gff.GffHelperFactory;
import jalview.io.gff.GffHelperI;
import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
import jalview.util.MapList;
import jalview.util.ParseHtmlBodyAndLinks;
import jalview.util.StringUtils;
+import java.awt.Color;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
* Perhaps an old style groups file with no colours -
* synthesize a colour from the feature type
*/
- UserColourScheme ucs = new UserColourScheme(ft);
- featureColours.put(ft, new FeatureColour(ucs.findColour('A')));
+ Color colour = ColorUtils.createColourFromName(ft);
+ featureColours.put(ft, new FeatureColour(colour));
}
SequenceFeature sf = new SequenceFeature(ft, desc, "", startPos,
endPos, featureGroup);
*/
public void registerFileFormat(FileFormatI format)
{
- registerFileFormat(format, false);
+ boolean isIdentifiable = format instanceof FileFormat
+ && ((FileFormat) format).isIdentifiable();
+ registerFileFormat(format, isIdentifiable);
}
protected void registerFileFormat(FileFormatI format,
package jalview.io;
import jalview.api.AlignExportSettingI;
-import jalview.bin.Cache;
import jalview.datamodel.AlignmentExportData;
import jalview.exceptions.NoFileSelectedException;
import jalview.gui.AlignmentPanel;
pSessionId);
}
- JalviewFileChooser jvFileChooser = new JalviewFileChooser(
- Cache.getProperty("LAST_DIRECTORY"), "html", "HTML files");
+ JalviewFileChooser jvFileChooser = new JalviewFileChooser("html",
+ "HTML files");
jvFileChooser.setFileView(new JalviewFileView());
jvFileChooser.setDialogTitle(MessageManager
import jalview.json.binding.biojson.v1.SequenceFeaturesPojo;
import jalview.json.binding.biojson.v1.SequenceGrpPojo;
import jalview.json.binding.biojson.v1.SequencePojo;
-import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
+import jalview.schemes.JalviewColourScheme;
+import jalview.schemes.ResidueColourScheme;
+import jalview.util.ColorUtils;
import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
import java.awt.Color;
{
// These color schemes require annotation, disable them if annotations
// are not exported
- if (globalColourScheme.equalsIgnoreCase("RNA Helices")
- || globalColourScheme.equalsIgnoreCase("T-COFFEE SCORES"))
+ if (globalColourScheme
+ .equalsIgnoreCase(JalviewColourScheme.RNAHelices.toString())
+ || globalColourScheme
+ .equalsIgnoreCase(JalviewColourScheme.TCoffee
+ .toString()))
{
- jsonAlignmentPojo.setGlobalColorScheme("None");
+ jsonAlignmentPojo.setGlobalColorScheme(ResidueColourScheme.NONE);
}
}
{
SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo();
seqGrpPojo.setGroupName(seqGrp.getName());
- seqGrpPojo.setColourScheme(ColourSchemeProperty
- .getColourName(seqGrp.cs));
+ seqGrpPojo.setColourScheme(seqGrp.getColourScheme()
+ .getSchemeName());
seqGrpPojo.setColourText(seqGrp.getColourText());
seqGrpPojo.setDescription(seqGrp.getDescription());
seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes());
}
SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, null,
displayBoxes, displayText, colourText, startRes, endRes);
- seqGrp.cs = ColourSchemeMapper.getJalviewColourScheme(colourScheme,
- seqGrp);
+ seqGrp.setColourScheme(ColourSchemeMapper.getJalviewColourScheme(
+ colourScheme, seqGrp));
seqGrp.setShowNonconserved(showNonconserved);
seqGrp.setDescription(description);
this.seqGroups.add(seqGrp);
annotations[count] = new Annotation(displayChar, desc, ss, val);
if (annot.get("colour") != null)
{
- Color color = UserColourScheme.getColourFromString(annot.get(
+ Color color = ColorUtils.parseColourString(annot.get(
"colour").toString());
annotations[count].colour = color;
}
}
}
}
- globalColourScheme = ColourSchemeProperty.getColourName(viewport
- .getGlobalColourScheme());
+ globalColourScheme = viewport.getGlobalColourScheme().getSchemeName();
setDisplayedFeatures(viewport.getFeaturesDisplayed());
showSeqFeatures = viewport.isShowSequenceFeatures();
//////////////////////////////////////////////////////////////////
package jalview.io;
+import jalview.bin.Cache;
import jalview.gui.JvOptionPane;
import jalview.util.MessageManager;
import jalview.util.Platform;
/**
* Constructor for a single choice of file extension and description
*
- * @param dir
* @param extension
* @param desc
*/
- public JalviewFileChooser(String dir, String extension, String desc)
+ public JalviewFileChooser(String extension, String desc)
{
- // TODO inline dir as Cache.getProperty("LAST_DIRECTORY") ? if applet
- // builds ok
- this(dir, new String[] { extension }, new String[] { desc }, desc,
- true);
+ this(Cache.getProperty("LAST_DIRECTORY"), new String[] { extension },
+ new String[] { desc }, desc, true);
}
JalviewFileChooser(String dir, String[] extensions, String[] descs,
import java.util.regex.Pattern;
/**
- * A file parse for T-Coffee score ascii format. This file contains the
- * alignment consensus for each resude in any sequence.
+ * A file parser for T-Coffee score ascii format. This file contains the
+ * alignment consensus for each residue in any sequence.
* <p>
- * This file is procuded by <code>t_coffee</code> providing the option
+ * This file is produced by <code>t_coffee</code> providing the option
* <code>-output=score_ascii </code> to the program command line
*
* An example file is the following
*/
public class TCoffeeScoreFile extends AlignFile
{
- public TCoffeeScoreFile(String inFile, DataSourceType fileSourceType)
- throws IOException
- {
- super(inFile, fileSourceType);
- }
+ /**
+ * TCOFFEE score colourscheme
+ */
+ static final Color[] colors = { new Color(102, 102, 255), // 0: lilac #6666FF
+ new Color(0, 255, 0), // 1: green #00FF00
+ new Color(102, 255, 0), // 2: lime green #66FF00
+ new Color(204, 255, 0), // 3: greeny yellow #CCFF00
+ new Color(255, 255, 0), // 4: yellow #FFFF00
+ new Color(255, 204, 0), // 5: orange #FFCC00
+ new Color(255, 153, 0), // 6: deep orange #FF9900
+ new Color(255, 102, 0), // 7: ochre #FF6600
+ new Color(255, 51, 0), // 8: red #FF3300
+ new Color(255, 34, 0) // 9: redder #FF2000
+ };
- public TCoffeeScoreFile(FileParse source) throws IOException
- {
- super(source);
- }
+ public final static String TCOFFEE_SCORE = "TCoffeeScore";
+
+ static Pattern SCORES_WITH_RESIDUE_NUMS = Pattern
+ .compile("^\\d+\\s([^\\s]+)\\s+\\d+$");
/** The {@link Header} structure holder */
Header header;
Integer fWidth;
+ public TCoffeeScoreFile(String inFile, DataSourceType fileSourceType)
+ throws IOException
+ {
+ super(inFile, fileSourceType);
+
+ }
+
+ public TCoffeeScoreFile(FileParse source) throws IOException
+ {
+ super(source);
+ }
+
/**
* Parse the provided reader for the T-Coffee scores file format
*
}
}
- static Pattern SCORES_WITH_RESIDUE_NUMS = Pattern
- .compile("^\\d+\\s([^\\s]+)\\s+\\d+$");
-
/**
* Read a scores block ihe provided stream.
*
}
/**
- * TCOFFEE score colourscheme
- */
- static final Color[] colors = { new Color(102, 102, 255), // #6666FF
- new Color(0, 255, 0), // #00FF00
- new Color(102, 255, 0), // #66FF00
- new Color(204, 255, 0), // #CCFF00
- new Color(255, 255, 0), // #FFFF00
- new Color(255, 204, 0), // #FFCC00
- new Color(255, 153, 0), // #FF9900
- new Color(255, 102, 0), // #FF6600
- new Color(255, 51, 0), // #FF3300
- new Color(255, 34, 0) // #FF2000
- };
-
- public final static String TCOFFEE_SCORE = "TCoffeeScore";
-
- /**
* generate annotation for this TCoffee score set on the given alignment
*
* @param al
import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
import jalview.api.SplitContainerI;
import jalview.bin.Cache;
-import jalview.gui.JvOptionPane;
import jalview.gui.JvSwingUtils;
import jalview.gui.Preferences;
import jalview.io.FileFormats;
-import jalview.schemes.ColourSchemeProperty;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import java.awt.BorderLayout;
import java.awt.Color;
protected JMenuItem closeMenuItem = new JMenuItem();
- protected JMenu colourMenu = new JMenu();
-
protected JMenu webService = new JMenu();
protected JMenuItem webServiceNoServices;
- public JCheckBoxMenuItem viewBoxesMenuItem = new JCheckBoxMenuItem();
+ protected JCheckBoxMenuItem viewBoxesMenuItem = new JCheckBoxMenuItem();
- public JCheckBoxMenuItem viewTextMenuItem = new JCheckBoxMenuItem();
+ protected JCheckBoxMenuItem viewTextMenuItem = new JCheckBoxMenuItem();
protected JMenu sortByAnnotScore = new JMenu();
protected JMenu outputTextboxMenu = new JMenu();
- protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem nucleotideColour = new JRadioButtonMenuItem();
+ protected JCheckBoxMenuItem annotationPanelMenuItem = new JCheckBoxMenuItem();
- protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
+ protected JCheckBoxMenuItem colourTextMenuItem = new JCheckBoxMenuItem();
- protected JRadioButtonMenuItem RNAInteractionColour = new JRadioButtonMenuItem();
-
- // protected JRadioButtonMenuItem covariationColour = new
- // JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem tcoffeeColour = new JRadioButtonMenuItem();
-
- public JCheckBoxMenuItem annotationPanelMenuItem = new JCheckBoxMenuItem();
-
- public JCheckBoxMenuItem colourTextMenuItem = new JCheckBoxMenuItem();
-
- public JCheckBoxMenuItem showNonconservedMenuItem = new JCheckBoxMenuItem();
+ protected JCheckBoxMenuItem showNonconservedMenuItem = new JCheckBoxMenuItem();
protected JMenuItem undoMenuItem = new JMenuItem();
protected JMenuItem redoMenuItem = new JMenuItem();
- public JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
-
- JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
-
- public JCheckBoxMenuItem wrapMenuItem = new JCheckBoxMenuItem();
+ protected JCheckBoxMenuItem wrapMenuItem = new JCheckBoxMenuItem();
- public JCheckBoxMenuItem renderGapsMenuItem = new JCheckBoxMenuItem();
-
- public JCheckBoxMenuItem abovePIDThreshold = new JCheckBoxMenuItem();
+ protected JCheckBoxMenuItem renderGapsMenuItem = new JCheckBoxMenuItem();
public JCheckBoxMenuItem showSeqFeatures = new JCheckBoxMenuItem();
JMenu pasteMenu = new JMenu();
- public JCheckBoxMenuItem applyToAllGroups = new JCheckBoxMenuItem();
+ protected JCheckBoxMenuItem seqLimits = new JCheckBoxMenuItem();
+
+ protected JCheckBoxMenuItem scaleAbove = new JCheckBoxMenuItem();
+
+ protected JCheckBoxMenuItem scaleLeft = new JCheckBoxMenuItem();
+
+ protected JCheckBoxMenuItem scaleRight = new JCheckBoxMenuItem();
+
+ protected JCheckBoxMenuItem applyToAllGroups;
+
+ protected JMenu colourMenu = new JMenu();
+
+ protected JRadioButtonMenuItem textColour;
- public JCheckBoxMenuItem seqLimits = new JCheckBoxMenuItem();
+ protected JCheckBoxMenuItem conservationMenuItem;
- public JCheckBoxMenuItem scaleAbove = new JCheckBoxMenuItem();
+ protected JMenuItem modifyConservation;
- public JCheckBoxMenuItem scaleLeft = new JCheckBoxMenuItem();
+ protected JCheckBoxMenuItem abovePIDThreshold;
- public JCheckBoxMenuItem scaleRight = new JCheckBoxMenuItem();
+ protected JMenuItem modifyPID;
- protected JMenuItem modifyConservation = new JMenuItem();
+ protected JMenuItem annotationColour;
protected JMenu sortByTreeMenu = new JMenu();
protected JCheckBoxMenuItem showDbRefsMenuitem = new JCheckBoxMenuItem();
- protected ButtonGroup colours = new ButtonGroup();
-
protected JMenuItem showTranslation = new JMenuItem();
protected JMenuItem showReverse = new JMenuItem();
protected JMenuItem runGroovy = new JMenuItem();
- protected JMenuItem rnahelicesColour = new JMenuItem();
-
protected JCheckBoxMenuItem autoCalculate = new JCheckBoxMenuItem();
protected JCheckBoxMenuItem sortByTree = new JCheckBoxMenuItem();
System.err.println(e.toString());
}
- if (!jalview.util.Platform.isAMac())
+ if (!Platform.isAMac())
{
closeMenuItem.setMnemonic('C');
outputTextboxMenu.setMnemonic('T');
pasteMenu.setMnemonic('P');
reload.setMnemonic('R');
}
-
- if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
- {
- java.util.Enumeration userColours = jalview.gui.UserDefinedColours
- .getUserColourSchemes().keys();
-
- while (userColours.hasMoreElements())
- {
- final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
- userColours.nextElement().toString());
- radioItem.setName("USER_DEFINED");
- radioItem.addMouseListener(new MouseAdapter()
- {
- @Override
- public void mousePressed(MouseEvent evt)
- {
- if (evt.isPopupTrigger()) // Mac
- {
- offerRemoval(radioItem);
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent evt)
- {
- if (evt.isPopupTrigger()) // Windows
- {
- offerRemoval(radioItem);
- }
- }
-
- /**
- * @param radioItem
- */
- void offerRemoval(final JRadioButtonMenuItem radioItem)
- {
- radioItem.removeActionListener(radioItem.getActionListeners()[0]);
-
- int option = JvOptionPane.showInternalConfirmDialog(
- jalview.gui.Desktop.desktop, MessageManager
- .getString("label.remove_from_default_list"),
- MessageManager
- .getString("label.remove_user_defined_colour"),
- JvOptionPane.YES_NO_OPTION);
- if (option == JvOptionPane.YES_OPTION)
- {
- jalview.gui.UserDefinedColours
- .removeColourFromDefaults(radioItem.getText());
- colourMenu.remove(radioItem);
- }
- else
- {
- radioItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- userDefinedColour_actionPerformed(evt);
- }
- });
- }
- }
- });
- radioItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- userDefinedColour_actionPerformed(evt);
- }
- });
- colourMenu.insert(radioItem, 15);
- colours.add(radioItem);
- }
- }
- colours.add(noColourmenuItem);
- colours.add(clustalColour);
- colours.add(zappoColour);
- colours.add(taylorColour);
- colours.add(hydrophobicityColour);
- colours.add(helixColour);
- colours.add(strandColour);
- colours.add(turnColour);
- colours.add(buriedColour);
- colours.add(userDefinedColour);
- colours.add(PIDColour);
- colours.add(BLOSUM62Colour);
- colours.add(nucleotideColour);
- colours.add(purinePyrimidineColour);
- // colours.add(covariationColour);
- colours.add(tcoffeeColour);
- colours.add(RNAInteractionColour);
- setColourSelected(jalview.bin.Cache.getDefault(
- Preferences.DEFAULT_COLOUR, "None"));
- }
-
- public void setColourSelected(String defaultColour)
- {
-
- if (defaultColour != null)
- {
- int index = ColourSchemeProperty
- .getColourIndexFromName(defaultColour);
-
- switch (index)
- {
- case ColourSchemeProperty.CLUSTAL:
- clustalColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.BLOSUM:
- BLOSUM62Colour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.PID:
- PIDColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.ZAPPO:
- zappoColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.TAYLOR:
- taylorColour.setSelected(true);
- break;
-
- case ColourSchemeProperty.HYDROPHOBIC:
- hydrophobicityColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.HELIX:
- helixColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.STRAND:
- strandColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.TURN:
- turnColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.BURIED:
- buriedColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.NUCLEOTIDE:
- nucleotideColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.TCOFFEE:
- tcoffeeColour.setSelected(true);
- break;
-
- case ColourSchemeProperty.PURINEPYRIMIDINE:
- purinePyrimidineColour.setSelected(true);
-
- break;
-
- case ColourSchemeProperty.RNAINTERACTION:
- RNAInteractionColour.setSelected(true);
-
- break;
- /*
- * case ColourSchemeProperty.COVARIATION:
- * covariationColour.setSelected(true);
- *
- * break;
- */
- case ColourSchemeProperty.USER_DEFINED:
- userDefinedColour.setSelected(true);
-
- break;
- case ColourSchemeProperty.NONE:
- default:
- noColourmenuItem.setSelected(true);
- break;
-
- }
- }
-
}
private void jbInit() throws Exception
{
+ initColourMenu();
+
JMenuItem saveAs = new JMenuItem(
MessageManager.getString("action.save_as"));
ActionListener al = new ActionListener()
saveAs_actionPerformed(e);
}
};
+
+ // FIXME getDefaultToolkit throws an exception in Headless mode
KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit
.getDefaultToolkit().getMenuShortcutKeyMask()
| KeyEvent.SHIFT_MASK, false);
}
});
showNonconservedMenuItem.setText(MessageManager
- .getString("label.show_non_conversed"));
+ .getString("label.show_non_conserved"));
showNonconservedMenuItem.setState(false);
showNonconservedMenuItem.addActionListener(new ActionListener()
{
statusBar.setText(MessageManager.getString("label.status_bar"));
outputTextboxMenu.setText(MessageManager
.getString("label.out_to_textbox"));
- clustalColour.setText(MessageManager.getString("label.clustalx"));
- clustalColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- clustalColour_actionPerformed(e);
- }
- });
- zappoColour.setText(MessageManager.getString("label.zappo"));
- zappoColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- zappoColour_actionPerformed(e);
- }
- });
- taylorColour.setText(MessageManager.getString("label.taylor"));
- taylorColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- taylorColour_actionPerformed(e);
- }
- });
- hydrophobicityColour.setText(MessageManager
- .getString("label.hydrophobicity"));
- hydrophobicityColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- hydrophobicityColour_actionPerformed(e);
- }
- });
- helixColour.setText(MessageManager.getString("label.helix_propensity"));
- helixColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- helixColour_actionPerformed(e);
- }
- });
- strandColour.setText(MessageManager
- .getString("label.strand_propensity"));
- strandColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- strandColour_actionPerformed(e);
- }
- });
- turnColour.setText(MessageManager.getString("label.turn_propensity"));
- turnColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- turnColour_actionPerformed(e);
- }
- });
- buriedColour.setText(MessageManager.getString("label.buried_index"));
- buriedColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- buriedColour_actionPerformed(e);
- }
- });
- userDefinedColour.setText(MessageManager
- .getString("action.user_defined"));
- userDefinedColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- userDefinedColour_actionPerformed(e);
- }
- });
- PIDColour
- .setText(MessageManager.getString("label.percentage_identity"));
- PIDColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- PIDColour_actionPerformed(e);
- }
- });
- BLOSUM62Colour
- .setText(MessageManager.getString("label.blosum62_score"));
- BLOSUM62Colour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- BLOSUM62Colour_actionPerformed(e);
- }
- });
- nucleotideColour.setText(MessageManager.getString("label.nucleotide"));
- nucleotideColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- nucleotideColour_actionPerformed(e);
- }
- });
-
- purinePyrimidineColour.setText(MessageManager
- .getString("label.purine_pyrimidine"));
- purinePyrimidineColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- purinePyrimidineColour_actionPerformed(e);
- }
- });
- RNAInteractionColour.setText("RNA Interaction type");
- RNAInteractionColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- RNAInteractionColour_actionPerformed(e);
- }
- });
- /*
- * covariationColour.setText("Covariation");
- * covariationColour.addActionListener(new ActionListener() { public void
- * actionPerformed(ActionEvent e) { covariationColour_actionPerformed(e); }
- * });
- */
JMenuItem avDistanceTreeBlosumMenuItem = new JMenuItem(
- MessageManager.getString("label.average_distance_bloslum62"));
+ MessageManager.getString("label.average_distance_blosum62"));
avDistanceTreeBlosumMenuItem.addActionListener(new ActionListener()
{
@Override
sortAnnotations_actionPerformed();
}
});
- colourTextMenuItem.setText(MessageManager
+ colourTextMenuItem = new JCheckBoxMenuItem(
+ MessageManager
.getString("label.colour_text"));
colourTextMenuItem.addActionListener(new ActionListener()
{
};
addMenuActionAndAccelerator(keyStroke, redoMenuItem, al);
- conservationMenuItem.setText(MessageManager
- .getString("action.by_conservation"));
- conservationMenuItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- conservationMenuItem_actionPerformed(e);
- }
- });
- noColourmenuItem.setText(MessageManager.getString("label.none"));
- noColourmenuItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- noColourmenuItem_actionPerformed(e);
- }
- });
wrapMenuItem.setText(MessageManager.getString("label.wrap"));
wrapMenuItem.addActionListener(new ActionListener()
{
};
addMenuActionAndAccelerator(keyStroke, findMenuItem, al);
- abovePIDThreshold.setText(MessageManager
- .getString("label.above_identity_threshold"));
- abovePIDThreshold.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- abovePIDThreshold_actionPerformed(e);
- }
- });
showSeqFeatures.setText(MessageManager
.getString("label.show_sequence_features"));
showSeqFeatures.addActionListener(new ActionListener()
}
});
- nucleotideColour.setText(MessageManager.getString("label.nucleotide"));
- nucleotideColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- nucleotideColour_actionPerformed(e);
- }
- });
-
- tcoffeeColour.setText(MessageManager.getString("label.tcoffee_scores"));
- tcoffeeColour.setEnabled(false);
- tcoffeeColour.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- tcoffeeColorScheme_actionPerformed(e);
- }
- });
-
JMenuItem deleteGroups = new JMenuItem(
MessageManager.getString("action.undefine_groups"));
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_U, Toolkit
};
addMenuActionAndAccelerator(keyStroke, deleteGroups, al);
+ JMenuItem annotationColumn = new JMenuItem(
+ MessageManager.getString("action.select_by_annotation"));
+ annotationColumn.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ annotationColumn_actionPerformed(e);
+ }
+ });
+
JMenuItem createGroup = new JMenuItem(
MessageManager.getString("action.create_groups"));
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit
};
addMenuActionAndAccelerator(keyStroke, pasteThis, al);
- applyToAllGroups.setText(MessageManager
- .getString("label.apply_colour_to_all_groups"));
- applyToAllGroups.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- applyToAllGroups_actionPerformed(e);
- }
- });
JMenuItem createPNG = new JMenuItem("PNG");
createPNG.addActionListener(new ActionListener()
{
});
- JMenuItem modifyPID = new JMenuItem(
- MessageManager.getString("label.modify_identity_threshold"));
- modifyPID.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- modifyPID_actionPerformed(e);
- }
- });
- modifyConservation.setText(MessageManager
- .getString("label.modify_conservation_threshold"));
- modifyConservation.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- modifyConservation_actionPerformed(e);
- }
- });
sortByTreeMenu
.setText(MessageManager.getString("action.by_tree_order"));
sort.setText(MessageManager.getString("action.sort"));
}
});
- JMenuItem annotationColour = new JMenuItem(
- MessageManager.getString("action.by_annotation"));
- annotationColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- annotationColour_actionPerformed(e);
- }
- });
-
- JMenuItem annotationColumn = new JMenuItem(
- MessageManager.getString("action.select_by_annotation"));
- annotationColumn.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- annotationColumn_actionPerformed(e);
- }
- });
-
- rnahelicesColour.setText(MessageManager
- .getString("action.by_rna_helixes"));
- rnahelicesColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- rnahelicesColour_actionPerformed(e);
- }
- });
-
JMenuItem associatedData = new JMenuItem(
MessageManager.getString("label.load_features_annotations"));
associatedData.addActionListener(new ActionListener()
tabbedPane.setToolTipText("<html><i>"
+ MessageManager.getString("label.rename_tab_eXpand_reGroup")
+ "</i></html>");
- JMenuItem textColour = new JMenuItem(
- MessageManager.getString("action.set_text_colour"));
- textColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- textColour_actionPerformed(e);
- }
- });
+
formatMenu.setText(MessageManager.getString("action.format"));
JMenu selectMenu = new JMenu(MessageManager.getString("action.select"));
idRightAlign.setText(MessageManager
autoAnnMenu.add(showGroupConsensus);
annotationsMenu.add(autoAnnMenu);
- colourMenu.add(applyToAllGroups);
- colourMenu.add(textColour);
- colourMenu.addSeparator();
- colourMenu.add(noColourmenuItem);
- colourMenu.add(clustalColour);
- colourMenu.add(BLOSUM62Colour);
- colourMenu.add(PIDColour);
- colourMenu.add(zappoColour);
- colourMenu.add(taylorColour);
- colourMenu.add(hydrophobicityColour);
- colourMenu.add(helixColour);
- colourMenu.add(strandColour);
- colourMenu.add(turnColour);
- colourMenu.add(buriedColour);
- colourMenu.add(nucleotideColour);
- colourMenu.add(purinePyrimidineColour);
- // colourMenu.add(RNAInteractionColour);
- // colourMenu.add(covariationColour);
- colourMenu.add(tcoffeeColour);
- colourMenu.add(userDefinedColour);
- colourMenu.addSeparator();
- colourMenu.add(conservationMenuItem);
- colourMenu.add(modifyConservation);
- colourMenu.add(abovePIDThreshold);
- colourMenu.add(modifyPID);
- colourMenu.add(annotationColour);
- colourMenu.add(rnahelicesColour);
sort.add(sortIDMenuItem);
sort.add(sortLengthMenuItem);
// selectMenu.add(listenToViewSelections);
}
+ /**
+ * Constructs the entries on the Colour menu (but does not add them to the
+ * menu).
+ */
+ protected void initColourMenu()
+ {
+ applyToAllGroups = new JCheckBoxMenuItem(
+ MessageManager.getString("label.apply_colour_to_all_groups"));
+ applyToAllGroups.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ applyToAllGroups_actionPerformed(applyToAllGroups.isSelected());
+ }
+ });
+
+ textColour = new JRadioButtonMenuItem(
+ MessageManager.getString("action.set_text_colour"));
+ textColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ textColour_actionPerformed();
+ }
+ });
+
+ conservationMenuItem = new JCheckBoxMenuItem(
+ MessageManager.getString("action.by_conservation"));
+ conservationMenuItem.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ conservationMenuItem_actionPerformed(conservationMenuItem
+ .isSelected());
+ }
+ });
+
+ abovePIDThreshold = new JCheckBoxMenuItem(
+ MessageManager.getString("label.above_identity_threshold"));
+ abovePIDThreshold.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ abovePIDThreshold_actionPerformed(abovePIDThreshold.isSelected());
+ }
+ });
+ modifyPID = new JMenuItem(
+ MessageManager.getString("label.modify_identity_threshold"));
+ modifyPID.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ modifyPID_actionPerformed();
+ }
+ });
+ modifyConservation = new JMenuItem(
+ MessageManager
+ .getString("label.modify_conservation_threshold"));
+ modifyConservation.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ modifyConservation_actionPerformed();
+ }
+ });
+
+ annotationColour = new JMenuItem(
+ MessageManager.getString("action.by_annotation"));
+ annotationColour.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ annotationColour_actionPerformed();
+ }
+ });
+ }
+
protected void selectHighlightedColumns_actionPerformed(
ActionEvent actionEvent)
{
{
}
- protected void clustalColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void zappoColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void taylorColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void hydrophobicityColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void helixColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void strandColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void turnColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void buriedColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void userDefinedColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void PIDColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void BLOSUM62Colour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void purinePyrimidineColour_actionPerformed(ActionEvent e)
- {
- }
-
- protected void RNAInteractionColour_actionPerformed(ActionEvent e)
- {
- }
-
- /*
- * protected void covariationColour_actionPerformed(ActionEvent e) { }
- */
-
- protected void noColourmenuItem_actionPerformed(ActionEvent e)
- {
- }
-
- protected void conservationMenuItem_actionPerformed(ActionEvent e)
+ protected void conservationMenuItem_actionPerformed(boolean selected)
{
}
{
}
- protected void abovePIDThreshold_actionPerformed(ActionEvent e)
+ protected void abovePIDThreshold_actionPerformed(boolean selected)
{
}
{
}
- protected void nucleotideColour_actionPerformed(ActionEvent e)
- {
- }
-
protected void deleteGroups_actionPerformed(ActionEvent e)
{
}
{
}
- protected void applyToAllGroups_actionPerformed(ActionEvent e)
+ protected void applyToAllGroups_actionPerformed(boolean selected)
{
}
}
- /**
- * Template method to handle the 'Color T-Coffee scores' menu event.
- * <p>
- * Subclasses override this method to provide a custom action.
- *
- * @param event
- * The raised event
- */
- protected void tcoffeeColorScheme_actionPerformed(ActionEvent event)
- {
-
- }
-
protected void jpred_actionPerformed(ActionEvent e)
{
}
{
}
- protected void modifyPID_actionPerformed(ActionEvent e)
+ protected void modifyPID_actionPerformed()
{
}
- protected void modifyConservation_actionPerformed(ActionEvent e)
+ protected void modifyConservation_actionPerformed()
{
}
}
- public void annotationColour_actionPerformed(ActionEvent e)
+ public void annotationColour_actionPerformed()
{
-
}
public void annotationColumn_actionPerformed(ActionEvent e)
{
-
- }
-
- public void rnahelicesColour_actionPerformed(ActionEvent e)
- {
-
}
public void associatedData_actionPerformed(ActionEvent e)
}
- public void textColour_actionPerformed(ActionEvent e)
+ public void textColour_actionPerformed()
{
}
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import javax.swing.AbstractCellEditor;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
-import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
+import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
/**
* Base class for the Preferences panel.
/*
* Connections tab components
*/
- protected JList linkURLList = new JList();
+ protected JTable linkUrlTable = new JTable();
+
+ protected JButton editLink = new JButton();
+
+ protected JButton deleteLink = new JButton();
+
+ protected JTextField filterTB = new JTextField();
+
+ protected JButton doReset = new JButton();
+
+ protected JButton userOnly = new JButton();
+
+ protected JLabel portLabel = new JLabel();
+
+ protected JLabel serverLabel = new JLabel();
protected JTextField proxyServerTB = new JTextField();
protected JTextField defaultBrowser = new JTextField();
- protected JList linkNameList = new JList();
-
protected JCheckBox useProxy = new JCheckBox();
protected JCheckBox usagestats = new JCheckBox();
tabbedPane.add(initConnectionsTab(),
MessageManager.getString("label.connections"));
+ tabbedPane.add(initLinksTab(),
+ MessageManager.getString("label.urllinks"));
+
tabbedPane.add(initOutputTab(),
MessageManager.getString("label.output"));
{
JPanel connectTab = new JPanel();
connectTab.setLayout(new GridBagLayout());
- JLabel serverLabel = new JLabel();
- serverLabel.setText(MessageManager.getString("label.address"));
- serverLabel.setHorizontalAlignment(SwingConstants.RIGHT);
- serverLabel.setFont(LABEL_FONT);
- proxyServerTB.setFont(LABEL_FONT);
- proxyPortTB.setFont(LABEL_FONT);
- JLabel portLabel = new JLabel();
- portLabel.setFont(LABEL_FONT);
- portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
- portLabel.setText(MessageManager.getString("label.port"));
+
+ // Label for browser text box
JLabel browserLabel = new JLabel();
- browserLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
+ browserLabel.setFont(LABEL_FONT);
browserLabel.setHorizontalAlignment(SwingConstants.TRAILING);
browserLabel.setText(MessageManager
.getString("label.default_browser_unix"));
defaultBrowser.setFont(LABEL_FONT);
defaultBrowser.setText("");
- usagestats.setText(MessageManager
- .getString("label.send_usage_statistics"));
- usagestats.setFont(LABEL_FONT);
- usagestats.setHorizontalAlignment(SwingConstants.RIGHT);
- usagestats.setHorizontalTextPosition(SwingConstants.LEADING);
- questionnaire.setText(MessageManager
- .getString("label.check_for_questionnaires"));
- questionnaire.setFont(LABEL_FONT);
- questionnaire.setHorizontalAlignment(SwingConstants.RIGHT);
- questionnaire.setHorizontalTextPosition(SwingConstants.LEADING);
- versioncheck.setText(MessageManager
- .getString("label.check_for_latest_version"));
- versioncheck.setFont(LABEL_FONT);
- versioncheck.setHorizontalAlignment(SwingConstants.RIGHT);
- versioncheck.setHorizontalTextPosition(SwingConstants.LEADING);
+
+ defaultBrowser.addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mouseClicked(MouseEvent e)
+ {
+ if (e.getClickCount() > 1)
+ {
+ defaultBrowser_mouseClicked(e);
+ }
+ }
+ });
+
+ JPanel proxyPanel = initConnTabProxyPanel();
+ initConnTabCheckboxes();
+
+ // Add default Browser text box
+ connectTab.add(browserLabel, new GridBagConstraints(0, 0, 1, 1, 0.0,
+ 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
+ new Insets(10, 0, 5, 5), 5, 1));
+ defaultBrowser.setFont(LABEL_FONT);
+ defaultBrowser.setText("");
+
+ connectTab.add(defaultBrowser, new GridBagConstraints(1, 0, 1, 1, 1.0,
+ 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
+ new Insets(10, 0, 5, 10), 30, 1));
+
+ // Add proxy server panel
+ connectTab.add(proxyPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0,
+ GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
+ new Insets(10, 0, 5, 12), 4, 10));
+
+ // Add usage stats, version check and questionnaire checkboxes
+ connectTab.add(usagestats, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,
+ GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
+ new Insets(0, 2, 5, 5), 70, 1));
+ connectTab.add(questionnaire, new GridBagConstraints(1, 2, 1, 1, 1.0,
+ 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
+ new Insets(0, 2, 5, 10), 70, 1));
+ connectTab.add(versioncheck, new GridBagConstraints(0, 3, 1, 1, 1.0,
+ 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
+ new Insets(0, 2, 5, 5), 70, 1));
+
+ // Add padding so the panel doesn't look ridiculous
+ JPanel spacePanel = new JPanel();
+ connectTab.add(spacePanel, new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0,
+ GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
+ 0, 0, 5), 70, 1));
+
+ return connectTab;
+ }
+
+ /**
+ * Initialises the Links tabbed panel.
+ *
+ * @return
+ */
+ private JPanel initLinksTab()
+ {
+ JPanel linkTab = new JPanel();
+ linkTab.setLayout(new GridBagLayout());
+
+ // Set up table for Url links
+ linkUrlTable.setFillsViewportHeight(true);
+ linkUrlTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
+ linkUrlTable.setAutoCreateRowSorter(true);
+ linkUrlTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+
+ // adjust row height so radio buttons actually fit
+ // don't do this in the renderer, it causes the awt thread to activate
+ // constantly
+ JRadioButton temp = new JRadioButton();
+ linkUrlTable.setRowHeight(temp.getMinimumSize().height);
+
+ // Table in scrollpane so that the table is given a scrollbar
+ JScrollPane linkScrollPane = new JScrollPane(linkUrlTable);
+ linkScrollPane.setBorder(null);
+
+ // Panel for links functionality
+ JPanel linkPanel = new JPanel(new GridBagLayout());
+ linkPanel.setBorder(new TitledBorder(MessageManager
+ .getString("label.url_linkfrom_sequence_id")));
+
+ // Put the Url links panel together
+
+ // Buttons go at top right, resizing only resizes the blank space vertically
+ JPanel buttonPanel = initLinkTabUrlButtons();
+ GridBagConstraints linkConstraints1 = new GridBagConstraints();
+ linkConstraints1.insets = new Insets(0, 0, 5, 0);
+ linkConstraints1.gridx = 0;
+ linkConstraints1.gridy = 0;
+ linkConstraints1.weightx = 1.0;
+ linkConstraints1.fill = GridBagConstraints.HORIZONTAL;
+ linkTab.add(buttonPanel, linkConstraints1);
+
+ // Links table goes at top left, resizing resizes the table
+ GridBagConstraints linkConstraints2 = new GridBagConstraints();
+ linkConstraints2.insets = new Insets(0, 0, 5, 5);
+ linkConstraints2.gridx = 0;
+ linkConstraints2.gridy = 1;
+ linkConstraints2.weightx = 1.0;
+ linkConstraints2.weighty = 1.0;
+ linkConstraints2.fill = GridBagConstraints.BOTH;
+ linkTab.add(linkScrollPane, linkConstraints2);
+
+ // Filter box and buttons goes at bottom left, resizing resizes the text box
+ JPanel filterPanel = initLinkTabFilterPanel();
+ GridBagConstraints linkConstraints3 = new GridBagConstraints();
+ linkConstraints3.insets = new Insets(0, 0, 0, 5);
+ linkConstraints3.gridx = 0;
+ linkConstraints3.gridy = 2;
+ linkConstraints3.weightx = 1.0;
+ linkConstraints3.fill = GridBagConstraints.HORIZONTAL;
+ linkTab.add(filterPanel, linkConstraints3);
+
+ return linkTab;
+ }
+
+ private JPanel initLinkTabFilterPanel()
+ {
+ // Filter textbox and reset button
+ JLabel filterLabel = new JLabel(
+ MessageManager.getString("label.filter"));
+ filterLabel.setFont(LABEL_FONT);
+ filterLabel.setHorizontalAlignment(SwingConstants.RIGHT);
+ filterLabel.setHorizontalTextPosition(SwingConstants.LEADING);
+
+ filterTB.setFont(LABEL_FONT);
+ filterTB.setText("");
+
+ doReset.setText(MessageManager.getString("action.showall"));
+ userOnly.setText(MessageManager.getString("action.customfilter"));
+
+ // Panel for filter functionality
+ JPanel filterPanel = new JPanel(new GridBagLayout());
+ filterPanel.setBorder(new TitledBorder("Filter"));
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.fill = GridBagConstraints.NONE;
+ gbc.anchor = GridBagConstraints.WEST;
+
+ filterPanel.add(filterLabel, gbc);
+
+ GridBagConstraints gbc1 = new GridBagConstraints();
+ gbc1.gridx = 1;
+ gbc1.gridwidth = 2;
+ gbc1.fill = GridBagConstraints.HORIZONTAL;
+ gbc1.anchor = GridBagConstraints.WEST;
+ gbc1.weightx = 1.0;
+ filterPanel.add(filterTB, gbc1);
+
+ GridBagConstraints gbc2 = new GridBagConstraints();
+ gbc2.gridx = 3;
+ gbc2.fill = GridBagConstraints.NONE;
+ gbc2.anchor = GridBagConstraints.WEST;
+ filterPanel.add(doReset, gbc2);
+
+ GridBagConstraints gbc3 = new GridBagConstraints();
+ gbc3.gridx = 4;
+ gbc3.fill = GridBagConstraints.NONE;
+ gbc3.anchor = GridBagConstraints.WEST;
+ filterPanel.add(userOnly, gbc3);
+
+ return filterPanel;
+ }
+
+ private JPanel initLinkTabUrlButtons()
+ {
+ // Buttons for new / edit / delete Url links
JButton newLink = new JButton();
newLink.setText(MessageManager.getString("action.new"));
+
+ editLink.setText(MessageManager.getString("action.edit"));
+
+ deleteLink.setText(MessageManager.getString("action.delete"));
+
+ // no current selection, so initially disable delete/edit buttons
+ editLink.setEnabled(false);
+ deleteLink.setEnabled(false);
+
newLink.addActionListener(new java.awt.event.ActionListener()
{
@Override
newLink_actionPerformed(e);
}
});
- JButton editLink = new JButton();
+
editLink.setText(MessageManager.getString("action.edit"));
editLink.addActionListener(new java.awt.event.ActionListener()
{
editLink_actionPerformed(e);
}
});
- JButton deleteLink = new JButton();
+
deleteLink.setText(MessageManager.getString("action.delete"));
deleteLink.addActionListener(new java.awt.event.ActionListener()
{
}
});
- linkURLList.addListSelectionListener(new ListSelectionListener()
- {
- @Override
- public void valueChanged(ListSelectionEvent e)
- {
- int index = linkURLList.getSelectedIndex();
- linkNameList.setSelectedIndex(index);
- }
- });
+ JPanel buttonPanel = new JPanel(new GridBagLayout());
+ buttonPanel.setBorder(new TitledBorder("Edit links"));
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.fill = GridBagConstraints.NONE;
+ buttonPanel.add(newLink, gbc);
+
+ GridBagConstraints gbc1 = new GridBagConstraints();
+ gbc1.gridx = 1;
+ gbc1.gridy = 0;
+ gbc1.fill = GridBagConstraints.NONE;
+ buttonPanel.add(editLink, gbc1);
+
+ GridBagConstraints gbc2 = new GridBagConstraints();
+ gbc2.gridx = 2;
+ gbc2.gridy = 0;
+ gbc2.fill = GridBagConstraints.NONE;
+ buttonPanel.add(deleteLink, gbc2);
+
+ GridBagConstraints gbc3 = new GridBagConstraints();
+ gbc3.gridx = 3;
+ gbc3.gridy = 0;
+ gbc3.fill = GridBagConstraints.HORIZONTAL;
+ gbc3.weightx = 1.0;
+ JPanel spacePanel = new JPanel();
+ spacePanel.setBorder(null);
+ buttonPanel.add(spacePanel, gbc3);
+
+ return buttonPanel;
+ }
- linkNameList.addListSelectionListener(new ListSelectionListener()
- {
- @Override
- public void valueChanged(ListSelectionEvent e)
- {
- int index = linkNameList.getSelectedIndex();
- linkURLList.setSelectedIndex(index);
- }
- });
+ /**
+ * Initialises the proxy server panel in the Connections tab
+ *
+ * @return the proxy server panel
+ */
+ private JPanel initConnTabProxyPanel()
+ {
+ // Label for server text box
+ serverLabel.setText(MessageManager.getString("label.address"));
+ serverLabel.setHorizontalAlignment(SwingConstants.RIGHT);
+ serverLabel.setFont(LABEL_FONT);
- JScrollPane linkScrollPane = new JScrollPane();
- linkScrollPane.setBorder(null);
- JPanel linkPanel = new JPanel();
- linkPanel.setBorder(new TitledBorder(MessageManager
- .getString("label.url_linkfrom_sequence_id")));
- linkPanel.setLayout(new BorderLayout());
- GridLayout gridLayout1 = new GridLayout();
- JPanel editLinkButtons = new JPanel();
- editLinkButtons.setLayout(gridLayout1);
- gridLayout1.setRows(3);
- linkNameList.setFont(LABEL_FONT);
- linkNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- BorderLayout borderLayout3 = new BorderLayout();
- JPanel linkPanel2 = new JPanel();
- linkPanel2.setLayout(borderLayout3);
- linkURLList.setFont(LABEL_FONT);
- linkURLList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ // Proxy server and port text boxes
+ proxyServerTB.setFont(LABEL_FONT);
+ proxyPortTB.setFont(LABEL_FONT);
- defaultBrowser.addMouseListener(new MouseAdapter()
- {
- @Override
- public void mouseClicked(MouseEvent e)
- {
- if (e.getClickCount() > 1)
- {
- defaultBrowser_mouseClicked(e);
- }
- }
- });
+ // Label for Port text box
+ portLabel.setFont(LABEL_FONT);
+ portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
+ portLabel.setText(MessageManager.getString("label.port"));
+
+ // Use proxy server checkbox
useProxy.setFont(LABEL_FONT);
useProxy.setHorizontalAlignment(SwingConstants.RIGHT);
useProxy.setHorizontalTextPosition(SwingConstants.LEADING);
useProxy_actionPerformed();
}
});
- linkPanel.add(editLinkButtons, BorderLayout.EAST);
- editLinkButtons.add(newLink, null);
- editLinkButtons.add(editLink, null);
- editLinkButtons.add(deleteLink, null);
- linkPanel.add(linkScrollPane, BorderLayout.CENTER);
- linkScrollPane.getViewport().add(linkPanel2, null);
- linkPanel2.add(linkURLList, BorderLayout.CENTER);
- linkPanel2.add(linkNameList, BorderLayout.WEST);
- JPanel jPanel1 = new JPanel();
+
+ // Make proxy server panel
+ JPanel proxyPanel = new JPanel();
TitledBorder titledBorder1 = new TitledBorder(
MessageManager.getString("label.proxy_server"));
- jPanel1.setBorder(titledBorder1);
- jPanel1.setLayout(new GridBagLayout());
- jPanel1.add(serverLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
- GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
- 2, 4, 0), 5, 0));
- jPanel1.add(portLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,
- GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
- 0, 4, 0), 11, 6));
- connectTab.add(linkPanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0,
- GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
- 16, 0, 0, 12), 359, -17));
- connectTab.add(jPanel1, new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0,
- GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
- 21, 0, 35, 12), 4, 6));
- connectTab.add(browserLabel, new GridBagConstraints(0, 1, 1, 1, 0.0,
+ proxyPanel.setBorder(titledBorder1);
+ proxyPanel.setLayout(new GridBagLayout());
+ proxyPanel.add(serverLabel, new GridBagConstraints(0, 1, 1, 1, 0.0,
0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
- new Insets(16, 0, 0, 0), 5, 1));
- jPanel1.add(useProxy, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
+ new Insets(0, 2, 2, 0), 5, 0));
+ proxyPanel.add(portLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,
+ GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
+ 0, 2, 0), 11, 0));
+ proxyPanel.add(useProxy, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
2, 5, 185), 2, -4));
- jPanel1.add(proxyPortTB, new GridBagConstraints(3, 1, 1, 1, 1.0, 0.0,
- GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(0, 2, 4, 2), 54, 1));
- jPanel1.add(proxyServerTB, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0,
- GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(0, 2, 4, 0), 263, 1));
- connectTab.add(defaultBrowser, new GridBagConstraints(1, 1, 1, 1, 1.0,
- 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(15, 0, 0, 15), 307, 1));
- connectTab.add(usagestats, new GridBagConstraints(0, 4, 1, 1, 1.0, 0.0,
- GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(0, 2, 4, 2), 70, 1));
- connectTab.add(questionnaire, new GridBagConstraints(1, 4, 1, 1, 1.0,
+ proxyPanel.add(proxyPortTB, new GridBagConstraints(3, 1, 1, 1, 1.0,
0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(0, 2, 4, 2), 70, 1));
- connectTab.add(versioncheck, new GridBagConstraints(0, 5, 1, 1, 1.0,
+ new Insets(0, 2, 2, 2), 54, 1));
+ proxyPanel.add(proxyServerTB, new GridBagConstraints(1, 1, 1, 1, 1.0,
0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(0, 2, 4, 2), 70, 1));
- return connectTab;
+ new Insets(0, 2, 2, 0), 263, 1));
+
+ return proxyPanel;
+ }
+
+ /**
+ * Initialises the checkboxes in the Connections tab
+ */
+ private void initConnTabCheckboxes()
+ {
+ // Usage stats checkbox label
+ usagestats.setText(MessageManager
+ .getString("label.send_usage_statistics"));
+ usagestats.setFont(LABEL_FONT);
+ usagestats.setHorizontalAlignment(SwingConstants.RIGHT);
+ usagestats.setHorizontalTextPosition(SwingConstants.LEADING);
+
+ // Questionnaire checkbox label
+ questionnaire.setText(MessageManager
+ .getString("label.check_for_questionnaires"));
+ questionnaire.setFont(LABEL_FONT);
+ questionnaire.setHorizontalAlignment(SwingConstants.RIGHT);
+ questionnaire.setHorizontalTextPosition(SwingConstants.LEADING);
+
+ // Check for latest version checkbox label
+ versioncheck.setText(MessageManager
+ .getString("label.check_for_latest_version"));
+ versioncheck.setFont(LABEL_FONT);
+ versioncheck.setHorizontalAlignment(SwingConstants.RIGHT);
+ versioncheck.setHorizontalTextPosition(SwingConstants.LEADING);
}
/**
public void useProxy_actionPerformed()
{
- proxyServerTB.setEnabled(useProxy.isSelected());
- proxyPortTB.setEnabled(useProxy.isSelected());
+ boolean enabled = useProxy.isSelected();
+ portLabel.setEnabled(enabled);
+ serverLabel.setEnabled(enabled);
+ proxyServerTB.setEnabled(enabled);
+ proxyPortTB.setEnabled(enabled);
+ }
+
+ /**
+ * Customer renderer for JTable: supports column of radio buttons
+ */
+ public class RadioButtonRenderer extends JRadioButton implements
+ TableCellRenderer
+ {
+ public RadioButtonRenderer()
+ {
+ setHorizontalAlignment(CENTER);
+ setToolTipText(MessageManager.getString("label.urltooltip"));
+ }
+
+ @Override
+ public Component getTableCellRendererComponent(JTable table,
+ Object value, boolean isSelected, boolean hasFocus, int row,
+ int column)
+ {
+ setSelected((boolean) value);
+
+ // set colours to match rest of table
+ if (isSelected)
+ {
+ setBackground(table.getSelectionBackground());
+ setForeground(table.getSelectionForeground());
+ }
+ else
+ {
+ setBackground(table.getBackground());
+ setForeground(table.getForeground());
+ }
+ return this;
+ }
}
+ /**
+ * Customer cell editor for JTable: supports column of radio buttons in
+ * conjunction with renderer
+ */
+ public class RadioButtonEditor extends AbstractCellEditor implements
+ TableCellEditor
+ {
+ private JRadioButton button = new JRadioButton();
+
+ public RadioButtonEditor()
+ {
+ button.setHorizontalAlignment(SwingConstants.CENTER);
+ this.button.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ fireEditingStopped();
+ }
+ });
+ }
+
+ @Override
+ public Component getTableCellEditorComponent(JTable table,
+ Object value, boolean isSelected, int row, int column)
+ {
+ button.setSelected((boolean) value);
+ return button;
+ }
+
+ @Override
+ public Object getCellEditorValue()
+ {
+ return button.isSelected();
+ }
+
+ }
}
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
-import java.awt.Panel;
import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.BorderFactory;
+import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
-public class GSequenceLink extends Panel
+public class GSequenceLink extends JPanel
{
+
+ JTextField nameTB = new JTextField();
+
+ JTextField urlTB = new JTextField();
+
+ JButton insertSeq = new JButton();
+
+ JButton insertDBAcc = new JButton();
+
+ JLabel insert = new JLabel();
+
+ JLabel jLabel1 = new JLabel();
+
+ JLabel jLabel2 = new JLabel();
+
+ JLabel jLabel3 = new JLabel();
+
+ JLabel jLabel4 = new JLabel();
+
+ JLabel jLabel5 = new JLabel();
+
+ JLabel jLabel6 = new JLabel();
+
+ JPanel jPanel1 = new JPanel();
+
+ GridBagLayout gridBagLayout1 = new GridBagLayout();
+
public GSequenceLink()
{
try
urlTB_keyTyped(e);
}
});
+
+ insertSeq.setLocation(77, 75);
+ insertSeq.setSize(141, 24);
+ insertSeq.setText(MessageManager.getString("action.seq_id"));
+ insertSeq.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ insertSeq_action(e);
+ }
+ });
+
+ insertDBAcc.setLocation(210, 75);
+ insertDBAcc.setSize(141, 24);
+ insertDBAcc.setText(MessageManager.getString("action.db_acc"));
+ insertDBAcc.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ insertDBAcc_action(e);
+ }
+ });
+
+ insert.setText(MessageManager.getString("label.insert"));
+ insert.setFont(JvSwingUtils.getLabelFont());
+ insert.setHorizontalAlignment(SwingConstants.RIGHT);
+ insert.setBounds(17, 78, 58, 16);
+
jLabel1.setFont(JvSwingUtils.getLabelFont());
jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
jLabel1.setText(MessageManager.getString("label.link_name"));
jLabel1.setBounds(new Rectangle(4, 10, 71, 24));
jLabel2.setFont(JvSwingUtils.getLabelFont());
jLabel2.setHorizontalAlignment(SwingConstants.TRAILING);
- jLabel2.setText(MessageManager.getString("label.url"));
+ jLabel2.setText(MessageManager.getString("label.url:"));
jLabel2.setBounds(new Rectangle(17, 37, 54, 27));
jLabel3.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
jLabel3.setText(MessageManager.getString("label.use_sequence_id_1"));
- jLabel3.setBounds(new Rectangle(21, 72, 351, 15));
+ jLabel3.setBounds(new Rectangle(21, 102, 351, 15));
jLabel4.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
jLabel4.setText(MessageManager.getString("label.use_sequence_id_2"));
- jLabel4.setBounds(new Rectangle(21, 88, 351, 15));
+ jLabel4.setBounds(new Rectangle(21, 118, 351, 15));
jLabel5.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
jLabel5.setText(MessageManager.getString("label.use_sequence_id_3"));
- jLabel5.setBounds(new Rectangle(21, 106, 351, 15));
+ jLabel5.setBounds(new Rectangle(21, 136, 351, 15));
String lastLabel = MessageManager.getString("label.use_sequence_id_4");
if (lastLabel.length() > 0)
// e.g. Spanish version has longer text
jLabel6.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
jLabel6.setText(lastLabel);
- jLabel6.setBounds(new Rectangle(21, 122, 351, 15));
+ jLabel6.setBounds(new Rectangle(21, 152, 351, 15));
}
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.add(jLabel1);
jPanel1.add(nameTB);
jPanel1.add(urlTB);
+ jPanel1.add(insertSeq);
+ jPanel1.add(insertDBAcc);
+ jPanel1.add(insert);
jPanel1.add(jLabel2);
jPanel1.add(jLabel3);
jPanel1.add(jLabel4);
jPanel1.add(jLabel5);
- int height = 130;
+ int height = 160;
if (lastLabel.length() > 0)
{
jPanel1.add(jLabel6);
- height = 146;
+ height = 176;
}
this.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
return false;
}
- JTextField nameTB = new JTextField();
-
- JTextField urlTB = new JTextField();
-
- JLabel jLabel1 = new JLabel();
-
- JLabel jLabel2 = new JLabel();
-
- JLabel jLabel3 = new JLabel();
-
- JLabel jLabel4 = new JLabel();
-
- JLabel jLabel5 = new JLabel();
-
- JLabel jLabel6 = new JLabel();
-
- JPanel jPanel1 = new JPanel();
-
- GridBagLayout gridBagLayout1 = new GridBagLayout();
+ public void notifyDuplicate()
+ {
+ JvOptionPane.showInternalMessageDialog(jalview.gui.Desktop.desktop,
+ MessageManager.getString("warn.name_cannot_be_duplicate"),
+ MessageManager.getString("label.invalid_name"),
+ JvOptionPane.WARNING_MESSAGE);
+ }
public void nameTB_keyTyped(KeyEvent e)
{
// }
}
+
+ public void insertSeq_action(ActionEvent e)
+ {
+ insertIntoUrl(insertSeq.getText());
+ }
+
+ public void insertDBAcc_action(ActionEvent e)
+ {
+ insertIntoUrl(insertDBAcc.getText());
+ }
+
+ private void insertIntoUrl(String insertion)
+ {
+ int pos = urlTB.getCaretPosition();
+ String text = urlTB.getText();
+ String newText = text.substring(0, pos) + insertion
+ + text.substring(pos);
+ urlTB.setText(newText);
+ }
}
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
slider.setDoubleBuffered(true);
slider.addMouseListener(new MouseAdapter()
{
+ @Override
public void mouseReleased(MouseEvent e)
{
slider_mouseReleased(e);
valueField.setPreferredSize(new Dimension(50, 12));
valueField.setText("");
valueField.setHorizontalAlignment(SwingConstants.CENTER);
- valueField.addActionListener(new java.awt.event.ActionListener()
+ valueField.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
- valueField_actionPerformed(e);
+ valueField_actionPerformed();
+ }
+ });
+ valueField.addFocusListener(new FocusAdapter()
+ {
+ @Override
+ public void focusLost(FocusEvent e)
+ {
+ valueField_actionPerformed();
}
});
label.setFont(new java.awt.Font("Verdana", 0, 11));
applyButton.setText(MessageManager.getString("action.apply"));
applyButton.addActionListener(new java.awt.event.ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
applyButton_actionPerformed(e);
undoButton.setText(MessageManager.getString("action.undo"));
undoButton.addActionListener(new java.awt.event.ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
undoButton_actionPerformed(e);
.getString("action.apply_all_groups"));
allGroupsCheck.addActionListener(new java.awt.event.ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
allGroupsCheck_actionPerformed(e);
}
/**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
+ * Action on changing the slider text field value
*/
- protected void valueField_actionPerformed(ActionEvent e)
+ protected void valueField_actionPerformed()
{
+ try
+ {
+ int i = Integer.valueOf(valueField.getText());
+ slider.setValue(i);
+ } catch (NumberFormatException ex)
+ {
+ valueField.setText(String.valueOf(slider.getValue()));
+ }
}
/**
package jalview.jbgui;
import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.gui.ColourMenuHelper.ColourChangeListener;
import jalview.util.MessageManager;
+import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import javax.swing.ButtonGroup;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JRadioButtonMenuItem;
public abstract class GStructureViewer extends JInternalFrame implements
- JalviewStructureDisplayI
+ JalviewStructureDisplayI, ColourChangeListener
{
// private AAStructureBindingModel bindingModel;
- protected JMenu savemenu = new JMenu();
+ protected JMenu savemenu;
- protected JMenu viewMenu = new JMenu();
+ protected JMenu viewMenu;
- protected JMenu chainMenu = new JMenu();
+ protected JMenu colourMenu;
- protected JMenu viewerActionMenu = new JMenu();
+ protected JMenu chainMenu;
- protected JMenuItem alignStructs = new JMenuItem();
+ protected JMenu viewerActionMenu;
- protected JMenuItem fitToWindow = new JMenuItem();
+ protected JMenuItem alignStructs;
- protected JRadioButtonMenuItem seqColour = new JRadioButtonMenuItem();
+ protected JMenuItem fitToWindow;
- protected JRadioButtonMenuItem chainColour = new JRadioButtonMenuItem();
+ protected JRadioButtonMenuItem seqColour;
- protected JRadioButtonMenuItem chargeColour = new JRadioButtonMenuItem();
+ protected JRadioButtonMenuItem chainColour;
- protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
+ protected JRadioButtonMenuItem chargeColour;
- protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
+ protected JRadioButtonMenuItem viewerColour;
- protected JRadioButtonMenuItem hydroColour = new JRadioButtonMenuItem();
+ protected JMenuItem helpItem;
- protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
+ protected JLabel statusBar;
- protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem userColour = new JRadioButtonMenuItem();
-
- protected JRadioButtonMenuItem viewerColour = new JRadioButtonMenuItem();
-
- protected JMenuItem helpItem = new JMenuItem();
-
- protected JLabel statusBar = new JLabel();
-
- protected JPanel statusPanel = new JPanel();
+ protected JPanel statusPanel;
/**
* Constructor
JMenu fileMenu = new JMenu();
fileMenu.setText(MessageManager.getString("action.file"));
+ savemenu = new JMenu();
savemenu.setActionCommand(MessageManager.getString("action.save_image"));
savemenu.setText(MessageManager.getString("action.save_as"));
viewMapping_actionPerformed(actionEvent);
}
});
+
+ viewMenu = new JMenu();
viewMenu.setText(MessageManager.getString("action.view"));
+ chainMenu = new JMenu();
chainMenu.setText(MessageManager.getString("action.show_chain"));
+ fitToWindow = new JMenuItem();
fitToWindow.setText(MessageManager.getString("label.fit_to_window"));
fitToWindow.addActionListener(new ActionListener()
{
}
});
- JMenu colourMenu = new JMenu();
- colourMenu.setText(MessageManager.getString("label.colours"));
-
- JMenuItem backGround = new JMenuItem();
- backGround
- .setText(MessageManager.getString("action.background_colour"));
- backGround.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- backGround_actionPerformed(actionEvent);
- }
- });
- seqColour.setSelected(false);
- seqColour.setText(MessageManager.getString("action.by_sequence"));
- seqColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- seqColour_actionPerformed(actionEvent);
- }
- });
- chainColour.setText(MessageManager.getString("action.by_chain"));
- chainColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- chainColour_actionPerformed(actionEvent);
- }
- });
- chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
- chargeColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- chargeColour_actionPerformed(actionEvent);
- }
- });
- zappoColour.setText(MessageManager.getString("label.zappo"));
- zappoColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- zappoColour_actionPerformed(actionEvent);
- }
- });
- taylorColour.setText(MessageManager.getString("label.taylor"));
- taylorColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- taylorColour_actionPerformed(actionEvent);
- }
- });
- hydroColour.setText(MessageManager.getString("label.hydrophobicity"));
- hydroColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- hydroColour_actionPerformed(actionEvent);
- }
- });
- strandColour.setText(MessageManager
- .getString("label.strand_propensity"));
- strandColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- strandColour_actionPerformed(actionEvent);
- }
- });
- helixColour.setText(MessageManager.getString("label.helix_propensity"));
- helixColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- helixColour_actionPerformed(actionEvent);
- }
- });
- turnColour.setText(MessageManager.getString("label.turn_propensity"));
- turnColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- turnColour_actionPerformed(actionEvent);
- }
- });
- buriedColour.setText(MessageManager.getString("label.buried_index"));
- buriedColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- buriedColour_actionPerformed(actionEvent);
- }
- });
- purinePyrimidineColour.setText(MessageManager
- .getString("label.purine_pyrimidine"));
- purinePyrimidineColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- purinePyrimidineColour_actionPerformed(actionEvent);
- }
- });
-
- userColour.setText(MessageManager.getString("action.user_defined"));
- userColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- userColour_actionPerformed(actionEvent);
- }
- });
- viewerColour.setSelected(false);
- viewerColour
- .setText(MessageManager.getString("label.colour_with_jmol"));
- viewerColour.setToolTipText(MessageManager
- .getString("label.let_jmol_manage_structure_colours"));
- viewerColour.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent actionEvent)
- {
- viewerColour_actionPerformed(actionEvent);
- }
- });
-
JMenu helpMenu = new JMenu();
helpMenu.setText(MessageManager.getString("action.help"));
+ helpItem = new JMenuItem();
helpItem.setText(MessageManager.getString("label.jmol_help"));
helpItem.addActionListener(new ActionListener()
{
showHelp_actionPerformed(actionEvent);
}
});
+ alignStructs = new JMenuItem();
alignStructs
.setText(MessageManager.getString("label.align_structures"));
alignStructs.addActionListener(new ActionListener()
alignStructs_actionPerformed(actionEvent);
}
});
- viewerActionMenu.setText(MessageManager.getString("label.jmol"));
- menuBar.add(fileMenu);
- menuBar.add(viewMenu);
- menuBar.add(colourMenu);
- menuBar.add(viewerActionMenu);
+
+ viewerActionMenu = new JMenu();
viewerActionMenu.setVisible(false);
- menuBar.add(helpMenu);
+ viewerActionMenu.add(alignStructs);
+ colourMenu = new JMenu();
+ colourMenu.setText(MessageManager.getString("label.colours"));
fileMenu.add(savemenu);
fileMenu.add(viewMapping);
savemenu.add(pdbFile);
savemenu.add(png);
savemenu.add(eps);
viewMenu.add(chainMenu);
-
- colourMenu.add(seqColour);
- colourMenu.add(chainColour);
- colourMenu.add(chargeColour);
- colourMenu.add(zappoColour);
- colourMenu.add(taylorColour);
- colourMenu.add(hydroColour);
- colourMenu.add(helixColour);
- colourMenu.add(strandColour);
- colourMenu.add(turnColour);
- colourMenu.add(buriedColour);
- colourMenu.add(purinePyrimidineColour);
- colourMenu.add(userColour);
- colourMenu.add(viewerColour);
- colourMenu.add(backGround);
-
- ButtonGroup colourButtons = new ButtonGroup();
-
- colourButtons.add(seqColour);
- colourButtons.add(chainColour);
- colourButtons.add(chargeColour);
- colourButtons.add(zappoColour);
- colourButtons.add(taylorColour);
- colourButtons.add(hydroColour);
- colourButtons.add(helixColour);
- colourButtons.add(strandColour);
- colourButtons.add(turnColour);
- colourButtons.add(buriedColour);
- colourButtons.add(purinePyrimidineColour);
- colourButtons.add(userColour);
- colourButtons.add(viewerColour);
-
helpMenu.add(helpItem);
- viewerActionMenu.add(alignStructs);
+ menuBar.add(fileMenu);
+ menuBar.add(viewMenu);
+ menuBar.add(colourMenu);
+ menuBar.add(viewerActionMenu);
+ menuBar.add(helpMenu);
+
+ statusPanel = new JPanel();
statusPanel.setLayout(new GridLayout());
- this.getContentPane().add(statusPanel, java.awt.BorderLayout.SOUTH);
+ this.getContentPane().add(statusPanel, BorderLayout.SOUTH);
+ statusBar = new JLabel();
statusPanel.add(statusBar, null);
}
}
- public void zappoColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void taylorColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void hydroColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void helixColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void strandColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void turnColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void buriedColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void userColour_actionPerformed(ActionEvent actionEvent)
- {
-
- }
-
- public void backGround_actionPerformed(ActionEvent actionEvent)
+ public void background_actionPerformed(ActionEvent actionEvent)
{
}
{
}
-
- // {
- // return bindingModel;
- // }
-
- // public void setBindingModel(AAStructureBindingModel bindingModel)
- // {
- // this.bindingModel = bindingModel;
- // }
-
}
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
protected JCheckBox caseSensitive = new JCheckBox();
- protected JButton lcaseColour = new JButton();
+ protected JCheckBox lcaseColour = new JCheckBox();
+
+ protected List<JButton> selectedButtons;
/**
* Creates a new GUserDefinedColours object.
okButton.setText(MessageManager.getString("action.ok"));
okButton.addActionListener(new java.awt.event.ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
- okButton_actionPerformed(e);
+ okButton_actionPerformed();
}
});
applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
applyButton.setText(MessageManager.getString("action.apply"));
- applyButton.addActionListener(new java.awt.event.ActionListener()
+ applyButton.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
- applyButton_actionPerformed(e);
+ applyButton_actionPerformed();
}
});
loadbutton.setFont(new java.awt.Font("Verdana", 0, 11));
loadbutton.setText(MessageManager.getString("action.load_scheme"));
loadbutton.addActionListener(new java.awt.event.ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
loadbutton_actionPerformed(e);
savebutton.setText(MessageManager.getString("action.save_scheme"));
savebutton.addActionListener(new java.awt.event.ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
savebutton_actionPerformed(e);
cancelButton.setText(MessageManager.getString("action.cancel"));
cancelButton.addActionListener(new java.awt.event.ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
cancelButton_actionPerformed(e);
caseSensitive.setText(MessageManager.getString("label.case_sensitive"));
caseSensitive.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
caseSensitive_actionPerformed(e);
});
lcaseColour
.setText(MessageManager.getString("label.lower_case_colour"));
- lcaseColour.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- lcaseColour_actionPerformed(e);
- }
- });
+ lcaseColour.setToolTipText(MessageManager
+ .getString("label.lower_case_tip"));
saveLoadPanel.add(savebutton);
saveLoadPanel.add(loadbutton);
colorChooser
.setChooserPanels(new AbstractColorChooserPanel[] { choosers[0] });
}
+
+ selectedButtons = new ArrayList<JButton>();
}
/**
* DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
*/
- protected void okButton_actionPerformed(ActionEvent e)
+ protected void okButton_actionPerformed()
{
}
/**
* DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
*/
- protected void applyButton_actionPerformed(ActionEvent e)
+ protected void applyButton_actionPerformed()
{
}
import java.io.PrintStream;
/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
+ * A class to model rectangular matrices of double values and operations on them
*/
-public class Matrix
+public class Matrix implements MatrixI
{
- /**
- * SMJSPUBLIC
+ /*
+ * the cell values in row-major order
*/
- public double[][] value;
+ private double[][] value;
- /** DOCUMENT ME!! */
- public int rows;
+ /*
+ * the number of rows
+ */
+ protected int rows;
- /** DOCUMENT ME!! */
- public int cols;
+ /*
+ * the number of columns
+ */
+ protected int cols;
- /** DOCUMENT ME!! */
- public double[] d; // Diagonal
+ protected double[] d; // Diagonal
- /** DOCUMENT ME!! */
- public double[] e; // off diagonal
+ protected double[] e; // off diagonal
/**
* maximum number of iterations for tqli
*
*/
- int maxIter = 45; // fudge - add 15 iterations, just in case
+ private static final int maxIter = 45; // fudge - add 15 iterations, just in
+ // case
+
+ /**
+ * Default constructor
+ */
+ public Matrix()
+ {
+ }
+
/**
* Creates a new Matrix object. For example
*
* <pre>
- * new Matrix(new double[][] {{2, 3}, {4, 5}, 2, 2)
+ * new Matrix(new double[][] {{2, 3, 4}, {5, 6, 7})
* constructs
- * (2 3)
- * (4 5)
+ * (2 3 4)
+ * (5 6 7)
* </pre>
*
* Note that ragged arrays (with not all rows, or columns, of the same
*
* @param values
* the matrix values in row-major order
- * @param rows
- * @param cols
*/
- public Matrix(double[][] values, int rows, int cols)
+ public Matrix(double[][] values)
{
- this.rows = rows;
- this.cols = cols;
+ this.rows = values.length;
+ this.cols = this.rows == 0 ? 0 : values[0].length;
this.value = values;
}
/**
- * Returns a new matrix which is the transposes of this one
+ * Returns a new matrix which is the transpose of this one
*
* @return DOCUMENT ME!
*/
- public Matrix transpose()
+ @Override
+ public MatrixI transpose()
{
double[][] out = new double[cols][rows];
}
}
- return new Matrix(out, cols, rows);
+ return new Matrix(out);
}
/**
*
* @param ps
* DOCUMENT ME!
+ * @param format
*/
- public void print(PrintStream ps)
+ @Override
+ public void print(PrintStream ps, String format)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
- Format.print(ps, "%8.2f", value[i][j]);
+ Format.print(ps, format, getValue(i, j));
}
ps.println();
* if the number of columns in the pre-multiplier is not equal to
* the number of rows in the multiplicand (this)
*/
- public Matrix preMultiply(Matrix in)
+ @Override
+ public MatrixI preMultiply(MatrixI in)
{
- if (in.cols != this.rows)
+ if (in.width() != rows)
{
throw new IllegalArgumentException("Can't pre-multiply " + this.rows
- + " rows by " + in.cols + " columns");
+ + " rows by " + in.width() + " columns");
}
- double[][] tmp = new double[in.rows][this.cols];
+ double[][] tmp = new double[in.height()][this.cols];
- for (int i = 0; i < in.rows; i++)
+ for (int i = 0; i < in.height(); i++)
{
for (int j = 0; j < this.cols; j++)
{
- tmp[i][j] = 0.0;
-
- for (int k = 0; k < in.cols; k++)
+ /*
+ * result[i][j] is the vector product of
+ * in.row[i] and this.column[j]
+ */
+ for (int k = 0; k < in.width(); k++)
{
- tmp[i][j] += (in.value[i][k] * this.value[k][j]);
+ tmp[i][j] += (in.getValue(i, k) * this.value[k][j]);
}
}
}
- return new Matrix(tmp, in.rows, this.cols);
+ return new Matrix(tmp);
}
/**
* number of columns in the multiplicand (this)
* @see #preMultiply(Matrix)
*/
- public Matrix postMultiply(Matrix in)
+ @Override
+ public MatrixI postMultiply(MatrixI in)
{
- if (in.rows != this.cols)
+ if (in.height() != this.cols)
{
throw new IllegalArgumentException("Can't post-multiply " + this.cols
- + " columns by " + in.rows + " rows");
+ + " columns by " + in.height() + " rows");
}
return in.preMultiply(this);
}
*
* @return
*/
- public Matrix copy()
+ @Override
+ public MatrixI copy()
{
double[][] newmat = new double[rows][cols];
for (int i = 0; i < rows; i++)
{
System.arraycopy(value[i], 0, newmat[i], 0, value[i].length);
- // for (int j = 0; j < cols; j++)
- // {
- // newmat[i][j] = value[i][j];
- // }
}
- return new Matrix(newmat, rows, cols);
+ return new Matrix(newmat);
}
/**
* DOCUMENT ME!
*/
+ @Override
public void tred()
{
int n = rows;
- int l;
int k;
int j;
int i;
for (i = n; i >= 2; i--)
{
- l = i - 1;
+ final int l = i - 1;
h = 0.0;
scale = 0.0;
{
for (k = 1; k <= l; k++)
{
- scale += Math.abs(value[i - 1][k - 1]);
+ double v = Math.abs(getValue(i - 1, k - 1));
+ scale += v;
}
if (scale == 0.0)
{
- e[i - 1] = value[i - 1][l - 1];
+ e[i - 1] = getValue(i - 1, l - 1);
}
else
{
for (k = 1; k <= l; k++)
{
- value[i - 1][k - 1] /= scale;
- h += (value[i - 1][k - 1] * value[i - 1][k - 1]);
+ double v = divideValue(i - 1, k - 1, scale);
+ h += v * v;
}
- f = value[i - 1][l - 1];
+ f = getValue(i - 1, l - 1);
if (f > 0)
{
e[i - 1] = scale * g;
h -= (f * g);
- value[i - 1][l - 1] = f - g;
+ setValue(i - 1, l - 1, f - g);
f = 0.0;
for (j = 1; j <= l; j++)
{
- value[j - 1][i - 1] = value[i - 1][j - 1] / h;
+ double val = getValue(i - 1, j - 1) / h;
+ setValue(j - 1, i - 1, val);
g = 0.0;
for (k = 1; k <= j; k++)
{
- g += (value[j - 1][k - 1] * value[i - 1][k - 1]);
+ g += (getValue(j - 1, k - 1) * getValue(i - 1, k - 1));
}
for (k = j + 1; k <= l; k++)
{
- g += (value[k - 1][j - 1] * value[i - 1][k - 1]);
+ g += (getValue(k - 1, j - 1) * getValue(i - 1, k - 1));
}
e[j - 1] = g / h;
- f += (e[j - 1] * value[i - 1][j - 1]);
+ f += (e[j - 1] * getValue(i - 1, j - 1));
}
hh = f / (h + h);
for (j = 1; j <= l; j++)
{
- f = value[i - 1][j - 1];
+ f = getValue(i - 1, j - 1);
g = e[j - 1] - (hh * f);
e[j - 1] = g;
for (k = 1; k <= j; k++)
{
- value[j - 1][k - 1] -= ((f * e[k - 1]) + (g * value[i - 1][k - 1]));
+ double val = (f * e[k - 1]) + (g * getValue(i - 1, k - 1));
+ addValue(j - 1, k - 1, -val);
}
}
}
}
else
{
- e[i - 1] = value[i - 1][l - 1];
+ e[i - 1] = getValue(i - 1, l - 1);
}
d[i - 1] = h;
for (i = 1; i <= n; i++)
{
- l = i - 1;
+ final int l = i - 1;
if (d[i - 1] != 0.0)
{
for (k = 1; k <= l; k++)
{
- g += (value[i - 1][k - 1] * value[k - 1][j - 1]);
+ g += (getValue(i - 1, k - 1) * getValue(k - 1, j - 1));
}
for (k = 1; k <= l; k++)
{
- value[k - 1][j - 1] -= (g * value[k - 1][i - 1]);
+ addValue(k - 1, j - 1, -(g * getValue(k - 1, i - 1)));
}
}
}
- d[i - 1] = value[i - 1][i - 1];
- value[i - 1][i - 1] = 1.0;
+ d[i - 1] = getValue(i - 1, i - 1);
+ setValue(i - 1, i - 1, 1.0);
for (j = 1; j <= l; j++)
{
- value[j - 1][i - 1] = 0.0;
- value[i - 1][j - 1] = 0.0;
+ setValue(j - 1, i - 1, 0.0);
+ setValue(i - 1, j - 1, 0.0);
}
}
}
/**
+ * Adds f to the value at [i, j] and returns the new value
+ *
+ * @param i
+ * @param j
+ * @param f
+ */
+ protected double addValue(int i, int j, double f)
+ {
+ double v = value[i][j] + f;
+ value[i][j] = v;
+ return v;
+ }
+
+ /**
+ * Divides the value at [i, j] by divisor and returns the new value. If d is
+ * zero, returns the unchanged value.
+ *
+ * @param i
+ * @param j
+ * @param divisor
+ * @return
+ */
+ protected double divideValue(int i, int j, double divisor)
+ {
+ if (divisor == 0d)
+ {
+ return getValue(i, j);
+ }
+ double v = value[i][j];
+ v = v / divisor;
+ value[i][j] = v;
+ return v;
+ }
+
+ /**
* DOCUMENT ME!
*/
+ @Override
public void tqli() throws Exception
{
int n = rows;
double s;
double r;
double p;
- ;
double g;
double f;
for (k = 1; k <= n; k++)
{
- f = value[k - 1][i];
- value[k - 1][i] = (s * value[k - 1][i - 1]) + (c * f);
- value[k - 1][i - 1] = (c * value[k - 1][i - 1]) - (s * f);
+ f = getValue(k - 1, i);
+ setValue(k - 1, i, (s * getValue(k - 1, i - 1)) + (c * f));
+ setValue(k - 1, i - 1, (c * getValue(k - 1, i - 1)) - (s * f));
}
}
}
}
+ @Override
+ public double getValue(int i, int j)
+ {
+ return value[i][j];
+ }
+
+ public void setValue(int i, int j, double val)
+ {
+ value[i][j] = val;
+ }
+
/**
* DOCUMENT ME!
*/
}
/**
- * DOCUMENT ME!
+ * Answers the first argument with the sign of the second argument
*
* @param a
- * DOCUMENT ME!
* @param b
- * DOCUMENT ME!
*
- * @return DOCUMENT ME!
+ * @return
*/
- public double sign(double a, double b)
+ static double sign(double a, double b)
{
if (b < 0)
{
*
* @param ps
* DOCUMENT ME!
+ * @param format
*/
- public void printD(PrintStream ps)
+ @Override
+ public void printD(PrintStream ps, String format)
{
for (int j = 0; j < rows; j++)
{
- Format.print(ps, "%15.4e", d[j]);
+ Format.print(ps, format, d[j]);
}
}
*
* @param ps
* DOCUMENT ME!
+ * @param format TODO
*/
- public void printE(PrintStream ps)
+ @Override
+ public void printE(PrintStream ps, String format)
{
for (int j = 0; j < rows; j++)
{
- Format.print(ps, "%15.4e", e[j]);
+ Format.print(ps, format, e[j]);
}
}
+
+ @Override
+ public double[] getD()
+ {
+ return d;
+ }
+
+ @Override
+ public double[] getE()
+ {
+ return e;
+ }
+
+ @Override
+ public int height() {
+ return rows;
+ }
+
+ @Override
+ public int width()
+ {
+ return cols;
+ }
+
+ @Override
+ public double[] getRow(int i)
+ {
+ double[] row = new double[cols];
+ System.arraycopy(value[i], 0, row, 0, cols);
+ return row;
+ }
}
--- /dev/null
+package jalview.math;
+
+import java.io.PrintStream;
+
+public interface MatrixI
+{
+ /**
+ * Answers the number of columns
+ *
+ * @return
+ */
+ int width();
+
+ /**
+ * Answers the number of rows
+ *
+ * @return
+ */
+ int height();
+
+ /**
+ * Answers the value at row i, column j
+ *
+ * @param i
+ * @param j
+ * @return
+ */
+ double getValue(int i, int j);
+
+ /**
+ * Answers a copy of the values in the i'th row
+ *
+ * @return
+ */
+ double[] getRow(int i);
+
+ MatrixI copy();
+
+ MatrixI transpose();
+
+ MatrixI preMultiply(MatrixI m);
+
+ MatrixI postMultiply(MatrixI m);
+
+ double[] getD();
+
+ double[] getE();
+
+ void print(PrintStream ps, String format);
+
+ void printD(PrintStream ps, String format);
+
+ void printE(PrintStream ps, String format);
+
+ void tqli() throws Exception;
+
+ void tred();
+
+}
--- /dev/null
+package jalview.math;
+
+import jalview.ext.android.SparseDoubleArray;
+
+/**
+ * A variant of Matrix intended for use for sparse (mostly zero) matrices. This
+ * class uses a SparseDoubleArray to hold each row of the matrix. The sparse
+ * array only stores non-zero values. This gives a smaller memory footprint, and
+ * fewer matrix calculation operations, for mostly zero matrices.
+ *
+ * @author gmcarstairs
+ */
+public class SparseMatrix extends Matrix
+{
+ /*
+ * we choose columns for the sparse arrays as this allows
+ * optimisation of the preMultiply() method used in PCA.run()
+ */
+ SparseDoubleArray[] sparseColumns;
+
+ /**
+ * Constructor given data in [row][column] order
+ *
+ * @param v
+ */
+ public SparseMatrix(double[][] v)
+ {
+ rows = v.length;
+ if (rows > 0) {
+ cols = v[0].length;
+ }
+ sparseColumns = new SparseDoubleArray[cols];
+
+ /*
+ * transpose v[row][col] into [col][row] order
+ */
+ for (int col = 0; col < cols; col++)
+ {
+ SparseDoubleArray sparseColumn = new SparseDoubleArray();
+ sparseColumns[col] = sparseColumn;
+ for (int row = 0; row < rows; row++)
+ {
+ double value = v[row][col];
+ if (value != 0d)
+ {
+ sparseColumn.put(row, value);
+ }
+ }
+ }
+ }
+
+ /**
+ * Answers the value at row i, column j
+ */
+ @Override
+ public double getValue(int i, int j)
+ {
+ return sparseColumns[j].get(i);
+ }
+
+ /**
+ * Sets the value at row i, column j to val
+ */
+ @Override
+ public void setValue(int i, int j, double val)
+ {
+ if (val == 0d)
+ {
+ sparseColumns[j].delete(i);
+ }
+ else
+ {
+ sparseColumns[j].put(i, val);
+ }
+ }
+
+ @Override
+ public double[] getColumn(int i)
+ {
+ double[] col = new double[height()];
+
+ SparseDoubleArray vals = sparseColumns[i];
+ for (int nonZero = 0; nonZero < vals.size(); nonZero++)
+ {
+ col[vals.keyAt(nonZero)] = vals.valueAt(nonZero);
+ }
+ return col;
+ }
+
+ @Override
+ public MatrixI copy()
+ {
+ double[][] vals = new double[height()][width()];
+ for (int i = 0; i < height(); i++)
+ {
+ vals[i] = getRow(i);
+ }
+ return new SparseMatrix(vals);
+ }
+
+ @Override
+ public MatrixI transpose()
+ {
+ double[][] out = new double[cols][rows];
+
+ /*
+ * for each column...
+ */
+ for (int i = 0; i < cols; i++)
+ {
+ /*
+ * put non-zero values into the corresponding row
+ * of the transposed matrix
+ */
+ SparseDoubleArray vals = sparseColumns[i];
+ for (int nonZero = 0; nonZero < vals.size(); nonZero++)
+ {
+ out[i][vals.keyAt(nonZero)] = vals.valueAt(nonZero);
+ }
+ }
+
+ return new SparseMatrix(out);
+ }
+
+ /**
+ * Answers a new matrix which is the product in.this. If the product contains
+ * less than 20% non-zero values, it is returned as a SparseMatrix, else as a
+ * Matrix.
+ * <p>
+ * This method is optimised for the sparse arrays which store column values
+ * for a SparseMatrix. Note that postMultiply is not so optimised. That would
+ * require redundantly also storing sparse arrays for the rows, which has not
+ * been done. Currently only preMultiply is used in Jalview.
+ */
+ @Override
+ public MatrixI preMultiply(MatrixI in)
+ {
+ if (in.width() != rows)
+ {
+ throw new IllegalArgumentException("Can't pre-multiply " + this.rows
+ + " rows by " + in.width() + " columns");
+ }
+ double[][] tmp = new double[in.height()][this.cols];
+
+ long count = 0L;
+ for (int i = 0; i < in.height(); i++)
+ {
+ for (int j = 0; j < this.cols; j++)
+ {
+ /*
+ * result[i][j] is the vector product of
+ * in.row[i] and this.column[j]
+ * we only need to use non-zero values from the column
+ */
+ SparseDoubleArray vals = sparseColumns[j];
+ boolean added = false;
+ for (int nonZero = 0; nonZero < vals.size(); nonZero++)
+ {
+ int myRow = vals.keyAt(nonZero);
+ double myValue = vals.valueAt(nonZero);
+ tmp[i][j] += (in.getValue(i, myRow) * myValue);
+ added = true;
+ }
+ if (added && tmp[i][j] != 0d)
+ {
+ count++; // non-zero entry in product
+ }
+ }
+ }
+
+ /*
+ * heuristic rule - if product is more than 80% zero
+ * then construct a SparseMatrix, else a Matrix
+ */
+ if (count * 5 < in.height() * cols)
+ {
+ return new SparseMatrix(tmp);
+ }
+ else
+ {
+ return new Matrix(tmp);
+ }
+ }
+
+ @Override
+ protected double divideValue(int i, int j, double divisor)
+ {
+ if (divisor == 0d)
+ {
+ return getValue(i, j);
+ }
+ double v = sparseColumns[j].divide(i, divisor);
+ return v;
+ }
+
+ @Override
+ protected double addValue(int i, int j, double addend)
+ {
+ double v = sparseColumns[j].add(i, addend);
+ return v;
+ }
+
+ /**
+ * Returns the fraction of the whole matrix size that is actually modelled in
+ * sparse arrays (normally, the non-zero values)
+ *
+ * @return
+ */
+ public float getFillRatio()
+ {
+ long count = 0L;
+ for (SparseDoubleArray col : sparseColumns)
+ {
+ count += col.size();
+ }
+ return count / (float) (height() * width());
+ }
+}
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.ProfilesI;
import jalview.schemes.ColourSchemeI;
+import jalview.schemes.NucleotideColourScheme;
import jalview.schemes.ResidueProperties;
+import jalview.schemes.ZappoColourScheme;
import jalview.util.Platform;
import java.awt.BasicStroke;
boolean av_renderHistogram = true, av_renderProfile = true,
av_normaliseProfile = false;
- ColourSchemeI profcolour = null;
+ ResidueShaderI profcolour = null;
private ColumnSelection columnSelection;
av_renderHistogram = av.isShowConsensusHistogram();
av_renderProfile = av.isShowSequenceLogo();
av_normaliseProfile = av.isNormaliseSequenceLogo();
- profcolour = av.getGlobalColourScheme();
- if (profcolour == null)
+ profcolour = av.getResidueShading();
+ if (profcolour == null || profcolour.getColourScheme() == null)
{
- // Set the default colour for sequence logo if the alignnent has no
- // colourscheme set
- profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
- : new jalview.schemes.ZappoColourScheme();
+ /*
+ * Use default colour for sequence logo if
+ * the alignment has no colourscheme set
+ * (would like to use user preference but n/a for applet)
+ */
+ ColourSchemeI col = av.getAlignment().isNucleotide() ? new NucleotideColourScheme()
+ : new ZappoColourScheme();
+ profcolour = new ResidueShader(col);
}
columnSelection = av.getColumnSelection();
hconsensus = av.getSequenceConsensusHash();
--- /dev/null
+package jalview.renderer;
+
+import jalview.analysis.Conservation;
+import jalview.api.ViewStyleI;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.schemes.ColourSchemeI;
+import jalview.util.ColorUtils;
+import jalview.util.Comparison;
+
+import java.awt.Color;
+import java.util.Map;
+
+/**
+ * A class that computes the colouring of an alignment (or subgroup). Currently
+ * the factors that may influence residue colouring are
+ * <ul>
+ * <li>the colour scheme that provides a colour for each aligned residue</li>
+ * <li>any threshold for colour, based on percentage identity with consensus</li>
+ * <li>any graduation based on conservation of physico-chemical properties</li>
+ * </ul>
+ *
+ * @author gmcarstairs
+ *
+ */
+public class ResidueShader implements ResidueShaderI
+{
+ private static final int INITIAL_CONSERVATION = 30;
+
+ /*
+ * the colour scheme that gives the colour of each residue
+ * before applying any conservation or PID shading
+ */
+ private ColourSchemeI colourScheme;
+
+ /*
+ * the consensus data for each column
+ */
+ private ProfilesI consensus;
+
+ /*
+ * if true, apply shading of colour by conservation
+ */
+ private boolean conservationColouring;
+
+ /*
+ * the physico-chemical property conservation scores for columns, with values
+ * 0-9, '+' (all properties conserved), '*' (residue fully conserved) or '-' (gap)
+ * (may be null if colour by conservation is not selected)
+ */
+ private char[] conservation;
+
+ /*
+ * minimum percentage identity for colour to be applied;
+ * if above zero, residue must match consensus (or joint consensus)
+ * and column have >= pidThreshold identity with the residue
+ */
+ private int pidThreshold;
+
+ /*
+ * if true, ignore gaps in percentage identity calculation
+ */
+ private boolean ignoreGaps;
+
+ /*
+ * setting of the By Conservation slider
+ */
+ private int conservationIncrement = INITIAL_CONSERVATION;
+
+ public ResidueShader(ColourSchemeI cs)
+ {
+ colourScheme = cs;
+ }
+
+ /**
+ * Default constructor
+ */
+ public ResidueShader()
+ {
+ }
+
+ /**
+ * Constructor given view style settings
+ *
+ * @param viewStyle
+ */
+ public ResidueShader(ViewStyleI viewStyle)
+ {
+ // TODO remove duplicated storing of conservation / pid thresholds?
+ this();
+ setConservationApplied(viewStyle.isConservationColourSelected());
+ // setThreshold(viewStyle.getThreshold());
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#setConsensus(jalview.datamodel.ProfilesI)
+ */
+ @Override
+ public void setConsensus(ProfilesI cons)
+ {
+ consensus = cons;
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#conservationApplied()
+ */
+ @Override
+ public boolean conservationApplied()
+ {
+ return conservationColouring;
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#setConservationApplied(boolean)
+ */
+ @Override
+ public void setConservationApplied(boolean conservationApplied)
+ {
+ conservationColouring = conservationApplied;
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#setConservation(jalview.analysis.Conservation)
+ */
+ @Override
+ public void setConservation(Conservation cons)
+ {
+ if (cons == null)
+ {
+ conservationColouring = false;
+ conservation = null;
+ }
+ else
+ {
+ conservationColouring = true;
+ conservation = cons.getConsSequence().getSequenceAsString()
+ .toCharArray();
+ }
+
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#alignmentChanged(jalview.datamodel.AnnotatedCollectionI,
+ * java.util.Map)
+ */
+ @Override
+ public void alignmentChanged(AnnotatedCollectionI alignment,
+ Map<SequenceI, SequenceCollectionI> hiddenReps)
+ {
+ if (colourScheme != null)
+ {
+ colourScheme.alignmentChanged(alignment, hiddenReps);
+ }
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#setThreshold(int, boolean)
+ */
+ @Override
+ public void setThreshold(int consensusThreshold, boolean ignoreGaps)
+ {
+ pidThreshold = consensusThreshold;
+ this.ignoreGaps = ignoreGaps;
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#setConservationInc(int)
+ */
+ @Override
+ public void setConservationInc(int i)
+ {
+ conservationIncrement = i;
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#getConservationInc()
+ */
+ @Override
+ public int getConservationInc()
+ {
+ return conservationIncrement;
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#getThreshold()
+ */
+ @Override
+ public int getThreshold()
+ {
+ return pidThreshold;
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#findColour(char, int,
+ * jalview.datamodel.SequenceI)
+ */
+ @Override
+ public Color findColour(char symbol, int position, SequenceI seq)
+ {
+ /*
+ * get 'base' colour
+ */
+ ProfileI profile = consensus == null ? null : consensus.get(position);
+ String modalResidue = profile == null ? null : profile
+ .getModalResidue();
+ float pid = profile == null ? 0f : profile
+ .getPercentageIdentity(ignoreGaps);
+ Color colour = colourScheme == null ? Color.white : colourScheme
+ .findColour(symbol, position, seq, modalResidue, pid);
+
+ /*
+ * apply PID threshold and consensus fading if in force
+ */
+ colour = adjustColour(symbol, position, colour);
+
+ return colour;
+ }
+
+ /**
+ * Adjusts colour by applying thresholding or conservation shading, if in
+ * force. That is
+ * <ul>
+ * <li>if there is a threshold set for colouring, and the residue doesn't
+ * match the consensus (or a joint consensus) residue, or the consensus score
+ * is not above the threshold, then the colour is set to white</li>
+ * <li>if conservation colouring is selected, the colour is faded by an amount
+ * depending on the conservation score for the column, and the conservation
+ * colour threshold</li>
+ * </ul>
+ *
+ * @param symbol
+ * @param column
+ * @param colour
+ * @return
+ */
+ protected Color adjustColour(char symbol, int column, Color colour)
+ {
+ if (!aboveThreshold(symbol, column))
+ {
+ colour = Color.white;
+ }
+
+ if (conservationColouring)
+ {
+ colour = applyConservation(colour, column);
+ }
+ return colour;
+ }
+
+ /**
+ * Answers true if there is a consensus profile for the specified column, and
+ * the given residue matches the consensus (or joint consensus) residue for
+ * the column, and the percentage identity for the profile is equal to or
+ * greater than the current threshold; else answers false. The percentage
+ * calculation depends on whether or not we are ignoring gapped sequences.
+ *
+ * @param residue
+ * @param column
+ * (index into consensus profiles)
+ *
+ * @return
+ * @see #setThreshold(int, boolean)
+ */
+ protected boolean aboveThreshold(char residue, int column)
+ {
+ if (pidThreshold == 0)
+ {
+ return true;
+ }
+ if ('a' <= residue && residue <= 'z')
+ {
+ // TO UPPERCASE !!!
+ // Faster than toUpperCase
+ residue -= ('a' - 'A');
+ }
+
+ if (consensus == null)
+ {
+ return false;
+ }
+
+ ProfileI profile = consensus.get(column);
+
+ /*
+ * test whether this is the consensus (or joint consensus) residue
+ */
+ if (profile != null
+ && profile.getModalResidue().contains(String.valueOf(residue)))
+ {
+ if (profile.getPercentageIdentity(ignoreGaps) >= pidThreshold)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Applies a combination of column conservation score, and conservation
+ * percentage slider, to 'bleach' out the residue colours towards white.
+ * <p>
+ * If a column is fully conserved (identical residues, conservation score 11,
+ * shown as *), or all 10 physico-chemical properties are conserved
+ * (conservation score 10, shown as +), then the colour is left unchanged.
+ * <p>
+ * Otherwise a 'bleaching' factor is computed and applied to the colour. This
+ * is designed to fade colours for scores of 0-9 completely to white at slider
+ * positions ranging from 18% - 100% respectively.
+ *
+ * @param currentColour
+ * @param column
+ *
+ * @return bleached (or unmodified) colour
+ */
+ protected Color applyConservation(Color currentColour, int column)
+ {
+ if (conservation == null || conservation.length <= column)
+ {
+ return currentColour;
+ }
+ char conservationScore = conservation[column];
+
+ /*
+ * if residues are fully conserved (* or 11), or all properties
+ * are conserved (+ or 10), leave colour unchanged
+ */
+ if (conservationScore == '*' || conservationScore == '+'
+ || conservationScore == (char) 10
+ || conservationScore == (char) 11)
+ {
+ return currentColour;
+ }
+
+ if (Comparison.isGap(conservationScore))
+ {
+ return Color.white;
+ }
+
+ /*
+ * convert score 0-9 to a bleaching factor 1.1 - 0.2
+ */
+ float bleachFactor = (11 - (conservationScore - '0')) / 10f;
+
+ /*
+ * scale this up by 0-5 (percentage slider / 20)
+ * as a result, scores of: 0 1 2 3 4 5 6 7 8 9
+ * fade to white at slider value: 18 20 22 25 29 33 40 50 67 100%
+ */
+ bleachFactor *= (conservationIncrement / 20f);
+
+ return ColorUtils.bleachColour(currentColour, bleachFactor);
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#getColourScheme()
+ */
+ @Override
+ public ColourSchemeI getColourScheme()
+ {
+ return this.colourScheme;
+ }
+
+ /**
+ * @see jalview.renderer.ResidueShaderI#setColourScheme(jalview.schemes.ColourSchemeI)
+ */
+ @Override
+ public void setColourScheme(ColourSchemeI cs)
+ {
+ colourScheme = cs;
+ }
+}
--- /dev/null
+package jalview.renderer;
+
+import jalview.analysis.Conservation;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.ProfilesI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.schemes.ColourSchemeI;
+
+import java.awt.Color;
+import java.util.Map;
+
+public interface ResidueShaderI
+{
+
+ public abstract void setConsensus(ProfilesI cons);
+
+ public abstract boolean conservationApplied();
+
+ public abstract void setConservationApplied(boolean conservationApplied);
+
+ public abstract void setConservation(Conservation cons);
+
+ public abstract void alignmentChanged(AnnotatedCollectionI alignment,
+ Map<SequenceI, SequenceCollectionI> hiddenReps);
+
+ /**
+ * Sets the percentage consensus threshold value, and whether gaps are ignored
+ * in percentage identity calculation
+ *
+ * @param consensusThreshold
+ * @param ignoreGaps
+ */
+ public abstract void setThreshold(int consensusThreshold,
+ boolean ignoreGaps);
+
+ public abstract void setConservationInc(int i);
+
+ public abstract int getConservationInc();
+
+ /**
+ * Get the percentage threshold for this colour scheme
+ *
+ * @return Returns the percentage threshold
+ */
+ public abstract int getThreshold();
+
+ /**
+ * Returns the possibly context dependent colour for the given symbol at the
+ * aligned position in the given sequence. For example, the colour may depend
+ * on the symbol's relationship to the consensus residue for the column.
+ *
+ * @param symbol
+ * @param position
+ * @param seq
+ * @return
+ */
+ public abstract Color findColour(char symbol, int position, SequenceI seq);
+
+ public abstract ColourSchemeI getColourScheme();
+
+ public abstract void setColourScheme(ColourSchemeI cs);
+
+}
\ No newline at end of file
IdentityHashMap<SequenceI, AlignmentAnnotation> seqannot = null;
@Override
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
AnnotationColourGradient acg = new AnnotationColourGradient(annotation,
- colourScheme, aboveAnnotationThreshold);
+ getColourScheme(), aboveAnnotationThreshold);
acg.thresholdIsMinMax = thresholdIsMinMax;
acg.annotationThreshold = (annotationThreshold == null) ? null
: new GraphLine(annotationThreshold);
{
if (originalColour instanceof AnnotationColourGradient)
{
- colourScheme = ((AnnotationColourGradient) originalColour).colourScheme;
+ setColourScheme(((AnnotationColourGradient) originalColour)
+ .getColourScheme());
}
else
{
- colourScheme = originalColour;
+ setColourScheme(originalColour);
}
this.annotation = annotation;
*
* @return DOCUMENT ME!
*/
+ @Override
public Color findColour(char c)
{
return Color.red;
{
return currentColour;
}
- if ((threshold == 0) || aboveThreshold(c, j))
+ // if ((threshold == 0) || aboveThreshold(c, j))
+ // {
+ if (annotation.annotations != null && j < annotation.annotations.length
+ && annotation.annotations[j] != null
+ && !jalview.util.Comparison.isGap(c))
{
- if (annotation.annotations != null
- && j < annotation.annotations.length
- && annotation.annotations[j] != null
- && !jalview.util.Comparison.isGap(c))
+ Annotation aj = annotation.annotations[j];
+ // 'use original colours' => colourScheme != null
+ // -> look up colour to be used
+ // predefined colours => preconfigured shading
+ // -> only use original colours reference if thresholding enabled &
+ // minmax exists
+ // annotation.hasIcons => null or black colours replaced with glyph
+ // colours
+ // -> reuse original colours if present
+ // -> if thresholding enabled then return colour on non-whitespace glyph
+
+ if (aboveAnnotationThreshold == NO_THRESHOLD
+ || (annotationThreshold != null && (aboveAnnotationThreshold == ABOVE_THRESHOLD ? aj.value >= annotationThreshold.value
+ : aj.value <= annotationThreshold.value)))
{
- Annotation aj = annotation.annotations[j];
- // 'use original colours' => colourScheme != null
- // -> look up colour to be used
- // predefined colours => preconfigured shading
- // -> only use original colours reference if thresholding enabled &
- // minmax exists
- // annotation.hasIcons => null or black colours replaced with glyph
- // colours
- // -> reuse original colours if present
- // -> if thresholding enabled then return colour on non-whitespace glyph
-
- if (aboveAnnotationThreshold == NO_THRESHOLD
- || (annotationThreshold != null && (aboveAnnotationThreshold == ABOVE_THRESHOLD ? aj.value >= annotationThreshold.value
- : aj.value <= annotationThreshold.value)))
+ if (predefinedColours && aj.colour != null
+ && !aj.colour.equals(Color.black))
{
- if (predefinedColours && aj.colour != null
- && !aj.colour.equals(Color.black))
- {
- currentColour = aj.colour;
- }
- else if (annotation.hasIcons
- && annotation.graph == AlignmentAnnotation.NO_GRAPH)
+ currentColour = aj.colour;
+ }
+ else if (annotation.hasIcons
+ && annotation.graph == AlignmentAnnotation.NO_GRAPH)
+ {
+ if (aj.secondaryStructure > ' ' && aj.secondaryStructure != '.'
+ && aj.secondaryStructure != '-')
{
- if (aj.secondaryStructure > ' ' && aj.secondaryStructure != '.'
- && aj.secondaryStructure != '-')
+ if (getColourScheme() != null)
{
- if (colourScheme != null)
+ currentColour = getColourScheme().findColour(c, j, seq, null,
+ 0f);
+ }
+ else
+ {
+ if (annotation.isRNA())
{
- currentColour = colourScheme.findColour(c, j, seq);
+ currentColour = ColourSchemeProperty.rnaHelices[(int) aj.value];
}
else
{
- if (annotation.isRNA())
- {
- currentColour = ColourSchemeProperty.rnaHelices[(int) aj.value];
- }
- else
- {
- currentColour = annotation.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR
- : annotation.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR
- : jalview.renderer.AnnotationRenderer.STEM_COLOUR;
- }
+ currentColour = annotation.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR
+ : annotation.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR
+ : jalview.renderer.AnnotationRenderer.STEM_COLOUR;
}
}
- else
- {
- //
- return Color.white;
- }
}
- else if (noGradient)
+ else
{
- if (colourScheme != null)
- {
- currentColour = colourScheme.findColour(c, j, seq);
- }
- else
- {
- if (aj.colour != null)
- {
- currentColour = aj.colour;
- }
- }
+ //
+ return Color.white;
+ }
+ }
+ else if (noGradient)
+ {
+ if (getColourScheme() != null)
+ {
+ currentColour = getColourScheme().findColour(c, j, seq, null,
+ 0f);
}
else
{
- currentColour = shadeCalculation(annotation, j);
+ if (aj.colour != null)
+ {
+ currentColour = aj.colour;
+ }
}
}
- if (conservationColouring)
+ else
{
- currentColour = applyConservation(currentColour, j);
+ currentColour = shadeCalculation(annotation, j);
}
}
+ // if (conservationColouring)
+ // {
+ // currentColour = applyConservation(currentColour, j);
+ // }
}
+ // }
return currentColour;
}
{
seqAssociated = sassoc;
}
+
+ @Override
+ public String getSchemeName()
+ {
+ return "Annotation";
+ }
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
super();
}
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
@Override
- public Color findColour(char res, int j, SequenceI seq)
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
{
+ return new Blosum62ColourScheme();
+ }
+
+ @Override
+ public Color findColour(char res, int j, SequenceI seq,
+ String consensusResidue, float pid)
+ {
+ /*
+ * compare as upper case; note consensusResidue is
+ * always computed as uppercase
+ */
if ('a' <= res && res <= 'z')
{
- // TO UPPERCASE !!!
res -= ('a' - 'A');
}
- if (consensus == null || consensus.get(j) == null
- || (threshold != 0 && !aboveThreshold(res, j)))
+ if (Comparison.isGap(res) || consensusResidue == null)
{
return Color.white;
}
- Color currentColour;
+ Color colour;
- if (!Comparison.isGap(res))
+ if (consensusResidue.indexOf(res) > -1)
+ {
+ colour = DARK_BLUE;
+ }
+ else
{
- /*
- * test if this is the consensus (or joint consensus) residue
- */
- String max = consensus.get(j).getModalResidue();
+ int c = 0;
- if (max.indexOf(res) > -1)
+ for (char consensus : consensusResidue.toCharArray())
{
- currentColour = DARK_BLUE;
+ c += ResidueProperties.getBLOSUM62(consensus, res);
}
- else
- {
- int c = 0;
- int max_aa = 0;
- int n = max.length();
- do
- {
- c += ResidueProperties.getBLOSUM62(max.charAt(max_aa), res);
- } while (++max_aa < n);
-
- if (c > 0)
- {
- currentColour = LIGHT_BLUE;
- }
- else
- {
- currentColour = Color.white;
- }
+ if (c > 0)
+ {
+ colour = LIGHT_BLUE;
}
-
- if (conservationColouring)
+ else
{
- currentColour = applyConservation(currentColour, j);
+ colour = Color.white;
}
}
- else
- {
- return Color.white;
- }
+ return colour;
+ }
- return currentColour;
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Blosum62.toString();
}
@Override
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
- Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+ public boolean isSimple()
{
- ColourSchemeI newcs = super.applyTo(sg, hiddenRepSequences);
- return newcs;
+ return false;
}
}
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
import java.awt.Color;
+import java.util.Map;
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
+ @Override
public Color makeColour(float c)
{
return new Color(0, (float) (1.0 - c), c);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Buried.toString();
+ }
+
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new BuriedColourScheme();
+ }
}
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
import java.awt.Color;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
private static final int SIXTY = 60;
- /*
- * Map from conventional colour names to Clustal version of the same
- */
- private static Map<Color, Color> colhash = new HashMap<Color, Color>();
+ enum ClustalColour
+ {
+ RED(0.9f, 0.2f, 0.1f), BLUE(0.5f, 0.7f, 0.9f), GREEN(0.1f, 0.8f, 0.1f),
+ ORANGE(0.9f, 0.6f, 0.3f), CYAN(0.1f, 0.7f, 0.7f),
+ PINK(0.9f, 0.5f, 0.5f), MAGENTA(0.8f, 0.3f, 0.8f), YELLOW(0.8f, 0.8f,
+ 0.0f);
+
+ final Color colour;
+
+ ClustalColour(float r, float g, float b)
+ {
+ colour = new Color(r, g, b);
+ }
+ }
+ private class ConsensusColour
+ {
+ Consensus[] cons;
+
+ Color c;
+
+ public ConsensusColour(ClustalColour col, Consensus[] conses)
+ {
+ this.cons = conses;
+ this.c = col.colour;
+ }
+ }
private int[][] cons2;
private boolean includeGaps = true;
- static
+ /**
+ * Default constructor (required for Class.newInstance())
+ */
+ public ClustalxColourScheme()
{
- colhash.put(Color.RED, new Color(0.9f, 0.2f, 0.1f));
- colhash.put(Color.BLUE, new Color(0.5f, 0.7f, 0.9f));
- colhash.put(Color.GREEN, new Color(0.1f, 0.8f, 0.1f));
- colhash.put(Color.ORANGE, new Color(0.9f, 0.6f, 0.3f));
- colhash.put(Color.CYAN, new Color(0.1f, 0.7f, 0.7f));
- colhash.put(Color.PINK, new Color(0.9f, 0.5f, 0.5f));
- colhash.put(Color.MAGENTA, new Color(0.8f, 0.3f, 0.8f));
- colhash.put(Color.YELLOW, new Color(0.8f, 0.8f, 0.0f));
+
}
public ClustalxColourScheme(AnnotatedCollectionI alignment,
alignmentChanged(alignment, hiddenReps);
}
+ @Override
public void alignmentChanged(AnnotatedCollectionI alignment,
Map<SequenceI, SequenceCollectionI> hiddenReps)
{
includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to
// get the current setting of the
// includeGaps param.
- int start = 0;
-
- // Initialize the array
- for (int j = 0; j < 24; j++)
- {
- for (int i = 0; i < maxWidth; i++)
- {
- cons2[i][j] = 0;
- }
- }
-
- int res;
- int i;
- int j = 0;
- char[] seq;
+ int res = 0;
for (SequenceI sq : seqs)
{
- seq = sq.getSequence();
+ char[] seq = sq.getSequence();
int end_j = seq.length - 1;
- for (i = start; i <= end_j; i++)
+ for (int i = 0; i <= end_j; i++)
{
if ((seq.length - 1) < i)
{
{
res = ResidueProperties.aaIndex[seq[i]];
}
-
cons2[i][res]++;
}
-
- j++;
}
this.size = seqs.size();
makeColours();
}
- public void makeColours()
+ void makeColours()
{
conses[0] = new Consensus("WLVIMAFCYHP", SIXTY);
conses[1] = new Consensus("WLVIMAFCYHP", EIGHTY);
Consensus[] tmp8 = new Consensus[1];
tmp8[0] = conses[30]; // G
- colours[7] = new ConsensusColour(colhash.get(Color.ORANGE), tmp8);
+ colours[7] = new ConsensusColour(ClustalColour.ORANGE, tmp8);
Consensus[] tmp9 = new Consensus[1];
tmp9[0] = conses[31]; // P
- colours[8] = new ConsensusColour(colhash.get(Color.YELLOW), tmp9);
+ colours[8] = new ConsensusColour(ClustalColour.YELLOW, tmp9);
Consensus[] tmp10 = new Consensus[1];
tmp10[0] = conses[27]; // C
- colours[9] = new ConsensusColour(colhash.get(Color.PINK), tmp8);
+ colours[9] = new ConsensusColour(ClustalColour.PINK, tmp8);
Consensus[] tmp1 = new Consensus[14];
tmp1[0] = conses[0]; // %
tmp1[11] = conses[25]; // Y
tmp1[12] = conses[18]; // P
tmp1[13] = conses[19]; // p
- colours[0] = new ConsensusColour(colhash.get(Color.BLUE), tmp1);
+ colours[0] = new ConsensusColour(ClustalColour.BLUE, tmp1);
- colours[10] = new ConsensusColour(colhash.get(Color.CYAN), tmp1);
+ colours[10] = new ConsensusColour(ClustalColour.CYAN, tmp1);
Consensus[] tmp2 = new Consensus[5];
tmp2[0] = conses[8]; // t
tmp2[2] = conses[22]; // T
tmp2[3] = conses[0]; // %
tmp2[4] = conses[1]; // #
- colours[1] = new ConsensusColour(colhash.get(Color.GREEN), tmp2);
+ colours[1] = new ConsensusColour(ClustalColour.GREEN, tmp2);
Consensus[] tmp3 = new Consensus[3];
tmp3[0] = conses[17]; // N
tmp3[1] = conses[29]; // D
tmp3[2] = conses[5]; // n
- colours[2] = new ConsensusColour(colhash.get(Color.GREEN), tmp3);
+ colours[2] = new ConsensusColour(ClustalColour.GREEN, tmp3);
Consensus[] tmp4 = new Consensus[6];
tmp4[0] = conses[6]; // q = QE
tmp4[3] = conses[3]; // +
tmp4[4] = conses[28]; // K
tmp4[5] = conses[20]; // R
- colours[3] = new ConsensusColour(colhash.get(Color.GREEN), tmp4);
+ colours[3] = new ConsensusColour(ClustalColour.GREEN, tmp4);
Consensus[] tmp5 = new Consensus[4];
tmp5[0] = conses[3]; // +
tmp5[1] = conses[28]; // K
tmp5[2] = conses[20]; // R
tmp5[3] = conses[19]; // Q
- colours[4] = new ConsensusColour(colhash.get(Color.RED), tmp5);
+ colours[4] = new ConsensusColour(ClustalColour.RED, tmp5);
Consensus[] tmp6 = new Consensus[6];
tmp6[0] = conses[3]; // -
tmp6[3] = conses[6]; // QE
tmp6[4] = conses[19]; // Q
tmp6[5] = conses[2]; // DE
- colours[5] = new ConsensusColour(colhash.get(Color.MAGENTA), tmp6);
+ colours[5] = new ConsensusColour(ClustalColour.MAGENTA, tmp6);
Consensus[] tmp7 = new Consensus[5];
tmp7[0] = conses[3]; // -
tmp7[2] = conses[10]; // E
tmp7[3] = conses[17]; // N
tmp7[4] = conses[2]; // DE
- colours[6] = new ConsensusColour(colhash.get(Color.MAGENTA), tmp7);
+ colours[6] = new ConsensusColour(ClustalColour.MAGENTA, tmp7);
// Now attach the ConsensusColours to the residue letters
residueColour = new ConsensusColour[20];
}
@Override
- public Color findColour(char c, int j, SequenceI seq)
+ protected Color findColour(char c, int j, SequenceI seq)
{
- Color currentColour;
-
- if (cons2.length <= j
- || (includeGaps && threshold != 0 && !aboveThreshold(c, j)))
+ // TODO why the test for includeGaps here?
+ if (cons2.length <= j || Comparison.isGap(c)
+ /*|| (includeGaps && threshold != 0 && !aboveThreshold(c, j))*/)
{
return Color.white;
}
int i = ResidueProperties.aaIndex[c];
- currentColour = Color.white;
+ Color colour = Color.white;
if (i > 19)
{
- return currentColour;
+ return colour;
}
- for (int k = 0; k < residueColour[i].conses.length; k++)
+ for (int k = 0; k < residueColour[i].cons.length; k++)
{
- if (residueColour[i].conses[k].isConserved(cons2, j, size,
+ if (residueColour[i].cons[k].isConserved(cons2, j, size,
includeGaps))
{
- currentColour = residueColour[i].c;
+ colour = residueColour[i].c;
}
}
if (i == 4)
{
+ /*
+ * override to colour C pink if >85% conserved
+ */
if (conses[27].isConserved(cons2, j, size, includeGaps))
{
- currentColour = colhash.get(Color.PINK);
+ colour = ClustalColour.PINK.colour;
}
}
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
-
- return currentColour;
+ return colour;
}
/**
}
@Override
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
ClustalxColourScheme css = new ClustalxColourScheme(sg,
css.includeGaps = includeGaps;
return css;
}
-}
-class ConsensusColour
-{
- Consensus[] conses;
-
- Color c;
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
- public ConsensusColour(Color c, Consensus[] conses)
+ @Override
+ public String getSchemeName()
{
- this.conses = conses;
+ return JalviewColourScheme.Clustal.toString();
+ }
- // this.list = list;
- this.c = c;
+ @Override
+ public boolean isSimple()
+ {
+ return false;
}
}
package jalview.schemes;
import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
public interface ColourSchemeI
{
/**
+ * Returns the possibly context dependent colour for the given symbol at the
+ * aligned position in the given sequence. For example, the colour may depend
+ * on the symbol's relationship to the consensus residue for the column.
*
- * @param c
- * @return the colour for the given character
- */
- public Color findColour(char c);
-
- /**
- *
- * @param c
- * - sequence symbol or gap
- * @param j
- * - position in seq
+ * @param symbol
+ * @param position
* @param seq
- * - sequence being coloured
- * @return context dependent colour for the given symbol at the position in
- * the given sequence
- */
- public Color findColour(char c, int j, SequenceI seq);
-
- /**
- * assign the given consensus profile for the colourscheme
- */
- public void setConsensus(ProfilesI hconsensus);
-
- /**
- * assign the given conservation to the colourscheme
- *
- * @param c
- */
- public void setConservation(jalview.analysis.Conservation c);
-
- /**
- * enable or disable conservation shading for this colourscheme
- *
- * @param conservationApplied
- */
- public void setConservationApplied(boolean conservationApplied);
-
- /**
- *
- * @return true if conservation shading is enabled for this colourscheme
+ * @param consensusResidue
+ * the modal symbol (e.g. K) or symbols (e.g. KF) for the column
+ * @param pid
+ * the percentage identity of the column's consensus (if known)
+ * @return
*/
- public boolean conservationApplied();
-
- /**
- * set scale factor for bleaching of colour in unconserved regions
- *
- * @param i
- */
- public void setConservationInc(int i);
+ Color findColour(char symbol, int position, SequenceI seq,
+ String consensusResidue, float pid);
/**
+ * Recalculate dependent data using the given sequence collection, taking
+ * account of hidden rows
*
- * @return scale factor for bleaching colour in unconserved regions
+ * @param alignment
+ * @param hiddenReps
*/
- public int getConservationInc();
+ void alignmentChanged(AnnotatedCollectionI alignment,
+ Map<SequenceI, SequenceCollectionI> hiddenReps);
/**
+ * Creates and returns a new instance of the colourscheme configured to colour
+ * the given collection. Note that even simple colour schemes should return a
+ * new instance for each call to this method, as different instances may have
+ * differing shading by consensus or percentage identity applied.
*
- * @return percentage identity threshold for applying colourscheme
+ * @param sg
+ * @param hiddenRepSequences
+ * @return copy of current scheme with any inherited settings transferred
*/
- public int getThreshold();
+ ColourSchemeI getInstance(AnnotatedCollectionI sg,
+ Map<SequenceI, SequenceCollectionI> hiddenRepSequences);
/**
- * set percentage identity threshold and type of %age identity calculation for
- * shading
+ * Answers true if the colour scheme is suitable for the given data, else
+ * false. For example, some colour schemes are specific to either peptide or
+ * nucleotide, or only apply if certain kinds of annotation are present.
*
- * @param ct
- * 0..100 percentage identity for applying this colourscheme
- * @param ignoreGaps
- * when true, calculate PID without including gapped positions
+ * @param ac
+ * @return
*/
- public void setThreshold(int ct, boolean ignoreGaps);
+ // TODO can make this method static in Java 8
+ boolean isApplicableTo(AnnotatedCollectionI ac);
/**
- * recalculate dependent data using the given sequence collection, taking
- * account of hidden rows
+ * Answers the 'official' name of the colour scheme (as used, for example, as
+ * a Jalview startup parameter)
*
- * @param alignment
- * @param hiddenReps
+ * @return
*/
- public void alignmentChanged(AnnotatedCollectionI alignment,
- Map<SequenceI, SequenceCollectionI> hiddenReps);
+ String getSchemeName();
/**
- * create a new instance of the colourscheme configured to colour the given
- * connection
+ * Answers true if the colour scheme depends only on the sequence symbol, and
+ * not on other information such as alignment consensus or annotation. (Note
+ * that simple colour schemes may have a fading by percentage identity or
+ * conservation overlaid.) Simple colour schemes can be propagated to
+ * structure viewers.
*
- * @param sg
- * @param hiddenRepSequences
- * @return copy of current scheme with any inherited settings transfered
+ * @return
*/
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
- Map<SequenceI, SequenceCollectionI> hiddenRepSequences);
-
+ boolean isSimple();
}
package jalview.schemes;
import jalview.datamodel.AnnotatedCollectionI;
+import jalview.util.ColorUtils;
import java.awt.Color;
*/
public class ColourSchemeProperty
{
- /** Undefined Colourscheme Index */
- public static final int UNDEFINED = -1;
-
- /** for schemes defined on the fly */
- public static final int USER_DEFINED = 0;
-
- /** No Colourscheme Index */
- public static final int NONE = 1;
-
- /** DOCUMENT ME!! */
- public static final int CLUSTAL = 2;
-
- /** DOCUMENT ME!! */
- public static final int BLOSUM = 3;
-
- /** DOCUMENT ME!! */
- public static final int PID = 4;
-
- /** DOCUMENT ME!! */
- public static final int ZAPPO = 5;
-
- /** DOCUMENT ME!! */
- public static final int TAYLOR = 6;
-
- /** DOCUMENT ME!! */
- public static final int HYDROPHOBIC = 7;
-
- /** DOCUMENT ME!! */
- public static final int HELIX = 8;
-
- /** DOCUMENT ME!! */
- public static final int STRAND = 9;
-
- /** DOCUMENT ME!! */
- public static final int TURN = 10;
-
- /** DOCUMENT ME!! */
- public static final int BURIED = 11;
-
- /** DOCUMENT ME!! */
- public static final int NUCLEOTIDE = 12;
/**
- * purine/pyrimidine
- */
- public static final int PURINEPYRIMIDINE = 13;
-
- public static final int COVARIATION = 14;
-
- public static final int TCOFFEE = 15;
-
- public static final int RNAHELIX = 16;
-
- public static final int RNAINTERACTION = 17;
-
- /**
- * index of first colourscheme (includes 'None')
- */
- public static final int FIRST_COLOUR = NONE;
-
- public static final int LAST_COLOUR = RNAINTERACTION;
-
- /**
- * DOCUMENT ME!
+ * Returns a colour scheme for the given name, with which the given data may
+ * be coloured. The name is not case-sensitive, and may be one of
+ * <ul>
+ * <li>any currently registered colour scheme; Jalview by default provides</li>
+ * <ul>
+ * <li>Clustal</li>
+ * <li>Blosum62</li>
+ * <li>% Identity</li>
+ * <li>Hydrophobic</li>
+ * <li>Zappo</li>
+ * <li>Taylor</li>
+ * <li>Helix Propensity</li>
+ * <li>Strand Propensity</li>
+ * <li>Turn Propensity</li>
+ * <li>Buried Index</li>
+ * <li>Nucleotide</li>
+ * <li>Purine/Pyrimidine</li>
+ * <li>T-Coffee Scores</li>
+ * <li>RNA Helices</li>
+ * </ul>
+ * <li>the name of a programmatically added colour scheme</li> <li>an AWT
+ * colour name e.g. red</li> <li>an AWT hex rgb colour e.g. ff2288</li> <li>
+ * residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow</li> </ul>
*
- * @param name
- * DOCUMENT ME!
+ * If none of these formats is matched, the string is converted to a colour
+ * using a hashing algorithm. For name "None", returns null.
*
- * @return DOCUMENT ME!
+ * @param forData
+ * @param name
+ * @return
*/
- public static int getColourIndexFromName(String name)
+ public static ColourSchemeI getColourScheme(AnnotatedCollectionI forData,
+ String name)
{
- int ret = UNDEFINED;
-
- if (name.equalsIgnoreCase("Clustal"))
+ if (ResidueColourScheme.NONE.equalsIgnoreCase(name))
{
- ret = CLUSTAL;
- }
- else if (name.equalsIgnoreCase("Blosum62"))
- {
- ret = BLOSUM;
- }
- else if (name.equalsIgnoreCase("% Identity"))
- {
- ret = PID;
- }
- else if (name.equalsIgnoreCase("Zappo"))
- {
- ret = ZAPPO;
- }
- else if (name.equalsIgnoreCase("Taylor"))
- {
- ret = TAYLOR;
- }
- else if (name.equalsIgnoreCase("Hydrophobic"))
- {
- ret = HYDROPHOBIC;
- }
- else if (name.equalsIgnoreCase("Helix Propensity"))
- {
- ret = HELIX;
- }
- else if (name.equalsIgnoreCase("Strand Propensity"))
- {
- ret = STRAND;
- }
- else if (name.equalsIgnoreCase("Turn Propensity"))
- {
- ret = TURN;
- }
- else if (name.equalsIgnoreCase("Buried Index"))
- {
- ret = BURIED;
- }
- else if (name.equalsIgnoreCase("Nucleotide"))
- {
- ret = NUCLEOTIDE;
- }
- else if (name.equalsIgnoreCase("T-Coffee Scores"))
- {
- ret = TCOFFEE;
- }
+ return null;
- else if (name.equalsIgnoreCase("User Defined"))
- {
- ret = USER_DEFINED;
- }
- else if (name.equalsIgnoreCase("None"))
- {
- ret = NONE;
- }
- else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
- {
- ret = PURINEPYRIMIDINE;
- }
- else if (name.equalsIgnoreCase("RNA Interaction type"))
- {
- ret = RNAINTERACTION;
- }
- else if (name.equalsIgnoreCase("RNA Helices"))
- {
- ret = RNAHELIX;
}
- // else if (name.equalsIgnoreCase("Covariation"))
- // {
- // ret = COVARIATION;
- // }
-
- return ret;
- }
- /**
- * DOCUMENT ME!
- *
- * @param cs
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public static String getColourName(ColourSchemeI cs)
- {
-
- int index = NONE;
-
- if (cs instanceof ClustalxColourScheme)
- {
- index = CLUSTAL;
- }
- else if (cs instanceof Blosum62ColourScheme)
- {
- index = BLOSUM;
- }
- else if (cs instanceof PIDColourScheme)
- {
- index = PID;
- }
- else if (cs instanceof ZappoColourScheme)
- {
- index = ZAPPO;
- }
- else if (cs instanceof TaylorColourScheme)
- {
- index = TAYLOR;
- }
- else if (cs instanceof HydrophobicColourScheme)
- {
- index = HYDROPHOBIC;
- }
- else if (cs instanceof HelixColourScheme)
- {
- index = HELIX;
- }
- else if (cs instanceof StrandColourScheme)
- {
- index = STRAND;
- }
- else if (cs instanceof TurnColourScheme)
- {
- index = TURN;
- }
- else if (cs instanceof BuriedColourScheme)
- {
- index = BURIED;
- }
- else if (cs instanceof NucleotideColourScheme)
- {
- index = NUCLEOTIDE;
- }
- else if (cs instanceof PurinePyrimidineColourScheme)
- {
- index = PURINEPYRIMIDINE;
- }
- else if (cs instanceof TCoffeeColourScheme)
- {
- index = TCOFFEE;
- }
- else if (cs instanceof RNAHelicesColour)
- {
- index = RNAHELIX;
- }
/*
- * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
+ * if this is the name of a registered colour scheme, just
+ * create a new instance of it
*/
- else if (cs instanceof UserColourScheme)
+ ColourSchemeI scheme = ColourSchemes.getInstance().getColourScheme(
+ name, forData, null);
+ if (scheme != null)
{
- if ((((UserColourScheme) cs).getName() != null)
- && (((UserColourScheme) cs).getName().length() > 0))
- {
- return ((UserColourScheme) cs).getName();
- }
- // get default colourscheme name
- index = USER_DEFINED;
+ return scheme;
}
- return getColourName(index);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param index
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public static String getColourName(int index)
- {
- String ret = null;
-
- switch (index)
- {
- case CLUSTAL:
- ret = "Clustal";
-
- break;
-
- case BLOSUM:
- ret = "Blosum62";
-
- break;
-
- case PID:
- ret = "% Identity";
-
- break;
-
- case ZAPPO:
- ret = "Zappo";
-
- break;
-
- case TAYLOR:
- ret = "Taylor";
- break;
-
- case HYDROPHOBIC:
- ret = "Hydrophobic";
-
- break;
-
- case HELIX:
- ret = "Helix Propensity";
-
- break;
-
- case STRAND:
- ret = "Strand Propensity";
-
- break;
-
- case TURN:
- ret = "Turn Propensity";
-
- break;
-
- case BURIED:
- ret = "Buried Index";
-
- break;
-
- case NUCLEOTIDE:
- ret = "Nucleotide";
-
- break;
-
- case PURINEPYRIMIDINE:
- ret = "Purine/Pyrimidine";
-
- break;
-
- case TCOFFEE:
- ret = "T-Coffee Scores";
-
- break;
-
- case RNAINTERACTION:
- ret = "RNA Interaction type";
-
- break;
- case RNAHELIX:
- ret = "RNA Helices";
-
- break;
/*
- * case COVARIATION: ret = "Covariation";
- *
- * break;
+ * try to parse the string as a residues colour scheme
+ * e.g. A=red;T,G=blue etc
+ * else parse the name as a colour specification
+ * e.g. "red" or "ff00ed",
+ * or failing that hash the name to a colour
*/
- case USER_DEFINED:
- ret = "User Defined";
-
- break;
-
- default:
- ret = "None";
-
- break;
- }
-
- return ret;
- }
-
- /**
- * retrieve or create colourscheme associated with name
- *
- * @param seqs
- * sequences to colour
- * @param width
- * range of sequences to colour
- * @param name
- * colourscheme name, applet colour parameter specification, or
- * string to parse as colour for new coloursheme
- * @return Valid Colourscheme
- */
- public static ColourSchemeI getColour(AnnotatedCollectionI alignment,
- String name)
- {
- int colindex = getColourIndexFromName(name);
- if (colindex == UNDEFINED)
- {
- if (name.indexOf('=') == -1)
- {
- // try to build a colour from the string directly
- try
- {
- return new UserColourScheme(name);
- } catch (Exception e)
- {
- // System.err.println("Ignoring unknown colourscheme name");
- }
- }
- else
- {
- // try to parse the string as a residue colourscheme
- try
- {
- // fix the launchApp user defined coloursheme transfer bug
- jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
- "white");
- ucs.parseAppletParameter(name);
-
- } catch (Exception e)
- {
- // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
- }
- }
- }
- return getColour(alignment, getColourIndexFromName(name));
- }
-
- /**
- * Construct an instance of ColourSchemeI corresponding to the given
- * colourscheme index
- *
- * @param seqs
- * sequences to be coloured by colourscheme
- * @param width
- * geometry of alignment
- * @param index
- * colourscheme number
- *
- * @return null or an instance of the colourscheme configured to colour given
- * sequence set
- */
- public static ColourSchemeI getColour(
- jalview.datamodel.AnnotatedCollectionI coll, int index)
- {
- // TODO 3.0 2.8 refactor signature to take an alignmentI like container so
- // colourschemes based on annotation can be initialised
- ColourSchemeI cs = null;
-
- switch (index)
- {
- case CLUSTAL:
- cs = new ClustalxColourScheme(coll, null);
-
- break;
-
- case BLOSUM:
- cs = new Blosum62ColourScheme();
-
- break;
-
- case PID:
- cs = new PIDColourScheme();
-
- break;
-
- case ZAPPO:
- cs = new ZappoColourScheme();
-
- break;
-
- case TAYLOR:
- cs = new TaylorColourScheme();
- break;
-
- case HYDROPHOBIC:
- cs = new HydrophobicColourScheme();
-
- break;
-
- case HELIX:
- cs = new HelixColourScheme();
-
- break;
-
- case STRAND:
- cs = new StrandColourScheme();
-
- break;
-
- case TURN:
- cs = new TurnColourScheme();
-
- break;
-
- case BURIED:
- cs = new BuriedColourScheme();
-
- break;
-
- case NUCLEOTIDE:
- cs = new NucleotideColourScheme();
-
- break;
-
- case PURINEPYRIMIDINE:
- cs = new PurinePyrimidineColourScheme();
-
- break;
-
- case TCOFFEE:
- cs = new TCoffeeColourScheme(coll);
- break;
-
- case RNAHELIX:
- cs = new RNAHelicesColour(coll);
- break;
-
- // case COVARIATION:
- // cs = new CovariationColourScheme(annotation);
- // break;
-
- case USER_DEFINED:
- Color[] col = new Color[24];
- for (int i = 0; i < 24; i++)
- {
- col[i] = Color.white;
- }
- cs = new UserColourScheme(col);
- break;
-
- default:
- break;
- }
-
- return cs;
- }
-
- public static Color getAWTColorFromName(String name)
- {
- Color col = null;
- name = name.toLowerCase();
- if (name.equals("black"))
- {
- col = Color.black;
- }
- else if (name.equals("blue"))
- {
- col = Color.blue;
- }
- else if (name.equals("cyan"))
- {
- col = Color.cyan;
- }
- else if (name.equals("darkGray"))
- {
- col = Color.darkGray;
- }
- else if (name.equals("gray"))
- {
- col = Color.gray;
- }
- else if (name.equals("green"))
- {
- col = Color.green;
- }
- else if (name.equals("lightGray"))
- {
- col = Color.lightGray;
- }
- else if (name.equals("magenta"))
- {
- col = Color.magenta;
- }
- else if (name.equals("orange"))
- {
- col = Color.orange;
- }
- else if (name.equals("pink"))
- {
- col = Color.pink;
- }
- else if (name.equals("red"))
- {
- col = Color.red;
- }
- else if (name.equals("white"))
- {
- col = Color.white;
- }
- else if (name.equals("yellow"))
- {
- col = Color.yellow;
- }
-
- return col;
+ UserColourScheme ucs = new UserColourScheme(name);
+ return ucs;
}
public static Color rnaHelices[] = null;
// Generate random colors and store
for (; j <= n; j++)
{
- rnaHelices[j] = jalview.util.ColorUtils
- .generateRandomColor(Color.white);
+ rnaHelices[j] = ColorUtils.generateRandomColor(Color.white);
}
}
/**
- * delete the existing cached RNA helces colours
+ * delete the existing cached RNA helices colours
*/
public static void resetRnaHelicesShading()
{
rnaHelices = null;
}
+ /**
+ * Returns the name of the colour scheme (or "None" if it is null)
+ *
+ * @param cs
+ * @return
+ */
+ public static String getColourName(ColourSchemeI cs)
+ {
+ return cs == null ? ResidueColourScheme.NONE : cs
+ .getSchemeName();
+ }
+
}
--- /dev/null
+package jalview.schemes;
+
+import jalview.binding.JalviewUserColours;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class ColourSchemes
+{
+ /*
+ * singleton instance of this class
+ */
+ private static ColourSchemes instance = new ColourSchemes();
+
+ /*
+ * a map from scheme name to an instance of it
+ */
+ private Map<String, ColourSchemeI> schemes;
+
+ /**
+ * Returns the singleton instance of this class
+ *
+ * @return
+ */
+ public static ColourSchemes getInstance()
+ {
+ return instance;
+ }
+
+ private ColourSchemes()
+ {
+ loadColourSchemes();
+ }
+
+ /**
+ * Loads an instance of each standard or user-defined colour scheme
+ *
+ * @return
+ */
+ void loadColourSchemes()
+ {
+ /*
+ * store in an order-preserving map, so items can be added to menus
+ * in the order in which they are 'discovered'
+ */
+ schemes = new LinkedHashMap<String, ColourSchemeI>();
+
+ for (JalviewColourScheme cs : JalviewColourScheme.values())
+ {
+ try
+ {
+ registerColourScheme(cs.getSchemeClass().newInstance());
+ } catch (InstantiationException | IllegalAccessException e)
+ {
+ System.err.println("Error instantiating colour scheme for "
+ + cs.toString() + " " + e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Registers a colour scheme
+ *
+ * @param cs
+ */
+ public void registerColourScheme(ColourSchemeI cs)
+ {
+ String name = cs.getSchemeName();
+ if (name == null)
+ {
+ System.err.println("ColourScheme name may not be null");
+ return;
+ }
+
+ /*
+ * name is lower-case for non-case-sensitive lookup
+ * (name in the colour keeps its true case)
+ */
+ String lower = name.toLowerCase();
+ if (schemes.containsKey(lower))
+ {
+ System.err
+ .println("Warning: overwriting colour scheme named " + name);
+ }
+ schemes.put(lower, cs);
+ }
+
+ /**
+ * Removes a colour scheme by name
+ *
+ * @param name
+ */
+ public void removeColourScheme(String name)
+ {
+ schemes.remove(name);
+ }
+
+ /**
+ * Returns an instance of the colour scheme with which the given view may be
+ * coloured
+ *
+ * @param name
+ * name of the colour scheme
+ * @param forData
+ * the data to be coloured
+ * @param optional
+ * map from hidden representative sequences to the sequences they
+ * represent
+ * @return
+ */
+ public ColourSchemeI getColourScheme(String name,
+ AnnotatedCollectionI forData,
+ Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+ {
+ if (name == null)
+ {
+ return null;
+ }
+ ColourSchemeI cs = schemes.get(name.toLowerCase());
+ return cs == null ? null : cs.getInstance(forData, hiddenRepSequences);
+ }
+
+ /**
+ * Returns an instance of the colour scheme with which the given view may be
+ * coloured
+ *
+ * @param name
+ * name of the colour scheme
+ * @param forData
+ * the data to be coloured
+ * @return
+ */
+ public ColourSchemeI getColourScheme(String name,
+ AnnotatedCollectionI forData)
+ {
+ return getColourScheme(name, forData, null);
+ }
+
+ /**
+ * Returns an iterable set of the colour schemes, in the order in which they
+ * were added
+ *
+ * @return
+ */
+ public Iterable<ColourSchemeI> getColourSchemes()
+ {
+ return schemes.values();
+ }
+
+ /**
+ * Answers true if there is a scheme with the given name, else false. The test
+ * is not case-sensitive.
+ *
+ * @param name
+ * @return
+ */
+ public boolean nameExists(String name)
+ {
+ if (name == null)
+ {
+ return false;
+ }
+ name = name.toLowerCase();
+ for (ColourSchemeI scheme : getColourSchemes())
+ {
+ if (name.equals(scheme.getSchemeName().toLowerCase()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Loads a user defined colour scheme from file. The file should contain a
+ * definition of residue colours in XML format as defined in
+ * JalviewUserColours.xsd.
+ *
+ * @param filePath
+ *
+ * @return
+ */
+ public static UserColourScheme loadColourScheme(String filePath)
+ {
+ UserColourScheme ucs = null;
+ Color[] newColours = null;
+ File file = new File(filePath);
+ try
+ {
+ InputStreamReader in = new InputStreamReader(
+ new FileInputStream(file), "UTF-8");
+
+ jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
+
+ org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller(
+ jucs);
+ jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar
+ .unmarshal(in);
+
+ /*
+ * non-case-sensitive colours are for 20 amino acid codes,
+ * B, Z, X and Gap
+ * optionally, lower-case alternatives for all except Gap
+ */
+ newColours = new Color[24];
+ Color[] lowerCase = new Color[23];
+ boolean caseSensitive = false;
+
+ String name;
+ int index;
+ for (int i = 0; i < jucs.getColourCount(); i++)
+ {
+ name = jucs.getColour(i).getName();
+ if (ResidueProperties.aa3Hash.containsKey(name))
+ {
+ index = ResidueProperties.aa3Hash.get(name).intValue();
+ }
+ else
+ {
+ index = ResidueProperties.aaIndex[name.charAt(0)];
+ }
+ if (index == -1)
+ {
+ continue;
+ }
+
+ Color color = new Color(Integer.parseInt(jucs.getColour(i)
+ .getRGB(), 16));
+ if (name.toLowerCase().equals(name))
+ {
+ caseSensitive = true;
+ lowerCase[index] = color;
+ }
+ else
+ {
+ newColours[index] = color;
+ }
+ }
+
+ /*
+ * instantiate the colour scheme
+ */
+ ucs = new UserColourScheme(newColours);
+ ucs.setName(jucs.getSchemeName());
+ if (caseSensitive)
+ {
+ ucs.setLowerCaseColours(lowerCase);
+ }
+ } catch (Exception ex)
+ {
+ // Could be old Jalview Archive format
+ try
+ {
+ InputStreamReader in = new InputStreamReader(new FileInputStream(
+ file), "UTF-8");
+
+ jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
+
+ jucs = JalviewUserColours.unmarshal(in);
+
+ newColours = new Color[jucs.getColourCount()];
+
+ for (int i = 0; i < 24; i++)
+ {
+ newColours[i] = new Color(Integer.parseInt(jucs.getColour(i)
+ .getRGB(), 16));
+ }
+ ucs = new UserColourScheme(newColours);
+ ucs.setName(jucs.getSchemeName());
+ } catch (Exception ex2)
+ {
+ ex2.printStackTrace();
+ }
+
+ if (newColours == null)
+ {
+ System.out.println("Error loading User ColourFile\n" + ex);
+ }
+ }
+
+ return ucs;
+ }
+}
package jalview.schemes;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
import java.awt.Color;
import java.util.Hashtable;
+import java.util.Map;
/**
* Became RNAHelicesColour.java. Placeholder for true covariation color scheme
*/
public class CovariationColourScheme extends ResidueColourScheme
{
- public Hashtable helixcolorhash = new Hashtable();
+ public Map<String, Color> helixcolorhash = new Hashtable<String, Color>();
- public Hashtable positionsToHelix = new Hashtable();
+ public Map<Integer, String> positionsToHelix = new Hashtable<Integer, String>();
int numHelix = 0;
public AlignmentAnnotation annotation;
/**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new CovariationColourScheme(coll.getAlignmentAnnotation()[0]);
+ }
+
+ /**
* Creates a new CovariationColourScheme object.
*/
public CovariationColourScheme(AlignmentAnnotation annotation)
for (int j = 0; j <= numHelix; j++)
{
- helixcolorhash.put(Integer.toString(j),
- jalview.util.ColorUtils.generateRandomColor(Color.white));
+ helixcolorhash.put(String.valueOf(j),
+ ColorUtils.generateRandomColor(Color.white));
}
}
*
* @return DOCUMENT ME!
*/
+ @Override
public Color findColour(char c)
{
// System.out.println("called"); log.debug
Color currentColour = Color.white;
String currentHelix = null;
// System.out.println(c + " " + j);
- currentHelix = (String) positionsToHelix.get(j);
+ currentHelix = positionsToHelix.get(j);
// System.out.println(positionsToHelix.get(j));
if (currentHelix != null)
{
- currentColour = (Color) helixcolorhash.get(currentHelix);
+ currentColour = helixcolorhash.get(currentHelix);
}
// System.out.println(c + " " + j + " helix " + currentHelix + " " +
return currentColour;
}
+ @Override
+ public boolean isNucleotideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return "Covariation";
+ }
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
import jalview.api.FeatureColourI;
import jalview.datamodel.SequenceFeature;
+import jalview.util.ColorUtils;
import jalview.util.Format;
import java.awt.Color;
/*
* only a simple colour specification - parse it
*/
- Color colour = UserColourScheme.getColourFromString(descriptor);
+ Color colour = ColorUtils.parseColourString(descriptor);
if (colour == null)
{
throw new IllegalArgumentException("Invalid colour descriptor: "
FeatureColour featureColour;
try
{
- featureColour = new FeatureColour(
- new UserColourScheme(mincol).findColour('A'),
- new UserColourScheme(maxcol).findColour('A'), min, max);
+ Color minColour = ColorUtils.parseColourString(mincol);
+ Color maxColour = ColorUtils.parseColourString(maxcol);
+ featureColour = new FeatureColour(minColour, maxColour, min, max);
featureColour.setColourByLabel(labelColour);
featureColour.setAutoScaled(autoScaled);
// add in any additional parameters
*/
public FeatureColour(Color low, Color high, float min, float max)
{
+ if (low == null)
+ {
+ low = Color.white;
+ }
+ if (high == null)
+ {
+ high = Color.black;
+ }
graduatedColour = true;
colour = null;
minColour = low;
{
if (isColourByLabel())
{
- return UserColourScheme
+ return ColorUtils
.createColourFromName(feature.getDescription());
}
*/
package jalview.schemes;
-import jalview.analysis.Conservation;
-import jalview.datamodel.ProfilesI;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.util.Map;
/**
* Colourscheme that takes its colours from some other colourscheme
public class FollowerColourScheme extends ResidueColourScheme
{
- protected ColourSchemeI colourScheme;
+ private ColourSchemeI colourScheme;
public ColourSchemeI getBaseColour()
{
}
@Override
- public void setConsensus(ProfilesI consensus)
+ public String getSchemeName()
{
- if (colourScheme != null)
- {
- colourScheme.setConsensus(consensus);
- }
+ return "Follower";
}
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
@Override
- public void setConservation(Conservation cons)
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
{
- if (colourScheme != null)
- {
- colourScheme.setConservation(cons);
- }
+ return new FollowerColourScheme();
}
- @Override
- public void setConservationInc(int i)
+ protected ColourSchemeI getColourScheme()
+ {
+ return colourScheme;
+ }
+
+ protected void setColourScheme(ColourSchemeI colourScheme)
{
- if (colourScheme != null)
- {
- colourScheme.setConservationInc(i);
- }
+ this.colourScheme = colourScheme;
}
}
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
import java.awt.Color;
+import java.util.Map;
public class HelixColourScheme extends ScoreColourScheme
{
ResidueProperties.helixmin, ResidueProperties.helixmax);
}
+ @Override
public Color makeColour(float c)
{
return new Color(c, (float) 1.0 - c, c);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Helix.toString();
+ }
+
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new HelixColourScheme();
+ }
}
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
import java.awt.Color;
+import java.util.Map;
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
+ @Override
public Color makeColour(float c)
{
return new Color(c, (float) 0.0, (float) 1.0 - c);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Hydrophobic.toString();
+ }
+
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new HydrophobicColourScheme();
+ }
}
--- /dev/null
+package jalview.schemes;
+
+
+/**
+ * An enum with the colour schemes supported by Jalview.
+ */
+public enum JalviewColourScheme
+{
+ /*
+ * the order of declaration is the default order in which
+ * items are added to Colour menus
+ */
+ Clustal("Clustal", ClustalxColourScheme.class), Blosum62("Blosum62",
+ Blosum62ColourScheme.class), PID("% Identity",
+ PIDColourScheme.class), Zappo("Zappo", ZappoColourScheme.class),
+ Taylor("Taylor", TaylorColourScheme.class), Hydrophobic("Hydrophobic",
+ HydrophobicColourScheme.class), Helix("Helix Propensity",
+ HelixColourScheme.class), Strand("Strand Propensity",
+ StrandColourScheme.class), Turn("Turn Propensity",
+ TurnColourScheme.class), Buried("Buried Index",
+ BuriedColourScheme.class), Nucleotide("Nucleotide",
+ NucleotideColourScheme.class), PurinePyrimidine(
+ "Purine/Pyrimidine", PurinePyrimidineColourScheme.class),
+ RNAHelices("RNA Helices", RNAHelicesColour.class), TCoffee(
+ "T-Coffee Scores", TCoffeeColourScheme.class);
+ // RNAInteraction("RNA Interaction type", RNAInteractionColourScheme.class)
+
+ private String name;
+
+ private Class<? extends ColourSchemeI> myClass;
+
+ /**
+ * Constructor given the name of the colour scheme (as used in Jalview
+ * parameters). Note this is not necessarily the same as the 'display name'
+ * used in menu options (as this may be language-dependent).
+ *
+ * @param s
+ */
+ JalviewColourScheme(String s, Class<? extends ColourSchemeI> cl)
+ {
+ name = s;
+ myClass = cl;
+ }
+
+ /**
+ * Returns the class of the colour scheme
+ *
+ * @return
+ */
+ public Class<? extends ColourSchemeI> getSchemeClass()
+ {
+ return myClass;
+ }
+
+ /**
+ * Returns the 'official' name of this colour scheme. This is the name that
+ * identifies the colour scheme as a start-up parameter for the Jalview
+ * application or applet. Note that it may not be the name shown in menu
+ * options, as these may be internationalised.
+ */
+ @Override
+ public String toString()
+ {
+ return name;
+ }
+}
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
-import java.awt.Color;
+import java.util.Map;
/**
* DOCUMENT ME!
*/
public NucleotideColourScheme()
{
- super(ResidueProperties.nucleotideIndex, ResidueProperties.nucleotide,
- 0);
+ super(ResidueProperties.nucleotideIndex, ResidueProperties.nucleotide);
+ }
+
+ @Override
+ public boolean isNucleotideSpecific()
+ {
+ return true;
}
- /**
- * DOCUMENT ME!
- *
- * @param n
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
@Override
- public Color findColour(char c)
+ public String getSchemeName()
{
- // System.out.println("called"); log.debug
- return colors[ResidueProperties.nucleotideIndex[c]];
+ return JalviewColourScheme.Nucleotide.toString();
}
/**
- * DOCUMENT ME!
- *
- * @param n
- * DOCUMENT ME!
- * @param j
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
*/
@Override
- public Color findColour(char c, int j, SequenceI seq)
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
{
- Color currentColour;
- if ((threshold == 0) || aboveThreshold(c, j))
- {
- try
- {
- currentColour = colors[ResidueProperties.nucleotideIndex[c]];
- } catch (Exception ex)
- {
- return Color.white;
- }
- }
- else
- {
- return Color.white;
- }
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
-
- return currentColour;
+ return new NucleotideColourScheme();
}
}
*/
package jalview.schemes;
-import jalview.datamodel.ProfileI;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.util.Comparison;
import java.awt.Color;
+import java.util.Map;
public class PIDColourScheme extends ResidueColourScheme
{
- public Color[] pidColours;
+ private static final Color[] pidColours = { new Color(100, 100, 255),
+ new Color(153, 153, 255), new Color(204, 204, 255), };
- public float[] thresholds;
+ private static final float[] thresholds = { 80, 60, 40, };
SequenceGroup group;
public PIDColourScheme()
{
- this.pidColours = ResidueProperties.pidColours;
- this.thresholds = ResidueProperties.pidThresholds;
}
@Override
- public Color findColour(char c, int j, SequenceI seq)
+ public Color findColour(char c, int j, SequenceI seq,
+ String consensusResidue, float pid)
{
+ /*
+ * compare as upper case; note consensusResidue is
+ * always computed as uppercase
+ */
if ('a' <= c && c <= 'z')
{
c -= ('a' - 'A');
}
- if (consensus == null || consensus.get(j) == null)
- {
- return Color.white;
- }
-
- if ((threshold != 0) && !aboveThreshold(c, j))
+ if (consensusResidue == null || Comparison.isGap(c))
{
return Color.white;
}
- Color currentColour = Color.white;
-
- double sc = 0;
-
+ Color colour = Color.white;
/*
* test whether this is the consensus (or joint consensus) residue
*/
- ProfileI profile = consensus.get(j);
- boolean matchesConsensus = profile.getModalResidue().contains(
+ boolean matchesConsensus = consensusResidue.contains(
String.valueOf(c));
if (matchesConsensus)
{
- sc = profile.getPercentageIdentity(ignoreGaps);
-
- if (!Comparison.isGap(c))
+ for (int i = 0; i < thresholds.length; i++)
{
- for (int i = 0; i < thresholds.length; i++)
+ if (pid > thresholds[i])
{
- if (sc > thresholds[i])
- {
- currentColour = pidColours[i];
- break;
- }
+ colour = pidColours[i];
+ break;
}
}
}
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
+ return colour;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.PID.toString();
+ }
- return currentColour;
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new PIDColourScheme();
+ }
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
}
}
*/
package jalview.schemes;
-import java.awt.Color;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.util.Map;
/**
* Class is based off of NucleotideColourScheme
public PurinePyrimidineColourScheme()
{
super(ResidueProperties.purinepyrimidineIndex,
- ResidueProperties.purinepyrimidine, 0);
+ ResidueProperties.purinepyrimidine);
}
- /**
- * Finds the corresponding color for the type of character inputed
- *
- * @param c
- * Character in sequence
- *
- * @return Color from purinepyrimidineIndex in
- * jalview.schemes.ResidueProperties
- */
- public Color findColour(char c)
+ @Override
+ public boolean isNucleotideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
{
- return colors[ResidueProperties.purinepyrimidineIndex[c]];
+ return JalviewColourScheme.PurinePyrimidine.toString();
}
/**
- * Returns color based on conservation
- *
- * @param c
- * Character in sequence
- * @param j
- * Threshold
- *
- * @return Color in RGB
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
*/
- public Color findColour(char c, int j)
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
{
- Color currentColour;
- if ((threshold == 0) || aboveThreshold(c, j))
- {
- try
- {
- currentColour = colors[ResidueProperties.purinepyrimidineIndex[c]];
- } catch (Exception ex)
- {
- return Color.white;
- }
- }
- else
- {
- return Color.white;
- }
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
-
- return currentColour;
+ return new PurinePyrimidineColourScheme();
}
}
package jalview.schemes;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
public AlignmentAnnotation annotation;
/**
+ * Default constructor (required for ColourSchemes cache)
+ */
+ public RNAHelicesColour()
+ {
+
+ }
+
+ /**
* Creates a new RNAHelicesColour object.
*/
public RNAHelicesColour(AlignmentAnnotation annotation)
}
@Override
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
- return new RNAHelicesColour(this);
+ return new RNAHelicesColour(sg);
+ }
+
+ @Override
+ public boolean isNucleotideSpecific()
+ {
+ return true;
+ }
+
+ /**
+ * Answers true if the data has RNA secondary structure annotation
+ */
+ @Override
+ public boolean isApplicableTo(AnnotatedCollectionI ac)
+ {
+ if (ac instanceof AlignmentI && ((AlignmentI) ac).hasRNAStructure())
+ {
+ return true;
+ }
+
+ /*
+ * not currently supporting this option for group annotation / colouring
+ */
+ return false;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.RNAHelices.toString();
+ }
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
}
-}
\ No newline at end of file
+}
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.SequenceGroup;
-import java.awt.event.ActionEvent;
import java.util.Hashtable;
+import java.util.Map;
import java.util.Vector;
/**
* change colors based on covariation.
*
* @author Lauren Michelle Lui
- *
+ * @deprecated this seems to be unfinished - just use RNAHelicesColour
*/
+@Deprecated
public class RNAHelicesColourChooser
{
ColourSchemeI oldcs;
- Hashtable oldgroupColours;
+ Map<SequenceGroup, ColourSchemeI> oldgroupColours;
- jalview.datamodel.AlignmentAnnotation currentAnnotation;
+ AlignmentAnnotation currentAnnotation;
boolean adjusting = false;
oldcs = av.getGlobalColourScheme();
if (av.getAlignment().getGroups() != null)
{
- oldgroupColours = new Hashtable();
+ oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
for (SequenceGroup sg : ap.getAlignment().getGroups())
{
- if (sg.cs != null)
+ if (sg.getColourScheme() != null)
{
- oldgroupColours.put(sg, sg.cs);
+ oldgroupColours.put(sg, sg.getColourScheme());
}
}
}
this.av = av;
this.ap = ap;
- if (oldcs instanceof RNAHelicesColour)
- {
- RNAHelicesColour rhc = (RNAHelicesColour) oldcs;
-
- }
-
adjusting = true;
- Vector list = new Vector();
+ Vector<String> list = new Vector<String>();
int index = 1;
AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
if (anns != null)
}
adjusting = false;
-
changeColour();
-
}
void changeColour()
{
return;
}
- RNAHelicesColour rhc = null;
-
- rhc = new RNAHelicesColour(av.getAlignment());
+ RNAHelicesColour rhc = new RNAHelicesColour(av.getAlignment());
av.setGlobalColourScheme(rhc);
ap.paintAlignment(true);
}
-
- void reset()
- {
- av.setGlobalColourScheme(oldcs);
- if (av.getAlignment().getGroups() != null)
- {
- for (SequenceGroup sg : ap.getAlignment().getGroups())
- {
- sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
- }
- }
- }
-
- public void annotations_actionPerformed(ActionEvent e)
- {
- changeColour();
- }
-
}
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
import java.awt.Color;
+import java.util.Map;
public class RNAInteractionColourScheme extends ResidueColourScheme
{
super();
}
- /**
- * DOCUMENT ME!
- *
- * @param n
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
@Override
public Color findColour(char c)
{
- // System.out.println("called"); log.debug
+ // FIXME this is just a copy of NucleotideColourScheme
return colors[ResidueProperties.nucleotideIndex[c]];
}
- /**
- * DOCUMENT ME!
- *
- * @param n
- * DOCUMENT ME!
- * @param j
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
@Override
public Color findColour(char c, int j, SequenceI seq)
{
- Color currentColour;
- if ((threshold == 0) || aboveThreshold(c, j))
+ // FIXME this is just a copy of NucleotideColourScheme
+ Color currentColour = Color.white;
+ try
{
- try
- {
- currentColour = colors[ResidueProperties.nucleotideIndex[c]];
- } catch (Exception ex)
- {
- return Color.white;
- }
- }
- else
+ currentColour = colors[ResidueProperties.nucleotideIndex[c]];
+ } catch (Exception ex)
{
- return Color.white;
- }
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
}
return currentColour;
}
+
+ @Override
+ public boolean isNucleotideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return "RNA Interaction type";
+ }
+
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new RNAInteractionColourScheme();
+ }
}
*/
package jalview.schemes;
-import jalview.analysis.Conservation;
import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.ProfileI;
-import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.util.ColorUtils;
import jalview.util.Comparison;
-import jalview.util.MessageManager;
import java.awt.Color;
import java.util.Map;
/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
+ * Base class for residue-based colour schemes
*/
-public class ResidueColourScheme implements ColourSchemeI
+public abstract class ResidueColourScheme implements ColourSchemeI
{
- final int[] symbolIndex;
+ public static final String NONE = "None";
- boolean conservationColouring = false;
-
- Color[] colors = null;
-
- int threshold = 0;
-
- /* Set when threshold colouring to either pid_gaps or pid_nogaps */
- protected boolean ignoreGaps = false;
+ public static final String USER_DEFINED = "User Defined";
/*
- * Consensus data indexed by column
+ * lookup up by character value e.g. 'G' to the colors array index
+ * e.g. if symbolIndex['K'] = 11 then colors[11] is the colour for K
*/
- ProfilesI consensus;
+ final int[] symbolIndex;
/*
- * Conservation string as a char array
+ * colour for residue characters as indexed by symbolIndex
*/
- char[] conservation;
+ Color[] colors = null;
- /*
- * The conservation slider percentage setting
- */
- int inc = 30;
+ /* Set when threshold colouring to either pid_gaps or pid_nogaps */
+ protected boolean ignoreGaps = false;
/**
* Creates a new ResidueColourScheme object.
* ResidueProperties.aaIndex)
* @param colors
* colours for symbols in sequences
- * @param threshold
- * threshold for conservation shading
*/
- public ResidueColourScheme(int[] aaOrnaIndex, Color[] colours,
- int threshold)
+ public ResidueColourScheme(int[] aaOrnaIndex, Color[] colours)
{
symbolIndex = aaOrnaIndex;
this.colors = colours;
- this.threshold = threshold;
}
/**
/**
* Find a colour without an index in a sequence
*/
- @Override
public Color findColour(char c)
{
- return colors == null ? Color.white : colors[symbolIndex[c]];
- }
+ Color colour = Color.white;
- @Override
- public Color findColour(char c, int j, SequenceI seq)
- {
- Color currentColour;
-
- if (colors != null && symbolIndex != null && (threshold == 0)
- || aboveThreshold(c, j))
+ if (!Comparison.isGap(c) && colors != null && symbolIndex != null
+ && c < symbolIndex.length
+ && symbolIndex[c] < colors.length)
{
- currentColour = colors[symbolIndex[c]];
- }
- else
- {
- currentColour = Color.white;
- }
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
+ colour = colors[symbolIndex[c]];
}
- return currentColour;
+ return colour;
}
/**
- * Get the percentage threshold for this colour scheme
- *
- * @return Returns the percentage threshold
+ * Default is to call the overloaded method that ignores consensus. A colour
+ * scheme that depends on consensus (for example, Blosum62), should override
+ * this method instead.
*/
@Override
- public int getThreshold()
+ public Color findColour(char c, int j, SequenceI seq,
+ String consensusResidue, float pid)
{
- return threshold;
+ return findColour(c, j, seq);
}
/**
- * Sets the percentage consensus threshold value, and whether gaps are ignored
- * in percentage identity calculation
- *
- * @param consensusThreshold
- * @param ignoreGaps
- */
- @Override
- public void setThreshold(int consensusThreshold, boolean ignoreGaps)
- {
- threshold = consensusThreshold;
- this.ignoreGaps = ignoreGaps;
- }
-
- /**
- * Answers true if there is a consensus profile for the specified column, and
- * the given residue matches the consensus (or joint consensus) residue for
- * the column, and the percentage identity for the profile is equal to or
- * greater than the current threshold; else answers false. The percentage
- * calculation depends on whether or not we are ignoring gapped sequences.
- *
- * @param residue
- * @param column
- * (index into consensus profiles)
+ * Default implementation looks up the residue colour in a fixed scheme, or
+ * returns White if not found. Override this method for a colour scheme that
+ * depends on the column position or sequence.
*
+ * @param c
+ * @param j
+ * @param seq
* @return
- * @see #setThreshold(int, boolean)
*/
- public boolean aboveThreshold(char residue, int column)
- {
- if ('a' <= residue && residue <= 'z')
- {
- // TO UPPERCASE !!!
- // Faster than toUpperCase
- residue -= ('a' - 'A');
- }
-
- if (consensus == null)
- {
- return false;
- }
-
- ProfileI profile = consensus.get(column);
-
- /*
- * test whether this is the consensus (or joint consensus) residue
- */
- if (profile != null
- && profile.getModalResidue().contains(String.valueOf(residue)))
- {
- if (profile.getPercentageIdentity(ignoreGaps) >= threshold)
- {
- return true;
- }
- }
-
- return false;
- }
-
- @Override
- public boolean conservationApplied()
- {
- return conservationColouring;
- }
-
- @Override
- public void setConservationApplied(boolean conservationApplied)
- {
- conservationColouring = conservationApplied;
- }
-
- @Override
- public void setConservationInc(int i)
+ protected Color findColour(char c, int j, SequenceI seq)
{
- inc = i;
+ return findColour(c);
}
@Override
- public int getConservationInc()
+ public void alignmentChanged(AnnotatedCollectionI alignment,
+ Map<SequenceI, SequenceCollectionI> hiddenReps)
{
- return inc;
}
/**
- * DOCUMENT ME!
- *
- * @param consensus
- * DOCUMENT ME!
+ * Answers false if the colour scheme is nucleotide or peptide specific, and
+ * the data does not match, else true. Override to modify or extend this test
+ * as required.
*/
@Override
- public void setConsensus(ProfilesI consensus)
- {
- if (consensus == null)
- {
- return;
- }
-
- this.consensus = consensus;
- }
-
- @Override
- public void setConservation(Conservation cons)
+ public boolean isApplicableTo(AnnotatedCollectionI ac)
{
- if (cons == null)
+ if (!isPeptideSpecific() && !isNucleotideSpecific())
{
- conservationColouring = false;
- conservation = null;
+ return true;
}
- else
+ if (ac == null)
{
- conservationColouring = true;
- int iSize = cons.getConsSequence().getLength();
- conservation = new char[iSize];
- for (int i = 0; i < iSize; i++)
- {
- conservation[i] = cons.getConsSequence().getCharAt(i);
- }
+ return true;
}
-
- }
-
- /**
- * Applies a combination of column conservation score, and conservation
- * percentage slider, to 'bleach' out the residue colours towards white.
- * <p>
- * If a column is fully conserved (identical residues, conservation score 11,
- * shown as *), or all 10 physico-chemical properties are conserved
- * (conservation score 10, shown as +), then the colour is left unchanged.
- * <p>
- * Otherwise a 'bleaching' factor is computed and applied to the colour. This
- * is designed to fade colours for scores of 0-9 completely to white at slider
- * positions ranging from 18% - 100% respectively.
- *
- * @param currentColour
- * @param column
- *
- * @return bleached (or unmodified) colour
- */
- Color applyConservation(Color currentColour, int column)
- {
- if (conservation == null || conservation.length <= column)
- {
- return currentColour;
- }
- char conservationScore = conservation[column];
-
/*
- * if residues are fully conserved (* or 11), or all properties
- * are conserved (+ or 10), leave colour unchanged
+ * pop-up menu on selection group before group created
+ * (no alignment context)
*/
- if (conservationScore == '*' || conservationScore == '+'
- || conservationScore == (char) 10
- || conservationScore == (char) 11)
+ // TODO: add nucleotide flag to SequenceGroup?
+ if (ac instanceof SequenceGroup && ac.getContext() == null)
{
- return currentColour;
- }
-
- if (Comparison.isGap(conservationScore))
- {
- return Color.white;
+ return true;
}
/*
- * convert score 0-9 to a bleaching factor 1.1 - 0.2
+ * inspect the data context (alignment) for residue type
*/
- float bleachFactor = (11 - (conservationScore - '0')) / 10f;
+ boolean nucleotide = ac.isNucleotide();
/*
- * scale this up by 0-5 (percentage slider / 20)
- * as a result, scores of: 0 1 2 3 4 5 6 7 8 9
- * fade to white at slider value: 18 20 22 25 29 33 40 50 67 100%
+ * does data type match colour scheme type?
*/
- bleachFactor *= (inc / 20f);
+ return (nucleotide && isNucleotideSpecific())
+ || (!nucleotide && isPeptideSpecific());
+ }
- return ColorUtils.bleachColour(currentColour, bleachFactor);
+ /**
+ * Answers true if the colour scheme is normally only for peptide data
+ *
+ * @return
+ */
+ public boolean isPeptideSpecific()
+ {
+ return false;
}
- @Override
- public void alignmentChanged(AnnotatedCollectionI alignment,
- Map<SequenceI, SequenceCollectionI> hiddenReps)
+ /**
+ * Answers true if the colour scheme is normally only for nucleotide data
+ *
+ * @return
+ */
+ public boolean isNucleotideSpecific()
{
+ return false;
}
+ /**
+ * Default method returns true. Override this to return false in colour
+ * schemes that are not determined solely by the sequence symbol.
+ */
@Override
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
- Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+ public boolean isSimple()
{
- try
- {
- return getClass().newInstance();
- } catch (Exception q)
- {
- throw new Error(MessageManager.formatMessage(
- "error.implementation_error_cannot_duplicate_colour_scheme",
- new String[] { getClass().getName() }), q);
- }
+ return true;
}
}
-3, 3, 0, -1, -4 },
{ -2, -2, 1, 6, -3, 0, 2, -1, -1, -3, -4, -1, -3, -3, -1, 0, -1, -4,
-3, -3, 4, 1, -1, -4 },
- { 0, 3, -3, -3, 9, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, -1,
+ { 0, -3, -3, -3, 9, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, -1,
-2, -2, -1, -3, -3, -2, -4 },
{ -1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2, 1, 0, -3, -1, 0, -1, -2, -1,
-2, 0, 3, -1, -4 },
scoreMatrices.put("DNA", new ScoreMatrix("DNA", DNA, 1));
}
- public static final Color[] pidColours = { midBlue,
- new Color(153, 153, 255),
- // Color.lightGray,
- new Color(204, 204, 255), };
-
- public static final float[] pidThresholds = { 80, 60, 40, };
-
public static List<String> STOP = Arrays.asList("TGA", "TAA", "TAG");
public static String START = "ATG";
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
import java.awt.Color;
+import java.util.Map;
/**
* DOCUMENT ME!
/**
* DOCUMENT ME!
*
- * @param s
- * DOCUMENT ME!
- * @param j
+ * @param c
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
- @Override
- public Color findColour(char c, int j, SequenceI seq)
+ public Color makeColour(float c)
{
- if (threshold > 0)
- {
- if (!aboveThreshold(c, j))
- {
- return Color.white;
- }
- }
-
- if (jalview.util.Comparison.isGap(c))
- {
- return Color.white;
- }
-
- Color currentColour = colors[ResidueProperties.aaIndex[c]];
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
+ return new Color(c, (float) 0.0, (float) 1.0 - c);
+ }
- return currentColour;
+ @Override
+ public String getSchemeName()
+ {
+ return "Score";
}
/**
- * DOCUMENT ME!
- *
- * @param c
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
*/
- public Color makeColour(float c)
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
{
- return new Color(c, (float) 0.0, (float) 1.0 - c);
+ return new ScoreColourScheme(symbolIndex, scores, min, max);
}
}
package jalview.schemes;
import jalview.analysis.scoremodels.PairwiseSeqScoreModel;
-import jalview.api.analysis.ScoreModelI;
+import jalview.math.Matrix;
+import jalview.math.MatrixI;
-public class ScoreMatrix extends PairwiseSeqScoreModel implements
- ScoreModelI
+public class ScoreMatrix extends PairwiseSeqScoreModel
{
String name;
}
/**
+ * Answers the score for substituting first char in A1 with first char in A2
*
* @param A1
* @param A2
- * @return score for substituting first char in A1 with first char in A2
+ * @return
*/
public int getPairwiseScore(String A1, String A2)
{
return getPairwiseScore(A1.charAt(0), A2.charAt(0));
}
+ @Override
public int getPairwiseScore(char c, char d)
{
- int pog = 0;
+ int score = 0;
try
{
: ResidueProperties.nucleotideIndex[c];
int b = (type == 0) ? ResidueProperties.aaIndex[d]
: ResidueProperties.nucleotideIndex[d];
-
- pog = matrix[a][b];
+ score = matrix[a][b];
} catch (Exception e)
{
// System.out.println("Unknown residue in " + A1 + " " + A2);
}
- return pog;
+ return score;
}
/**
* pretty print the matrix
*/
+ @Override
public String toString()
{
return outputMatrix(false);
}
return sb.toString();
}
+
+ /**
+ * Computes an NxN matrix where N is the number of sequences, and entry [i, j]
+ * is sequence[i] pairwise multiplied with sequence[j], as a sum of scores
+ * computed using the current score matrix. For example
+ * <ul>
+ * <li>Sequences:</li>
+ * <li>FKL</li>
+ * <li>R-D</li>
+ * <li>QIA</li>
+ * <li>GWC</li>
+ * <li>Score matrix is BLOSUM62</li>
+ * <li>Gaps treated same as X (unknown)</li>
+ * <li>product [0, 0] = F.F + K.K + L.L = 6 + 5 + 4 = 15</li>
+ * <li>product [1, 1] = R.R + -.- + D.D = 5 + -1 + 6 = 10</li>
+ * <li>product [2, 2] = Q.Q + I.I + A.A = 5 + 4 + 4 = 13</li>
+ * <li>product [3, 3] = G.G + W.W + C.C = 6 + 11 + 9 = 26</li>
+ * <li>product[0, 1] = F.R + K.- + L.D = -3 + -1 + -3 = -8
+ * <li>and so on</li>
+ * </ul>
+ */
+ public MatrixI computePairwiseScores(String[] seqs)
+ {
+ double[][] values = new double[seqs.length][];
+ for (int row = 0; row < seqs.length; row++)
+ {
+ values[row] = new double[seqs.length];
+ for (int col = 0; col < seqs.length; col++)
+ {
+ int total = 0;
+ int width = Math.min(seqs[row].length(), seqs[col].length());
+ for (int i = 0; i < width; i++)
+ {
+ char c1 = seqs[row].charAt(i);
+ char c2 = seqs[col].charAt(i);
+ int score = getPairwiseScore(c1, c2);
+ total += score;
+ }
+ values[row][col] = total;
+ }
+ }
+ return new Matrix(values);
+ }
}
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
import java.awt.Color;
+import java.util.Map;
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
+ @Override
public Color makeColour(float c)
{
return new Color(c, c, (float) 1.0 - c);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Strand.toString();
+ }
+
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new StrandColourScheme();
+ }
}
import java.awt.Color;
import java.util.ArrayList;
import java.util.IdentityHashMap;
+import java.util.List;
import java.util.Map;
/**
*/
public class TCoffeeColourScheme extends ResidueColourScheme
{
+ IdentityHashMap<SequenceI, Color[]> seqMap;
- static final Color[] colors = { new Color(102, 102, 255), // #6666FF
- new Color(0, 255, 0), // #00FF00
- new Color(102, 255, 0), // #66FF00
- new Color(204, 255, 0), // #CCFF00
- new Color(255, 255, 0), // #FFFF00
- new Color(255, 204, 0), // #FFCC00
- new Color(255, 153, 0), // #FF9900
- new Color(255, 102, 0), // #FF6600
- new Color(255, 51, 0), // #FF3300
- new Color(255, 34, 0) // #FF2000
- };
+ /**
+ * Default constructor (required for Class.newInstance())
+ */
+ public TCoffeeColourScheme()
+ {
- IdentityHashMap<SequenceI, Color[]> seqMap;
+ }
/**
* the color scheme needs to look at the alignment to get and cache T-COFFEE
alignmentChanged(alignment, null);
}
+ /**
+ * Finds the TCoffeeScore annotation (if any) for each sequence and notes the
+ * annotation colour for each column position. The colours are fixed for
+ * scores 0-9 and are set when annotation is parsed.
+ *
+ * @see TCoffeeScoreFile#annotateAlignment(AlignmentI, boolean)
+ */
@Override
public void alignmentChanged(AnnotatedCollectionI alignment,
Map<SequenceI, SequenceCollectionI> hiddenReps)
// assume only one set of TCOFFEE scores - but could have more than one
// potentially.
- ArrayList<AlignmentAnnotation> annots = new ArrayList<AlignmentAnnotation>();
+ List<AlignmentAnnotation> annots = new ArrayList<AlignmentAnnotation>();
// Search alignment to get all tcoffee annotation and pick one set of
// annotation to use to colour seqs.
seqMap = new IdentityHashMap<SequenceI, Color[]>();
@Override
public Color findColour(char c, int j, SequenceI seq)
{
- Color[] cols;
-
- if (seqMap == null || (cols = seqMap.get(seq)) == null)
+ if (seqMap == null)
+ {
+ return Color.WHITE;
+ }
+ Color[] cols = seqMap.get(seq);
+ if (cols == null)
{
// see above TODO about computing a colour for each residue in each
// column: cc = _rcols[i][indexFor[c]];
}
@Override
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
return new TCoffeeColourScheme(sg);
}
+
+ /**
+ * Answers true if the data has TCoffee score annotation
+ */
+ @Override
+ public boolean isApplicableTo(AnnotatedCollectionI ac)
+ {
+ AnnotatedCollectionI alcontext = ac instanceof AlignmentI ? ac : ac
+ .getContext();
+ if (alcontext == null)
+ {
+ return false;
+ }
+ Iterable<AlignmentAnnotation> anns = alcontext
+ .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE);
+ return anns.iterator().hasNext();
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.TCoffee.toString();
+ }
+
+ @Override
+ public boolean isSimple()
+ {
+ return false;
+ }
}
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.util.Map;
+
public class TaylorColourScheme extends ResidueColourScheme
{
public TaylorColourScheme()
{
- super(ResidueProperties.aaIndex, ResidueProperties.taylor, 0);
+ super(ResidueProperties.aaIndex, ResidueProperties.taylor);
+ }
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Taylor.toString();
+ }
+
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new TaylorColourScheme();
}
}
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
import java.awt.Color;
+import java.util.Map;
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
+ @Override
public Color makeColour(float c)
{
return new Color(c, 1 - c, 1 - c);
}
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Turn.toString();
+ }
+
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new TurnColourScheme();
+ }
}
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
+import jalview.util.StringUtils;
import java.awt.Color;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.StringTokenizer;
public class UserColourScheme extends ResidueColourScheme
{
+ /*
+ * lookup (by symbol index) of lower case colours (if configured)
+ */
Color[] lowerCaseColours;
protected String schemeName;
}
@Override
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
- UserColourScheme usc = new UserColourScheme(colors);
- if (lowerCaseColours != null)
+ return new UserColourScheme(this);
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @return
+ */
+ protected UserColourScheme(UserColourScheme from)
+ {
+ this(from.colors);
+ schemeName = from.schemeName;
+ if (from.lowerCaseColours != null)
{
- usc.schemeName = new String(schemeName);
- usc.lowerCaseColours = new Color[lowerCaseColours.length];
- System.arraycopy(lowerCaseColours, 0, usc.lowerCaseColours, 0,
- lowerCaseColours.length);
+ lowerCaseColours = new Color[from.lowerCaseColours.length];
+ System.arraycopy(from.lowerCaseColours, 0, lowerCaseColours, 0,
+ from.lowerCaseColours.length);
}
- return usc;
}
+ /**
+ * Constructor for an animino acid colour scheme. The colour specification may
+ * be one of
+ * <ul>
+ * <li>an AWT colour name e.g. red</li>
+ * <li>an AWT hex rgb colour e.g. ff2288</li>
+ * <li>residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow</li>
+ * </ul>
+ *
+ * @param colour
+ */
public UserColourScheme(String colour)
{
super(ResidueProperties.aaIndex);
- Color col = getColourFromString(colour);
+
+ if (colour.contains("="))
+ {
+ /*
+ * a list of colours per residue(s)
+ */
+ parseAppletParameter(colour);
+ return;
+ }
+
+ Color col = ColorUtils.parseColourString(colour);
if (col == null)
{
System.out.println("Making colour from name: " + colour);
- col = createColourFromName(colour);
+ col = ColorUtils.createColourFromName(colour);
}
- colors = new Color[24];
- for (int i = 0; i < 24; i++)
+ setAll(col);
+ schemeName = colour;
+ }
+
+ /**
+ * Sets all symbols to the specified colour
+ *
+ * @param col
+ */
+ protected void setAll(Color col)
+ {
+ if (symbolIndex == null)
+ {
+ return;
+ }
+ int max = 0;
+ for (int index : symbolIndex)
+ {
+ max = Math.max(max, index);
+ }
+ colors = new Color[max + 1];
+ for (int i = 0; i <= max; i++)
{
colors[i] = col;
}
- schemeName = colour;
}
public Color[] getColours()
return schemeName;
}
- public static Color getColourFromString(String colour)
- {
- if (colour == null)
- {
- return null;
- }
- colour = colour.trim();
-
- Color col = null;
- try
- {
- int value = Integer.parseInt(colour, 16);
- col = new Color(value);
- } catch (NumberFormatException ex)
- {
- }
-
- if (col == null)
- {
- col = ColourSchemeProperty.getAWTColorFromName(colour);
- }
-
- if (col == null)
- {
- try
- {
- java.util.StringTokenizer st = new java.util.StringTokenizer(
- colour, ",");
- int r = Integer.parseInt(st.nextToken());
- int g = Integer.parseInt(st.nextToken());
- int b = Integer.parseInt(st.nextToken());
- col = new Color(r, g, b);
- } catch (Exception ex)
- {
- }
- }
-
- return col;
-
- }
-
- public static Color createColourFromName(String name)
+ /**
+ * Parse and save residue colours specified as (for example)
+ *
+ * <pre>
+ * D,E=red; K,R,H=0022FF; c=100,50,75
+ * </pre>
+ *
+ * This should be a semi-colon separated list of colours, which may be defined
+ * by colour name, hex value or comma-separated RGB triple. Each colour is
+ * defined for a comma-separated list of amino acid single letter codes. (Note
+ * that this also allows a colour scheme to be defined for ACGT, but not for
+ * U.)
+ *
+ * @param paramValue
+ */
+ void parseAppletParameter(String paramValue)
{
- int r, g, b;
-
- int lsize = name.length();
- int start = 0, end = lsize / 3;
-
- int rgbOffset = Math.abs(name.hashCode() % 10) * 15;
-
- r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
- start = end;
- end += lsize / 3;
- if (end > lsize)
- {
- end = lsize;
- }
+ setAll(Color.white);
- g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
-
- b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
-
- Color color = new Color(r, g, b);
-
- return color;
- }
-
- public void parseAppletParameter(String paramValue)
- {
- // TODO: need a function to generate appletParameter colour string from a
- // UCS
StringTokenizer st = new StringTokenizer(paramValue, ";");
StringTokenizer st2;
String token = null, colour, residues;
st2 = new StringTokenizer(residues, " ,");
while (st2.hasMoreTokens())
{
- token = st2.nextToken();
+ String residue = st2.nextToken();
- if (ResidueProperties.aaIndex[token.charAt(0)] == -1)
+ int colIndex = ResidueProperties.aaIndex[residue.charAt(0)];
+ if (colIndex == -1)
{
continue;
}
- int colIndex = ResidueProperties.aaIndex[token.charAt(0)];
-
- if (token.equalsIgnoreCase("lowerCase"))
+ if (residue.equalsIgnoreCase("lowerCase"))
{
if (lowerCaseColours == null)
{
- lowerCaseColours = new Color[23];
+ lowerCaseColours = new Color[colors.length];
}
- for (int i = 0; i < 23; i++)
+ for (int i = 0; i < lowerCaseColours.length; i++)
{
if (lowerCaseColours[i] == null)
{
- lowerCaseColours[i] = getColourFromString(colour);
+ lowerCaseColours[i] = ColorUtils.parseColourString(colour);
}
}
continue;
}
- if (token.equals(token.toLowerCase()))
+ if (residue.equals(residue.toLowerCase()))
{
if (lowerCaseColours == null)
{
- lowerCaseColours = new Color[23];
+ lowerCaseColours = new Color[colors.length];
}
- lowerCaseColours[colIndex] = getColourFromString(colour);
+ lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour);
}
else
{
- colors[colIndex] = getColourFromString(colour);
+ colors[colIndex] = ColorUtils.parseColourString(colour);
}
}
}
}
- @Override
- public Color findColour(char c, int j, SequenceI seq)
+ public void setLowerCaseColours(Color[] lcolours)
{
- Color currentColour;
- int index = ResidueProperties.aaIndex[c];
+ lowerCaseColours = lcolours;
+ }
- if ((threshold == 0) || aboveThreshold(c, j))
+ /**
+ * Returns the colour for the given residue character. If the residue is
+ * lower-case, and there is a specific colour defined for lower case, that
+ * colour is returned, else the colour for the upper case residue.
+ */
+ @Override
+ public Color findColour(char c)
+ {
+ if ('a' <= c && c <= 'z' && lowerCaseColours != null)
{
- if (lowerCaseColours != null && 'a' <= c && c <= 'z')
- {
- currentColour = lowerCaseColours[index];
- }
- else
+ Color colour = lowerCaseColours[symbolIndex[c]];
+ if (colour != null)
{
- currentColour = colors[index];
+ return colour;
}
}
- else
+ return super.findColour(c);
+ }
+
+ /**
+ * Answers the customised name of the colour scheme, if it has one, else
+ * "User Defined"
+ */
+ @Override
+ public String getSchemeName()
+ {
+ if (schemeName != null && schemeName.length() > 0)
{
- currentColour = Color.white;
+ return schemeName;
}
+ return "User Defined";
+ }
+
+ /**
+ * Generate an applet colour parameter like A,C,D=12ffe9;Q,W=2393fd;w=9178dd
+ *
+ * @return
+ */
+ public String toAppletParameter()
+ {
+ /*
+ * step 1: build a map from colours to the symbol(s) that have the colour
+ */
+ Map<Color, List<String>> colours = new HashMap<Color, List<String>>();
- if (conservationColouring)
+ for (char symbol = 'A'; symbol <= 'Z'; symbol++)
{
- currentColour = applyConservation(currentColour, j);
+ String residue = String.valueOf(symbol);
+ int index = symbolIndex[symbol];
+ Color c = colors[index];
+ if (c != null && !c.equals(Color.white))
+ {
+ if (colours.get(c) == null)
+ {
+ colours.put(c, new ArrayList<String>());
+ }
+ colours.get(c).add(residue);
+ }
+ if (lowerCaseColours != null)
+ {
+ c = lowerCaseColours[index];
+ if (c != null && !c.equals(Color.white))
+ {
+ residue = residue.toLowerCase();
+ if (colours.get(c) == null)
+ {
+ colours.put(c, new ArrayList<String>());
+ }
+ colours.get(c).add(residue);
+ }
+ }
}
- return currentColour;
- }
+ /*
+ * step 2: make a list of { A,G,R=12f9d6 } residues/colour specs
+ */
+ List<String> residueColours = new ArrayList<String>();
+ for (Entry<Color, List<String>> cols : colours.entrySet())
+ {
+ boolean first = true;
+ StringBuilder sb = new StringBuilder();
+ for (String residue : cols.getValue())
+ {
+ if (!first)
+ {
+ sb.append(",");
+ }
+ sb.append(residue);
+ first = false;
+ }
+ sb.append("=");
+ /*
+ * get color as hex value, dropping the alpha (ff) part
+ */
+ String hexString = Integer.toHexString(cols.getKey().getRGB())
+ .substring(2);
+ sb.append(hexString);
+ residueColours.add(sb.toString());
+ }
- public void setLowerCaseColours(Color[] lcolours)
- {
- lowerCaseColours = lcolours;
+ /*
+ * sort and output
+ */
+ Collections.sort(residueColours);
+ return StringUtils.listToDelimitedString(residueColours, ";");
}
-
}
*/
package jalview.schemes;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.util.Map;
+
/**
* DOCUMENT ME!
*
*/
public ZappoColourScheme()
{
- super(ResidueProperties.aaIndex, ResidueProperties.zappo, 0);
+ super(ResidueProperties.aaIndex, ResidueProperties.zappo);
+ }
+
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return JalviewColourScheme.Zappo.toString();
+ }
+
+ /**
+ * Returns a new instance of this colour scheme with which the given data may
+ * be coloured
+ */
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI coll,
+ Map<SequenceI, SequenceCollectionI> hrs)
+ {
+ return new ZappoColourScheme();
}
}
*/
package jalview.structures.models;
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
import jalview.api.StructureSelectionManagerProvider;
import jalview.api.structures.JalviewStructureDisplayI;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.io.DataSourceType;
+import jalview.schemes.ColourSchemeI;
import jalview.structure.AtomSpec;
import jalview.structure.StructureListener;
import jalview.structure.StructureMapping;
+import jalview.structure.StructureMappingcommandSet;
import jalview.structure.StructureSelectionManager;
import jalview.util.Comparison;
import jalview.util.MessageManager;
+import java.awt.Color;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
*/
protected String[] modelFileNames = null;
+ public String fileLoadingError;
+
/**
* Data bean class to simplify parameterisation in superposeStructures
*/
{
return null;
}
+
+ public abstract void setJalviewColourScheme(ColourSchemeI cs);
+
+ public abstract void superposeStructures(AlignmentI[] als, int[] alm,
+ ColumnSelection[] alc);
+
+ public abstract void setBackgroundColour(Color col);
+
+ protected abstract StructureMappingcommandSet[] getColourBySequenceCommands(
+ String[] files, SequenceRenderer sr, FeatureRenderer fr,
+ AlignmentI alignment);
+
+ /**
+ * returns the current featureRenderer that should be used to colour the
+ * structures
+ *
+ * @param alignment
+ *
+ * @return
+ */
+ public abstract FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment);
+
+ /**
+ * returns the current sequenceRenderer that should be used to colour the
+ * structures
+ *
+ * @param alignment
+ *
+ * @return
+ */
+ public abstract SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment);
+
+ protected abstract void colourBySequence(
+ StructureMappingcommandSet[] colourBySequenceCommands);
+
+ public abstract void colourByChain();
+
+ public abstract void colourByCharge();
+
+ /**
+ * colour any structures associated with sequences in the given alignment
+ * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
+ * if colourBySequence is enabled.
+ */
+ public void colourBySequence(AlignmentViewPanel alignmentv)
+ {
+ boolean showFeatures = alignmentv.getAlignViewport()
+ .isShowSequenceFeatures();
+ if (!colourBySequence || !isLoadingFinished())
+ {
+ return;
+ }
+ if (getSsm() == null)
+ {
+ return;
+ }
+ String[] files = getPdbFile();
+
+ SequenceRenderer sr = getSequenceRenderer(alignmentv);
+
+ FeatureRenderer fr = null;
+ if (showFeatures)
+ {
+ fr = getFeatureRenderer(alignmentv);
+ }
+ AlignmentI alignment = alignmentv.getAlignment();
+
+ StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands(
+ files, sr, fr, alignment);
+ colourBySequence(colourBySequenceCommands);
+ }
+
+ public boolean hasFileLoadingError()
+ {
+ return fileLoadingError != null && fileLoadingError.length() > 0;
+ }
}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.urls;
+
+import static jalview.util.UrlConstants.DB_ACCESSION;
+import static jalview.util.UrlConstants.DELIM;
+import static jalview.util.UrlConstants.SEP;
+import static jalview.util.UrlConstants.SEQUENCE_ID;
+
+import jalview.util.MessageManager;
+import jalview.util.UrlConstants;
+import jalview.util.UrlLink;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.StringTokenizer;
+
+/**
+ *
+ * Implements the UrlProviderI interface for a UrlProvider object which serves
+ * custom URLs defined by the user
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class CustomUrlProvider extends UrlProviderImpl
+{
+ // Default sequence URL link label for SRS
+ private static final String SRS_LABEL = "SRS";
+
+ // map of string ids to urlLinks (selected)
+ private HashMap<String, UrlLink> selectedUrls;
+
+ // map of string ids to urlLinks (not selected)
+ private HashMap<String, UrlLink> nonselectedUrls;
+
+ /**
+ * Construct UrlProvider for custom (user-entered) URLs
+ *
+ * @param inMenuUrlList
+ * list of URLs set to be displayed in menu, in form stored in Cache.
+ * i.e. SEP delimited string
+ * @param storedUrlList
+ * list of custom URLs entered by user but not currently displayed in
+ * menu, in form stored in Cache
+ */
+ public CustomUrlProvider(String inMenuUrlList, String storedUrlList)
+ {
+ try
+ {
+ selectedUrls = parseUrlStrings(inMenuUrlList);
+ nonselectedUrls = parseUrlStrings(storedUrlList);
+ } catch (Exception ex)
+ {
+ System.out
+ .println(ex.getMessage() + "\nError parsing sequence links");
+ }
+ }
+
+ /**
+ * Construct UrlProvider for custom (user-entered) URLs
+ *
+ * @param urlList
+ * list of URLs to be displayed in menu, as (label,url) pairs
+ * @param storedUrlList
+ * list of custom URLs entered by user but not currently displayed in
+ * menu, as (label,url) pairs
+ */
+ public CustomUrlProvider(Map<String, String> inMenuUrlList,
+ Map<String, String> storedUrlList)
+ {
+ try
+ {
+ selectedUrls = parseUrlList(inMenuUrlList);
+ nonselectedUrls = parseUrlList(storedUrlList);
+ } catch (Exception ex)
+ {
+ System.out
+ .println(ex.getMessage() + "\nError parsing sequence links");
+ }
+ }
+
+ private HashMap<String, UrlLink> parseUrlStrings(String urlStrings)
+ {
+ // cachedUrlList is in form <label>|<url>|<label>|<url>...
+ // parse cachedUrlList into labels (used as id) and url links
+ HashMap<String, UrlLink> urls = new HashMap<String, UrlLink>();
+
+ StringTokenizer st = new StringTokenizer(urlStrings, SEP);
+ while (st.hasMoreElements())
+ {
+ String name = st.nextToken();
+
+ if (!isMiriamId(name))
+ {
+ // this one of our custom urls
+ String url = st.nextToken();
+ // check for '|' within a regex
+ int rxstart = url.indexOf(DELIM + DB_ACCESSION + DELIM);
+ if (rxstart == -1)
+ {
+ rxstart = url.indexOf(DELIM + SEQUENCE_ID + DELIM);
+ }
+ while (rxstart == -1 && url.indexOf("/=" + DELIM) == -1
+ && st.hasMoreTokens())
+ {
+ url = url + SEP + st.nextToken();
+ }
+ urls.put(name, new UrlLink(name, url, name));
+ }
+ }
+ upgradeOldLinks(urls);
+ return urls;
+ }
+
+ private HashMap<String, UrlLink> parseUrlList(Map<String, String> urlList)
+ {
+ HashMap<String, UrlLink> urls = new HashMap<String, UrlLink>();
+ if (urlList == null)
+ {
+ return urls;
+ }
+
+ Iterator<Map.Entry<String, String>> it = urlList.entrySet().iterator();
+ while (it.hasNext())
+ {
+ Map.Entry<String, String> pair = it.next();
+ urls.put(pair.getKey(),
+ new UrlLink(pair.getKey(), pair.getValue(),
+ pair.getKey()));
+ }
+ upgradeOldLinks(urls);
+ return urls;
+ }
+
+ /*
+ * Upgrade any legacy links which may have been left lying around
+ */
+ private void upgradeOldLinks(HashMap<String, UrlLink> urls)
+ {
+ // upgrade old SRS link
+ if (urls.containsKey(SRS_LABEL))
+ {
+ urls.remove(SRS_LABEL);
+ UrlLink link = new UrlLink(UrlConstants.DEFAULT_STRING);
+ link.setLabel(UrlConstants.DEFAULT_LABEL);
+ urls.put(UrlConstants.DEFAULT_LABEL, link);
+ }
+ }
+
+ @Override
+ public List<String> getLinksForMenu()
+ {
+ List<String> links = new ArrayList<String>();
+ Iterator<Map.Entry<String, UrlLink>> it = selectedUrls.entrySet()
+ .iterator();
+ while (it.hasNext())
+ {
+ Map.Entry<String, UrlLink> pair = it.next();
+ links.add(pair.getValue().toString());
+ }
+ return links;
+ }
+
+ @Override
+ public List<UrlLinkDisplay> getLinksForTable()
+ {
+ ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
+ displayLinks = getLinksForTable(selectedUrls, true);
+ displayLinks.addAll(getLinksForTable(nonselectedUrls, false));
+ return displayLinks;
+ }
+
+ private ArrayList<UrlLinkDisplay> getLinksForTable(
+ HashMap<String, UrlLink> urlList, boolean selected)
+ {
+ return super.getLinksForTable(urlList, null, selected);
+ }
+
+ @Override
+ public boolean setPrimaryUrl(String id)
+ {
+ if (selectedUrls.containsKey(id))
+ {
+ primaryUrl = id;
+ }
+ else if (nonselectedUrls.containsKey(id))
+ {
+ primaryUrl = id;
+ }
+ else
+ {
+ primaryUrl = null;
+ }
+
+ return (primaryUrl != null);
+ }
+
+ @Override
+ public String writeUrlsAsString(boolean selected)
+ {
+ StringBuffer links = new StringBuffer();
+ HashMap<String, UrlLink> urls;
+ if (selected)
+ {
+ urls = selectedUrls;
+ }
+ else
+ {
+ urls = nonselectedUrls;
+ }
+ if (urls.size() > 0)
+ {
+ for (Entry<String, UrlLink> entry : urls.entrySet())
+ {
+ links.append(entry.getValue().toString());
+ links.append(SEP);
+ }
+
+ // remove last SEP
+ links.setLength(links.length() - 1);
+ }
+ else
+ {
+ urls.clear();
+ }
+ return links.toString();
+ }
+
+ @Override
+ public String getPrimaryUrl(String seqid)
+ {
+ String result = super.getPrimaryUrl(seqid, selectedUrls);
+ if (result == null)
+ {
+ result = super.getPrimaryUrl(seqid, nonselectedUrls);
+ }
+ return result;
+ }
+
+ @Override
+ public String getPrimaryUrlId()
+ {
+ return primaryUrl;
+ }
+
+ @Override
+ public String getPrimaryTarget(String seqid)
+ {
+ return selectedUrls.get(primaryUrl).getTarget();
+ }
+
+ @Override
+ public void setUrlData(List<UrlLinkDisplay> links)
+ {
+ HashMap<String, UrlLink> unselurls = new HashMap<String, UrlLink>();
+ HashMap<String, UrlLink> selurls = new HashMap<String, UrlLink>();
+
+ Iterator<UrlLinkDisplay> it = links.iterator();
+ while (it.hasNext())
+ {
+ UrlLinkDisplay link = it.next();
+
+ // MIRIAM ids will be handled by a different UrlProvider class
+ if (!isMiriamId(link.getId()))
+ {
+ // don't allow duplicate key names as entries will be overwritten
+ if (unselurls.containsKey(link.getId())
+ || selurls.containsKey(link.getId()))
+ {
+ throw new IllegalArgumentException(MessageManager.formatMessage(
+ "exception.url_cannot_have_duplicate_id", link.getId()));
+ }
+ if (link.getIsSelected())
+ {
+ selurls.put(link.getId(),
+ new UrlLink(link.getDescription(), link.getUrl(), link.getDescription()));
+ }
+ else
+ {
+ unselurls
+ .put(link.getId(),
+ new UrlLink(link.getDescription(), link.getUrl(), link
+ .getDescription()));
+ }
+ // sort out primary and selected ids
+ if (link.getIsPrimary())
+ {
+ setPrimaryUrl(link.getId());
+ }
+ }
+
+ }
+ nonselectedUrls = unselurls;
+ selectedUrls = selurls;
+ }
+
+ @Override
+ public String choosePrimaryUrl()
+ {
+ // unilaterally set the primary id to the EMBL_EBI link
+ if ((!nonselectedUrls.containsKey(UrlConstants.DEFAULT_LABEL))
+ && (!selectedUrls.containsKey(UrlConstants.DEFAULT_LABEL)))
+ {
+ UrlLink link = new UrlLink(UrlConstants.DEFAULT_STRING);
+ link.setLabel(UrlConstants.DEFAULT_LABEL);
+ selectedUrls.put(UrlConstants.DEFAULT_LABEL, link);
+ }
+ primaryUrl = UrlConstants.DEFAULT_LABEL;
+ return UrlConstants.DEFAULT_LABEL;
+ }
+
+ @Override
+ public boolean contains(String id)
+ {
+ return (selectedUrls.containsKey(id) || nonselectedUrls.containsKey(id));
+ }
+
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.urls;
+
+/**
+ * Holds settings for identifiers.org e.g. url, download location
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class IdOrgSettings
+{
+ private static String url;
+
+ private static String location;
+
+ public static void setUrl(String seturl)
+ {
+ url = seturl;
+ }
+
+ public static void setDownloadLocation(String setloc)
+ {
+ location = setloc;
+ }
+
+ public static String getUrl()
+ {
+ return url;
+ }
+
+ public static String getDownloadLocation()
+ {
+ return location;
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.urls;
+
+import static jalview.util.UrlConstants.DB_ACCESSION;
+import static jalview.util.UrlConstants.DELIM;
+import static jalview.util.UrlConstants.SEP;
+
+import jalview.util.UrlLink;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+/**
+ *
+ * Implements the UrlProviderI interface for a UrlProvider object which serves
+ * URLs from identifiers.org
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class IdentifiersUrlProvider extends UrlProviderImpl
+{
+
+ private static final String LOCAL_KEY = "Local";
+
+ private static final String ID_ORG_KEY = "identifiers.org";
+
+ // map of string ids to urls
+ private HashMap<String, UrlLink> urls;
+
+ // list of selected urls
+ private ArrayList<String> selectedUrls;
+
+ public IdentifiersUrlProvider(String cachedUrlList)
+ {
+ urls = readIdentifiers(IdOrgSettings.getDownloadLocation());
+ selectedUrls = new ArrayList<String>();
+ checkSelectionMatchesUrls(cachedUrlList);
+ }
+
+ /**
+ * Read data from an identifiers.org download file
+ *
+ * @param idFileName
+ * name of identifiers.org download file
+ * @return hashmap of identifiers.org data, keyed by MIRIAM id
+ */
+ private HashMap<String, UrlLink> readIdentifiers(
+ String idFileName)
+ {
+ JSONParser parser = new JSONParser();
+
+ // identifiers.org data
+ HashMap<String, UrlLink> idData = new HashMap<String, UrlLink>();
+
+ try
+ {
+ FileReader reader = new FileReader(idFileName);
+ String key = "";
+ JSONObject obj = (JSONObject) parser.parse(reader);
+ if (obj.containsKey(ID_ORG_KEY))
+ {
+ key = ID_ORG_KEY;
+ }
+ else if (obj.containsKey(LOCAL_KEY))
+ {
+ key = LOCAL_KEY;
+ }
+ else
+ {
+ System.out
+ .println("Unexpected key returned from identifiers jalview service");
+ return idData;
+ }
+
+ JSONArray jsonarray = (JSONArray) obj.get(key);
+
+ // loop over each entry in JSON array and build HashMap entry
+ for (int i = 0; i < jsonarray.size(); i++)
+ {
+ JSONObject item = (JSONObject) jsonarray.get(i);
+
+ String url = (String) item.get("url") + "/" + DELIM + DB_ACCESSION
+ + DELIM;
+ UrlLink link = new UrlLink((String) item.get("name"), url,
+ (String) item.get("prefix"));
+ idData.put((String) item.get("id"), link);
+ }
+ } catch (FileNotFoundException e)
+ {
+ e.printStackTrace();
+ idData.clear();
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ idData.clear();
+ } catch (ParseException e)
+ {
+ e.printStackTrace();
+ idData.clear();
+ }
+ return idData;
+ }
+
+ private void checkSelectionMatchesUrls(String cachedUrlList)
+ {
+ StringTokenizer st = new StringTokenizer(cachedUrlList, SEP);
+ while (st.hasMoreElements())
+ {
+ String id = st.nextToken();
+
+ if (isMiriamId(id))
+ {
+ // this is an identifiers.org MIRIAM id
+ if (urls.containsKey(id))
+ {
+ selectedUrls.add(id);
+ }
+ }
+ }
+
+ // reset defaultUrl in case it is no longer selected
+ setPrimaryUrl(primaryUrl);
+ }
+
+ @Override
+ public boolean setPrimaryUrl(String id)
+ {
+ if (urls.containsKey(id))
+ {
+ primaryUrl = id;
+ }
+ else
+ {
+ primaryUrl = null;
+ }
+
+ return urls.containsKey(id);
+ }
+
+ @Override
+ public String writeUrlsAsString(boolean selected)
+ {
+ if (!selected)
+ {
+ return ""; // we don't cache unselected identifiers.org urls
+ }
+
+ StringBuffer links = new StringBuffer();
+ if (!selectedUrls.isEmpty())
+ {
+ for (String k : selectedUrls)
+ {
+ links.append(k);
+ links.append(SEP);
+ }
+ // remove last SEP
+ links.setLength(links.length() - 1);
+ }
+ return links.toString();
+ }
+
+ @Override
+ public List<String> getLinksForMenu()
+ {
+ List<String> links = new ArrayList<String>();
+ for (String key : selectedUrls)
+ {
+ links.add(urls.get(key).toStringWithTarget());
+ }
+ return links;
+ }
+
+ @Override
+ public List<UrlLinkDisplay> getLinksForTable()
+ {
+ return super.getLinksForTable(urls, selectedUrls, false);
+ }
+
+ @Override
+ public void setUrlData(List<UrlLinkDisplay> links)
+ {
+ selectedUrls = new ArrayList<String>();
+
+ Iterator<UrlLinkDisplay> it = links.iterator();
+ while (it.hasNext())
+ {
+ UrlLinkDisplay link = it.next();
+
+ // Handle links with MIRIAM ids only
+ if (isMiriamId(link.getId()))
+ {
+ // select/deselect links accordingly and set default url
+ if (urls.containsKey(link.getId()))
+ {
+ if (link.getIsSelected())
+ {
+ selectedUrls.add(link.getId());
+ }
+ if (link.getIsPrimary())
+ {
+ setPrimaryUrl(link.getId());
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public String getPrimaryUrl(String seqid)
+ {
+ return super.getPrimaryUrl(seqid, urls);
+ }
+
+ @Override
+ public String getPrimaryUrlId()
+ {
+ return primaryUrl;
+ }
+
+ @Override
+ public String getPrimaryTarget(String seqid)
+ {
+ return null;
+ }
+
+ @Override
+ public String choosePrimaryUrl()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean contains(String id)
+ {
+ return (urls.containsKey(id));
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.urls;
+
+import jalview.util.MessageManager;
+import jalview.util.UrlLink;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * UrlLink table row definition
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+
+public class UrlLinkDisplay
+{
+ private String id; // id is not supplied to display, but used to identify
+ // entries when saved
+
+ private boolean isPrimary;
+
+ private boolean isSelected;
+
+ private UrlLink link;
+
+ // Headers for columns in table
+ private final static List<String> colNames = new ArrayList<String>()
+ {
+ {
+ add(MessageManager.formatMessage("label.database"));
+ add(MessageManager.formatMessage("label.name"));
+ add(MessageManager.formatMessage("label.url"));
+ add(MessageManager.formatMessage("label.inmenu"));
+ add(MessageManager.formatMessage("label.primary"));
+ add(MessageManager.formatMessage("label.id"));
+ }
+ };
+
+ // column positions
+ public final static int DATABASE = 0;
+
+ public final static int NAME = 1;
+
+ public final static int URL = 2;
+
+ public final static int SELECTED = 3;
+
+ public final static int PRIMARY = 4;
+
+ public final static int ID = 5;
+
+ public UrlLinkDisplay(String rowId, UrlLink rowLink,
+ boolean rowSelected, boolean rowDefault)
+ {
+ id = rowId;
+ isPrimary = rowDefault;
+ isSelected = rowSelected;
+
+ link = rowLink;
+ }
+
+ // getters/setters
+ public String getId()
+ {
+ return id;
+ }
+
+ public String getDescription()
+ {
+ return link.getLabel();
+ }
+
+ public String getDBName()
+ {
+ return link.getTarget();
+ }
+
+ public String getUrl()
+ {
+ return link.getUrlWithToken();
+ }
+
+ public boolean getIsPrimary()
+ {
+ return isPrimary;
+ }
+
+ public boolean getIsSelected()
+ {
+ return isSelected;
+ }
+
+ public void setDBName(String name)
+ {
+ link.setTarget(name);
+ }
+
+ public void setUrl(String rowUrl)
+ {
+ link = new UrlLink(getDescription(), rowUrl, getDBName());
+ }
+
+ public void setDescription(String desc)
+ {
+ link.setLabel(desc);
+ }
+
+ public void setIsDefault(boolean rowDefault)
+ {
+ isPrimary = rowDefault;
+ }
+
+ public void setIsSelected(boolean rowSelected)
+ {
+ isSelected = rowSelected;
+ }
+
+ public Object getValue(int index)
+ {
+ switch (index)
+ {
+ case ID:
+ return id;
+ case URL:
+ return getUrl();
+ case PRIMARY:
+ return isPrimary;
+ case SELECTED:
+ return isSelected;
+ case NAME:
+ return getDescription();
+ case DATABASE:
+ return getDBName();
+ default:
+ return null;
+ }
+ }
+
+ public void setValue(int index, Object value)
+ {
+ switch (index)
+ {
+ case ID:
+ id = (String) value;
+ break;
+ case URL:
+ setUrl((String) value);
+ break;
+ case PRIMARY:
+ isPrimary = (boolean) value;
+ break;
+ case SELECTED:
+ isSelected = (boolean) value;
+ break;
+ case NAME:
+ setDescription((String) value);
+ case DATABASE:
+ setDBName((String) value);
+ break;
+ default:
+ // do nothing
+ }
+ }
+
+ /**
+ * Identify editable columns
+ *
+ * @param index
+ * index of column
+ * @return whether column can be edited in table
+ */
+ public boolean isEditable(int index)
+ {
+ if (index == PRIMARY)
+ {
+ // primary link must not be a $DB_ACCESSION$ link
+ // so only allow editing if it is not
+ return (!link.usesDBAccession());
+ }
+ else if (index == SELECTED)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Get list of column names to display in UI
+ *
+ * @return column names
+ */
+ public static List<String> getDisplayColumnNames()
+ {
+ // Display names between DESCRIPTION and ID (excludes ID)
+ return colNames.subList(DATABASE, ID);
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.urls;
+
+import jalview.bin.Cache;
+import jalview.urls.api.UrlProviderI;
+import jalview.util.UrlLink;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.RowFilter.Entry;
+import javax.swing.event.TableModelEvent;
+import javax.swing.event.TableModelListener;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableModel;
+
+/**
+ * TableModel for UrlLinks table
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+
+public class UrlLinkTableModel extends AbstractTableModel
+{
+ // local storage of data
+ private List<UrlLinkDisplay> data;
+
+ // supplier of url data
+ private UrlProviderI dataProvider;
+
+ // list of columns to display in table in correct order
+ private List<String> displayColumns;
+
+ // row in table which is currently the primary
+ private int primaryRow;
+
+ /**
+ * UrlLinkTableModel constructor
+ *
+ * @param baseData
+ * base data set to be presented in table
+ * @param entryNames
+ * keys of entries in baseData's nested hashmap. Should match order
+ * in displayColNames
+ * @param displayColNames
+ * names of columns to display in order.
+ * @param keyColName
+ * name of column corresponding to keys in baseData
+ */
+ public UrlLinkTableModel(UrlProviderI baseData)
+ {
+ dataProvider = baseData;
+ data = baseData.getLinksForTable();
+ displayColumns = UrlLinkDisplay.getDisplayColumnNames();
+
+ // find the primary row
+ primaryRow = 0;
+ Iterator<UrlLinkDisplay> it = data.iterator();
+ while (it.hasNext())
+ {
+ if (it.next().getIsPrimary())
+ {
+ break;
+ }
+ else
+ {
+ primaryRow++;
+ }
+ }
+
+ // set up listener which updates data source when table changes
+ this.addTableModelListener(new TableModelListener()
+ {
+ @Override
+ public void tableChanged(TableModelEvent e)
+ {
+ try
+ {
+ // update the UrlProvider from data list
+ dataProvider.setUrlData(data);
+ } catch (IllegalArgumentException ex)
+ {
+ Cache.log.error(ex.getMessage());
+ }
+ }
+ });
+
+ }
+
+ @Override
+ public int getRowCount()
+ {
+ if (data == null)
+ {
+ return 0;
+ }
+ else
+ {
+ return data.size();
+ }
+ }
+
+ @Override
+ public int getColumnCount()
+ {
+ return displayColumns.size();
+ }
+
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex)
+ {
+ return data.get(rowIndex).getValue(columnIndex);
+ }
+
+ @Override
+ public boolean isCellEditable(int rowIndex, int columnIndex)
+ {
+ return data.get(rowIndex).isEditable(columnIndex);
+ }
+
+ /**
+ * Determine if a row is editable indirectly (rather than directly in table as
+ * in isCellEditable)
+ *
+ * @param rowIndex
+ * @return true if row can be edited indirectly
+ */
+ public boolean isRowEditable(int rowIndex)
+ {
+ // to edit, row must be a user entered row
+ return (dataProvider.isUserEntry(data.get(rowIndex).getId()));
+ }
+
+ /**
+ * Determine if a row is deletable
+ *
+ * @param rowIndex
+ * the row to be tested
+ * @return true if row can be deleted
+ */
+ public boolean isRowDeletable(int rowIndex)
+ {
+ // to delete, row must be a user entered row, and not the default row
+ return (dataProvider.isUserEntry(data.get(rowIndex).getId()) && !data
+ .get(rowIndex).getIsPrimary());
+ }
+
+ @Override
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex)
+ {
+ if (columnIndex == UrlLinkDisplay.PRIMARY)
+ {
+ // Default url column: exactly one row must always be true
+ if (rowIndex != primaryRow)
+ {
+ // selected row is not currently the default
+ // set the current default to false
+ data.get(primaryRow).setValue(columnIndex, false);
+ fireTableRowsUpdated(primaryRow, primaryRow);
+
+ // set the default to be the selected row
+ primaryRow = rowIndex;
+ data.get(rowIndex).setValue(columnIndex, aValue);
+
+ fireTableRowsUpdated(rowIndex, rowIndex);
+ }
+ }
+ else
+ {
+ data.get(rowIndex).setValue(columnIndex, aValue);
+ fireTableRowsUpdated(rowIndex, rowIndex);
+ }
+ }
+
+ @Override
+ public Class<?> getColumnClass(int columnIndex)
+ {
+ return getValueAt(0, columnIndex).getClass();
+ }
+
+ @Override
+ public String getColumnName(int columnIndex)
+ {
+ return displayColumns.get(columnIndex);
+ }
+
+ public void removeRow(int rowIndex)
+ {
+ // remove the row from data
+ data.remove(rowIndex);
+
+ // update default row
+ if (primaryRow > rowIndex)
+ {
+ primaryRow--;
+ }
+
+ // fire update which will update data source
+ fireTableRowsDeleted(rowIndex, rowIndex);
+ }
+
+ public int insertRow(String name, String url)
+ {
+ // add a row to the data
+ UrlLink link = new UrlLink(name, url, name);
+ UrlLinkDisplay u = new UrlLinkDisplay(name, link, true, false);
+ int index = data.size();
+ data.add(u);
+
+ // fire update which will update data source
+ fireTableRowsInserted(index, index);
+ return index;
+ }
+
+ public int getPrimaryColumn()
+ {
+ return UrlLinkDisplay.PRIMARY;
+ }
+
+ public int getNameColumn()
+ {
+ return UrlLinkDisplay.NAME;
+ }
+
+ public int getDatabaseColumn()
+ {
+ return UrlLinkDisplay.DATABASE;
+ }
+
+ public int getIdColumn()
+ {
+ return UrlLinkDisplay.ID;
+ }
+
+ public int getUrlColumn()
+ {
+ return UrlLinkDisplay.URL;
+ }
+
+ public int getSelectedColumn()
+ {
+ return UrlLinkDisplay.SELECTED;
+ }
+
+ public boolean isUserEntry(
+ Entry<? extends TableModel, ? extends Object> entry)
+ {
+ return dataProvider
+ .isUserEntry(entry.getStringValue(UrlLinkDisplay.ID));
+ }
+
+ public boolean isUniqueName(String name)
+ {
+ return !dataProvider.contains(name);
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.urls;
+
+import static jalview.util.UrlConstants.SEP;
+
+import jalview.urls.api.UrlProviderI;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ *
+ * Implements the UrlProviderI interface for a composite UrlProvider object
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class UrlProvider implements UrlProviderI
+{
+ // List of actual URL link providers
+ private List<UrlProviderI> providers;
+
+ // Specific reference to custom URL link provider
+ private UrlProviderI customProvider;
+
+ /**
+ * Constructor for UrlProvider composite
+ *
+ * @param defaultUrlString
+ * id of default url
+ * @param allProviders
+ * list of UrlProviders this provider gives access to
+ */
+ public UrlProvider(String defaultUrlString,
+ List<UrlProviderI> allProviders)
+ {
+ providers = allProviders;
+
+ customProvider = findCustomProvider();
+
+ // check that the defaultUrl still exists
+ if (!contains(defaultUrlString))
+ {
+ // if the defaultUrl can't be found in any of the providers
+ // set up a custom default url
+ choosePrimaryUrl();
+ }
+ else
+ {
+ setPrimaryUrl(defaultUrlString);
+ }
+ }
+
+ /*
+ * Store ref to custom url provider
+ */
+ private UrlProviderI findCustomProvider()
+ {
+ for (UrlProviderI p : providers)
+ {
+ if (p instanceof CustomUrlProvider)
+ {
+ return p;
+ }
+ }
+
+ System.out
+ .println("Error initialising UrlProvider - no custom url provider");
+ return null;
+ }
+
+ @Override
+ public boolean setPrimaryUrl(String id)
+ {
+ boolean outcome = false;
+ for (UrlProviderI p : providers)
+ {
+ if (p.setPrimaryUrl(id))
+ {
+ outcome = true;
+ }
+ }
+ if (!outcome)
+ {
+ throw new IllegalArgumentException();
+ }
+ return outcome;
+ }
+
+ @Override
+ public boolean contains(String id)
+ {
+ boolean outcome = false;
+ for (UrlProviderI p : providers)
+ {
+ if (p.contains(id))
+ {
+ outcome = true;
+ }
+ }
+ return outcome;
+ }
+
+ @Override
+ public String writeUrlsAsString(boolean selected)
+ {
+ String result = "";
+ for (UrlProviderI p : providers)
+ {
+ String next = p.writeUrlsAsString(selected);
+ if (!next.isEmpty())
+ {
+ result += next;
+ result += SEP;
+ }
+ }
+ // remove last sep
+ if (!result.isEmpty())
+ {
+ result = result.substring(0, result.length() - 1);
+ }
+ return result;
+ }
+
+ @Override
+ public Vector<String> getLinksForMenu()
+ {
+ Vector<String> fullLinks = new Vector<String>();
+ for (UrlProviderI p : providers)
+ {
+ List<String> links = p.getLinksForMenu();
+ if (links != null)
+ {
+ // will obliterate links with same keys from different providers
+ // must have checks in place to prevent user from duplicating ids
+ fullLinks.addAll(links);
+ }
+ }
+ return fullLinks;
+ }
+
+ @Override
+ public List<UrlLinkDisplay> getLinksForTable()
+ {
+ ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
+ for (UrlProviderI p : providers)
+ {
+ displayLinks.addAll(p.getLinksForTable());
+ }
+ return displayLinks;
+ }
+
+ @Override
+ public void setUrlData(List<UrlLinkDisplay> links)
+ {
+ for (UrlProviderI p : providers)
+ {
+ p.setUrlData(links);
+ }
+ }
+
+ @Override
+ public String getPrimaryUrl(String seqid)
+ {
+ String link = null;
+ for (UrlProviderI p : providers)
+ {
+ if (p.getPrimaryUrl(seqid) == null)
+ {
+ continue;
+ }
+ else
+ {
+ link = p.getPrimaryUrl(seqid);
+ break;
+ }
+ }
+ return link;
+ }
+
+ @Override
+ public String getPrimaryUrlId()
+ {
+ String id = null;
+ for (UrlProviderI p : providers)
+ {
+ if (p.getPrimaryUrlId() == null)
+ {
+ continue;
+ }
+ else
+ {
+ id = p.getPrimaryUrlId();
+ break;
+ }
+ }
+ return id;
+ }
+
+ @Override
+ public String getPrimaryTarget(String seqid)
+ {
+ String target = null;
+ for (UrlProviderI p : providers)
+ {
+ if (p.getPrimaryTarget(seqid) == null)
+ {
+ continue;
+ }
+ else
+ {
+ target = p.getPrimaryTarget(seqid);
+ break;
+ }
+ }
+ return target;
+ }
+
+ @Override
+ public String choosePrimaryUrl()
+ {
+ // choose a custom url default
+ return customProvider.choosePrimaryUrl();
+ }
+
+ @Override
+ public boolean isUserEntry(String id)
+ {
+ return customProvider.isUserEntry(id);
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.urls;
+
+import jalview.urls.api.UrlProviderI;
+import jalview.util.UrlLink;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.regex.Pattern;
+
+/**
+ * Leaf node of UrlProvider composite
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+
+public abstract class UrlProviderImpl implements UrlProviderI
+{
+ // minimum length of substitution in url link string
+ protected static final int MIN_SUBST_LENGTH = 4;
+
+ private static final Pattern MIRIAM_PATTERN = Pattern
+ .compile("^MIR:\\d{8}$");
+
+ protected String primaryUrl;
+
+ protected String getPrimaryUrl(String seqid, HashMap<String, UrlLink> urls)
+ {
+ if (seqid.length() < MIN_SUBST_LENGTH)
+ {
+ return null;
+ }
+ else if (primaryUrl == null)
+ {
+ return null;
+ }
+ else if (!urls.containsKey(primaryUrl))
+ {
+ return null;
+ }
+ else
+ {
+ String url = null;
+ UrlLink urlLink = urls.get(primaryUrl);
+ String[] primaryUrls = urlLink.makeUrls(seqid, true);
+ if (primaryUrls == null || primaryUrls[0] == null
+ || primaryUrls[0].length() < MIN_SUBST_LENGTH)
+ {
+ url = null;
+ }
+ else
+ {
+ // just take first URL made from regex
+ url = primaryUrls[1];
+ }
+ return url;
+ }
+ }
+
+ @Override
+ public List<UrlLinkDisplay> getLinksForTable()
+ {
+ return null;
+ }
+
+ protected ArrayList<UrlLinkDisplay> getLinksForTable(
+ HashMap<String, UrlLink> urls, ArrayList<String> selectedUrls,
+ boolean selected)
+ {
+ ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
+ for (Entry<String, UrlLink> entry : urls.entrySet())
+ {
+ String key = entry.getKey();
+ boolean isPrimary = (key.equals(primaryUrl));
+ boolean isSelected;
+ if (selectedUrls != null)
+ {
+ isSelected = selectedUrls.contains(key);
+ }
+ else
+ {
+ isSelected = selected;
+ }
+ displayLinks.add(new UrlLinkDisplay(key, entry.getValue(),
+ isSelected, isPrimary));
+ }
+ return displayLinks;
+ }
+
+ protected boolean isMiriamId(String id)
+ {
+ return MIRIAM_PATTERN.matcher(id).matches();
+ }
+
+ @Override
+ public boolean isUserEntry(String id)
+ {
+ return !isMiriamId(id);
+ }
+}
+
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.urls.api;
+
+
+/**
+ * Interface to UrlProvider factories
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public interface UrlProviderFactoryI
+{
+ public UrlProviderI createUrlProvider();
+
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.urls.api;
+
+import jalview.urls.UrlLinkDisplay;
+
+import java.util.List;
+
+/**
+ * Methods for providing consistent access to up-to-date URLs
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public interface UrlProviderI
+{
+
+ /**
+ * Get names and urls in the UrlProvider as strings for display
+ *
+ */
+ List<String> getLinksForMenu();
+
+ /**
+ * Get names and urls as strings for display
+ *
+ */
+ List<UrlLinkDisplay> getLinksForTable();
+
+ /**
+ * Set names and urls from display settings
+ */
+ void setUrlData(List<UrlLinkDisplay> links);
+
+ /**
+ * Get the link for the primary URL
+ *
+ * @seqid sequence id for which to build link
+ * @return link for the primary URL
+ */
+ String getPrimaryUrl(String seqid);
+
+ /**
+ * Get the primary URL id
+ *
+ * @return id for primary URL
+ */
+ String getPrimaryUrlId();
+
+ /**
+ * Get the target of the link for the primary URL
+ *
+ * @seqid sequence id for which to build link
+ * @return target of link for the primary URL
+ */
+ String getPrimaryTarget(String seqid);
+
+ /**
+ * Set the primary URL: if only one URL can be used, this URL is the one which
+ * should be chosen, e.g. provides the URL to be used on double-click of a
+ * sequence id
+ *
+ * @param id
+ * the id of the URL to set as primary
+ * @return true if setting is successful
+ * @throws IllegalArgumentException
+ * if id does not exist as a url in the UrlProvider
+ */
+ boolean setPrimaryUrl(String id) throws IllegalArgumentException;
+
+ /**
+ * Test if UrlProvider contains a url
+ *
+ * @param id
+ * to test for
+ * @return true of UrlProvider contains this id, false otherwise
+ */
+ boolean contains(String id);
+
+ /**
+ * Write out all URLs as a string suitable for serialising
+ *
+ * @return string representation of available URLs
+ */
+ String writeUrlsAsString(boolean selected);
+
+ /**
+ * Choose the primary URL in the event of the selected primary being
+ * unavailable
+ *
+ * @return id of chosen primary url
+ */
+ String choosePrimaryUrl();
+
+ /**
+ * Determine if id is for a user-defined URL
+ */
+ boolean isUserEntry(String id);
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.urls.applet;
+
+import jalview.urls.CustomUrlProvider;
+import jalview.urls.UrlProvider;
+import jalview.urls.api.UrlProviderFactoryI;
+import jalview.urls.api.UrlProviderI;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * UrlProvider factory for applet code
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+
+public class AppletUrlProviderFactory implements UrlProviderFactoryI
+{
+ private String provDefaultUrl;
+
+ private Map<String, String> provUrlList;
+
+ public AppletUrlProviderFactory(String defaultUrlString,
+ Map<String, String> urlList)
+ {
+ provDefaultUrl = defaultUrlString;
+ provUrlList = urlList;
+ }
+
+ @Override
+ public UrlProviderI createUrlProvider()
+ {
+ // create all the UrlProviders we need
+ List<UrlProviderI> providers = new ArrayList<UrlProviderI>();
+ UrlProviderI customProvider = new CustomUrlProvider(provUrlList, null);
+ providers.add(customProvider);
+
+ UrlProviderI prov = new UrlProvider(provDefaultUrl, providers);
+ return prov;
+ }
+
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.urls.desktop;
+
+import jalview.urls.CustomUrlProvider;
+import jalview.urls.IdentifiersUrlProvider;
+import jalview.urls.UrlProvider;
+import jalview.urls.api.UrlProviderFactoryI;
+import jalview.urls.api.UrlProviderI;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * UrlProvider factory for desktop code
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+
+public class DesktopUrlProviderFactory implements UrlProviderFactoryI
+{
+
+ private String provDefaultUrl;
+
+ private String menuUrlList;
+
+ private String nonMenuUrlList;
+
+ public DesktopUrlProviderFactory(String defaultUrlString,
+ String cachedUrlList, String userUrlList)
+ {
+ provDefaultUrl = defaultUrlString;
+ menuUrlList = cachedUrlList;
+ nonMenuUrlList = userUrlList;
+ }
+
+ @Override
+ public UrlProviderI createUrlProvider()
+ {
+ // create all the UrlProviders we need
+ List<UrlProviderI> providers = new ArrayList<UrlProviderI>();
+
+ UrlProviderI idProvider = new IdentifiersUrlProvider(menuUrlList);
+ UrlProviderI customProvider = new CustomUrlProvider(menuUrlList,
+ nonMenuUrlList);
+ providers.add(idProvider);
+ providers.add(customProvider);
+
+ return new UrlProvider(provDefaultUrl, providers);
+ }
+
+}
return new Color(red, green, blue);
}
}
+
+ /**
+ * Parses a string into a Color, where the accepted formats are
+ * <ul>
+ * <li>an AWT colour name e.g. white</li>
+ * <li>a hex colour value (without prefix) e.g. ff0000</li>
+ * <li>an rgb triple e.g. 100,50,150</li>
+ * </ul>
+ *
+ * @param colour
+ * @return the parsed colour, or null if parsing fails
+ */
+ public static Color parseColourString(String colour)
+ {
+ if (colour == null)
+ {
+ return null;
+ }
+ colour = colour.trim();
+
+ Color col = null;
+ try
+ {
+ int value = Integer.parseInt(colour, 16);
+ col = new Color(value);
+ } catch (NumberFormatException ex)
+ {
+ }
+
+ if (col == null)
+ {
+ col = ColorUtils.getAWTColorFromName(colour);
+ }
+
+ if (col == null)
+ {
+ try
+ {
+ String[] tokens = colour.split(",");
+ if (tokens.length == 3)
+ {
+ int r = Integer.parseInt(tokens[0].trim());
+ int g = Integer.parseInt(tokens[1].trim());
+ int b = Integer.parseInt(tokens[2].trim());
+ col = new Color(r, g, b);
+ }
+ } catch (Exception ex)
+ {
+ // non-numeric token or out of 0-255 range
+ }
+ }
+
+ return col;
+ }
+
+ /**
+ * Constructs a colour from a text string. The hashcode of the whole string is
+ * scaled to the range 0-135. This is added to RGB values made from the
+ * hashcode of each third of the string, and scaled to the range 20-229.
+ *
+ * @param name
+ * @return
+ */
+ public static Color createColourFromName(String name)
+ {
+ if (name == null)
+ {
+ return Color.white;
+ }
+ int lsize = name.length();
+ int start = 0;
+ int end = lsize / 3;
+
+ int rgbOffset = Math.abs(name.hashCode() % 10) * 15; // 0-135
+
+ /*
+ * red: first third
+ */
+ int r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
+ start = end;
+ end += lsize / 3;
+ if (end > lsize)
+ {
+ end = lsize;
+ }
+
+ /*
+ * green: second third
+ */
+ int g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
+
+ /*
+ * blue: third third
+ */
+ int b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
+
+ Color color = new Color(r, g, b);
+
+ return color;
+ }
+
+ /**
+ * Returns the Color constant for a given colour name e.g. "pink", or null if
+ * the name is not recognised
+ *
+ * @param name
+ * @return
+ */
+ public static Color getAWTColorFromName(String name)
+ {
+ if (name == null)
+ {
+ return null;
+ }
+ Color col = null;
+ name = name.toLowerCase();
+
+ // or make a static map; or use reflection on the field name
+ switch (name)
+ {
+ case "black":
+ col = Color.black;
+ break;
+ case "blue":
+ col = Color.blue;
+ break;
+ case "cyan":
+ col = Color.cyan;
+ break;
+ case "darkgray":
+ col = Color.darkGray;
+ break;
+ case "gray":
+ col = Color.gray;
+ break;
+ case "green":
+ col = Color.green;
+ break;
+ case "lightgray":
+ col = Color.lightGray;
+ break;
+ case "magenta":
+ col = Color.magenta;
+ break;
+ case "orange":
+ col = Color.orange;
+ break;
+ case "pink":
+ col = Color.pink;
+ break;
+ case "red":
+ col = Color.red;
+ break;
+ case "white":
+ col = Color.white;
+ break;
+ case "yellow":
+ col = Color.yellow;
+ break;
+ }
+
+ return col;
+ }
}
*/
package jalview.util;
-import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.gui.EPSOptions;
import jalview.gui.IProgressIndicator;
{
return null;
}
- return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
- PNG_EXTENSION, PNG_DESCRIPTION);
+ return new JalviewFileChooser(PNG_EXTENSION, PNG_DESCRIPTION);
}
static JalviewFileChooser getEPSChooser()
{
return null;
}
- return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
- EPS_EXTENSION, EPS_DESCRIPTION);
+ return new JalviewFileChooser(EPS_EXTENSION, EPS_DESCRIPTION);
}
private void setProgressMessage(String message)
{
return null;
}
- return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
- SVG_EXTENSION, SVG_DESCRIPTION);
+ return new JalviewFileChooser(SVG_EXTENSION, SVG_DESCRIPTION);
}
}
* Copy group name, colours etc, but not sequences or sequence colour scheme
*/
SequenceGroup mappedGroup = new SequenceGroup(sg);
- mappedGroup.cs = mapTo.getGlobalColourScheme();
+ mappedGroup.setColourScheme(mapTo.getGlobalColourScheme());
mappedGroup.clear();
int minStartCol = -1;
public ParseHtmlBodyAndLinks(String description, boolean removeHTML,
String newline)
{
- StringBuilder sb = new StringBuilder(description.length());
if (description == null || description.length() == 0)
{
htmlContent = false;
return;
}
+ StringBuilder sb = new StringBuilder(description.length());
if (description.toUpperCase().indexOf("<HTML>") == -1)
{
htmlContent = false;
public static final String SEQUENCE_ID = "SEQUENCE_ID";
/*
- * Default sequence URL link string for EMBL-EBI search
+ * Separator character used in Url links
+ */
+ public static final String SEP = "|";
+
+ /*
+ * Delimiter character used in Url links
*/
- public static final String EMBLEBI_STRING = "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$";
+ public static final String DELIM = "$";
/*
- * Default sequence URL link string for SRS
+ * Default sequence URL link label for EMBL-EBI search
+ */
+ public static final String DEFAULT_LABEL = "EMBL-EBI Search";
+
+ /*
+ * Default sequence URL link string for EMBL-EBI search
*/
- public static final String SRS_STRING = "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry";
+ public static final String DEFAULT_STRING = DEFAULT_LABEL
+ + "|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$";
/*
* not instantiable
package jalview.util;
import static jalview.util.UrlConstants.DB_ACCESSION;
+import static jalview.util.UrlConstants.DELIM;
+import static jalview.util.UrlConstants.SEP;
import static jalview.util.UrlConstants.SEQUENCE_ID;
import jalview.datamodel.DBRefEntry;
* documentation todo.
*/
- // Internal constants
- private static final String SEP = "|";
+ private static final String EQUALS = "=";
- private static final String DELIM = "$";
+ private static final String SPACE = " ";
private String urlSuffix;
private String label;
+ private String dbname;
+
private String regexReplace;
private boolean dynamic = false;
dynamic = true;
usesDBaccession = true;
- sep = parseTargetAndLabel(sep, psqid, link);
+ sep = parseLabel(sep, psqid, link);
- parseUrl(link, DB_ACCESSION, psqid, sep);
+ int endOfRegex = parseUrl(link, DB_ACCESSION, psqid, sep);
+ parseTarget(link, sep, endOfRegex);
}
else if (nsqid > -1)
{
dynamic = true;
- sep = parseTargetAndLabel(sep, nsqid, link);
+ sep = parseLabel(sep, nsqid, link);
+
+ int endOfRegex = parseUrl(link, SEQUENCE_ID, nsqid, sep);
- parseUrl(link, SEQUENCE_ID, nsqid, sep);
+ parseTarget(link, sep, endOfRegex);
}
else
{
- target = link.substring(0, sep);
- sep = link.lastIndexOf(SEP);
- label = link.substring(0, sep);
- urlPrefix = link.substring(sep + 1).trim();
+ label = link.substring(0, sep).trim();
+
+ // if there's a third element in the url link string
+ // it is the target name, otherwise target=label
+ int lastsep = link.lastIndexOf(SEP);
+ if (lastsep != sep)
+ {
+ urlPrefix = link.substring(sep + 1, lastsep).trim();
+ target = link.substring(lastsep + 1).trim();
+ }
+ else
+ {
+ urlPrefix = link.substring(sep + 1).trim();
+ target = label;
+ }
+
regexReplace = null; // implies we trim any prefix if necessary //
urlSuffix = null;
}
}
/**
+ * Alternative constructor for separate name, link and description
+ *
+ * @param name
+ * The string used to match the link to a DB reference id
+ * @param url
+ * The url to link to
+ * @param desc
+ * The description of the associated target DB
+ */
+ public UrlLink(String name, String url, String desc)
+ {
+ this(name + SEP + url + SEP + desc);
+ }
+
+ /**
* @return the url_suffix
*/
- public String getUrl_suffix()
+ public String getUrlSuffix()
{
return urlSuffix;
}
/**
* @return the url_prefix
*/
- public String getUrl_prefix()
+ public String getUrlPrefix()
{
return urlPrefix;
}
return label;
}
+ public String getUrlWithToken()
+ {
+ String var = (usesDBaccession ? DB_ACCESSION : SEQUENCE_ID);
+
+ return urlPrefix
+ + (dynamic ? (DELIM + var + ((regexReplace != null) ? EQUALS
+ + regexReplace + EQUALS + DELIM : DELIM)) : "")
+ + ((urlSuffix == null) ? "" : urlSuffix);
+ }
+
/**
* @return the regexReplace
*/
}
/**
+ * Set the target
+ *
+ * @param desc
+ */
+ public void setTarget(String desc)
+ {
+ target = desc;
+ }
+
+ /**
* return one or more URL strings by applying regex to the given idstring
*
* @param idstring
+ rg.stringMatched(s) + "'");
}
// try to collate subgroup matches
- Vector subs = new Vector();
+ Vector<String> subs = new Vector<String>();
// have to loop through submatches, collating them at top level
// match
int s = 0; // 1;
String[] res = new String[subs.size()];
for (int r = 0, rs = subs.size(); r < rs; r++)
{
- res[r] = (String) subs.elementAt(r);
+ res[r] = subs.elementAt(r);
}
subs.removeAllElements();
return res;
@Override
public String toString()
{
- String var = (usesDBaccession ? DB_ACCESSION : SEQUENCE_ID);
+ return label + SEP + getUrlWithToken();
+ }
- return label
- + SEP
- + urlPrefix
- + (dynamic ? (DELIM + var + ((regexReplace != null) ? "="
- + regexReplace + "=" + DELIM : DELIM)) : "")
- + ((urlSuffix == null) ? "" : urlSuffix);
+ /**
+ * @return delimited string containing label, url and target
+ */
+ public String toStringWithTarget()
+ {
+ return label + SEP + getUrlWithToken() + SEP + target;
}
/**
+ * Parse the label from the link string
*
* @param firstSep
* Location of first occurrence of separator in link string
* Link string containing database name and url
* @return Position of last separator symbol prior to any regex symbols
*/
- protected int parseTargetAndLabel(int firstSep, int psqid, String link)
+ protected int parseLabel(int firstSep, int psqid, String link)
{
int p = firstSep;
int sep = firstSep;
// Assuming that the URL itself does not contain any SEP symbols
// sep now contains last pipe symbol position prior to any regex symbols
label = link.substring(0, sep);
- if (label.indexOf(SEP) > -1)
- {
- // SEP terminated database name / www target at start of Label
- target = label.substring(0, label.indexOf(SEP));
- }
- else if (label.indexOf(" ") > 2)
+
+ return sep;
+ }
+
+ /**
+ * Parse the target from the link string
+ *
+ * @param link
+ * Link string containing database name and url
+ * @param sep
+ * Location of first separator symbol
+ * @param endOfRegex
+ * Location of end of any regular expression in link string
+ */
+ protected void parseTarget(String link, int sep, int endOfRegex)
+ {
+ int lastsep = link.lastIndexOf(SEP);
+
+ if ((lastsep != sep) && (lastsep > endOfRegex))
{
- // space separated Label - matches database name
- target = label.substring(0, label.indexOf(" "));
+ // final element in link string is the target
+ target = link.substring(lastsep + 1).trim();
}
else
{
target = label;
}
- return sep;
+
+ if (target.indexOf(SEP) > -1)
+ {
+ // SEP terminated database name / www target at start of Label
+ target = target.substring(0, target.indexOf(SEP));
+ }
+ else if (target.indexOf(SPACE) > 2)
+ {
+ // space separated label - first word matches database name
+ target = target.substring(0, target.indexOf(SPACE));
+ }
}
/**
* Position of id or name in link string
* @param sep
* Position of separator in link string
+ * @return Location of end of any regex in link string
*/
- protected void parseUrl(String link, String varName, int sqidPos, int sep)
+ protected int parseUrl(String link, String varName, int sqidPos, int sep)
{
urlPrefix = link.substring(sep + 1, sqidPos).trim();
// verify format is really correct.
if (link.indexOf(DELIM + varName + DELIM) == sqidPos)
{
- urlSuffix = link.substring(sqidPos + startLength - 1);
+ int lastsep = link.lastIndexOf(SEP);
+ if (lastsep < sqidPos + startLength - 1)
+ {
+ // the last SEP character was before the regex, ignore
+ lastsep = link.length();
+ }
+ urlSuffix = link.substring(sqidPos + startLength - 1, lastsep)
+ .trim();
regexReplace = null;
}
else
+ link;
}
}
+
+ return p;
}
/**
*/
protected void createStaticLink(Map<String, List<String>> linkset)
{
- if (!linkset.containsKey(label + SEP + getUrl_prefix()))
+ if (!linkset.containsKey(label + SEP + getUrlPrefix()))
{
// Add a non-dynamic link
- linkset.put(label + SEP + getUrl_prefix(),
- Arrays.asList(target, label, null, getUrl_prefix()));
+ linkset.put(label + SEP + getUrlPrefix(),
+ Arrays.asList(target, label, null, getUrlPrefix()));
}
}
}
}
}
-
- private static void testUrls(UrlLink ul, String idstring, String[] urls)
- {
-
- if (urls == null)
- {
- System.out.println("Created NO urls.");
- }
- else
- {
- System.out.println("Created " + (urls.length / 2) + " Urls.");
- for (int uls = 0; uls < urls.length; uls += 2)
- {
- System.out.println("URL Replacement text : " + urls[uls]
- + " : URL : " + urls[uls + 1]);
- }
- }
- }
-
- public static void main(String argv[])
- {
- String[] links = new String[] {
- /*
- * "AlinkT|Target|http://foo.foo.soo/",
- * "myUrl1|http://$SEQUENCE_ID=/[0-9]+/=$.someserver.org/foo",
- * "myUrl2|http://$SEQUENCE_ID=/(([0-9]+).+([A-Za-z]+))/=$.someserver.org/foo"
- * ,
- * "myUrl3|http://$SEQUENCE_ID=/([0-9]+).+([A-Za-z]+)/=$.someserver.org/foo"
- * , "myUrl4|target|http://$SEQUENCE_ID$.someserver.org/foo|too",
- * "PF1|http://us.expasy.org/cgi-bin/niceprot.pl?$SEQUENCE_ID=/(?:PFAM:)?(.+)/=$"
- * ,
- * "PF2|http://us.expasy.org/cgi-bin/niceprot.pl?$SEQUENCE_ID=/(PFAM:)?(.+)/=$"
- * ,
- * "PF3|http://us.expasy.org/cgi-bin/niceprot.pl?$SEQUENCE_ID=/PFAM:(.+)/=$"
- * , "NOTFER|http://notfer.org/$SEQUENCE_ID=/(?<!\\s)(.+)/=$",
- */
- "NESTED|http://nested/$" + DB_ACCESSION
- + "=/^(?:Label:)?(?:(?:gi\\|(\\d+))|([^:]+))/=$/nested" };
- String[] idstrings = new String[] {
- /*
- * //"LGUL_human", //"QWIQW_123123", "uniprot|why_do+_12313_foo",
- * //"123123312", "123123 ABCDE foo", "PFAM:PF23943",
- */
- "Label:gi|9234|pdb|102L|A" };
- // TODO: test the setLabel method.
- for (int i = 0; i < links.length; i++)
- {
- UrlLink ul = new UrlLink(links[i]);
- if (ul.isValid())
- {
- System.out.println("\n\n\n");
- System.out.println("Link " + i + " " + links[i] + " : "
- + ul.toString());
- System.out.println(" pref : "
- + ul.getUrl_prefix()
- + "\n suf : "
- + ul.getUrl_suffix()
- + "\n : "
- + ((ul.getRegexReplace() != null) ? ul.getRegexReplace()
- : ""));
- for (int ids = 0; ids < idstrings.length; ids++)
- {
- System.out.println("ID String : " + idstrings[ids]
- + "\nWithout onlyIfMatches:");
- String[] urls = ul.makeUrls(idstrings[ids], false);
- testUrls(ul, idstrings[ids], urls);
- System.out.println("With onlyIfMatches set.");
- urls = ul.makeUrls(idstrings[ids], true);
- testUrls(ul, idstrings[ids], urls);
- }
- }
- else
- {
- System.err.println("Invalid URLLink : " + links[i] + " : "
- + ul.getInvalidMessage());
- }
- }
- }
}
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.schemes.Blosum62ColourScheme;
+import jalview.renderer.ResidueShader;
+import jalview.renderer.ResidueShaderI;
import jalview.schemes.ColourSchemeI;
-import jalview.schemes.PIDColourScheme;
import jalview.structure.CommandListener;
import jalview.structure.StructureSelectionManager;
import jalview.structure.VamsasSource;
protected boolean ignoreGapsInConsensusCalculation = false;
- protected ColourSchemeI globalColourScheme = null;
+ protected ResidueShaderI residueShading;
@Override
public void setGlobalColourScheme(ColourSchemeI cs)
// TODO: logic refactored from AlignFrame changeColour -
// TODO: autorecalc stuff should be changed to rely on the worker system
// check to see if we should implement a changeColour(cs) method rather than
- // put th logic in here
+ // put the logic in here
// - means that caller decides if they want to just modify state and defer
// calculation till later or to do all calculations in thread.
// via changecolour
- globalColourScheme = cs;
- boolean recalc = false;
+
+ /*
+ * only instantiate alignment colouring once, thereafter update it;
+ * this means that any conservation or PID threshold settings
+ * persist when the alignment colour scheme is changed
+ */
+ if (residueShading == null)
+ {
+ residueShading = new ResidueShader(viewStyle);
+ }
+ residueShading.setColourScheme(cs);
+
+ // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
+ // ...problem: groups need these, but do not currently have a ViewStyle
+
if (cs != null)
{
- recalc = getConservationSelected();
- if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
- || cs instanceof Blosum62ColourScheme)
- {
- recalc = true;
- cs.setThreshold(viewStyle.getThreshold(),
- ignoreGapsInConsensusCalculation);
- }
- else
+ if (getConservationSelected())
{
- cs.setThreshold(0, ignoreGapsInConsensusCalculation);
+ residueShading.setConservation(hconservation);
}
- if (recalc)
- {
- cs.setConsensus(hconsensus);
- cs.setConservation(hconservation);
- }
- cs.setConservationApplied(getConservationSelected());
- cs.alignmentChanged(alignment, hiddenRepSequences);
+ residueShading.alignmentChanged(alignment, hiddenRepSequences);
}
+
+ /*
+ * if 'apply colour to all groups' is selected... do so
+ * (but don't transfer any colour threshold settings to groups)
+ */
if (getColourAppliesToAllGroups())
{
for (SequenceGroup sg : getAlignment().getGroups())
{
- if (cs == null)
- {
- sg.cs = null;
- continue;
- }
- sg.cs = cs.applyTo(sg, getHiddenRepSequences());
- sg.setConsPercGaps(ConsPercGaps);
- if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
- || cs instanceof Blosum62ColourScheme)
- {
- sg.cs.setThreshold(viewStyle.getThreshold(),
- isIgnoreGapsConsensus());
- recalc = true;
- }
- else
+ /*
+ * retain any colour thresholds per group while
+ * changing choice of colour scheme (JAL-2386)
+ */
+ sg.setColourScheme(cs);
+ if (cs != null)
{
- sg.cs.setThreshold(0, isIgnoreGapsConsensus());
- }
-
- if (getConservationSelected())
- {
- sg.cs.setConservationApplied(true);
- recalc = true;
- }
- else
- {
- sg.cs.setConservation(null);
- // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
- }
- if (recalc)
- {
- sg.recalcConservation();
- }
- else
- {
- sg.cs.alignmentChanged(sg, hiddenRepSequences);
+ sg.getGroupColourScheme()
+ .alignmentChanged(sg, hiddenRepSequences);
}
}
}
@Override
public ColourSchemeI getGlobalColourScheme()
{
- return globalColourScheme;
+ return residueShading == null ? null : residueShading
+ .getColourScheme();
+ }
+
+ @Override
+ public ResidueShaderI getResidueShading()
+ {
+ return residueShading;
}
protected AlignmentAnnotation consensus;
hconsensus = null;
hcomplementConsensus = null;
// colour scheme may hold reference to consensus
- globalColourScheme = null;
+ residueShading = null;
// TODO remove listeners from changeSupport?
changeSupport = null;
setAlignment(null);
}
/**
- * Set the selection group for this window.
+ * Set the selection group for this window. Also sets the current alignment as
+ * the context for the group, if it does not already have one.
*
* @param sg
* - group holding references to sequences in this alignment view
public void setSelectionGroup(SequenceGroup sg)
{
selectionGroup = sg;
+ if (sg != null && sg.getContext() == null)
+ {
+ sg.setContext(alignment);
+ }
}
public void setHiddenColumns(ColumnSelection colsel)
if (ap != null)
{
updateConsensus(ap);
- if (globalColourScheme != null)
+ if (residueShading != null)
{
- globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
+ residueShading.setThreshold(residueShading.getThreshold(),
ignoreGapsInConsensusCalculation);
}
}
selectionGroup.setEndRes(alWidth - 1);
}
- resetAllColourSchemes();
+ updateAllColourSchemes();
calculator.restartWorkers();
// alignment.adjustSequenceAnnotations();
}
/**
* reset scope and do calculations for all applied colourschemes on alignment
*/
- void resetAllColourSchemes()
+ void updateAllColourSchemes()
{
- ColourSchemeI cs = globalColourScheme;
- if (cs != null)
+ ResidueShaderI rs = residueShading;
+ if (rs != null)
{
- cs.alignmentChanged(alignment, hiddenRepSequences);
+ rs.alignmentChanged(alignment, hiddenRepSequences);
- cs.setConsensus(hconsensus);
- if (cs.conservationApplied())
+ rs.setConsensus(hconsensus);
+ if (rs.conservationApplied())
{
- cs.setConservation(Conservation.calculateConservation("All",
+ rs.setConservation(Conservation.calculateConservation("All",
alignment.getSequences(), 0, alignment.getWidth(), false,
getConsPercGaps(), false));
}
public void setViewStyle(ViewStyleI settingsForView)
{
viewStyle = new ViewStyle(settingsForView);
+ if (residueShading != null)
+ {
+ residueShading.setConservationApplied(settingsForView
+ .isConservationColourSelected());
+ }
}
@Override
public class PCAModel
{
+ /*
+ * Jalview 2.10.1 treated gaps as X (peptide) or N (nucleotide)
+ * for pairwise scoring; 2.10.2 uses gap score (last column) in
+ * score matrix (JAL-2397)
+ * Set this flag to true (via Groovy) for 2.10.1 behaviour
+ */
+ private static boolean scoreGapAsAny = false;
public PCAModel(AlignmentView seqstrings2, SequenceI[] seqs2,
boolean nucleotide2)
public void run()
{
-
- pca = new PCA(seqstrings.getSequenceStrings(' '), nucleotide,
+ char gapChar = scoreGapAsAny ? (nucleotide ? 'N' : 'X') : ' ';
+ String[] sequenceStrings = seqstrings.getSequenceStrings(gapChar);
+ pca = new PCA(sequenceStrings, nucleotide,
score_matrix);
pca.setJvCalcMode(jvCalcMode);
pca.run();
ii++;
}
- double[][] comps = new double[ii][ii];
-
- for (int i = 0; i < ii; i++)
- {
- if (pca.getEigenvalue(i) > 1e-4)
- {
- comps[i] = pca.component(i);
- }
- }
-
- top = pca.getM().rows - 1;
+ int height = pca.getHeight();
+ // top = pca.getM().height() - 1;
+ top = height - 1;
points = new Vector<SequencePoint>();
float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
- for (int i = 0; i < pca.getM().rows; i++)
+ for (int i = 0; i < height; i++)
{
SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
points.addElement(sp);
}
-
}
public void updateRc(RotatableCanvasI rc)
{
- rc.setPoints(points, pca.getM().rows);
+ rc.setPoints(points, pca.getHeight());
}
public boolean isNucleotide()
// note: actual indices for components are dim1-1, etc (patch for JAL-1123)
float[][] scores = pca.getComponents(dim1 - 1, dim2 - 1, dim3 - 1, 100);
- for (int i = 0; i < pca.getM().rows; i++)
+ for (int i = 0; i < pca.getHeight(); i++)
{
- ((SequencePoint) points.elementAt(i)).coord = scores[i];
+ points.elementAt(i).coord = scores[i];
}
}
import jalview.datamodel.SequenceI;
import jalview.renderer.seqfeatures.FeatureRenderer;
import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
import java.awt.Color;
import java.beans.PropertyChangeListener;
FeatureColourI fc = featureColours.get(featureType);
if (fc == null)
{
- Color col = UserColourScheme.createColourFromName(featureType);
+ Color col = ColorUtils.createColourFromName(featureType);
fc = new FeatureColour(col);
featureColours.put(featureType, fc);
}
import jalview.datamodel.Annotation;
import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceI;
-import jalview.schemes.ColourSchemeI;
+import jalview.renderer.ResidueShaderI;
public class ConsensusThread extends AlignCalcWorker
{
*/
protected void setColourSchemeConsensus(ProfilesI hconsensus)
{
- ColourSchemeI globalColourScheme = alignViewport
- .getGlobalColourScheme();
- if (globalColourScheme != null)
+ ResidueShaderI cs = alignViewport.getResidueShading();
+ if (cs != null)
{
- globalColourScheme.setConsensus(hconsensus);
+ cs.setConsensus(hconsensus);
}
}
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
import jalview.schemes.FeatureColour;
-import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
import jalview.ws.jws2.jabaws2.Jws2Instance;
import jalview.ws.params.WsParamSetI;
annot.description += "<br/>" + threshNote;
}
annot.description += "</html>";
- Color col = UserColourScheme.createColourFromName(typeName
+ Color col = ColorUtils.createColourFromName(typeName
+ scr.getMethod());
for (int p = 0, ps = annot.annotations.length; p < ps; p++)
{
@Override
public List<String> getURLEncodedParameter()
{
- ArrayList<String> prms = new ArrayList<String>();
- prms.add("format='" + format + "'");
+ List<String> prms = new ArrayList<String>();
+ prms.add("format='" + format.getName() + "'");
if (type != null)
{
prms.add("type='" + type.toString() + "'");
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.ws.utils;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+
+public class UrlDownloadClient
+{
+ public UrlDownloadClient()
+ {
+
+ }
+
+ /**
+ * Download and save a file from a URL
+ *
+ * @param urlstring
+ * url to download from, as string
+ * @param outfile
+ * the name of file to save the URLs to
+ * @throws IOException
+ */
+ public void download(String urlstring, String outfile) throws IOException
+ {
+ FileOutputStream fos = null;
+ ReadableByteChannel rbc = null;
+ Path temp = null;
+ try
+ {
+ temp = Files.createTempFile(".jalview_", ".tmp");
+
+ URL url = new URL(urlstring);
+ rbc = Channels.newChannel(url.openStream());
+ fos = new FileOutputStream(temp.toString());
+ fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
+
+ // copy tempfile to outfile once our download completes
+ // incase something goes wrong
+ Files.copy(temp, Paths.get(outfile),
+ StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException e)
+ {
+ throw e;
+ } finally
+ {
+ try
+ {
+ if (fos != null)
+ {
+ fos.close();
+ }
+ } catch (IOException e)
+ {
+ System.out
+ .println("Exception while closing download file output stream: "
+ + e.getMessage());
+ }
+ try
+ {
+ if (rbc != null)
+ {
+ rbc.close();
+ }
+ } catch (IOException e)
+ {
+ System.out.println("Exception while closing download channel: "
+ + e.getMessage());
+ }
+ try
+ {
+ if (temp != null)
+ {
+ Files.deleteIfExists(temp);
+ }
+ } catch (IOException e)
+ {
+ System.out.println("Exception while deleting download temp file: "
+ + e.getMessage());
+ }
+ }
+ }
+}
AlignmentAnnotation ann = iter.next();
assertEquals("D.melanogaster.2", ann.sequenceRef.getName());
assertFalse(iter.hasNext());
+
+ // invalid id
+ anns = al.findAnnotation("CalcIdForD.melanogaster.?");
+ assertFalse(iter.hasNext());
+ anns = al.findAnnotation(null);
+ assertFalse(iter.hasNext());
}
@Test(groups = { "Functional" })
assertEquals("[10, 50]", Arrays.toString(hidden.get(0)));
assertEquals("[60, 70]", Arrays.toString(hidden.get(1)));
}
+
+ @Test(groups = { "Functional" })
+ public void testStretchGroup_expand()
+ {
+ /*
+ * test that emulates clicking column 4 (selected)
+ * and dragging right to column 5 (all base 0)
+ */
+ ColumnSelection cs = new ColumnSelection();
+ cs.addElement(4);
+ SequenceGroup sg = new SequenceGroup();
+ sg.setStartRes(4);
+ sg.setEndRes(4);
+ cs.stretchGroup(5, sg, 4, 4);
+ assertEquals(cs.getSelected().size(), 2);
+ assertTrue(cs.contains(4));
+ assertTrue(cs.contains(5));
+ assertEquals(sg.getStartRes(), 4);
+ assertEquals(sg.getEndRes(), 5);
+
+ /*
+ * emulate drag right with columns 10-20 already selected
+ */
+ cs.clear();
+ for (int i = 10; i <= 20; i++)
+ {
+ cs.addElement(i);
+ }
+ assertEquals(cs.getSelected().size(), 11);
+ sg = new SequenceGroup();
+ sg.setStartRes(10);
+ sg.setEndRes(20);
+ cs.stretchGroup(21, sg, 10, 20);
+ assertEquals(cs.getSelected().size(), 12);
+ assertTrue(cs.contains(10));
+ assertTrue(cs.contains(21));
+ assertEquals(sg.getStartRes(), 10);
+ assertEquals(sg.getEndRes(), 21);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testStretchGroup_shrink()
+ {
+ /*
+ * emulate drag left to 19 with columns 10-20 already selected
+ */
+ ColumnSelection cs = new ColumnSelection();
+ for (int i = 10; i <= 20; i++)
+ {
+ cs.addElement(i);
+ }
+ assertEquals(cs.getSelected().size(), 11);
+ SequenceGroup sg = new SequenceGroup();
+ sg.setStartRes(10);
+ sg.setEndRes(20);
+ cs.stretchGroup(19, sg, 10, 20);
+ assertEquals(cs.getSelected().size(), 10);
+ assertTrue(cs.contains(10));
+ assertTrue(cs.contains(19));
+ assertFalse(cs.contains(20));
+ assertEquals(sg.getStartRes(), 10);
+ assertEquals(sg.getEndRes(), 19);
+ }
}
--- /dev/null
+package jalview.datamodel;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import jalview.schemes.NucleotideColourScheme;
+
+import org.testng.annotations.Test;
+
+public class SequenceGroupTest
+{
+ @Test(groups={"Functional"})
+ public void testAddSequence()
+ {
+ SequenceGroup sg = new SequenceGroup();
+ assertTrue(sg.getSequences().isEmpty());
+
+ SequenceI seq1 = new Sequence("seq1", "abc");
+ SequenceI seq2 = new Sequence("seq2", "abc");
+ SequenceI seq3 = new Sequence(seq1);
+
+ sg.addSequence(null, false);
+ assertTrue(sg.getSequences().isEmpty());
+ sg.addSequence(seq1, false);
+ assertEquals(sg.getSequences().size(), 1);
+ assertTrue(sg.getSequences().contains(seq1));
+ // adding the same sequence again does nothing
+ sg.addSequence(seq1, false);
+ assertEquals(sg.getSequences().size(), 1);
+ assertTrue(sg.getSequences().contains(seq1));
+ sg.addSequence(seq2, false);
+ sg.addSequence(seq2, false);
+ sg.addSequence(seq3, false);
+ assertEquals(sg.getSequences().size(), 3);
+ assertTrue(sg.getSequences().contains(seq1));
+ assertTrue(sg.getSequences().contains(seq2));
+ assertTrue(sg.getSequences().contains(seq3));
+ }
+
+ @Test(groups={"Functional"})
+ public void testAddOrRemove()
+ {
+ SequenceGroup sg = new SequenceGroup();
+ assertTrue(sg.getSequences().isEmpty());
+
+ SequenceI seq1 = new Sequence("seq1", "abc");
+ SequenceI seq2 = new Sequence("seq2", "abc");
+ SequenceI seq3 = new Sequence(seq1);
+
+ sg.addOrRemove(seq1, false);
+ assertEquals(sg.getSequences().size(), 1);
+ sg.addOrRemove(seq2, false);
+ assertEquals(sg.getSequences().size(), 2);
+ sg.addOrRemove(seq3, false);
+ assertEquals(sg.getSequences().size(), 3);
+ assertTrue(sg.getSequences().contains(seq1));
+ assertTrue(sg.getSequences().contains(seq2));
+ assertTrue(sg.getSequences().contains(seq3));
+ sg.addOrRemove(seq1, false);
+ assertEquals(sg.getSequences().size(), 2);
+ assertFalse(sg.getSequences().contains(seq1));
+ }
+
+ @Test(groups={"Functional"})
+ public void testGetColourScheme()
+ {
+ SequenceGroup sg = new SequenceGroup();
+ assertNotNull(sg.getGroupColourScheme());
+ assertNull(sg.getColourScheme());
+
+ sg.setGroupColourScheme(null);
+ assertNull(sg.getColourScheme());
+
+ NucleotideColourScheme scheme = new NucleotideColourScheme();
+ sg.setColourScheme(scheme);
+ assertSame(scheme, sg.getColourScheme());
+ }
+
+ @Test(groups={"Functional"})
+ public void testSetContext()
+ {
+ SequenceGroup sg1 = new SequenceGroup();
+ SequenceGroup sg2 = new SequenceGroup();
+ SequenceGroup sg3 = new SequenceGroup();
+ assertNull(sg1.getContext());
+ sg1.setContext(null);
+ assertNull(sg1.getContext());
+ try
+ {
+ sg1.setContext(sg1); // self-reference :-O
+ fail("Expected exception");
+ } catch (IllegalArgumentException e)
+ {
+ // expected
+ assertNull(sg1.getContext());
+ }
+ sg1.setContext(sg2);
+ assertSame(sg2, sg1.getContext());
+ sg2.setContext(sg3);
+ try
+ {
+ sg3.setContext(sg1); // circular reference :-O
+ fail("Expected exception");
+ } catch (IllegalArgumentException e)
+ {
+ // expected
+ assertNull(sg3.getContext());
+ }
+ }
+
+ @Test(groups = { "Functional" })
+ public void testContains()
+ {
+ /*
+ * essentially the same tests as AlignmentI.findGroup
+ * but from a particular group's perspective
+ */
+
+ SequenceI seq1 = new Sequence("seq1", "ABCDEF---GHI");
+ SequenceI seq2 = new Sequence("seq2", "---JKLMNO---");
+ AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2 });
+ /*
+ * add a group consisting of just "DEF"
+ */
+ SequenceGroup sg1 = new SequenceGroup();
+ sg1.addSequence(seq1, false);
+ sg1.setStartRes(3);
+ sg1.setEndRes(5);
+
+ /*
+ * test sequence membership
+ */
+ assertTrue(sg1.contains(seq1));
+ assertFalse(sg1.contains(seq2));
+
+ /*
+ * test sequence+position
+ */
+
+ assertFalse(sg1.contains(seq1, 2)); // position not in group
+ assertFalse(sg1.contains(seq1, 6)); // position not in group
+ assertFalse(sg1.contains(seq2, 5)); // sequence not in group
+ assertTrue(sg1.contains(seq1, 3)); // yes
+ assertTrue(sg1.contains(seq1, 4));
+ assertTrue(sg1.contains(seq1, 5));
+
+ /*
+ * add a group consisting of
+ * EF--
+ * KLMN
+ */
+ SequenceGroup sg2 = new SequenceGroup();
+ sg2.addSequence(seq1, false);
+ sg2.addSequence(seq2, false);
+ sg2.setStartRes(4);
+ sg2.setEndRes(7);
+ a.addGroup(sg2);
+
+ /*
+ * if a residue is in more than one group, method returns
+ * the first found (in order groups were added)
+ */
+ assertTrue(sg2.contains(seq1, 4));
+ assertTrue(sg2.contains(seq1, 5));
+
+ /*
+ * seq2 only belongs to the second group
+ */
+ assertTrue(sg2.contains(seq2, 4));
+ assertTrue(sg2.contains(seq2, 5));
+ assertTrue(sg2.contains(seq2, 6));
+ assertTrue(sg2.contains(seq2, 7));
+ assertFalse(sg2.contains(seq2, 3));
+ assertFalse(sg2.contains(seq2, 8));
+ sg2.setEndRes(8);
+ assertTrue(sg2.contains(seq2, 8));
+ sg2.deleteSequence(seq2, false);
+ assertFalse(sg2.contains(seq2));
+
+ }
+}
--- /dev/null
+package jalview.ext.android;
+
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.Test;
+
+public class SparseDoubleArrayTest
+{
+
+ @Test
+ public void testConstructor()
+ {
+ double[] d = new double[] { 0d, 0d, 1.2d, 0d, 0d, 3.4d };
+ SparseDoubleArray s = new SparseDoubleArray(d);
+ for (int i = 0; i < d.length; i++)
+ {
+ assertEquals(s.get(i), d[i], "At [" + i + "]");
+ }
+ }
+
+ @Test
+ public void testAdd()
+ {
+ double[] d = new double[] { 0d, 0d, 1.2d, 0d, 0d, 3.4d };
+ SparseDoubleArray s = new SparseDoubleArray(d);
+ // add to zero (absent)
+ s.add(0, 3.2d);
+ assertEquals(s.get(0), 3.2d);
+ // add to non-zero
+ s.add(0, 2.5d);
+ assertEquals(s.get(0), 5.7d);
+ // add negative value
+ s.add(2, -5.3d);
+ assertEquals(s.get(2), -4.1d);
+ // add to unset value
+ s.add(12, 9.8d);
+ assertEquals(s.get(12), 9.8d);
+ }
+
+ @Test
+ public void testDivide()
+ {
+ double delta = 1.0e-10;
+ double[] d = new double[] { 0d, 2.4d, 1.2d, 0d, -4.8d, -3.6d };
+ SparseDoubleArray s = new SparseDoubleArray(d);
+ assertEquals(s.divide(0, 1d), 0d); // no such entry
+ assertEquals(s.divide(2, 0d), 0d); // zero divisor
+ assertEquals(s.divide(1, 2d), 1.2d, delta); // + / +
+ assertEquals(s.divide(2, -2d), -0.6d, delta); // + / -
+ assertEquals(s.divide(4, 3d), -1.6d, delta); // - / +
+ assertEquals(s.divide(5, -3d), 1.2d, delta); // - / -
+ }
+}
{
Map<Object, AtomSpecModel> map = new LinkedHashMap<Object, AtomSpecModel>();
- ChimeraCommands.addRange(map, Color.blue, 0, 2, 5, "A");
- ChimeraCommands.addRange(map, Color.blue, 0, 7, 7, "B");
- ChimeraCommands.addRange(map, Color.blue, 0, 9, 23, "A");
- ChimeraCommands.addRange(map, Color.blue, 1, 1, 1, "A");
- ChimeraCommands.addRange(map, Color.blue, 1, 4, 7, "B");
- ChimeraCommands.addRange(map, Color.yellow, 1, 8, 8, "A");
- ChimeraCommands.addRange(map, Color.yellow, 1, 3, 5, "A");
- ChimeraCommands.addRange(map, Color.red, 0, 3, 5, "A");
- ChimeraCommands.addRange(map, Color.red, 0, 6, 9, "A");
+ ChimeraCommands.addColourRange(map, Color.blue, 0, 2, 5, "A");
+ ChimeraCommands.addColourRange(map, Color.blue, 0, 7, 7, "B");
+ ChimeraCommands.addColourRange(map, Color.blue, 0, 9, 23, "A");
+ ChimeraCommands.addColourRange(map, Color.blue, 1, 1, 1, "A");
+ ChimeraCommands.addColourRange(map, Color.blue, 1, 4, 7, "B");
+ ChimeraCommands.addColourRange(map, Color.yellow, 1, 8, 8, "A");
+ ChimeraCommands.addColourRange(map, Color.yellow, 1, 3, 5, "A");
+ ChimeraCommands.addColourRange(map, Color.red, 0, 3, 5, "A");
+ ChimeraCommands.addColourRange(map, Color.red, 0, 6, 9, "A");
// Colours should appear in the Chimera command in the order in which
// they were added; within colour, by model, by chain, ranges in start order
* start with just one feature/value...
*/
featuresMap.put("chain", featureValues);
- ChimeraCommands.addRange(featureValues, "X", 0, 8, 20, "A");
+ ChimeraCommands.addColourRange(featureValues, "X", 0, 8, 20, "A");
List<String> commands = ChimeraCommands
.buildSetAttributeCommands(featuresMap);
assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:8-20.A");
// add same feature value, overlapping range
- ChimeraCommands.addRange(featureValues, "X", 0, 3, 9, "A");
+ ChimeraCommands.addColourRange(featureValues, "X", 0, 3, 9, "A");
// same feature value, contiguous range
- ChimeraCommands.addRange(featureValues, "X", 0, 21, 25, "A");
+ ChimeraCommands.addColourRange(featureValues, "X", 0, 21, 25, "A");
commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
assertEquals(1, commands.size());
assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:3-25.A");
// same feature value and model, different chain
- ChimeraCommands.addRange(featureValues, "X", 0, 21, 25, "B");
+ ChimeraCommands.addColourRange(featureValues, "X", 0, 21, 25, "B");
// same feature value and chain, different model
- ChimeraCommands.addRange(featureValues, "X", 1, 26, 30, "A");
+ ChimeraCommands.addColourRange(featureValues, "X", 1, 26, 30, "A");
commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
assertEquals(1, commands.size());
assertEquals(commands.get(0),
"setattr r jv_chain \"X\" #0:3-25.A,21-25.B|#1:26-30.A");
// same feature, different value
- ChimeraCommands.addRange(featureValues, "Y", 0, 40, 50, "A");
+ ChimeraCommands.addColourRange(featureValues, "Y", 0, 40, 50, "A");
commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
assertEquals(2, commands.size());
// commands are ordered by feature type but not by value
featuresMap.clear();
featureValues.clear();
featuresMap.put("side-chain binding!", featureValues);
- ChimeraCommands.addRange(featureValues, "metal ion!", 0, 7, 15, "A");
+ ChimeraCommands.addColourRange(featureValues, "metal ion!", 0, 7, 15,
+ "A");
// feature names are sanitised to change space or hyphen to underscore
commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
assertTrue(commands
*/
package jalview.gui;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+import jalview.bin.Cache;
+import jalview.bin.Jalview;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+import jalview.io.Jalview2xmlTests;
+import jalview.renderer.ResidueShaderI;
+import jalview.schemes.BuriedColourScheme;
+import jalview.schemes.HelixColourScheme;
+import jalview.schemes.JalviewColourScheme;
+import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TurnColourScheme;
+import jalview.util.MessageManager;
+import java.awt.Color;
import java.util.List;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class AlignFrameTest
{
+ AlignFrame af;
@BeforeClass(alwaysRun = true)
public void setUpJvOptionPane()
seq2.addSequenceFeature(new SequenceFeature("Turn", "", 7, 9,
Float.NaN, null));
AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
- AlignFrame af = new AlignFrame(al, al.getWidth(), al.getHeight());
+ AlignFrame alignFrame = new AlignFrame(al, al.getWidth(), al.getHeight());
/*
* hiding a feature not present does nothing
*/
- assertFalse(af.hideFeatureColumns("exon", true));
- assertTrue(af.getViewport().getColumnSelection().isEmpty());
- assertTrue(af.getViewport().getColumnSelection().getHiddenColumns()
+ assertFalse(alignFrame.hideFeatureColumns("exon", true));
+ assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
+ assertTrue(alignFrame.getViewport().getColumnSelection().getHiddenColumns()
.isEmpty());
- assertFalse(af.hideFeatureColumns("exon", false));
- assertTrue(af.getViewport().getColumnSelection().isEmpty());
- assertTrue(af.getViewport().getColumnSelection().getHiddenColumns()
+ assertFalse(alignFrame.hideFeatureColumns("exon", false));
+ assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
+ assertTrue(alignFrame.getViewport().getColumnSelection().getHiddenColumns()
.isEmpty());
/*
* hiding a feature in all columns does nothing
*/
- assertFalse(af.hideFeatureColumns("Metal", true));
- assertTrue(af.getViewport().getColumnSelection().isEmpty());
- List<int[]> hidden = af.getViewport().getColumnSelection()
+ assertFalse(alignFrame.hideFeatureColumns("Metal", true));
+ assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
+ List<int[]> hidden = alignFrame.getViewport().getColumnSelection()
.getHiddenColumns();
assertTrue(hidden.isEmpty());
* sequence positions [2-4], [7-9] are column positions
* [1-3], [6-8] base zero
*/
- assertTrue(af.hideFeatureColumns("Turn", true));
- hidden = af.getViewport().getColumnSelection().getHiddenColumns();
- assertEquals(2, hidden.size());
- assertEquals(1, hidden.get(0)[0]);
- assertEquals(3, hidden.get(0)[1]);
- assertEquals(6, hidden.get(1)[0]);
- assertEquals(8, hidden.get(1)[1]);
+ assertTrue(alignFrame.hideFeatureColumns("Turn", true));
+ hidden = alignFrame.getViewport().getColumnSelection().getHiddenColumns();
+ assertEquals(hidden.size(), 2);
+ assertEquals(hidden.get(0)[0], 1);
+ assertEquals(hidden.get(0)[1], 3);
+ assertEquals(hidden.get(1)[0], 6);
+ assertEquals(hidden.get(1)[1], 8);
+ }
+
+ @BeforeClass(alwaysRun = true)
+ public static void setUpBeforeClass() throws Exception
+ {
+ /*
+ * use read-only test properties file
+ */
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ Jalview.main(new String[] { "-nonews" });
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
+ {
+ Desktop.instance.closeAll_actionPerformed(null);
+ }
+
+ /**
+ * configure (read-only) properties for test to ensure Consensus is computed
+ * for colour Above PID testing
+ */
+ @BeforeMethod(alwaysRun = true)
+ public void setUp()
+ {
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ Cache.applicationProperties.setProperty("SHOW_IDENTITY",
+ Boolean.TRUE.toString());
+ af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
+ DataSourceType.FILE);
+
+ /*
+ * wait for Consensus thread to complete
+ */
+ synchronized (this)
+ {
+ while (af.getViewport().getConsensusSeq() == null)
+ {
+ try
+ {
+ wait(50);
+ } catch (InterruptedException e)
+ {
+ }
+ }
+ }
+ }
+
+ /**
+ * Test that changing background (alignment) colour scheme
+ * <ul>
+ * <li>with Apply Colour to All Groups not selected, does not change group
+ * colours</li>
+ * <li>with Apply Colour to All Groups selected, does change group colours</li>
+ * <li>in neither case, changes alignment or group colour thresholds (PID or
+ * Conservation)</li>
+ * </ul>
+ */
+ @Test(groups = "Functional")
+ public void testChangeColour_background_groupsAndThresholds()
+ {
+ AlignViewport av = af.getViewport();
+ AlignmentI al = av.getAlignment();
+
+ /*
+ * Colour alignment by Buried Index
+ */
+ af.applyToAllGroups_actionPerformed(false);
+ af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
+ assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
+ assertFalse(av.getResidueShading().conservationApplied());
+ assertEquals(av.getResidueShading().getThreshold(), 0);
+
+ /*
+ * Apply Conservation 20%
+ */
+ af.conservationMenuItem_actionPerformed(true);
+ SliderPanel sp = SliderPanel.getSliderPanel();
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.conservation_colour_increment",
+ new String[] { "Background" }));
+ assertTrue(sp.isForConservation());
+ sp.valueChanged(20);
+ assertTrue(av.getResidueShading().conservationApplied());
+ assertEquals(av.getResidueShading().getConservationInc(), 20);
+
+ /*
+ * Apply PID threshold 10% (conservation still applies as well)
+ */
+ af.abovePIDThreshold_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.percentage_identity_threshold",
+ new String[] { "Background" }));
+ sp.valueChanged(10);
+ assertEquals(av.getResidueShading().getThreshold(), 10);
+ assertTrue(av.getResidueShading().conservationApplied());
+ assertEquals(av.getResidueShading().getConservationInc(), 20);
+
+ /*
+ * create a group with Strand colouring, 30% Conservation
+ * and 40% PID threshold
+ */
+ SequenceGroup sg = new SequenceGroup();
+ sg.addSequence(al.getSequenceAt(0), false);
+ sg.setStartRes(15);
+ sg.setEndRes(25);
+ av.setSelectionGroup(sg);
+
+ /*
+ * apply 30% Conservation to group
+ */
+ PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
+ popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
+ .toString());
+ assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
+ assertEquals(al.getGroups().size(), 1);
+ assertSame(al.getGroups().get(0), sg);
+ popupMenu.conservationMenuItem_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.conservation_colour_increment",
+ new String[] { sg.getName() }));
+ sp.valueChanged(30);
+ assertTrue(sg.getGroupColourScheme().conservationApplied());
+ assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
+
+ /*
+ * apply 40% PID threshold to group
+ */
+ popupMenu.abovePIDColour_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.percentage_identity_threshold",
+ new String[] { sg.getName() }));
+ sp.valueChanged(40);
+ assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
+ // conservation threshold is unchanged:
+ assertTrue(sg.getGroupColourScheme().conservationApplied());
+ assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
+
+ /*
+ * change alignment colour - group colour, and all thresholds,
+ * should be unaffected
+ */
+ af.changeColour_actionPerformed(JalviewColourScheme.Turn.toString());
+ assertTrue(av.getGlobalColourScheme() instanceof TurnColourScheme);
+ assertTrue(av.getResidueShading().conservationApplied());
+ assertEquals(av.getResidueShading().getConservationInc(), 20);
+ assertEquals(av.getResidueShading().getThreshold(), 10);
+ assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
+ assertTrue(sg.getGroupColourScheme().conservationApplied());
+ assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
+ assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
+
+ /*
+ * Now change alignment colour with Apply Colour To All Groups
+ * - group colour should change, but not colour thresholds
+ */
+ af.applyToAllGroups_actionPerformed(true);
+ af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
+ assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
+ assertTrue(av.getResidueShading().conservationApplied());
+ assertEquals(av.getResidueShading().getConservationInc(), 20);
+ assertEquals(av.getResidueShading().getThreshold(), 10);
+ assertTrue(sg.getColourScheme() instanceof HelixColourScheme);
+ assertTrue(sg.getGroupColourScheme().conservationApplied());
+ assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
+ assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
+ }
+
+ /**
+ * Test residue colouring with various options
+ * <ol>
+ * <li>no PID or Conservation threshold</li>
+ * <li>colour by Conservation applied</li>
+ * <li>colour by Conservation removed</li>
+ * <li>colour above PID - various values</li>
+ * <li>colour above PID removed</li>
+ * <li>Above PID plus By Conservation combined</li>
+ * <li>remove Above PID to leave just By Conservation</li>
+ * <li>re-add Above PID</li>
+ * <li>remove By Conservation to leave just Above PID</li>
+ * <li>remove Above PID to leave original colours</li>
+ * </ol>
+ */
+ @Test(groups = "Functional")
+ public void testColourThresholdActions()
+ {
+ AlignViewport av = af.getViewport();
+ AlignmentI al = av.getAlignment();
+
+ /*
+ * Colour alignment by Helix Propensity, no thresholds
+ */
+ af.applyToAllGroups_actionPerformed(false);
+ af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
+ assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
+ assertFalse(av.getResidueShading().conservationApplied());
+ assertEquals(av.getResidueShading().getThreshold(), 0);
+
+ /*
+ * inspect the colour of
+ * FER_CAPAN.9(I), column 14 (14 base 0)
+ * FER_CAPAN.10(SER), column 16 (15 base 0)
+ */
+ SequenceI ferCapan = al.findName("FER_CAPAN");
+ ResidueShaderI rs = av.getResidueShading();
+ Color c = rs.findColour('I', 14, ferCapan);
+ Color i_original = new Color(138, 117, 138);
+ assertEquals(c, i_original);
+ c = rs.findColour('S', 15, ferCapan);
+ Color s_original = new Color(54, 201, 54);
+ assertEquals(c, s_original);
+
+ /*
+ * colour by conservation with increment 10
+ */
+ af.conservationMenuItem_actionPerformed(true);
+ SliderPanel sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ assertEquals(sp.getValue(), 30); // initial slider setting
+ sp.valueChanged(10);
+ assertSame(rs, av.getResidueShading());
+ c = rs.findColour('I', 14, ferCapan);
+ Color i_faded = new Color(196, 186, 196);
+ assertEquals(c, i_faded);
+ c = rs.findColour('S', 15, ferCapan);
+ Color s_faded = new Color(144, 225, 144);
+ assertEquals(c, s_faded);
+
+ /*
+ * deselect By Conservation - colour should revert
+ */
+ af.conservationMenuItem_actionPerformed(false);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_original);
+
+ /*
+ * now Above PID, threshold = 0%
+ * should be no change
+ */
+ af.abovePIDThreshold_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ assertEquals(sp.getValue(), 0); // initial slider setting
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, i_original);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_original);
+
+ /*
+ * Above PID, threshold = 1%
+ * 15.I becomes White because no match to consensus (V)
+ * 16.S remains coloured as matches 66.66% consensus
+ */
+ sp.valueChanged(1);
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, Color.white);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_original);
+
+ /*
+ * threshold 66% - no further change yet...
+ */
+ sp.valueChanged(66);
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, Color.white);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_original);
+
+ /*
+ * threshold 67% - now both residues are white
+ */
+ sp.valueChanged(67);
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, Color.white);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, Color.white);
+
+ /*
+ * deselect Above PID - colours should revert
+ */
+ af.abovePIDThreshold_actionPerformed(false);
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, i_original);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_original);
+
+ /*
+ * Now combine Above 50% PID and By Conservation 10%
+ * 15.I is White because no match to consensus (V)
+ * 16.S is coloured but faded
+ */
+ af.abovePIDThreshold_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ sp.valueChanged(50);
+ af.conservationMenuItem_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ sp.valueChanged(10);
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, Color.white);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_faded);
+
+ /*
+ * turn off Above PID - should just leave Conservation fading as before
+ */
+ af.abovePIDThreshold_actionPerformed(false);
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, i_faded);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_faded);
+
+ /*
+ * Now add Above 50% PID to conservation colouring
+ * - should give the same as PID followed by conservation (above)
+ */
+ af.abovePIDThreshold_actionPerformed(true);
+ SliderPanel.getSliderPanel().valueChanged(50);
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, Color.white);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_faded);
+
+ /*
+ * turn off By Conservation
+ * should leave I white, S original (unfaded) colour
+ */
+ af.conservationMenuItem_actionPerformed(false);
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, Color.white);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_original);
+
+ /*
+ * finally turn off Above PID to leave original colours
+ */
+ af.abovePIDThreshold_actionPerformed(false);
+ c = rs.findColour('I', 14, ferCapan);
+ assertEquals(c, i_original);
+ c = rs.findColour('S', 15, ferCapan);
+ assertEquals(c, s_original);
+ }
+
+ /**
+ * Verify that making a New View transfers alignment and group colour schemes,
+ * including any thresholds, to the new view. Because New View is performed by
+ * saving and reloading a 'project' file, this is similar to verifying a
+ * project save and reload.
+ *
+ * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
+ */
+ @Test(groups = "Functional")
+ public void testNewView_colourThresholds()
+ {
+ AlignViewport av = af.getViewport();
+ AlignmentI al = av.getAlignment();
+
+ /*
+ * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
+ */
+ af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
+ assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
+ af.abovePIDThreshold_actionPerformed(true);
+ SliderPanel sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ sp.valueChanged(10);
+ af.conservationMenuItem_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ sp.valueChanged(20);
+ ResidueShaderI rs = av.getResidueShading();
+ assertEquals(rs.getThreshold(), 10);
+ assertTrue(rs.conservationApplied());
+ assertEquals(rs.getConservationInc(), 20);
+
+ /*
+ * create a group with Strand colouring, 30% Conservation
+ * and 40% PID threshold
+ */
+ SequenceGroup sg = new SequenceGroup();
+ sg.addSequence(al.getSequenceAt(0), false);
+ sg.setStartRes(15);
+ sg.setEndRes(25);
+ av.setSelectionGroup(sg);
+ PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
+ popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
+ .toString());
+ assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
+ assertEquals(al.getGroups().size(), 1);
+ assertSame(al.getGroups().get(0), sg);
+ popupMenu.conservationMenuItem_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ sp.valueChanged(30);
+ popupMenu.abovePIDColour_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ sp.valueChanged(40);
+ rs = sg.getGroupColourScheme();
+ assertTrue(rs.conservationApplied());
+ assertEquals(rs.getConservationInc(), 30);
+ assertEquals(rs.getThreshold(), 40);
+
+ /*
+ * set slider panel focus to the background alignment
+ */
+ af.conservationMenuItem_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.conservation_colour_increment",
+ new String[] { "Background" }));
+
+ /*
+ * make a new View, verify alignment and group colour schemes
+ */
+ af.newView_actionPerformed(null);
+ assertEquals(af.alignPanel.getViewName(), "View 1");
+ AlignViewport av2 = af.getViewport();
+ assertNotSame(av, av2);
+ rs = av2.getResidueShading();
+ assertNotSame(av.getResidueShading(), rs);
+ assertEquals(rs.getThreshold(), 10);
+ assertTrue(rs.conservationApplied());
+ assertEquals(rs.getConservationInc(), 20);
+ assertEquals(av2.getAlignment().getGroups().size(), 1);
+ sg = av2.getAlignment().getGroups().get(0);
+ rs = sg.getGroupColourScheme();
+ assertTrue(rs.conservationApplied());
+ assertEquals(rs.getConservationInc(), 30);
+ assertEquals(rs.getThreshold(), 40);
+
+ /*
+ * check the Conservation SliderPanel (still open) is linked to
+ * and updates the new view (JAL-2385)
+ */
+ sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.conservation_colour_increment",
+ new String[] { "View 1" }));
+ sp.valueChanged(22);
+ assertEquals(av2.getResidueShading().getConservationInc(), 22);
}
}
import jalview.datamodel.SearchResults;
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.io.DataSourceType;
import jalview.io.FileLoader;
@BeforeClass(alwaysRun = true)
public static void setUpBeforeClass() throws Exception
{
- Jalview.main(new String[] { "-props", "test/jalview/testProps.jvprops" });
+ Jalview.main(new String[] { "-nonews", "-props",
+ "test/jalview/testProps.jvprops" });
}
@BeforeMethod(alwaysRun = true)
public void testSetGlobalColourScheme()
{
/*
- * test for JAL-2283 don't inadvertently turn on colour by conservation
+ * test for JAL-2283: don't inadvertently turn on colour by conservation
*/
- Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "NONE");
+ Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "None");
Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
Boolean.TRUE.toString());
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
"examples/uniref50.fa", DataSourceType.FILE);
ColourSchemeI cs = new PIDColourScheme();
af.getViewport().setGlobalColourScheme(cs);
- assertFalse(cs.conservationApplied());
+ assertFalse(af.getViewport().getResidueShading()
+ .conservationApplied());
}
@Test(groups = { "Functional" })
af.getViewport().setSearchResults(null);
assertFalse(af.getViewport().hasSearchResults());
}
+
+ /**
+ * Verify that setting the selection group has the side-effect of setting the
+ * context on the group, unless it already has one
+ */
+ @Test(groups = { "Functional" })
+ public void testSetSelectionGroup()
+ {
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ "examples/uniref50.fa", DataSourceType.FILE);
+ AlignViewport av = af.getViewport();
+ SequenceGroup sg1 = new SequenceGroup();
+ SequenceGroup sg2 = new SequenceGroup();
+
+ av.setSelectionGroup(sg1);
+ assertSame(sg1.getContext(), av.getAlignment()); // context set
+
+ sg2.setContext(sg1);
+ av.setSelectionGroup(sg2);
+ assertSame(sg2.getContext(), sg1); // unchanged
+ }
}
*/
public class AnnotationChooserTest
{
+ /*
+ * number of automatically computed annotation rows
+ * (Conservation, Quality, Consensus, Occupancy)
+ */
+ private static final int AUTOCALCD = 4;
@BeforeClass(alwaysRun = true)
public void setUpJvOptionPane()
types = AnnotationChooser.getAnnotationTypes(
parentPanel.getAlignment(), false);
- assertEquals("Not six annotation types", 6, types.size());
+ assertEquals("Not six annotation types", 7, types.size());
assertTrue("IUPRED missing", types.contains("IUPRED"));
assertTrue("JMol missing", types.contains("JMol"));
assertTrue("Beauty missing", types.contains("Beauty"));
assertTrue("Consensus missing", types.contains("Consensus"));
assertTrue("Quality missing", types.contains("Quality"));
assertTrue("Conservation missing", types.contains("Conservation"));
+ assertTrue("Occupancy missing", types.contains("Occupancy"));
}
/**
AlignmentAnnotation[] anns = parentPanel.getAlignment()
.getAlignmentAnnotation();
- assertTrue(anns[5].visible); // JMol for seq3
- assertTrue(anns[7].visible); // JMol for seq1
+ assertTrue(anns[AUTOCALCD + 2].visible); // JMol for seq3
+ assertTrue(anns[AUTOCALCD + 4].visible); // JMol for seq1
setSelected(getTypeCheckbox("JMol"), true);
assertTrue(anns[0].visible); // Conservation
assertTrue(anns[1].visible); // Quality
assertTrue(anns[2].visible); // Consensus
- assertTrue(anns[3].visible); // IUPred for seq0
- assertTrue(anns[4].visible); // Beauty
- assertFalse(anns[5].visible); // JMol for seq3 - not selected but hidden
- assertTrue(anns[6].visible); // IUPRED for seq2
- assertFalse(anns[7].visible); // JMol for seq1 - selected and hidden
+ assertTrue(anns[3].visible); // Occupancy
+ assertTrue(anns[4].visible); // IUPred for seq0
+ assertTrue(anns[5].visible); // Beauty
+ assertFalse(anns[6].visible); // JMol for seq3 - not selected but hidden
+ assertTrue(anns[7].visible); // IUPRED for seq2
+ assertFalse(anns[8].visible); // JMol for seq1 - selected and hidden
}
/**
AlignmentAnnotation[] anns = parentPanel.getAlignment()
.getAlignmentAnnotation();
- assertTrue(anns[7].visible); // JMol for seq1
+ assertTrue(anns[AUTOCALCD + 4].visible); // JMol for seq1
setSelected(getTypeCheckbox("JMol"), true);
assertTrue(anns[0].visible); // Conservation
assertTrue(anns[1].visible); // Quality
assertTrue(anns[2].visible); // Consensus
- assertTrue(anns[3].visible); // IUPred for seq0
- assertTrue(anns[4].visible); // Beauty
- assertTrue(anns[5].visible); // JMol for seq3 not in selection group
- assertTrue(anns[6].visible); // IUPRED for seq2
- assertFalse(anns[7].visible); // JMol for seq1 in selection group
+ assertTrue(anns[3].visible); // Occupancy
+ assertTrue(anns[4].visible); // IUPred for seq0
+ assertTrue(anns[5].visible); // Beauty
+ assertTrue(anns[6].visible); // JMol for seq3 not in selection group
+ assertTrue(anns[7].visible); // IUPRED for seq2
+ assertFalse(anns[8].visible); // JMol for seq1 in selection group
}
/**
// select JMol - all hidden
setSelected(typeCheckbox, true);
- assertFalse(anns[5].visible); // JMol for seq3
- assertFalse(anns[7].visible); // JMol for seq1
+ assertFalse(anns[AUTOCALCD + 2].visible); // JMol for seq3
+ assertFalse(anns[AUTOCALCD + 4].visible); // JMol for seq1
// deselect JMol - all unhidden
setSelected(typeCheckbox, false);
assertTrue(anns[0].visible); // Conservation
assertTrue(anns[1].visible); // Quality
assertTrue(anns[2].visible); // Consensus
- assertTrue(anns[3].visible); // IUPred for seq0
- assertTrue(anns[4].visible); // Beauty
- assertTrue(anns[5].visible); // JMol for seq3
- assertTrue(anns[6].visible); // IUPRED for seq2
- assertTrue(anns[7].visible); // JMol for seq1
+ assertTrue(anns[3].visible); // Occupancy
+ assertTrue(anns[4].visible); // IUPred for seq0
+ assertTrue(anns[5].visible); // Beauty
+ assertTrue(anns[6].visible); // JMol for seq3
+ assertTrue(anns[7].visible); // IUPRED for seq2
+ assertTrue(anns[8].visible); // JMol for seq1
}
/**
setSelected(allSequencesCheckbox, true);
setSelected(hideCheckbox, true);
setSelected(getTypeCheckbox("JMol"), true);
- assertFalse(anns[5].visible); // JMol for seq3
- assertFalse(anns[7].visible); // JMol for seq1
+ assertFalse(anns[AUTOCALCD + 2].visible); // JMol for seq3
+ assertFalse(anns[AUTOCALCD + 4].visible); // JMol for seq1
// ...now show them...
setSelected(showCheckbox, true);
assertTrue(anns[0].visible); // Conservation
assertTrue(anns[1].visible); // Quality
assertTrue(anns[2].visible); // Consensus
- assertTrue(anns[3].visible); // IUPred for seq0
- assertTrue(anns[4].visible); // Beauty
- assertTrue(anns[5].visible); // JMol for seq3
- assertTrue(anns[6].visible); // IUPRED for seq2
- assertTrue(anns[7].visible); // JMol for seq1
+ assertTrue(anns[3].visible); // Occupancy
+ assertTrue(anns[4].visible); // IUPred for seq0
+ assertTrue(anns[5].visible); // Beauty
+ assertTrue(anns[6].visible); // JMol for seq3
+ assertTrue(anns[7].visible); // IUPRED for seq2
+ assertTrue(anns[8].visible); // JMol for seq1
}
/**
setSelected(hideCheckbox, true);
setSelected(getTypeCheckbox("JMol"), true);
- assertTrue(anns[5].visible); // JMol for seq3
- assertFalse(anns[7].visible); // JMol for seq1
+ assertTrue(anns[AUTOCALCD + 2].visible); // JMol for seq3
+ assertFalse(anns[AUTOCALCD + 4].visible); // JMol for seq1
// ...now show them...
setSelected(showCheckbox, true);
assertTrue(anns[0].visible); // Conservation
assertTrue(anns[1].visible); // Quality
assertTrue(anns[2].visible); // Consensus
- assertTrue(anns[3].visible); // IUPred for seq0
- assertTrue(anns[4].visible); // Beauty
- assertTrue(anns[5].visible); // JMol for seq3
- assertTrue(anns[6].visible); // IUPRED for seq2
- assertTrue(anns[7].visible); // JMol for seq1
+ assertTrue(anns[3].visible); // Occupancy
+ assertTrue(anns[4].visible); // IUPred for seq0
+ assertTrue(anns[5].visible); // Beauty
+ assertTrue(anns[6].visible); // JMol for seq3
+ assertTrue(anns[7].visible); // IUPRED for seq2
+ assertTrue(anns[8].visible); // JMol for seq1
}
/**
final Checkbox typeCheckbox = getTypeCheckbox("JMol");
// select JMol - all shown
setSelected(typeCheckbox, true);
- assertTrue(anns[5].visible); // JMol for seq3
- assertTrue(anns[7].visible); // JMol for seq1
+ assertTrue(anns[AUTOCALCD + 2].visible); // JMol for seq3
+ assertTrue(anns[AUTOCALCD + 4].visible); // JMol for seq1
// deselect JMol - all hidden
setSelected(typeCheckbox, false);
assertTrue(anns[0].visible); // Conservation
assertTrue(anns[1].visible); // Quality
assertTrue(anns[2].visible); // Consensus
- assertTrue(anns[3].visible); // IUPred for seq0
- assertTrue(anns[4].visible); // Beauty
- assertFalse(anns[5].visible); // JMol for seq3
- assertTrue(anns[6].visible); // IUPRED for seq2
- assertFalse(anns[7].visible); // JMol for seq1
+ assertTrue(anns[3].visible); // Occupancy
+ assertTrue(anns[4].visible); // IUPred for seq0
+ assertTrue(anns[5].visible); // Beauty
+ assertFalse(anns[6].visible); // JMol for seq3
+ assertTrue(anns[7].visible); // IUPRED for seq2
+ assertFalse(anns[8].visible); // JMol for seq1
}
/**
// select JMol - should remain visible
setSelected(getTypeCheckbox("JMol"), true);
- assertTrue(anns[5].visible); // JMol for seq3
- assertTrue(anns[7].visible); // JMol for seq1
+ assertTrue(anns[AUTOCALCD + 2].visible); // JMol for seq3
+ assertTrue(anns[AUTOCALCD + 4].visible); // JMol for seq1
// deselect JMol - should be hidden for selected sequences only
setSelected(getTypeCheckbox("JMol"), false);
assertTrue(anns[0].visible); // Conservation
assertTrue(anns[1].visible); // Quality
assertTrue(anns[2].visible); // Consensus
- assertTrue(anns[3].visible); // IUPred for seq0
- assertTrue(anns[4].visible); // Beauty
- assertTrue(anns[5].visible); // JMol for seq3 not in selection group
- assertTrue(anns[6].visible); // IUPRED for seq2
- assertFalse(anns[7].visible); // JMol for seq1 in selection group
+ assertTrue(anns[3].visible); // Occupancy
+ assertTrue(anns[4].visible); // IUPred for seq0
+ assertTrue(anns[5].visible); // Beauty
+ assertTrue(anns[6].visible); // JMol for seq3 not in selection group
+ assertTrue(anns[7].visible); // IUPRED for seq2
+ assertFalse(anns[8].visible); // JMol for seq1 in selection group
}
/**
AlignmentAnnotation[] anns = parentPanel.getAlignment()
.getAlignmentAnnotation();
- // remember 3 annotations to skip (Conservation/Quality/Consensus)
- assertFalse(testee.isInActionScope(anns[3]));
- assertFalse(testee.isInActionScope(anns[4]));
- assertFalse(testee.isInActionScope(anns[5]));
- assertTrue(testee.isInActionScope(anns[6]));
- assertTrue(testee.isInActionScope(anns[7]));
+ assertFalse(testee.isInActionScope(anns[AUTOCALCD]));
+ assertFalse(testee.isInActionScope(anns[AUTOCALCD + 1]));
+ assertFalse(testee.isInActionScope(anns[AUTOCALCD + 2]));
+ assertTrue(testee.isInActionScope(anns[AUTOCALCD + 3]));
+ assertTrue(testee.isInActionScope(anns[AUTOCALCD + 4]));
}
/**
AlignmentAnnotation[] anns = parentPanel.getAlignment()
.getAlignmentAnnotation();
- // remember 3 annotations to skip (Conservation/Quality/Consensus)
- assertTrue(testee.isInActionScope(anns[3]));
- assertTrue(testee.isInActionScope(anns[4]));
- assertTrue(testee.isInActionScope(anns[5]));
- assertFalse(testee.isInActionScope(anns[6]));
- assertFalse(testee.isInActionScope(anns[7]));
+ assertTrue(testee.isInActionScope(anns[AUTOCALCD]));
+ assertTrue(testee.isInActionScope(anns[AUTOCALCD + 1]));
+ assertTrue(testee.isInActionScope(anns[AUTOCALCD + 2]));
+ assertFalse(testee.isInActionScope(anns[AUTOCALCD + 3]));
+ assertFalse(testee.isInActionScope(anns[AUTOCALCD + 4]));
}
/**
assertTrue(anns[0].visible); // Conservation
assertTrue(anns[1].visible); // Quality
assertTrue(anns[2].visible); // Consensus
- assertFalse(anns[3].visible); // IUPRED
- assertTrue(anns[4].visible); // Beauty (not seq-related)
- assertFalse(anns[5].visible); // JMol
- assertFalse(anns[6].visible); // IUPRED
- assertFalse(anns[7].visible); // JMol
+ assertTrue(anns[3].visible); // Occupancy
+ assertFalse(anns[4].visible); // IUPRED
+ assertTrue(anns[5].visible); // Beauty (not seq-related)
+ assertFalse(anns[6].visible); // JMol
+ assertFalse(anns[7].visible); // IUPRED
+ assertFalse(anns[8].visible); // JMol
// reset - should all be visible
testee.resetOriginalState();
assertEquals(4, showOptions.length); // includes 'All' and separator
assertEquals(4, hideOptions.length);
- assertEquals("All", ((JMenuItem) showOptions[0]).getText());
+ String all = MessageManager.getString("label.all");
+ assertEquals(all, ((JMenuItem) showOptions[0]).getText());
assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
assertEquals(JSeparator.HORIZONTAL,
((JSeparator) showOptions[1]).getOrientation());
assertEquals("SSP", ((JMenuItem) showOptions[3]).getText());
assertEquals("JPred", ((JMenuItem) showOptions[3]).getToolTipText());
- assertEquals("All", ((JMenuItem) hideOptions[0]).getText());
+ assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
assertEquals(JSeparator.HORIZONTAL,
((JSeparator) hideOptions[1]).getOrientation());
assertEquals(2, showOptions.length); // includes 'All' and separator
assertEquals(4, hideOptions.length);
- assertEquals("All", ((JMenuItem) showOptions[0]).getText());
+ String all = MessageManager.getString("label.all");
+ assertEquals(all, ((JMenuItem) showOptions[0]).getText());
assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
assertEquals(JSeparator.HORIZONTAL,
((JSeparator) showOptions[1]).getOrientation());
- assertEquals("All", ((JMenuItem) hideOptions[0]).getText());
+ assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
assertEquals(JSeparator.HORIZONTAL,
((JSeparator) hideOptions[1]).getOrientation());
assertEquals(4, showOptions.length); // includes 'All' and separator
assertEquals(2, hideOptions.length);
- assertEquals("All", ((JMenuItem) showOptions[0]).getText());
+ String all = MessageManager.getString("label.all");
+ assertEquals(all, ((JMenuItem) showOptions[0]).getText());
assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
assertEquals(JSeparator.HORIZONTAL,
((JSeparator) showOptions[1]).getOrientation());
assertEquals("Temp", ((JMenuItem) showOptions[3]).getText());
assertEquals("PDB2", ((JMenuItem) showOptions[3]).getToolTipText());
- assertEquals("All", ((JMenuItem) hideOptions[0]).getText());
+ assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
assertEquals(JSeparator.HORIZONTAL,
((JSeparator) hideOptions[1]).getOrientation());
}
}
- public static AlignmentI readAlignmentFile(File f)
+ AlignmentI readAlignmentFile(File f)
{
System.out.println("Reading file: " + f);
String ff = f.getPath();
* - label for IO class used to write and read back in the data from
* f
*/
-
- // @Test(groups ={ "Functional" })
- public static void testAnnotationFileIO(String testname, File f,
+ void testAnnotationFileIO(String testname, File f,
File annotFile)
{
System.out.println("Test: " + testname + "\nReading annotation file '"
import java.util.Iterator;
import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class FileFormatsTest
{
- @AfterMethod()
+ @AfterMethod(alwaysRun = true)
public void tearDown()
{
FileFormats.getInstance().reset();
}
+ @BeforeMethod(alwaysRun = true)
+ public void setUp()
+ {
+ FileFormats.getInstance().reset();
+ }
+
@Test(groups = "Functional")
- public void testIsDynamic()
+ public void testIsIdentifiable()
{
FileFormats formats = FileFormats.getInstance();
- for (FileFormatI ff : FileFormat.values())
- {
- assertFalse(formats.isIdentifiable(ff));
- }
- assertTrue(formats.isIdentifiable(null));
+ assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Fasta
+ .getName())));
+ assertTrue(formats.isIdentifiable(formats.forName(FileFormat.MMCif
+ .getName())));
+ assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Jnet
+ .getName())));
+ assertFalse(formats.isIdentifiable(formats.forName(FileFormat.Jalview
+ .getName())));
+ assertFalse(formats.isIdentifiable(null));
/*
- * remove and re-add a format: it is now considered 'dynamically added'
+ * remove and re-add a format: it is still 'identifiable'
*/
formats.deregisterFileFormat(FileFormat.Fasta.getName());
assertNull(formats.forName(FileFormat.Fasta.getName()));
FileFormats formats = FileFormats.getInstance();
assertSame(FileFormat.MMCif,
formats.forName(FileFormat.MMCif.getName()));
- assertFalse(formats.isIdentifiable(FileFormat.MMCif));
+ assertTrue(formats.isIdentifiable(FileFormat.MMCif));
/*
* deregister mmCIF format
/*
* re-register mmCIF format
- * it is reinstated (but now classed as 'dynamic')
+ * it is reinstated (still 'identifiable')
*/
formats.registerFileFormat(FileFormat.MMCif);
assertSame(FileFormat.MMCif,
null, true, true, false, 21, 29);
ColourSchemeI scheme = ColourSchemeMapper.getJalviewColourScheme(
"zappo", seqGrp);
- seqGrp.cs = scheme;
+ seqGrp.cs.setColourScheme(scheme);
seqGrp.setShowNonconserved(false);
seqGrp.setDescription(null);
*/
package jalview.io;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertSame;
-import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
import jalview.gui.AlignmentPanel;
import jalview.gui.Desktop;
import jalview.gui.Jalview2XML;
import jalview.gui.JvOptionPane;
+import jalview.gui.PopupMenu;
+import jalview.gui.SliderPanel;
+import jalview.renderer.ResidueShaderI;
import jalview.schemes.AnnotationColourGradient;
+import jalview.schemes.BuriedColourScheme;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.JalviewColourScheme;
+import jalview.schemes.RNAHelicesColour;
+import jalview.schemes.StrandColourScheme;
import jalview.schemes.TCoffeeColourScheme;
import jalview.structure.StructureImportSettings;
import jalview.viewmodel.AlignmentViewport;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Jalview2xmlTests extends Jalview2xmlBase
{
+ @Override
@BeforeClass(alwaysRun = true)
public void setUpJvOptionPane()
{
String inFile = "examples/RF00031_folded.stk";
String tfile = File.createTempFile("JalviewTest", ".jvp")
.getAbsolutePath();
- AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
- inFile, DataSourceType.FILE);
- assertTrue("Didn't read input file " + inFile, af != null);
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
+ DataSourceType.FILE);
+ assertNotNull(af, "Didn't read input file " + inFile);
int olddsann = countDsAnn(af.getViewport());
- assertTrue("Didn't find any dataset annotations", olddsann > 0);
- af.rnahelicesColour_actionPerformed(null);
+ assertTrue(olddsann > 0, "Didn't find any dataset annotations");
+ af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices
+ .toString());
assertTrue(
- "Couldn't apply RNA helices colourscheme",
- af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
- assertTrue("Failed to store as a project.",
- af.saveAlignment(tfile, FileFormat.Jalview));
+ af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
+ "Couldn't apply RNA helices colourscheme");
+ assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
+ "Failed to store as a project.");
af.closeMenuItem_actionPerformed(true);
af = null;
- af = new FileLoader().LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
- assertTrue("Failed to import new project", af != null);
+ af = new FileLoader()
+ .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
+ assertNotNull(af, "Failed to import new project");
int newdsann = countDsAnn(af.getViewport());
- assertTrue(
+ assertEquals(olddsann, newdsann,
"Differing numbers of dataset sequence annotation\nOriginally "
- + olddsann + " and now " + newdsann,
- olddsann == newdsann);
+ + olddsann + " and now " + newdsann);
System.out
.println("Read in same number of annotations as originally present ("
+ olddsann + ")");
assertTrue(
- "RNA helices colourscheme was not applied on import.",
- af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
+
+ af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour,
+ "RNA helices colourscheme was not applied on import.");
}
@Test(groups = { "Functional" })
String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii";
String tfile = File.createTempFile("JalviewTest", ".jvp")
.getAbsolutePath();
- AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
- inFile, DataSourceType.FILE);
- assertNotNull("Didn't read input file " + inFile, af);
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
+ DataSourceType.FILE);
+ assertNotNull(af, "Didn't read input file " + inFile);
af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
- assertSame("Didn't set T-coffee colourscheme", af.getViewport()
- .getGlobalColourScheme().getClass(), TCoffeeColourScheme.class);
- assertNotNull("Recognise T-Coffee score from string",
- ColourSchemeProperty.getColour(af.getViewport()
- .getAlignment(), ColourSchemeProperty.getColourName(af
- .getViewport().getGlobalColourScheme())));
-
- assertTrue("Failed to store as a project.",
- af.saveAlignment(tfile, FileFormat.Jalview));
+ assertSame(af.getViewport().getGlobalColourScheme().getClass(),
+ TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme");
+ assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport()
+ .getAlignment(), af.getViewport().getGlobalColourScheme()
+ .getSchemeName()), "Recognise T-Coffee score from string");
+
+ assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
+ "Failed to store as a project.");
af.closeMenuItem_actionPerformed(true);
af = null;
- af = new FileLoader().LoadFileWaitTillLoaded(tfile,
- DataSourceType.FILE);
- assertNotNull("Failed to import new project", af);
- assertSame("Didn't set T-coffee colourscheme for imported project.", af
- .getViewport().getGlobalColourScheme().getClass(),
- TCoffeeColourScheme.class);
+ af = new FileLoader()
+ .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
+ assertNotNull(af, "Failed to import new project");
+ assertSame(af.getViewport().getGlobalColourScheme().getClass(),
+ TCoffeeColourScheme.class,
+ "Didn't set T-coffee colourscheme for imported project.");
System.out
.println("T-Coffee score shading successfully recovered from project.");
}
String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva";
String tfile = File.createTempFile("JalviewTest", ".jvp")
.getAbsolutePath();
- AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, DataSourceType.FILE);
- assertNotNull("Didn't read input file " + inFile, af);
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
+ DataSourceType.FILE);
+ assertNotNull(af, "Didn't read input file " + inFile);
af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null);
AlignmentAnnotation[] aa = af.getViewport().getAlignment()
.getSequenceAt(0).getAnnotation("IUPredWS (Short)");
assertTrue(
- "Didn't find any IUPred annotation to use to shade alignment.",
- aa != null && aa.length > 0);
+
+ aa != null && aa.length > 0,
+ "Didn't find any IUPred annotation to use to shade alignment.");
AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null,
AnnotationColourGradient.ABOVE_THRESHOLD);
AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0],
SequenceGroup sg = new SequenceGroup();
sg.setStartRes(57);
sg.setEndRes(92);
- sg.cs = gcs;
+ sg.cs.setColourScheme(gcs);
af.getViewport().getAlignment().addGroup(sg);
sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
af.alignPanel.alignmentChanged();
- assertTrue("Failed to store as a project.",
- af.saveAlignment(tfile, FileFormat.Jalview));
+ assertTrue(af.saveAlignment(tfile, FileFormat.Jalview),
+ "Failed to store as a project.");
af.closeMenuItem_actionPerformed(true);
af = null;
- af = new FileLoader().LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
- assertTrue("Failed to import new project", af != null);
+ af = new FileLoader()
+ .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE);
+ assertNotNull(af, "Failed to import new project");
// check for group and alignment colourschemes
ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
- .get(0).cs;
- assertNotNull("Didn't recover global colourscheme", _rcs);
- assertTrue("Didn't recover annotation colour global scheme",
- _rcs instanceof AnnotationColourGradient);
+ .get(0).getColourScheme();
+ assertNotNull(_rcs, "Didn't recover global colourscheme");
+ assertTrue(_rcs instanceof AnnotationColourGradient,
+ "Didn't recover annotation colour global scheme");
AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
- assertTrue("Annotation colourscheme wasn't sequence associated",
- __rcs.isSeqAssociated());
+ assertTrue(__rcs.isSeqAssociated(),
+ "Annotation colourscheme wasn't sequence associated");
boolean diffseqcols = false, diffgseqcols = false;
SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray();
for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
&& (!diffseqcols || !diffgseqcols); p++)
{
- if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
- .findColour(sqs[5].getCharAt(p), p, sqs[5]))
+ if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
+ .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
{
diffseqcols = true;
}
}
- assertTrue("Got Different sequence colours", diffseqcols);
+ assertTrue(diffseqcols, "Got Different sequence colours");
System.out
.println("Per sequence colourscheme (Background) successfully applied and recovered.");
- assertNotNull("Didn't recover group colourscheme", _rgcs);
- assertTrue("Didn't recover annotation colour group colourscheme",
- _rgcs instanceof AnnotationColourGradient);
+ assertNotNull(_rgcs, "Didn't recover group colourscheme");
+ assertTrue(_rgcs instanceof AnnotationColourGradient,
+ "Didn't recover annotation colour group colourscheme");
__rcs = (AnnotationColourGradient) _rgcs;
- assertTrue("Group Annotation colourscheme wasn't sequence associated",
- __rcs.isSeqAssociated());
+ assertTrue(__rcs.isSeqAssociated(),
+ "Group Annotation colourscheme wasn't sequence associated");
for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
&& (!diffseqcols || !diffgseqcols); p++)
{
- if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
- .findColour(sqs[2].getCharAt(p), p, sqs[2]))
+ if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
+ .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
{
diffgseqcols = true;
}
}
- assertTrue("Got Different group sequence colours", diffgseqcols);
+ assertTrue(diffgseqcols, "Got Different group sequence colours");
System.out
.println("Per sequence (Group) colourscheme successfully applied and recovered.");
}
.getAlignFrames().length;
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
"examples/exampleFile_2_7.jar", DataSourceType.FILE);
- assertNotNull("Didn't read in the example file correctly.", af);
- assertTrue("Didn't gather the views in the example file.",
- Desktop.getAlignFrames().length == 1 + origCount);
+ assertNotNull(af, "Didn't read in the example file correctly.");
+ assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
+ "Didn't gather the views in the example file.");
}
StructureImportSettings.setVisibleChainAnnotation(true);
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
"examples/exampleFile_2_7.jar", DataSourceType.FILE);
- assertNotNull("Didn't read in the example file correctly.", af);
+ assertNotNull(af, "Didn't read in the example file correctly.");
AlignmentViewPanel sps = null;
for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
{
break;
}
}
- assertNotNull("Couldn't find the structure view", sps);
+ assertNotNull(sps, "Couldn't find the structure view");
AlignmentAnnotation refan = null;
for (AlignmentAnnotation ra : sps.getAlignment()
.getAlignmentAnnotation())
break;
}
}
- assertNotNull("Annotation secondary structure not found.", refan);
+ assertNotNull(refan, "Annotation secondary structure not found.");
SequenceI sq = sps.getAlignment().findName("1A70|");
- assertNotNull("Couldn't find 1a70 null chain", sq);
+ assertNotNull(sq, "Couldn't find 1a70 null chain");
// compare the manually added temperature factor annotation
// to the track automatically transferred from the pdb structure on load
- assertNotNull("1a70 has no annotation", sq.getDatasetSequence()
- .getAnnotation());
+ assertNotNull(sq.getDatasetSequence().getAnnotation(),
+ "1a70 has no annotation");
for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation())
{
AlignmentAnnotation alaa;
try
{
assertTrue(
- "Mismatch at alignment position " + p,
(alaa.annotations[p] == null && refan.annotations[p] == null)
- || alaa.annotations[p].value == refan.annotations[p].value);
+ || alaa.annotations[p].value == refan.annotations[p].value,
+ "Mismatch at alignment position " + p);
} catch (NullPointerException q)
{
Assert.fail("Mismatch of alignment annotations at position "
{
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
"examples/exampleFile_2_7.jar", DataSourceType.FILE);
- assertNotNull("Didn't read in the example file correctly.", af);
+ assertNotNull(af, "Didn't read in the example file correctly.");
AlignmentViewPanel sps = null, groups = null;
for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels())
{
groups = ap;
}
}
- assertNotNull("Couldn't find the structure view", sps);
- assertNotNull("Couldn't find the MAFFT view", groups);
+ assertNotNull(sps, "Couldn't find the structure view");
+ assertNotNull(groups, "Couldn't find the MAFFT view");
ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle();
ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle();
// check FileLoader returned a reference to the one alignFrame that is
// actually on the Desktop
- assertTrue(
- "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window",
- af == Desktop.getAlignFrameFor(af.getViewport()));
+ assertSame(
+ af,
+ Desktop.getAlignFrameFor(af.getViewport()),
+ "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window");
Desktop.explodeViews(af);
{
Assert.assertEquals(Desktop.getAlignFrames().length, 0);
}
- af = new FileLoader().LoadFileWaitTillLoaded(
- tfile.getAbsolutePath(), DataSourceType.FILE);
+ af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
+ DataSourceType.FILE);
Assert.assertNotNull(af);
Assert.assertEquals(
Desktop.getAlignFrames().length,
Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
Assert.assertEquals(
- oldviews,
- Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
+ Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
+ oldviews);
}
/**
Desktop.instance.closeAll_actionPerformed(null);
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
"examples/exampleFile_2_7.jar", DataSourceType.FILE);
- assertNotNull("Didn't read in the example file correctly.", af);
+ assertNotNull(af, "Didn't read in the example file correctly.");
String afid = af.getViewport().getSequenceSetId();
// remember reference sequence for each panel
Assert.assertEquals(Desktop.getAlignFrames().length, 0);
}
- af = new FileLoader().LoadFileWaitTillLoaded(
- tfile.getAbsolutePath(), DataSourceType.FILE);
+ af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
+ DataSourceType.FILE);
afid = af.getViewport().getSequenceSetId();
for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
Desktop.instance.closeAll_actionPerformed(null);
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
"examples/uniref50.fa", DataSourceType.FILE);
- assertNotNull("Didn't read in the example file correctly.", af);
+ assertNotNull(af, "Didn't read in the example file correctly.");
String afid = af.getViewport().getSequenceSetId();
// make a second view of the alignment
af.newView_actionPerformed(null);
assertSame(repSeq, sg.getSeqrep());
assertTrue(sg.getSequences().contains(repSeq));
assertTrue(sg.getSequences().contains(precedingSeq));
- assertTrue("alignment has groups", alignment.getGroups().isEmpty());
+ assertTrue(alignment.getGroups().isEmpty(), "alignment has groups");
Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
.getHiddenRepSequences();
assertNotNull(hiddenRepSeqsMap);
{
Assert.assertEquals(Desktop.getAlignFrames().length, 0);
}
-
- af = new FileLoader().LoadFileWaitTillLoaded(
- tfile.getAbsolutePath(), DataSourceType.FILE);
+
+ af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
+ DataSourceType.FILE);
afid = af.getViewport().getSequenceSetId();
for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
AlignmentI alignment = ap.getAlignment();
List<SequenceGroup> groups = alignment.getGroups();
assertNotNull(groups);
- assertTrue("Alignment has groups", groups.isEmpty());
+ assertTrue(groups.isEmpty(), "Alignment has groups");
Map<SequenceI, SequenceCollectionI> hiddenRepSeqsMap = av
.getHiddenRepSequences();
- assertNotNull("No hidden represented sequences", hiddenRepSeqsMap);
+ assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences");
assertEquals(1, hiddenRepSeqsMap.size());
assertEquals(repSeqs.get(viewName).getDisplayId(true),
hiddenRepSeqsMap.keySet().iterator().next()
List<String> hidden = hiddenSeqNames.get(ap.getViewName());
HiddenSequences hs = alignment.getHiddenSequences();
assertEquals(
+ hidden.size(),
+ hs.getSize(),
"wrong number of restored hidden sequences in "
- + ap.getViewName(), hidden.size(), hs.getSize());
+ + ap.getViewName());
}
}
String exampleFile = "examples/3W5V.pdb";
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile,
DataSourceType.FILE);
- assertNotNull("Didn't read in the example file correctly.", af);
+ assertNotNull(af, "Didn't read in the example file correctly.");
String afid = af.getViewport().getSequenceSetId();
AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid);
"Recovered PDBEntry should have a non-null file entry");
}
}
+
+ /**
+ * Configure an alignment and a sub-group each with distinct colour schemes,
+ * Conservation and PID thresholds, and confirm these are restored from the
+ * saved project.
+ *
+ * @throws IOException
+ */
+ @Test(groups = { "Functional" })
+ public void testStoreAndRecoverColourThresholds() throws IOException
+ {
+ Desktop.instance.closeAll_actionPerformed(null);
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ "examples/uniref50.fa", DataSourceType.FILE);
+
+ AlignViewport av = af.getViewport();
+ AlignmentI al = av.getAlignment();
+
+ /*
+ * Colour alignment by Buried Index, Above 10% PID, By Conservation 20%
+ */
+ af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
+ assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
+ af.abovePIDThreshold_actionPerformed(true);
+ SliderPanel sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ sp.valueChanged(10);
+ af.conservationMenuItem_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ sp.valueChanged(20);
+ ResidueShaderI rs = av.getResidueShading();
+ assertEquals(rs.getThreshold(), 10);
+ assertTrue(rs.conservationApplied());
+ assertEquals(rs.getConservationInc(), 20);
+
+ /*
+ * create a group with Strand colouring, 30% Conservation
+ * and 40% PID threshold
+ */
+ SequenceGroup sg = new SequenceGroup();
+ sg.addSequence(al.getSequenceAt(0), false);
+ sg.setStartRes(15);
+ sg.setEndRes(25);
+ av.setSelectionGroup(sg);
+ PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
+ popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
+ .toString());
+ assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
+ assertEquals(al.getGroups().size(), 1);
+ assertSame(al.getGroups().get(0), sg);
+ popupMenu.conservationMenuItem_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ sp.valueChanged(30);
+ popupMenu.abovePIDColour_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ sp.valueChanged(40);
+ assertTrue(sg.getGroupColourScheme().conservationApplied());
+ assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
+ assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
+
+ /*
+ * save project, close windows, reload project, verify
+ */
+ File tfile = File.createTempFile("testStoreAndRecoverColourThresholds",
+ ".jvp");
+ tfile.deleteOnExit();
+ new Jalview2XML(false).saveState(tfile);
+ Desktop.instance.closeAll_actionPerformed(null);
+ af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
+ DataSourceType.FILE);
+ Assert.assertNotNull(af, "Failed to reload project");
+
+ /*
+ * verify alignment (background) colouring
+ */
+ rs = af.getViewport().getResidueShading();
+ assertTrue(rs.getColourScheme() instanceof BuriedColourScheme);
+ assertEquals(rs.getThreshold(), 10);
+ assertTrue(rs.conservationApplied());
+ assertEquals(rs.getConservationInc(), 20);
+
+ /*
+ * verify group colouring
+ */
+ assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1);
+ rs = af.getViewport().getAlignment().getGroups().get(0)
+ .getGroupColourScheme();
+ assertTrue(rs.getColourScheme() instanceof StrandColourScheme);
+ assertEquals(rs.getThreshold(), 40);
+ assertTrue(rs.conservationApplied());
+ assertEquals(rs.getConservationInc(), 30);
+ }
}
public class JalviewFileViewTest
{
- @Test
+ @Test(groups = "Functional")
public void testGetImageIcon()
{
JalviewFileView jfv = new JalviewFileView();
assertNull(jfv.getImageIcon("images/file.png"));
}
- @Test
+ @Test(groups = "Functional")
public void testGetExtension()
{
assertEquals(JalviewFileView.getExtension(new File("text.txt")), "txt");
"/a/longer/file/path/text")));
}
- @Test
+ @Test(groups = "Functional")
public void testGetTypeDescription()
{
JalviewFileView jfw = new JalviewFileView();
package jalview.math;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.util.Arrays;
+import java.util.Random;
import org.testng.annotations.Test;
+import org.testng.internal.junit.ArrayAsserts;
public class MatrixTest
{
+ final static double DELTA = 0.0001d;
+
@Test(groups = "Timing")
public void testPreMultiply_timing()
{
int cols = 1000;
double[][] d1 = new double[rows][cols];
double[][] d2 = new double[cols][rows];
- Matrix m1 = new Matrix(d1, rows, cols);
- Matrix m2 = new Matrix(d2, cols, rows);
+ Matrix m1 = new Matrix(d1);
+ Matrix m2 = new Matrix(d2);
long start = System.currentTimeMillis();
m1.preMultiply(m2);
long elapsed = System.currentTimeMillis() - start;
@Test(groups = "Functional")
public void testPreMultiply()
{
- Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 } }, 1, 3); // 1x3
- Matrix m2 = new Matrix(new double[][] { { 5 }, { 6 }, { 7 } }, 3, 1); // 3x1
+ Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 } }); // 1x3
+ Matrix m2 = new Matrix(new double[][] { { 5 }, { 6 }, { 7 } }); // 3x1
/*
* 1x3 times 3x1 is 1x1
* 2x5 + 3x6 + 4*7 = 56
*/
- Matrix m3 = m2.preMultiply(m1);
- assertEquals(m3.rows, 1);
- assertEquals(m3.cols, 1);
- assertEquals(m3.value[0][0], 56d);
+ MatrixI m3 = m2.preMultiply(m1);
+ assertEquals(m3.height(), 1);
+ assertEquals(m3.width(), 1);
+ assertEquals(m3.getValue(0, 0), 56d);
/*
* 3x1 times 1x3 is 3x3
*/
m3 = m1.preMultiply(m2);
- assertEquals(m3.rows, 3);
- assertEquals(m3.cols, 3);
- assertEquals(Arrays.toString(m3.value[0]), "[10.0, 15.0, 20.0]");
- assertEquals(Arrays.toString(m3.value[1]), "[12.0, 18.0, 24.0]");
- assertEquals(Arrays.toString(m3.value[2]), "[14.0, 21.0, 28.0]");
+ assertEquals(m3.height(), 3);
+ assertEquals(m3.width(), 3);
+ assertEquals(Arrays.toString(m3.getRow(0)), "[10.0, 15.0, 20.0]");
+ assertEquals(Arrays.toString(m3.getRow(1)), "[12.0, 18.0, 24.0]");
+ assertEquals(Arrays.toString(m3.getRow(2)), "[14.0, 21.0, 28.0]");
}
@Test(
expectedExceptions = { IllegalArgumentException.class })
public void testPreMultiply_tooManyColumns()
{
- Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }, 2,
- 3); // 2x3
+ Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3
/*
* 2x3 times 2x3 invalid operation -
expectedExceptions = { IllegalArgumentException.class })
public void testPreMultiply_tooFewColumns()
{
- Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }, 2,
- 3); // 2x3
+ Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3
/*
* 3x2 times 3x2 invalid operation -
private boolean matrixEquals(Matrix m1, Matrix m2) {
- return Arrays.deepEquals(m1.value, m2.value);
+ if (m1.width() != m2.width() || m1.height() != m2.height())
+ {
+ return false;
+ }
+ for (int i = 0; i < m1.height(); i++)
+ {
+ if (!Arrays.equals(m1.getRow(i), m2.getRow(i)))
+ {
+ return false;
+ }
+ }
+ return true;
}
@Test(groups = "Functional")
* (3020 30200)
* (5040 50400)
*/
- Matrix m1 = new Matrix(new double[][] { { 2, 3 }, { 4, 5 } }, 2, 2);
- Matrix m2 = new Matrix(new double[][] { { 10, 100 }, { 1000, 10000 } },
- 2, 2);
- Matrix m3 = m1.postMultiply(m2);
- assertEquals(Arrays.toString(m3.value[0]), "[3020.0, 30200.0]");
- assertEquals(Arrays.toString(m3.value[1]), "[5040.0, 50400.0]");
+ MatrixI m1 = new Matrix(new double[][] { { 2, 3 }, { 4, 5 } });
+ MatrixI m2 = new Matrix(new double[][] { { 10, 100 }, { 1000, 10000 } });
+ MatrixI m3 = m1.postMultiply(m2);
+ assertEquals(Arrays.toString(m3.getRow(0)), "[3020.0, 30200.0]");
+ assertEquals(Arrays.toString(m3.getRow(1)), "[5040.0, 50400.0]");
/*
* also check m2.preMultiply(m1) - should be same as m1.postMultiply(m2)
*/
m3 = m2.preMultiply(m1);
- assertEquals(Arrays.toString(m3.value[0]), "[3020.0, 30200.0]");
- assertEquals(Arrays.toString(m3.value[1]), "[5040.0, 50400.0]");
+ assertEquals(Arrays.toString(m3.getRow(0)), "[3020.0, 30200.0]");
+ assertEquals(Arrays.toString(m3.getRow(1)), "[5040.0, 50400.0]");
/*
* m1 has more rows than columns
* (2).(10 100 1000) = (20 200 2000)
* (3) (30 300 3000)
*/
- m1 = new Matrix(new double[][] { { 2 }, { 3 } }, 2, 1);
- m2 = new Matrix(new double[][] { { 10, 100, 1000 } }, 1, 3);
+ m1 = new Matrix(new double[][] { { 2 }, { 3 } });
+ m2 = new Matrix(new double[][] { { 10, 100, 1000 } });
m3 = m1.postMultiply(m2);
- assertEquals(m3.rows, 2);
- assertEquals(m3.cols, 3);
- assertEquals(Arrays.toString(m3.value[0]), "[20.0, 200.0, 2000.0]");
- assertEquals(Arrays.toString(m3.value[1]), "[30.0, 300.0, 3000.0]");
+ assertEquals(m3.height(), 2);
+ assertEquals(m3.width(), 3);
+ assertEquals(Arrays.toString(m3.getRow(0)), "[20.0, 200.0, 2000.0]");
+ assertEquals(Arrays.toString(m3.getRow(1)), "[30.0, 300.0, 3000.0]");
m3 = m2.preMultiply(m1);
- assertEquals(m3.rows, 2);
- assertEquals(m3.cols, 3);
- assertEquals(Arrays.toString(m3.value[0]), "[20.0, 200.0, 2000.0]");
- assertEquals(Arrays.toString(m3.value[1]), "[30.0, 300.0, 3000.0]");
+ assertEquals(m3.height(), 2);
+ assertEquals(m3.width(), 3);
+ assertEquals(Arrays.toString(m3.getRow(0)), "[20.0, 200.0, 2000.0]");
+ assertEquals(Arrays.toString(m3.getRow(1)), "[30.0, 300.0, 3000.0]");
/*
* m1 has more columns than rows
* [0, 0] = 2*5 + 3*6 + 4*7 = 56
* [0, 1] = 2*4 + 3*3 + 4*2 = 25
*/
- m1 = new Matrix(new double[][] { { 2, 3, 4 } }, 1, 3);
- m2 = new Matrix(new double[][] { { 5, 4 }, { 6, 3 }, { 7, 2 } }, 3, 2);
+ m1 = new Matrix(new double[][] { { 2, 3, 4 } });
+ m2 = new Matrix(new double[][] { { 5, 4 }, { 6, 3 }, { 7, 2 } });
m3 = m1.postMultiply(m2);
- assertEquals(m3.rows, 1);
- assertEquals(m3.cols, 2);
- assertEquals(m3.value[0][0], 56d);
- assertEquals(m3.value[0][1], 25d);
+ assertEquals(m3.height(), 1);
+ assertEquals(m3.width(), 2);
+ assertEquals(m3.getRow(0)[0], 56d);
+ assertEquals(m3.getRow(0)[1], 25d);
/*
* and check premultiply equivalent
*/
m3 = m2.preMultiply(m1);
- assertEquals(m3.rows, 1);
- assertEquals(m3.cols, 2);
- assertEquals(m3.value[0][0], 56d);
- assertEquals(m3.value[0][1], 25d);
+ assertEquals(m3.height(), 1);
+ assertEquals(m3.width(), 2);
+ assertEquals(m3.getRow(0)[0], 56d);
+ assertEquals(m3.getRow(0)[1], 25d);
+ }
+
+ @Test(groups = "Functional")
+ public void testCopy()
+ {
+ Random r = new Random();
+ int rows = 5;
+ int cols = 11;
+ double[][] in = new double[rows][cols];
+
+ for (int i = 0; i < rows; i++)
+ {
+ for (int j = 0; j < cols; j++)
+ {
+ in[i][j] = r.nextDouble();
+ }
+ }
+ Matrix m1 = new Matrix(in);
+ Matrix m2 = (Matrix) m1.copy();
+ assertTrue(matrixEquals(m1, m2));
}
/**
}
}
- Matrix origmat = new Matrix(in, n, n);
+ Matrix origmat = new Matrix(in);
// System.out.println(" --- Original matrix ---- ");
// / origmat.print(System.out);
// System.out.println();
// System.out.println(" --- transpose matrix ---- ");
- Matrix trans = origmat.transpose();
+ MatrixI trans = origmat.transpose();
// trans.print(System.out);
// System.out.println();
// System.out.println(" --- OrigT * Orig ---- ");
- Matrix symm = trans.postMultiply(origmat);
+ MatrixI symm = trans.postMultiply(origmat);
// symm.print(System.out);
// System.out.println();
// }
// System.out.println();
}
+
+ @Test(groups = "Timing")
+ public void testSign()
+ {
+ assertEquals(Matrix.sign(-1, -2), -1d);
+ assertEquals(Matrix.sign(-1, 2), 1d);
+ assertEquals(Matrix.sign(-1, 0), 1d);
+ assertEquals(Matrix.sign(1, -2), -1d);
+ assertEquals(Matrix.sign(1, 2), 1d);
+ assertEquals(Matrix.sign(1, 0), 1d);
+ }
+
+ /**
+ * Helper method to make values for a sparse, pseudo-random symmetric matrix
+ *
+ * @param rows
+ * @param cols
+ * @param occupancy
+ * one in 'occupancy' entries will be non-zero
+ * @return
+ */
+ public double[][] getSparseValues(int rows, int cols, int occupancy)
+ {
+ Random r = new Random(1729);
+
+ /*
+ * generate whole number values between -12 and +12
+ * (to mimic score matrices used in Jalview)
+ */
+ double[][] d = new double[rows][cols];
+ int m = 0;
+ for (int i = 0; i < rows; i++)
+ {
+ if (++m % occupancy == 0)
+ {
+ d[i][i] = r.nextInt() % 13; // diagonal
+ }
+ for (int j = 0; j < i; j++)
+ {
+ if (++m % occupancy == 0)
+ {
+ d[i][j] = r.nextInt() % 13;
+ d[j][i] = d[i][j];
+ }
+ }
+ }
+ return d;
+
+ }
+
+ /**
+ * Verify that the results of method tred() are the same if the calculation is
+ * redone
+ */
+ @Test(groups = "Functional")
+ public void testTred_reproducible()
+ {
+ /*
+ * make a pseudo-random symmetric matrix as required for tred/tqli
+ */
+ int rows = 10;
+ int cols = rows;
+ double[][] d = getSparseValues(rows, cols, 3);
+
+ /*
+ * make a copy of the values so m1, m2 are not
+ * sharing arrays!
+ */
+ double[][] d1 = new double[rows][cols];
+ for (int row = 0; row < rows; row++)
+ {
+ for (int col = 0; col < cols; col++)
+ {
+ d1[row][col] = d[row][col];
+ }
+ }
+ Matrix m1 = new Matrix(d);
+ Matrix m2 = new Matrix(d1);
+ assertMatricesMatch(m1, m2); // sanity check
+ m1.tred();
+ m2.tred();
+ assertMatricesMatch(m1, m2);
+ }
+
+ private void assertMatricesMatch(MatrixI m1, MatrixI m2)
+ {
+ if (m1.height() != m2.height())
+ {
+ fail("height mismatch");
+ }
+ if (m1.width() != m2.width())
+ {
+ fail("width mismatch");
+ }
+ for (int row = 0; row < m1.height(); row++)
+ {
+ for (int col = 0; col < m1.width(); col++)
+ {
+ double v2 = m2.getValue(row, col);
+ double v1 = m1.getValue(row, col);
+ if (Math.abs(v1 - v2) > DELTA)
+ {
+ fail(String.format("At [%d, %d] %f != %f", row, col, v1, v2));
+ }
+ }
+ }
+ ArrayAsserts.assertArrayEquals(m1.getD(), m2.getD(), 0.00001d);
+ ArrayAsserts.assertArrayEquals(m1.getE(), m2.getE(), 0.00001d);
+ }
}
--- /dev/null
+package jalview.math;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Random;
+
+import org.testng.annotations.Test;
+import org.testng.internal.junit.ArrayAsserts;
+
+public class SparseMatrixTest
+{
+ final static double DELTA = 0.0001d;
+
+ Random r = new Random(1729);
+
+ @Test(groups = "Functional")
+ public void testConstructor()
+ {
+ MatrixI m1 = new SparseMatrix(
+ new double[][] { { 2, 0, 4 }, { 0, 6, 0 } });
+ assertEquals(m1.getValue(0, 0), 2d);
+ assertEquals(m1.getValue(0, 1), 0d);
+ assertEquals(m1.getValue(0, 2), 4d);
+ assertEquals(m1.getValue(1, 0), 0d);
+ assertEquals(m1.getValue(1, 1), 6d);
+ assertEquals(m1.getValue(1, 2), 0d);
+ }
+
+ @Test(groups = "Functional")
+ public void testTranspose()
+ {
+ MatrixI m1 = new SparseMatrix(
+ new double[][] { { 2, 0, 4 }, { 5, 6, 0 } });
+ MatrixI m2 = m1.transpose();
+ assertTrue(m2 instanceof SparseMatrix);
+ assertEquals(m2.height(), 3);
+ assertEquals(m2.width(), 2);
+ assertEquals(m2.getValue(0, 0), 2d);
+ assertEquals(m2.getValue(0, 1), 5d);
+ assertEquals(m2.getValue(1, 0), 0d);
+ assertEquals(m2.getValue(1, 1), 6d);
+ assertEquals(m2.getValue(2, 0), 4d);
+ assertEquals(m2.getValue(2, 1), 0d);
+ }
+ @Test(groups = "Functional")
+ public void testPreMultiply()
+ {
+ MatrixI m1 = new SparseMatrix(new double[][] { { 2, 3, 4 } }); // 1x3
+ MatrixI m2 = new SparseMatrix(new double[][] { { 5 }, { 6 }, { 7 } }); // 3x1
+
+ /*
+ * 1x3 times 3x1 is 1x1
+ * 2x5 + 3x6 + 4*7 = 56
+ */
+ MatrixI m3 = m2.preMultiply(m1);
+ assertFalse(m3 instanceof SparseMatrix);
+ assertEquals(m3.height(), 1);
+ assertEquals(m3.width(), 1);
+ assertEquals(m3.getValue(0, 0), 56d);
+
+ /*
+ * 3x1 times 1x3 is 3x3
+ */
+ m3 = m1.preMultiply(m2);
+ assertEquals(m3.height(), 3);
+ assertEquals(m3.width(), 3);
+ assertEquals(m3.getValue(0, 0), 10d);
+ assertEquals(m3.getValue(0, 1), 15d);
+ assertEquals(m3.getValue(0, 2), 20d);
+ assertEquals(m3.getValue(1, 0), 12d);
+ assertEquals(m3.getValue(1, 1), 18d);
+ assertEquals(m3.getValue(1, 2), 24d);
+ assertEquals(m3.getValue(2, 0), 14d);
+ assertEquals(m3.getValue(2, 1), 21d);
+ assertEquals(m3.getValue(2, 2), 28d);
+ }
+
+ @Test(
+ groups = "Functional",
+ expectedExceptions = { IllegalArgumentException.class })
+ public void testPreMultiply_tooManyColumns()
+ {
+ Matrix m1 = new SparseMatrix(
+ new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3
+
+ /*
+ * 2x3 times 2x3 invalid operation -
+ * multiplier has more columns than multiplicand has rows
+ */
+ m1.preMultiply(m1);
+ fail("Expected exception");
+ }
+
+ @Test(
+ groups = "Functional",
+ expectedExceptions = { IllegalArgumentException.class })
+ public void testPreMultiply_tooFewColumns()
+ {
+ Matrix m1 = new SparseMatrix(
+ new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3
+
+ /*
+ * 3x2 times 3x2 invalid operation -
+ * multiplier has more columns than multiplicand has row
+ */
+ m1.preMultiply(m1);
+ fail("Expected exception");
+ }
+
+ @Test(groups = "Functional")
+ public void testPostMultiply()
+ {
+ /*
+ * Square matrices
+ * (2 3) . (10 100)
+ * (4 5) (1000 10000)
+ * =
+ * (3020 30200)
+ * (5040 50400)
+ */
+ MatrixI m1 = new SparseMatrix(new double[][] { { 2, 3 }, { 4, 5 } });
+ MatrixI m2 = new SparseMatrix(new double[][] { { 10, 100 },
+ { 1000, 10000 } });
+ MatrixI m3 = m1.postMultiply(m2);
+ assertEquals(m3.getValue(0, 0), 3020d);
+ assertEquals(m3.getValue(0, 1), 30200d);
+ assertEquals(m3.getValue(1, 0), 5040d);
+ assertEquals(m3.getValue(1, 1), 50400d);
+
+ /*
+ * also check m2.preMultiply(m1) - should be same as m1.postMultiply(m2)
+ */
+ MatrixI m4 = m2.preMultiply(m1);
+ assertMatricesMatch(m3, m4, 0.00001d);
+
+ /*
+ * m1 has more rows than columns
+ * (2).(10 100 1000) = (20 200 2000)
+ * (3) (30 300 3000)
+ */
+ m1 = new SparseMatrix(new double[][] { { 2 }, { 3 } });
+ m2 = new SparseMatrix(new double[][] { { 10, 100, 1000 } });
+ m3 = m1.postMultiply(m2);
+ assertEquals(m3.height(), 2);
+ assertEquals(m3.width(), 3);
+ assertEquals(m3.getValue(0, 0), 20d);
+ assertEquals(m3.getValue(0, 1), 200d);
+ assertEquals(m3.getValue(0, 2), 2000d);
+ assertEquals(m3.getValue(1, 0), 30d);
+ assertEquals(m3.getValue(1, 1), 300d);
+ assertEquals(m3.getValue(1, 2), 3000d);
+
+ m4 = m2.preMultiply(m1);
+ assertMatricesMatch(m3, m4, 0.00001d);
+
+ /*
+ * m1 has more columns than rows
+ * (2 3 4) . (5 4) = (56 25)
+ * (6 3)
+ * (7 2)
+ * [0, 0] = 2*5 + 3*6 + 4*7 = 56
+ * [0, 1] = 2*4 + 3*3 + 4*2 = 25
+ */
+ m1 = new SparseMatrix(new double[][] { { 2, 3, 4 } });
+ m2 = new SparseMatrix(new double[][] { { 5, 4 }, { 6, 3 }, { 7, 2 } });
+ m3 = m1.postMultiply(m2);
+ assertEquals(m3.height(), 1);
+ assertEquals(m3.width(), 2);
+ assertEquals(m3.getValue(0, 0), 56d);
+ assertEquals(m3.getValue(0, 1), 25d);
+
+ /*
+ * and check premultiply equivalent
+ */
+ m4 = m2.preMultiply(m1);
+ assertMatricesMatch(m3, m4, 0.00001d);
+ }
+
+ @Test(groups = "Timing")
+ public void testSign()
+ {
+ assertEquals(Matrix.sign(-1, -2), -1d);
+ assertEquals(Matrix.sign(-1, 2), 1d);
+ assertEquals(Matrix.sign(-1, 0), 1d);
+ assertEquals(Matrix.sign(1, -2), -1d);
+ assertEquals(Matrix.sign(1, 2), 1d);
+ assertEquals(Matrix.sign(1, 0), 1d);
+ }
+
+ /**
+ * Verify that the results of method tred() are the same for SparseMatrix as
+ * they are for Matrix (i.e. a regression test rather than an absolute test of
+ * correctness of results)
+ */
+ @Test(groups = "Functional")
+ public void testTred_matchesMatrix()
+ {
+ /*
+ * make a pseudo-random symmetric matrix as required for tred/tqli
+ */
+ int rows = 10;
+ int cols = rows;
+ double[][] d = getSparseValues(rows, cols, 3);
+
+ /*
+ * make a copy of the values so m1, m2 are not
+ * sharing arrays!
+ */
+ double[][] d1 = new double[rows][cols];
+ for (int row = 0; row < rows; row++)
+ {
+ for (int col = 0; col < cols; col++)
+ {
+ d1[row][col] = d[row][col];
+ }
+ }
+ Matrix m1 = new Matrix(d);
+ Matrix m2 = new SparseMatrix(d1);
+ assertMatricesMatch(m1, m2, 0.00001d); // sanity check
+ m1.tred();
+ m2.tred();
+ assertMatricesMatch(m1, m2, 0.00001d);
+ }
+
+ private void assertMatricesMatch(MatrixI m1, MatrixI m2, double delta)
+ {
+ if (m1.height() != m2.height())
+ {
+ fail("height mismatch");
+ }
+ if (m1.width() != m2.width())
+ {
+ fail("width mismatch");
+ }
+ for (int row = 0; row < m1.height(); row++)
+ {
+ for (int col = 0; col < m1.width(); col++)
+ {
+ double v2 = m2.getValue(row, col);
+ double v1 = m1.getValue(row, col);
+ if (Math.abs(v1 - v2) > DELTA)
+ {
+ fail(String.format("At [%d, %d] %f != %f", row, col, v1, v2));
+ }
+ }
+ }
+ ArrayAsserts.assertArrayEquals(m1.getD(), m2.getD(), delta);
+ ArrayAsserts.assertArrayEquals(m1.getE(), m2.getE(), 0.00001d);
+ }
+
+ @Test
+ public void testGetValue()
+ {
+ double[][] d = new double[][] { { 0, 0, 1, 0, 0 }, { 2, 3, 0, 0, 0 },
+ { 4, 0, 0, 0, 5 } };
+ MatrixI m = new SparseMatrix(d);
+ for (int row = 0; row < 3; row++)
+ {
+ for (int col = 0; col < 5; col++)
+ {
+ assertEquals(m.getValue(row, col), d[row][col],
+ String.format("At [%d, %d]", row, col));
+ }
+ }
+ }
+
+ /**
+ * Verify that the results of method tqli() are the same for SparseMatrix as
+ * they are for Matrix (i.e. a regression test rather than an absolute test of
+ * correctness of results)
+ *
+ * @throws Exception
+ */
+ @Test(groups = "Functional")
+ public void testTqli_matchesMatrix() throws Exception
+ {
+ /*
+ * make a pseudo-random symmetric matrix as required for tred
+ */
+ int rows = 6;
+ int cols = rows;
+ double[][] d = getSparseValues(rows, cols, 3);
+
+ /*
+ * make a copy of the values so m1, m2 are not
+ * sharing arrays!
+ */
+ double[][] d1 = new double[rows][cols];
+ for (int row = 0; row < rows; row++)
+ {
+ for (int col = 0; col < cols; col++)
+ {
+ d1[row][col] = d[row][col];
+ }
+ }
+ Matrix m1 = new Matrix(d);
+ Matrix m2 = new SparseMatrix(d1);
+
+ // have to do tred() before doing tqli()
+ m1.tred();
+ m2.tred();
+ assertMatricesMatch(m1, m2, 0.00001d);
+
+ m1.tqli();
+ m2.tqli();
+ assertMatricesMatch(m1, m2, 0.00001d);
+ }
+
+ /**
+ * Helper method to make values for a sparse, pseudo-random symmetric matrix
+ *
+ * @param rows
+ * @param cols
+ * @param occupancy
+ * one in 'occupancy' entries will be non-zero
+ * @return
+ */
+ public double[][] getSparseValues(int rows, int cols, int occupancy)
+ {
+ /*
+ * generate whole number values between -12 and +12
+ * (to mimic score matrices used in Jalview)
+ */
+ double[][] d = new double[rows][cols];
+ int m = 0;
+ for (int i = 0; i < rows; i++)
+ {
+ if (++m % occupancy == 0)
+ {
+ d[i][i] = r.nextInt() % 13; // diagonal
+ }
+ for (int j = 0; j < i; j++)
+ {
+ if (++m % occupancy == 0)
+ {
+ d[i][j] = r.nextInt() % 13;
+ d[j][i] = d[i][j];
+ }
+ }
+ }
+ return d;
+
+ }
+
+ /**
+ * Test that verifies that the result of preMultiply is a SparseMatrix if more
+ * than 80% zeroes, else a Matrix
+ */
+ @Test(groups = "Functional")
+ public void testPreMultiply_sparseProduct()
+ {
+ MatrixI m1 = new SparseMatrix(new double[][] { { 1 }, { 0 }, { 0 },
+ { 0 }, { 0 } }); // 5x1
+ MatrixI m2 = new SparseMatrix(new double[][] { { 1, 1, 1, 1 } }); // 1x4
+
+ /*
+ * m1.m2 makes a row of 4 1's, and 4 rows of zeros
+ * 20% non-zero so not 'sparse'
+ */
+ MatrixI m3 = m2.preMultiply(m1);
+ assertFalse(m3 instanceof SparseMatrix);
+
+ /*
+ * replace a 1 with a 0 in the product:
+ * it is now > 80% zero so 'sparse'
+ */
+ m2 = new SparseMatrix(new double[][] { { 1, 1, 1, 0 } });
+ m3 = m2.preMultiply(m1);
+ assertTrue(m3 instanceof SparseMatrix);
+ }
+
+ @Test(groups = "Functional")
+ public void testFillRatio()
+ {
+ SparseMatrix m1 = new SparseMatrix(new double[][] { { 2, 0, 4, 1, 0 },
+ { 0, 6, 0, 0, 0 } });
+ assertEquals(m1.getFillRatio(), 0.4f);
+ }
+
+ /**
+ * Verify that the results of method tred() are the same if the calculation is
+ * redone
+ */
+ @Test(groups = "Functional")
+ public void testTred_reproducible()
+ {
+ /*
+ * make a pseudo-random symmetric matrix as required for tred/tqli
+ */
+ int rows = 10;
+ int cols = rows;
+ double[][] d = getSparseValues(rows, cols, 3);
+
+ /*
+ * make a copy of the values so m1, m2 are not
+ * sharing arrays!
+ */
+ double[][] d1 = new double[rows][cols];
+ for (int row = 0; row < rows; row++)
+ {
+ for (int col = 0; col < cols; col++)
+ {
+ d1[row][col] = d[row][col];
+ }
+ }
+ Matrix m1 = new SparseMatrix(d);
+ Matrix m2 = new SparseMatrix(d1);
+ assertMatricesMatch(m1, m2, 1.0e16); // sanity check
+ m1.tred();
+ m2.tred();
+ assertMatricesMatch(m1, m2, 0.00001d);
+ }
+}
\ No newline at end of file
--- /dev/null
+package jalview.renderer;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+import jalview.analysis.Conservation;
+import jalview.datamodel.Profile;
+import jalview.datamodel.ProfileI;
+import jalview.datamodel.Profiles;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.schemes.PIDColourScheme;
+
+import java.awt.Color;
+import java.util.Collections;
+
+import org.testng.annotations.Test;
+
+public class ResidueShaderTest
+{
+
+ @Test(groups = "Functional")
+ public void testAboveThreshold()
+ {
+ /*
+ * make up profiles for this alignment:
+ * AR-Q
+ * AR--
+ * SR-T
+ * SR-T
+ */
+ ProfileI[] profiles = new ProfileI[4];
+ profiles[0] = new Profile(4, 0, 2, "AS");
+ profiles[1] = new Profile(4, 0, 4, "R");
+ profiles[2] = new Profile(4, 4, 0, "");
+ profiles[3] = new Profile(4, 1, 2, "T");
+ ResidueShader ccs = new ResidueShader(new PIDColourScheme());
+ ccs.setConsensus(new Profiles(profiles));
+
+ /*
+ * no threshold
+ */
+ ccs.setThreshold(0, true);
+ assertTrue(ccs.aboveThreshold('a', 0));
+ assertTrue(ccs.aboveThreshold('S', 0));
+ assertTrue(ccs.aboveThreshold('W', 0));
+ assertTrue(ccs.aboveThreshold('R', 1));
+ assertTrue(ccs.aboveThreshold('W', 2));
+ assertTrue(ccs.aboveThreshold('t', 3));
+ assertTrue(ccs.aboveThreshold('Q', 3));
+
+ /*
+ * with threshold, include gaps
+ */
+ ccs.setThreshold(60, false);
+ assertFalse(ccs.aboveThreshold('a', 0));
+ assertFalse(ccs.aboveThreshold('S', 0));
+ assertTrue(ccs.aboveThreshold('R', 1));
+ assertFalse(ccs.aboveThreshold('W', 2));
+ assertFalse(ccs.aboveThreshold('t', 3)); // 50% < 60%
+
+ /*
+ * with threshold, ignore gaps
+ */
+ ccs.setThreshold(60, true);
+ assertFalse(ccs.aboveThreshold('a', 0));
+ assertFalse(ccs.aboveThreshold('S', 0));
+ assertTrue(ccs.aboveThreshold('R', 1));
+ assertFalse(ccs.aboveThreshold('W', 2));
+ assertTrue(ccs.aboveThreshold('t', 3)); // 67% > 60%
+ }
+
+ /**
+ * Test colour bleaching based on conservation score and conservation slider.
+ * Scores of 10 or 11 should leave colours unchanged. Gap is always white.
+ */
+ @Test(groups = "Functional")
+ public void testApplyConservation()
+ {
+ ResidueShader ccs = new ResidueShader(new PIDColourScheme());
+
+ // no conservation present - no fading
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 12));
+
+ /*
+ * stub Conservation to return a given consensus string
+ */
+ final String consSequence = "0123456789+*-";
+ Conservation cons = new Conservation(null,
+ Collections.<SequenceI> emptyList(), 0, 0)
+ {
+ @Override
+ public SequenceI getConsSequence()
+ {
+ return new Sequence("seq", consSequence);
+ }
+ };
+ ccs.setConservation(cons);
+
+ // column out of range:
+ assertEquals(Color.RED,
+ ccs.applyConservation(Color.RED, consSequence.length()));
+
+ /*
+ * with 100% threshold, 'fade factor' is
+ * (11-score)/10 * 100/20 = (11-score)/2
+ * which is >= 1 for all scores i.e. all fade to white except +, *
+ */
+ ccs.setConservationInc(100);
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 0));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 1));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 2));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 3));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 4));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 5));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 6));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 7));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 8));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 9));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 10));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 11));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 12));
+
+ /*
+ * with 0% threshold, there should be no fading
+ */
+ ccs.setConservationInc(0);
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 0));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 1));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 2));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 3));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 4));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 5));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 6));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 7));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 8));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 9));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 10));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 11));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 12)); // gap
+
+ /*
+ * with 40% threshold, 'fade factor' is
+ * (11-score)/10 * 40/20 = (11-score)/5
+ * which is {>1, >1, >1, >1, >1, >1, 1, 0.8, 0.6, 0.4} for score 0-9
+ * e.g. score 7 colour fades 80% of the way to white (255, 255, 255)
+ */
+ ccs.setConservationInc(40);
+ Color colour = new Color(155, 105, 55);
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 0));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 1));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 2));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 3));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 4));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 5));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 6));
+ assertEquals(new Color(235, 225, 215), ccs.applyConservation(colour, 7));
+ assertEquals(new Color(215, 195, 175), ccs.applyConservation(colour, 8));
+ assertEquals(new Color(195, 165, 135), ccs.applyConservation(colour, 9));
+ assertEquals(colour, ccs.applyConservation(colour, 10));
+ assertEquals(colour, ccs.applyConservation(colour, 11));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 12));
+ }
+
+}
--- /dev/null
+package jalview.renderer;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+import jalview.renderer.ScaleRenderer.ScaleMark;
+
+import java.util.List;
+
+import org.testng.annotations.Test;
+
+public class ScaleRendererTest
+{
+ @Test(groups = "Functional")
+ public void testCalculateMarks()
+ {
+ String data = ">Seq/20-45\nABCDEFGHIJKLMNOPQRSTUVWXYS\n";
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(data,
+ DataSourceType.PASTE);
+ AlignViewport av = af.getViewport();
+
+ /*
+ * scale has minor ticks at 5 and 15, major at 10 and 20
+ * (these are base 1, ScaleMark holds base 0 values)
+ */
+ List<ScaleMark> marks = new ScaleRenderer().calculateMarks(av, 0, 25);
+ assertEquals(marks.size(), 4);
+
+ assertFalse(marks.get(0).major);
+ assertEquals(marks.get(0).column, 4);
+ assertNull(marks.get(0).text);
+
+ assertTrue(marks.get(1).major);
+ assertEquals(marks.get(1).column, 9);
+ assertEquals(marks.get(1).text, "10");
+
+ assertFalse(marks.get(2).major);
+ assertEquals(marks.get(2).column, 14);
+ assertNull(marks.get(2).text);
+
+ assertTrue(marks.get(3).major);
+ assertEquals(marks.get(3).column, 19);
+ assertEquals(marks.get(3).text, "20");
+
+ /*
+ * now hide columns 9-11 and 18-20 (base 1)
+ * scale marks are now in the same columns as before, but
+ * with column numbering adjusted for hidden columns
+ */
+ av.hideColumns(8, 10);
+ av.hideColumns(17, 19);
+ marks = new ScaleRenderer().calculateMarks(av, 0, 25);
+ assertEquals(marks.size(), 4);
+ assertFalse(marks.get(0).major);
+ assertEquals(marks.get(0).column, 4);
+ assertNull(marks.get(0).text);
+ assertTrue(marks.get(1).major);
+ assertEquals(marks.get(1).column, 9);
+ assertEquals(marks.get(1).text, "13"); // +3 hidden columns
+ assertFalse(marks.get(2).major);
+ assertEquals(marks.get(2).column, 14);
+ assertNull(marks.get(2).text);
+ assertTrue(marks.get(3).major);
+ assertEquals(marks.get(3).column, 19);
+ assertEquals(marks.get(3).text, "26"); // +6 hidden columns
+ }
+}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class Blosum62ColourSchemeTest
+{
+ /**
+ * Test the method that determines colour as:
+ * <ul>
+ * <li>white if there is no consensus</li>
+ * <li>white if 'residue' is a gap</li>
+ * <li>dark blue if residue matches consensus (or joint consensus)</li>
+ * <li>else, total the residue's Blosum score with the consensus residue(s)</li>
+ * <ul>
+ * <li>if positive, light blue, else white</li>
+ * </ul>
+ * <ul>
+ */
+ @Test
+ public void testFindColour()
+ {
+ ColourSchemeI blosum = new Blosum62ColourScheme();
+ Color lightBlue = new Color(204, 204, 255);
+ Color darkBlue = new Color(154, 154, 255);
+
+ /*
+ * findColour does not use column, sequence or pid score
+ * we assume consensus residue is computed as upper case
+ */
+ assertEquals(blosum.findColour('A', 0, null, "A", 0f), darkBlue);
+ assertEquals(blosum.findColour('a', 0, null, "A", 0f), darkBlue);
+
+ /*
+ * L has a Blosum score of
+ * -1 with A
+ * -4 with B
+ * 0 with F
+ * 2 with I
+ * -1 with T
+ * 1 with V
+ * etc
+ */
+ assertEquals(blosum.findColour('L', 0, null, "A", 0f), Color.white); // -1
+ assertEquals(blosum.findColour('L', 0, null, "B", 0f), Color.white); // -4
+ assertEquals(blosum.findColour('L', 0, null, "F", 0f), Color.white); // 0
+ assertEquals(blosum.findColour('L', 0, null, "I", 0f), lightBlue); // 2
+ assertEquals(blosum.findColour('L', 0, null, "TV", 0f), Color.white); // 0
+ assertEquals(blosum.findColour('L', 0, null, "IV", 0f), lightBlue); // 3
+ assertEquals(blosum.findColour('L', 0, null, "IT", 0f), lightBlue); // 1
+ assertEquals(blosum.findColour('L', 0, null, "IAT", 0f), Color.white); // 0
+ }
+}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.datamodel.AlignmentI;
+import jalview.gui.AlignFrame;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class ClustalxColourSchemeTest
+{
+ // @formatter:off
+ private static final String FASTA =
+ ">seq1\nAAANNNRQ\n" +
+ ">seq2\nAAANNNRQ\n" +
+ ">seq3\nAAANNNRQ\n" +
+ ">seq4\nAAANNNRQ\n" +
+ ">seq5\nAAANYYKQ\n" +
+ ">seq6\nAAANYYKQ\n" +
+ ">seq7\nAVKWYYKQ\n" +
+ ">seq8\nKKKWYYQQ\n" +
+ ">seq9\nKKKWWYQQ\n" +
+ ">seq0\nKKKWWWQW\n";
+ // @formatter:on
+
+ @Test(groups = "Functional")
+ public void testFindColour()
+ {
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
+ DataSourceType.PASTE);
+ AlignmentI al = af.getViewport().getAlignment();
+ ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
+
+ /*
+ * column 1 is 70% A which is above Clustalx threshold of 60%
+ */
+ Color clustalBlue = new Color(0.5f, 0.7f, 0.9f);
+ assertEquals(cs.findColour('A', 0, al.getSequenceAt(0)), clustalBlue);
+
+ /*
+ * column 2 is 70% A or V which is above Clustalx threshold for group
+ */
+ assertEquals(cs.findColour('A', 0, al.getSequenceAt(1)), clustalBlue);
+
+ /*
+ * column 3 is 60% A which is not above Clustalx threshold
+ * the Ks in the other rows are not in the same Clustalx group
+ */
+ assertEquals(cs.findColour('A', 2, al.getSequenceAt(1)), Color.white);
+
+ /*
+ * column 4 is 60% N which is above Clustalx threshold of 50%
+ */
+ Color clustalGreen = new Color(0.1f, 0.8f, 0.1f);
+ assertEquals(cs.findColour('N', 3, al.getSequenceAt(1)), clustalGreen);
+
+ /*
+ * column 5 is 40% N and 40% Y which fails to pass the threshold of
+ * 50% N or 85% either
+ */
+ assertEquals(cs.findColour('N', 4, al.getSequenceAt(1)), Color.white);
+
+ /*
+ * column 6 is 40% N and 50% Y which fails to pass the threshold of
+ * 85% for either
+ */
+ assertEquals(cs.findColour('N', 5, al.getSequenceAt(1)), Color.white);
+
+ /*
+ * column 7 is 40% R and 30% K which combine to make > 60%
+ */
+ Color clustalRed = new Color(0.9f, 0.2f, 0.1f);
+ assertEquals(cs.findColour('R', 6, al.getSequenceAt(1)), clustalRed);
+ assertEquals(cs.findColour('K', 6, al.getSequenceAt(7)), clustalRed);
+
+ /*
+ * column 8 is >85% Q which qualifies K and R to be red
+ */
+ assertEquals(cs.findColour('R', 7, al.getSequenceAt(1)), clustalRed);
+ assertEquals(cs.findColour('K', 7, al.getSequenceAt(1)), clustalRed);
+
+ // TODO more test cases; check if help documentation matches implementation
+ }
+
+ // @formatter:on
+
+ /**
+ * Test for colour calculation when the consensus percentage ignores gapped
+ * sequences
+ */
+ @Test(groups = "Functional")
+ public void testFindColour_ignoreGaps()
+ {
+ /*
+ * CCC
+ * CCC
+ * -CC
+ * first column is 66% C (blue) including gaps
+ * or 100% C ignoring gaps
+ */
+ String fasta = ">seq1\nCCC\n>seq2\nccc\n>seq3\n-CC\n";
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
+ DataSourceType.PASTE);
+ AlignmentI al = af.getViewport().getAlignment();
+ ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
+
+ /*
+ * column 1 is 66% C which is above Clustalx threshold of 60%
+ */
+ Color clustalBlue = ClustalxColourScheme.ClustalColour.BLUE.colour;
+ assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
+
+ /*
+ * set directly to ignore gaps
+ */
+ cs.setIncludeGaps(false);
+ Color clustalPink = ClustalxColourScheme.ClustalColour.PINK.colour;
+ assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);
+
+ /*
+ * set ignore gaps on the viewport...
+ */
+ cs.setIncludeGaps(true);
+ assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
+ af.getViewport().setIgnoreGapsConsensus(true, af.alignPanel);
+ // next test fails: colour scheme does not read ignore gaps flag from
+ // viewport
+ // assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);
+ }
+}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class ColourSchemePropertyTest
+{
+ @Test(groups = "Functional")
+ public void testGetColourName()
+ {
+ SequenceI seq = new Sequence("Seq1", "abcd");
+ AlignmentI al = new Alignment(new SequenceI[] { seq });
+ ColourSchemeI cs = new ClustalxColourScheme(al, null);
+ assertEquals(ColourSchemeProperty.getColourName(cs), "Clustal");
+ cs = new Blosum62ColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs), "Blosum62");
+ cs = new PIDColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs), "% Identity");
+ cs = new HydrophobicColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs), "Hydrophobic");
+ cs = new ZappoColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs), "Zappo");
+ cs = new TaylorColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs), "Taylor");
+ cs = new HelixColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs),
+ "Helix Propensity");
+ cs = new StrandColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs),
+ "Strand Propensity");
+ cs = new TurnColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs), "Turn Propensity");
+ cs = new BuriedColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs), "Buried Index");
+ cs = new NucleotideColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs), "Nucleotide");
+ cs = new PurinePyrimidineColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs),
+ "Purine/Pyrimidine");
+ cs = new TCoffeeColourScheme(al);
+ assertEquals(ColourSchemeProperty.getColourName(cs), "T-Coffee Scores");
+ cs = new RNAHelicesColour(al);
+ assertEquals(ColourSchemeProperty.getColourName(cs), "RNA Helices");
+ cs = new RNAInteractionColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs),
+ "RNA Interaction type");
+ cs = new UserColourScheme();
+ assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
+
+ /*
+ * UserColourScheme may have a bespoke name
+ */
+ ((UserColourScheme) cs).setName("stripy");
+ assertEquals(ColourSchemeProperty.getColourName(cs), "stripy");
+ ((UserColourScheme) cs).setName("");
+ assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
+ ((UserColourScheme) cs).setName(null);
+ assertEquals(ColourSchemeProperty.getColourName(cs), "User Defined");
+
+ assertEquals(ColourSchemeProperty.getColourName(null), "None");
+ }
+
+ @Test(groups = "Functional")
+ public void testGetColourScheme()
+ {
+ SequenceI seq = new Sequence("Seq1", "abcd");
+ AlignmentI al = new Alignment(new SequenceI[] { seq });
+ // the strings here correspond to JalviewColourScheme.toString() values
+ ColourSchemeI cs = ColourSchemeProperty.getColourScheme(al, "Clustal");
+ assertTrue(cs instanceof ClustalxColourScheme);
+ // not case-sensitive
+ cs = ColourSchemeProperty.getColourScheme(al, "CLUSTAL");
+ assertTrue(cs instanceof ClustalxColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "clustal");
+ assertTrue(cs instanceof ClustalxColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Blosum62");
+ assertTrue(cs instanceof Blosum62ColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "% Identity");
+ assertTrue(cs instanceof PIDColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Zappo");
+ assertTrue(cs instanceof ZappoColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Taylor");
+ assertTrue(cs instanceof TaylorColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Hydrophobic");
+ assertTrue(cs instanceof HydrophobicColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Helix Propensity");
+ assertTrue(cs instanceof HelixColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Strand Propensity");
+ assertTrue(cs instanceof StrandColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Turn Propensity");
+ assertTrue(cs instanceof TurnColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Buried Index");
+ assertTrue(cs instanceof BuriedColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Nucleotide");
+ assertTrue(cs instanceof NucleotideColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "Purine/Pyrimidine");
+ assertTrue(cs instanceof PurinePyrimidineColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "T-Coffee Scores");
+ assertTrue(cs instanceof TCoffeeColourScheme);
+ cs = ColourSchemeProperty.getColourScheme(al, "RNA Helices");
+ assertTrue(cs instanceof RNAHelicesColour);
+ // 'None' is a special value
+ assertNull(ColourSchemeProperty.getColourScheme(al, "None"));
+ assertNull(ColourSchemeProperty.getColourScheme(al, "none"));
+ // default is to convert the name into a fixed colour
+ cs = ColourSchemeProperty.getColourScheme(al, "elephants");
+ assertTrue(cs instanceof UserColourScheme);
+
+ /*
+ * explicit aa colours
+ */
+ UserColourScheme ucs = (UserColourScheme) ColourSchemeProperty
+ .getColourScheme(al,
+ "R,G=red;C=blue;c=green;Q=10,20,30;S,T=11ffdd");
+ assertEquals(ucs.findColour('H'), Color.white);
+ assertEquals(ucs.findColour('R'), Color.red);
+ assertEquals(ucs.findColour('r'), Color.red);
+ assertEquals(ucs.findColour('G'), Color.red);
+ assertEquals(ucs.findColour('C'), Color.blue);
+ assertEquals(ucs.findColour('c'), Color.green);
+ assertEquals(ucs.findColour('Q'), new Color(10, 20, 30));
+ assertEquals(ucs.findColour('S'), new Color(0x11ffdd));
+ assertEquals(ucs.findColour('T'), new Color(0x11ffdd));
+ }
+}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+
+import jalview.bin.Cache;
+import jalview.bin.Jalview;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
+import jalview.gui.SequenceRenderer;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+import jalview.schemes.ClustalxColourScheme.ClustalColour;
+
+import java.awt.Color;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class ColourSchemesTest
+{
+ /*
+ * a colour scheme that alternates Taylor and Zappo
+ * colouring by column
+ */
+ class Stripy extends ResidueColourScheme
+ {
+ private ResidueColourScheme odd;
+
+ private ResidueColourScheme even;
+
+ private Stripy()
+ {
+ }
+
+ /**
+ * constructor given colours for odd and even columns
+ *
+ * @param odd
+ * @param even
+ */
+ private Stripy(ColourSchemeI cs1, ColourSchemeI cs2)
+ {
+ odd = (ResidueColourScheme) cs1;
+ even = (ResidueColourScheme) cs2;
+ }
+
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
+ Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+ {
+ final ColourSchemeI cs1 = ColourSchemes.getInstance()
+ .getColourScheme(JalviewColourScheme.Taylor.toString(),
+ (AnnotatedCollectionI) null);
+ final ColourSchemeI cs2 = ColourSchemes.getInstance()
+ .getColourScheme(JalviewColourScheme.Zappo.toString(),
+ (AnnotatedCollectionI) null);
+ return new Stripy(cs1, cs2);
+ }
+
+ @Override
+ public Color findColour(char c, int j, SequenceI seq)
+ {
+ if (j % 2 == 1)
+ {
+ return odd.findColour(c, j, seq);
+ }
+ else
+ {
+ return even.findColour(c, j, seq);
+ }
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return "stripy";
+ }
+ };
+
+ /*
+ * a colour scheme that is Clustal but using AWT colour equivalents
+ */
+ class MyClustal extends ResidueColourScheme
+ {
+ ClustalxColourScheme delegate;
+
+ private MyClustal()
+ {
+ }
+
+ private MyClustal(AnnotatedCollectionI sg,
+ Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+ {
+ delegate = new ClustalxColourScheme(sg, hiddenRepSequences);
+ }
+
+ @Override
+ public Color findColour(char c, int j, SequenceI seq)
+ {
+ Color col = delegate.findColour(c, j, seq);
+ Color result = col;
+ if (col.equals(ClustalColour.BLUE.colour))
+ {
+ result = Color.blue;
+ }
+ else if (col.equals(ClustalColour.CYAN.colour))
+ {
+ result = Color.cyan;
+ }
+ else if (col.equals(ClustalColour.GREEN.colour))
+ {
+ result = Color.green;
+ }
+ else if (col.equals(ClustalColour.MAGENTA.colour))
+ {
+ result = Color.magenta;
+ }
+ else if (col.equals(ClustalColour.ORANGE.colour))
+ {
+ result = Color.orange;
+ }
+ else if (col.equals(ClustalColour.PINK.colour))
+ {
+ result = Color.pink;
+ }
+ else if (col.equals(ClustalColour.RED.colour))
+ {
+ result = Color.red;
+ }
+ else if (col.equals(ClustalColour.YELLOW.colour))
+ {
+ result = Color.yellow;
+ }
+ return result;
+ }
+
+ @Override
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
+ Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+ {
+ return new MyClustal(sg, hiddenRepSequences);
+ }
+
+ @Override
+ public String getSchemeName()
+ {
+ return "MyClustal";
+ }
+
+ }
+
+ @BeforeClass(alwaysRun = true)
+ public static void setUpBeforeClass() throws Exception
+ {
+ /*
+ * use read-only test properties file
+ */
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ Jalview.main(new String[] { "-nonews" });
+ }
+
+ @AfterClass(alwaysRun = true)
+ public static void tearDownAfterClass() throws Exception
+ {
+ Desktop.instance.closeAll_actionPerformed(null);
+ }
+
+ @Test(groups = "Functional")
+ public void testGetColourSchemes()
+ {
+ /*
+ * this just verifies that built-in colour schemes are loaded into ColourSchemes
+ * in the order in which they are declared in the JalviewColourScheme enum
+ * (this also determines their order in Colour menus)
+ */
+ Iterator<ColourSchemeI> schemes = ColourSchemes.getInstance().getColourSchemes().iterator();
+ JalviewColourScheme[] jalviewSchemes = JalviewColourScheme.values();
+ int i = 0;
+ while (schemes.hasNext() && i < jalviewSchemes.length)
+ {
+ assertTrue(schemes.next().getSchemeName()
+ .equals(jalviewSchemes[i].toString()));
+ i++;
+ }
+ }
+
+ @Test(groups = "Functional")
+ public void testGetColourScheme()
+ {
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ ">seq1\nAGLRTWQU", DataSourceType.PASTE);
+ ColourSchemes schemes = ColourSchemes.getInstance();
+
+ AnnotatedCollectionI al = af.getViewport().getAlignment();
+
+ for (JalviewColourScheme cs : JalviewColourScheme.values())
+ {
+ ColourSchemeI registered = schemes.getColourScheme(cs.toString(), al);
+ assertSame(registered.getClass(), cs.getSchemeClass());
+ }
+ af.closeMenuItem_actionPerformed(true);
+ }
+
+ @Test(groups = "Functional")
+ public void testRegisterColourScheme()
+ {
+ ColourSchemes.getInstance().registerColourScheme(new Stripy());
+ ColourSchemes.getInstance().registerColourScheme(new MyClustal());
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ "examples/uniref50.fa", DataSourceType.FILE);
+ /*
+ * set a breakpoint here to see and play with the newly registered
+ * colour schemes in the AlignFrame colour menu
+ */
+ SequenceRenderer sr = new SequenceRenderer(af.getViewport());
+ SequenceI seq = af.getViewport().getAlignment().findName("FER_CAPAA");
+
+ /*
+ * set and check Taylor colours
+ */
+ af.changeColour_actionPerformed(JalviewColourScheme.Taylor.toString());
+ Color taylor1 = sr.getResidueBoxColour(seq, 88); // E 255,0,102
+ Color taylor2 = sr.getResidueBoxColour(seq, 89); // A 204,255,0
+ Color taylor3 = sr.getResidueBoxColour(seq, 90); // G 255,153,0
+ assertEquals(taylor1, new Color(255, 0, 102));
+ assertEquals(taylor2, new Color(204, 255, 0));
+ assertEquals(taylor3, new Color(255, 153, 0));
+
+ /*
+ * set and check Zappo colours
+ */
+ af.changeColour_actionPerformed(JalviewColourScheme.Zappo.toString());
+ Color zappo1 = sr.getResidueBoxColour(seq, 88); // E red
+ Color zappo2 = sr.getResidueBoxColour(seq, 89); // A pink
+ Color zappo3 = sr.getResidueBoxColour(seq, 90); // G magenta
+ assertEquals(zappo1, Color.red);
+ assertEquals(zappo2, Color.pink);
+ assertEquals(zappo3, Color.magenta);
+
+ /*
+ * set 'stripy' colours - odd columns are Taylor and even are Zappo
+ */
+ af.changeColour_actionPerformed("stripy");
+ Color stripy1 = sr.getResidueBoxColour(seq, 88);
+ Color stripy2 = sr.getResidueBoxColour(seq, 89);
+ Color stripy3 = sr.getResidueBoxColour(seq, 90);
+ assertEquals(stripy1, zappo1);
+ assertEquals(stripy2, taylor2);
+ assertEquals(stripy3, zappo3);
+
+ /*
+ * set and check Clustal colours
+ */
+ af.changeColour_actionPerformed(JalviewColourScheme.Clustal.toString());
+ Color clustal1 = sr.getResidueBoxColour(seq, 88);
+ Color clustal2 = sr.getResidueBoxColour(seq, 89);
+ Color clustal3 = sr.getResidueBoxColour(seq, 90);
+ assertEquals(clustal1, ClustalColour.MAGENTA.colour);
+ assertEquals(clustal2, ClustalColour.BLUE.colour);
+ assertEquals(clustal3, ClustalColour.ORANGE.colour);
+
+ /*
+ * set 'MyClustal' colours - uses AWT colour equivalents
+ */
+ af.changeColour_actionPerformed("MyClustal");
+ Color myclustal1 = sr.getResidueBoxColour(seq, 88);
+ Color myclustal2 = sr.getResidueBoxColour(seq, 89);
+ Color myclustal3 = sr.getResidueBoxColour(seq, 90);
+ assertEquals(myclustal1, Color.MAGENTA);
+ assertEquals(myclustal2, Color.BLUE);
+ assertEquals(myclustal3, Color.ORANGE);
+ }
+
+ /**
+ * Tests for check if scheme name exists. Built-in scheme names are the
+ * toString() values of enum JalviewColourScheme.
+ */
+ @Test(groups = "Functional")
+ public void testNameExists()
+ {
+ ColourSchemes cs = ColourSchemes.getInstance();
+ assertFalse(cs.nameExists(null));
+ assertFalse(cs.nameExists(""));
+ assertTrue(cs.nameExists("Clustal"));
+ assertTrue(cs.nameExists("CLUSTAL"));
+ assertFalse(cs.nameExists("CLUSTAL "));
+ assertTrue(cs.nameExists("% Identity"));
+ assertFalse(cs.nameExists("PID"));
+ }
+}
import jalview.datamodel.SequenceFeature;
import jalview.gui.JvOptionPane;
+import jalview.util.ColorUtils;
import jalview.util.Format;
import java.awt.Color;
fc.setColourByLabel(true);
SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f,
null);
- Color expected = UserColourScheme.createColourFromName("desc");
+ Color expected = ColorUtils.createColourFromName("desc");
assertEquals(expected, fc.getColor(sf));
}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.Test;
+
+public class JalviewColourSchemeTest
+{
+ @Test(groups = "Functional")
+ public void testGetSchemeClass()
+ {
+ assertTrue(JalviewColourScheme.Clustal.getSchemeClass() == ClustalxColourScheme.class);
+ assertTrue(JalviewColourScheme.Blosum62.getSchemeClass() == Blosum62ColourScheme.class);
+ assertTrue(JalviewColourScheme.PID.getSchemeClass() == PIDColourScheme.class);
+ assertTrue(JalviewColourScheme.Hydrophobic.getSchemeClass() == HydrophobicColourScheme.class);
+ assertTrue(JalviewColourScheme.Zappo.getSchemeClass() == ZappoColourScheme.class);
+ assertTrue(JalviewColourScheme.Taylor.getSchemeClass() == TaylorColourScheme.class);
+ assertTrue(JalviewColourScheme.Helix.getSchemeClass() == HelixColourScheme.class);
+ assertTrue(JalviewColourScheme.Strand.getSchemeClass() == StrandColourScheme.class);
+ assertTrue(JalviewColourScheme.Turn.getSchemeClass() == TurnColourScheme.class);
+ assertTrue(JalviewColourScheme.Buried.getSchemeClass() == BuriedColourScheme.class);
+ assertTrue(JalviewColourScheme.Nucleotide.getSchemeClass() == NucleotideColourScheme.class);
+ assertTrue(JalviewColourScheme.PurinePyrimidine.getSchemeClass() == PurinePyrimidineColourScheme.class);
+ assertTrue(JalviewColourScheme.TCoffee.getSchemeClass() == TCoffeeColourScheme.class);
+ assertTrue(JalviewColourScheme.RNAHelices.getSchemeClass() == RNAHelicesColour.class);
+ }
+
+ @Test(groups = "Functional")
+ public void testToString()
+ {
+ assertEquals(JalviewColourScheme.Clustal.toString(), "Clustal");
+ assertEquals(JalviewColourScheme.Blosum62.toString(), "Blosum62");
+ assertEquals(JalviewColourScheme.PID.toString(), "% Identity");
+ assertEquals(JalviewColourScheme.Zappo.toString(), "Zappo");
+ assertEquals(JalviewColourScheme.Taylor.toString(), "Taylor");
+ assertEquals(JalviewColourScheme.Hydrophobic.toString(), "Hydrophobic");
+ assertEquals(JalviewColourScheme.Helix.toString(), "Helix Propensity");
+ assertEquals(JalviewColourScheme.Strand.toString(), "Strand Propensity");
+ assertEquals(JalviewColourScheme.Turn.toString(), "Turn Propensity");
+ assertEquals(JalviewColourScheme.Buried.toString(), "Buried Index");
+ assertEquals(JalviewColourScheme.Nucleotide.toString(), "Nucleotide");
+ assertEquals(JalviewColourScheme.PurinePyrimidine.toString(),
+ "Purine/Pyrimidine");
+ assertEquals(JalviewColourScheme.TCoffee.toString(), "T-Coffee Scores");
+ assertEquals(JalviewColourScheme.RNAHelices.toString(), "RNA Helices");
+ }
+}
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class PIDColourSchemeTest
+{
+ static final Color white = Color.white;
+
+ static final Color over40 = new Color(204, 204, 255);
+
+ static final Color over60 = new Color(153, 153, 255);
+
+ static final Color over80 = new Color(100, 100, 255);
+
+ /**
+ * Test findColour for cases:
+ * <ul>
+ * <li>gap: white</li>
+ * <li>no match to consensus: white</li>
+ * <li>match consensus with pid > 80%: 100,100,255</li>
+ * <li>match consensus with pid > 60%: 153, 153, 255</li>
+ * <li>match consensus with pid > 40%: 204, 204, 255</li>
+ * <li>match consensus with pid <= 40%: white</li>
+ * <li>joint consensus matching</li>
+ * <li>case insensitive matching</li>
+ * <ul>
+ */
+ @Test(groups = "Functional")
+ public void testFindColour()
+ {
+ ColourSchemeI scheme = new PIDColourScheme();
+
+ /*
+ * doesn't use column or sequence
+ * we assume consensus residue is computed as upper case
+ */
+ assertEquals(scheme.findColour('A', 0, null, "A", 0f), white);
+ assertEquals(scheme.findColour('A', 0, null, "A", 40f), white);
+ assertEquals(scheme.findColour('A', 0, null, "A", 40.1f), over40);
+ assertEquals(scheme.findColour('A', 0, null, "A", 60f), over40);
+ assertEquals(scheme.findColour('A', 0, null, "A", 60.1f), over60);
+ assertEquals(scheme.findColour('A', 0, null, "A", 80f), over60);
+ assertEquals(scheme.findColour('A', 0, null, "A", 80.1f), over80);
+ assertEquals(scheme.findColour('A', 0, null, "A", 100f), over80);
+ assertEquals(scheme.findColour('A', 0, null, "KFV", 100f), white);
+
+ assertEquals(scheme.findColour('a', 0, null, "A", 80f), over60);
+ assertEquals(scheme.findColour('A', 0, null, "AC", 80f), over60);
+ assertEquals(scheme.findColour('A', 0, null, "KCA", 80f), over60);
+ }
+
+ /**
+ * Test that changing the 'ignore gaps in consensus' in the viewport (an
+ * option on the annotation label popup menu) results in a change to the
+ * colouring
+ */
+ @Test(groups = "Functional")
+ public void testFindColour_ignoreGaps()
+ {
+ /*
+ * AAAAA
+ * AAAAA
+ * -CCCC
+ * FFFFF
+ *
+ * first column consensus is A
+ * first column PID is 50%, or 67% ignoring gaps
+ */
+ String seqs = ">seq1\nAAAAA\n>seq2\nAAAAA\n>seq3\n-CCCC\n>seq4\nFFFFF\n";
+
+ /*
+ * load data and wait for consensus to be computed
+ */
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqs,
+ DataSourceType.PASTE);
+ AlignViewport viewport = af.getViewport();
+ viewport.setIgnoreGapsConsensus(false, af.alignPanel);
+ while (viewport.getConsensusSeq() == null)
+ {
+ synchronized (this)
+ {
+ try
+ {
+ wait(50);
+ } catch (InterruptedException e)
+ {
+ }
+ }
+ }
+ af.changeColour_actionPerformed(JalviewColourScheme.PID.toString());
+
+ SequenceI seq = viewport.getAlignment().getSequenceAt(0);
+
+ /*
+ * including gaps, A should be coloured for 50% consensus
+ */
+ Color c = viewport
+ .getResidueShading().findColour('A', 0, seq);
+ assertEquals(c, over40);
+
+ /*
+ * now choose to ignore gaps; colour should be for 67%
+ */
+ viewport.setIgnoreGapsConsensus(true, af.alignPanel);
+ c = viewport
+ .getResidueShading().findColour('A', 0, seq);
+ assertEquals(c, over60);
+ }
+}
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
-import jalview.datamodel.Profile;
-import jalview.datamodel.ProfileI;
-import jalview.datamodel.Profiles;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
import jalview.gui.JvOptionPane;
-
-import java.awt.Color;
+import jalview.io.TCoffeeScoreFile;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ResidueColourSchemeTest
{
+ @BeforeClass(alwaysRun = true)
+ public void setUp()
+ {
+
+ }
@BeforeClass(alwaysRun = true)
public void setUpJvOptionPane()
}
@Test(groups = "Functional")
- public void testAboveThreshold()
+ public void testIsApplicableTo()
{
+ SequenceI pep1 = new Sequence("pep1", "APQTWLS");
+ SequenceI pep2 = new Sequence("pep2", "AILFQYG");
+ SequenceI dna1 = new Sequence("dna1", "ACTGAC");
+ SequenceI dna2 = new Sequence("dna2", "TCCAAG");
+ AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
+ AlignmentI nucleotide = new Alignment(new SequenceI[] { dna1, dna2 });
+
/*
- * make up profiles for this alignment:
- * AR-Q
- * AR--
- * SR-T
- * SR-T
+ * peptide-specific colour schemes
*/
- ProfileI[] profiles = new ProfileI[4];
- profiles[0] = new Profile(4, 0, 2, "AS");
- profiles[1] = new Profile(4, 0, 4, "R");
- profiles[2] = new Profile(4, 4, 0, "");
- profiles[3] = new Profile(4, 1, 2, "T");
- ResidueColourScheme rcs = new ResidueColourScheme();
- rcs.setConsensus(new Profiles(profiles));
-
+ assertTrue(new ClustalxColourScheme(peptide, null)
+ .isApplicableTo(peptide));
+ assertFalse(new ClustalxColourScheme(nucleotide, null)
+ .isApplicableTo(nucleotide));
+ assertTrue(new Blosum62ColourScheme().isApplicableTo(peptide));
+ assertFalse(new Blosum62ColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new BuriedColourScheme().isApplicableTo(peptide));
+ assertFalse(new BuriedColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new HelixColourScheme().isApplicableTo(peptide));
+ assertFalse(new HelixColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new HydrophobicColourScheme().isApplicableTo(peptide));
+ assertFalse(new HydrophobicColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new StrandColourScheme().isApplicableTo(peptide));
+ assertFalse(new StrandColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new TaylorColourScheme().isApplicableTo(peptide));
+ assertFalse(new TaylorColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new TurnColourScheme().isApplicableTo(peptide));
+ assertFalse(new TurnColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new ZappoColourScheme().isApplicableTo(peptide));
+ assertFalse(new ZappoColourScheme().isApplicableTo(nucleotide));
+
+ /*
+ * nucleotide-specific colour schemes
+ */
+ assertFalse(new NucleotideColourScheme().isApplicableTo(peptide));
+ assertTrue(new NucleotideColourScheme().isApplicableTo(nucleotide));
+ assertFalse(new PurinePyrimidineColourScheme().isApplicableTo(peptide));
+ assertTrue(new PurinePyrimidineColourScheme()
+ .isApplicableTo(nucleotide));
+ assertFalse(new RNAInteractionColourScheme().isApplicableTo(peptide));
+ assertTrue(new RNAInteractionColourScheme().isApplicableTo(nucleotide));
+
/*
- * no threshold
+ * indifferent
*/
- rcs.setThreshold(0, true);
- assertTrue(rcs.aboveThreshold('a', 0));
- assertTrue(rcs.aboveThreshold('S', 0));
- assertFalse(rcs.aboveThreshold('W', 0));
- assertTrue(rcs.aboveThreshold('R', 1));
- assertFalse(rcs.aboveThreshold('W', 2));
- assertTrue(rcs.aboveThreshold('t', 3));
- assertFalse(rcs.aboveThreshold('Q', 3));
+ assertTrue(new UserColourScheme().isApplicableTo(peptide));
+ assertTrue(new UserColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
+ .isApplicableTo(peptide));
+ assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
+ .isApplicableTo(nucleotide));
+ ResidueColourScheme rcs = new PIDColourScheme();
+ assertTrue(rcs.isApplicableTo(peptide));
+ assertTrue(rcs.isApplicableTo(nucleotide));
+ assertTrue(new PIDColourScheme().isApplicableTo(peptide));
+ assertTrue(new PIDColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new FollowerColourScheme().isApplicableTo(peptide));
+ assertTrue(new FollowerColourScheme().isApplicableTo(nucleotide));
/*
- * with threshold, include gaps
+ * TCoffee colour requires the presence of TCoffee score annotation
*/
- rcs.setThreshold(60, false);
- assertFalse(rcs.aboveThreshold('a', 0));
- assertFalse(rcs.aboveThreshold('S', 0));
- assertTrue(rcs.aboveThreshold('R', 1));
- assertFalse(rcs.aboveThreshold('W', 2));
- assertFalse(rcs.aboveThreshold('t', 3)); // 50% < 60%
+ assertFalse(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
+ assertFalse(new TCoffeeColourScheme(nucleotide)
+ .isApplicableTo(nucleotide));
+ AlignmentAnnotation aa = new AlignmentAnnotation("T-COFFEE", "", null);
+ aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
+ peptide.addAnnotation(aa);
+ aa = new AlignmentAnnotation("T-COFFEE", "", null);
+ aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
+ nucleotide.addAnnotation(aa);
+ assertTrue(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
+ assertTrue(new TCoffeeColourScheme(nucleotide)
+ .isApplicableTo(nucleotide));
/*
- * with threshold, ignore gaps
+ * RNAHelices requires the presence of rna secondary structure
*/
- rcs.setThreshold(60, true);
- assertFalse(rcs.aboveThreshold('a', 0));
- assertFalse(rcs.aboveThreshold('S', 0));
- assertTrue(rcs.aboveThreshold('R', 1));
- assertFalse(rcs.aboveThreshold('W', 2));
- assertTrue(rcs.aboveThreshold('t', 3)); // 67% > 60%
+ assertFalse(new RNAHelicesColour(peptide).isApplicableTo(peptide));
+ assertFalse(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
+ // add secondary structure (small but perfectly formed)
+ Annotation[] ss = new Annotation[2];
+ ss[0] = new Annotation("", "", '{', 0f);
+ ss[1] = new Annotation("", "", '}', 0f);
+ nucleotide.addAnnotation(new AlignmentAnnotation("SS", "", ss));
+ assertTrue(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
}
- /**
- * Test colour bleaching based on conservation score and conservation slider.
- * Scores of 10 or 11 should leave colours unchanged. Gap is always white.
- */
@Test(groups = "Functional")
- public void testApplyConservation()
+ public void testIsApplicableTo_dynamicColourScheme()
{
- ResidueColourScheme rcs = new ResidueColourScheme();
-
- // no conservation present - no fading
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 12));
-
- // cheat by setting conservation sequence directly
- // rather than calculating it - good enough for this test
- String consensus = "0123456789+*-";
- rcs.conservation = consensus.toCharArray();
-
- // column out of range:
- assertEquals(Color.RED,
- rcs.applyConservation(Color.RED, consensus.length()));
-
+ SequenceI pep1 = new Sequence("pep1", "APQTWLS");
+ SequenceI pep2 = new Sequence("pep2", "AILFQYG");
+ AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
+
/*
- * with 100% threshold, 'fade factor' is
- * (11-score)/10 * 100/20 = (11-score)/2
- * which is >= 1 for all scores i.e. all fade to white except +, *
+ * demonstrate that we can 'plug in' a colour scheme with specified
+ * criteria for applicability; here, that there are more than 2 sequences
*/
- rcs.setConservationInc(100);
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 0));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 1));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 2));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 3));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 4));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 5));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 6));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 7));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 8));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 9));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 10));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 11));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 12));
+ ColourSchemeI cs = new UserColourScheme()
+ {
+ @Override
+ public boolean isApplicableTo(AnnotatedCollectionI ac)
+ {
+ AlignmentI al = ac.getContext() == null ? (AlignmentI) ac
+ : (AlignmentI) ac.getContext();
+ return al.getSequences().size() > 2;
+ }
+ };
+ assertFalse(cs.isApplicableTo(peptide));
+ peptide.addSequence(pep1);
+ assertTrue(cs.isApplicableTo(peptide));
+ }
- /*
- * with 0% threshold, there should be no fading
- */
- rcs.setConservationInc(0);
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 0));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 1));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 2));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 3));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 4));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 5));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 6));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 7));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 8));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 9));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 10));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 11));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 12)); // gap
+ @Test(groups = "Functional")
+ public void testGetName()
+ {
+ SequenceI pep1 = new Sequence("pep1", "APQTWLS");
+ AlignmentI peptide = new Alignment(new SequenceI[] { pep1 });
- /*
- * with 40% threshold, 'fade factor' is
- * (11-score)/10 * 40/20 = (11-score)/5
- * which is {>1, >1, >1, >1, >1, >1, 1, 0.8, 0.6, 0.4} for score 0-9
- * e.g. score 7 colour fades 80% of the way to white (255, 255, 255)
- */
- rcs.setConservationInc(40);
- Color colour = new Color(155, 105, 55);
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 0));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 1));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 2));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 3));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 4));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 5));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 6));
- assertEquals(new Color(235, 225, 215), rcs.applyConservation(colour, 7));
- assertEquals(new Color(215, 195, 175), rcs.applyConservation(colour, 8));
- assertEquals(new Color(195, 165, 135), rcs.applyConservation(colour, 9));
- assertEquals(colour, rcs.applyConservation(colour, 10));
- assertEquals(colour, rcs.applyConservation(colour, 11));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 12));
+ assertEquals("Blosum62", new Blosum62ColourScheme().getSchemeName());
+ assertEquals("Buried Index", new BuriedColourScheme().getSchemeName());
+ assertEquals("Helix Propensity", new HelixColourScheme().getSchemeName());
+ assertEquals("Hydrophobic", new HydrophobicColourScheme().getSchemeName());
+ assertEquals("Strand Propensity", new StrandColourScheme().getSchemeName());
+ assertEquals("Taylor", new TaylorColourScheme().getSchemeName());
+ assertEquals("Turn Propensity", new TurnColourScheme().getSchemeName());
+ assertEquals("Zappo", new ZappoColourScheme().getSchemeName());
+ assertEquals("Nucleotide", new NucleotideColourScheme().getSchemeName());
+ assertEquals("Purine/Pyrimidine",
+ new PurinePyrimidineColourScheme().getSchemeName());
+ assertEquals("RNA Interaction type",
+ new RNAInteractionColourScheme().getSchemeName());
+ assertEquals("User Defined", new UserColourScheme().getSchemeName());
+ assertEquals("Score", new ScoreColourScheme(new int[] {},
+ new double[] {}, 0, 0d).getSchemeName());
+ assertEquals("% Identity", new PIDColourScheme().getSchemeName());
+ assertEquals("Follower", new FollowerColourScheme().getSchemeName());
+ assertEquals("T-Coffee Scores",
+ new TCoffeeColourScheme(peptide).getSchemeName());
+ assertEquals("RNA Helices",
+ new RNAHelicesColour(peptide).getSchemeName());
}
}
import java.util.Map;
import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
public class ScoreMatrixPrinter
{
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
}
- @Test(groups = { "Functional" })
public void printAllMatrices()
{
for (Map.Entry<String, ScoreModelI> sm : ResidueProperties.scoreMatrices
}
}
- @Test(groups = { "Functional" })
public void printHTMLMatrices()
{
for (Map.Entry<String, ScoreModelI> _sm : ResidueProperties.scoreMatrices
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.math.MatrixI;
+
+import org.testng.annotations.Test;
+
+public class ScoreMatrixTest
+{
+ @Test(groups = "Functional")
+ public void testSymmetric()
+ {
+ verifySymmetric(ResidueProperties.getScoreMatrix("BLOSUM62"));
+ verifySymmetric(ResidueProperties.getScoreMatrix("PAM250"));
+ verifySymmetric(ResidueProperties.getScoreMatrix("DNA"));
+ }
+
+ private void verifySymmetric(ScoreMatrix sm)
+ {
+ int[][] m = sm.getMatrix();
+ int rows = m.length;
+ for (int row = 0; row < rows; row++)
+ {
+ assertEquals(m[row].length, rows);
+ for (int col = 0; col < rows; col++)
+ {
+ assertEquals(m[row][col], m[col][row], String.format("%s [%s, %s]",
+ sm.getName(), ResidueProperties.aa[row],
+ ResidueProperties.aa[col]));
+ }
+ }
+
+ /*
+ * also check the score matrix is sized for
+ * the number of symbols scored, plus gap
+ */
+ assertEquals(rows, (sm.isDNA() ? ResidueProperties.maxNucleotideIndex
+ : ResidueProperties.maxProteinIndex) + 1);
+ }
+
+ /**
+ * A test that just asserts the expected values in the Blosum62 score matrix
+ */
+ @Test(groups = "Functional")
+ public void testBlosum62_values()
+ {
+ ScoreMatrix sm = ResidueProperties.getScoreMatrix("BLOSUM62");
+
+ /*
+ * verify expected scores against ARNDCQEGHILKMFPSTWYVBZX
+ * scraped from https://www.ncbi.nlm.nih.gov/Class/FieldGuide/BLOSUM62.txt
+ */
+ verifyValues(sm, 'A', new int[] { 4, -1, -2, -2, 0, -1, -1, 0, -2, -1,
+ -1, -1, -1, -2, -1, 1, 0, -3, -2, 0, -2, -1, 0 });
+ verifyValues(sm, 'R', new int[] { -1, 5, 0, -2, -3, 1, 0, -2, 0, -3,
+ -2, 2, -1, -3, -2, -1, -1, -3, -2, -3, -1, 0, -1 });
+ verifyValues(sm, 'N', new int[] { -2, 0, 6, 1, -3, 0, 0, 0, 1, -3, -3,
+ 0, -2, -3, -2, 1, 0, -4, -2, -3, 3, 0, -1 });
+ verifyValues(sm, 'D', new int[] { -2, -2, 1, 6, -3, 0, 2, -1, -1, -3,
+ -4, -1, -3, -3, -1, 0, -1, -4, -3, -3, 4, 1, -1 });
+ verifyValues(sm, 'C', new int[] { 0, -3, -3, -3, 9, -3, -4, -3, -3, -1,
+ -1, -3, -1, -2, -3, -1, -1, -2, -2, -1, -3, -3, -2 });
+ verifyValues(sm, 'Q', new int[] { -1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2,
+ 1, 0, -3, -1, 0, -1, -2, -1, -2, 0, 3, -1 });
+ verifyValues(sm, 'E', new int[] { -1, 0, 0, 2, -4, 2, 5, -2, 0, -3, -3,
+ 1, -2, -3, -1, 0, -1, -3, -2, -2, 1, 4, -1 });
+ verifyValues(sm, 'G', new int[] { 0, -2, 0, -1, -3, -2, -2, 6, -2, -4,
+ -4, -2, -3, -3, -2, 0, -2, -2, -3, -3, -1, -2, -1 });
+ verifyValues(sm, 'H', new int[] { -2, 0, 1, -1, -3, 0, 0, -2, 8, -3,
+ -3, -1, -2, -1, -2, -1, -2, -2, 2, -3, 0, 0, -1 });
+ verifyValues(sm, 'I', new int[] { -1, -3, -3, -3, -1, -3, -3, -4, -3,
+ 4, 2, -3, 1, 0, -3, -2, -1, -3, -1, 3, -3, -3, -1 });
+ verifyValues(sm, 'L', new int[] { -1, -2, -3, -4, -1, -2, -3, -4, -3,
+ 2, 4, -2, 2, 0, -3, -2, -1, -2, -1, 1, -4, -3, -1 });
+ verifyValues(sm, 'K', new int[] { -1, 2, 0, -1, -3, 1, 1, -2, -1, -3,
+ -2, 5, -1, -3, -1, 0, -1, -3, -2, -2, 0, 1, -1 });
+ verifyValues(sm, 'M', new int[] { -1, -1, -2, -3, -1, 0, -2, -3, -2, 1,
+ 2, -1, 5, 0, -2, -1, -1, -1, -1, 1, -3, -1, -1 });
+ verifyValues(sm, 'F', new int[] { -2, -3, -3, -3, -2, -3, -3, -3, -1,
+ 0, 0, -3, 0, 6, -4, -2, -2, 1, 3, -1, -3, -3, -1 });
+ verifyValues(sm, 'P', new int[] { -1, -2, -2, -1, -3, -1, -1, -2, -2,
+ -3, -3, -1, -2, -4, 7, -1, -1, -4, -3, -2, -2, -1, -2 });
+ verifyValues(sm, 'S', new int[] { 1, -1, 1, 0, -1, 0, 0, 0, -1, -2, -2,
+ 0, -1, -2, -1, 4, 1, -3, -2, -2, 0, 0, 0 });
+ verifyValues(sm, 'T', new int[] { 0, -1, 0, -1, -1, -1, -1, -2, -2, -1,
+ -1, -1, -1, -2, -1, 1, 5, -2, -2, 0, -1, -1, 0 });
+ verifyValues(sm, 'W', new int[] { -3, -3, -4, -4, -2, -2, -3, -2, -2,
+ -3, -2, -3, -1, 1, -4, -3, -2, 11, 2, -3, -4, -3, -2 });
+ verifyValues(sm, 'Y', new int[] { -2, -2, -2, -3, -2, -1, -2, -3, 2,
+ -1, -1, -2, -1, 3, -3, -2, -2, 2, 7, -1, -3, -2, -1 });
+ verifyValues(sm, 'V', new int[] { 0, -3, -3, -3, -1, -2, -2, -3, -3, 3,
+ 1, -2, 1, -1, -2, -2, 0, -3, -1, 4, -3, -2, -1 });
+ verifyValues(sm, 'B', new int[] { -2, -1, 3, 4, -3, 0, 1, -1, 0, -3,
+ -4, 0, -3, -3, -2, 0, -1, -4, -3, -3, 4, 1, -1 });
+ verifyValues(sm, 'Z', new int[] { -1, 0, 0, 1, -3, 3, 4, -2, 0, -3, -3,
+ 1, -1, -3, -1, 0, -1, -3, -2, -2, 1, 4, -1 });
+ verifyValues(sm, 'X', new int[] { 0, -1, -1, -1, -2, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -2, 0, 0, -2, -1, -1, -1, -1, -1 });
+ }
+ /**
+ * Helper method to check pairwise scores for one residue
+ *
+ * @param sm
+ * @param res
+ * @param expected
+ * score values against 'res', in ResidueProperties.aaIndex order
+ */
+ private void verifyValues(ScoreMatrix sm, char res, int[] expected)
+ {
+ for (int j = 0; j < expected.length; j++)
+ {
+ char c2 = ResidueProperties.aa[j].charAt(0);
+ assertEquals(sm.getPairwiseScore(res, c2), expected[j],
+ String.format("%s->%s", res, c2));
+ }
+ }
+
+ @Test(groups = "Functional")
+ public void testComputePairwiseScores()
+ {
+ String[] seqs = new String[] { "FKL", "R-D", "QIA", "GWC" };
+ ScoreMatrix sm = ResidueProperties.getScoreMatrix("BLOSUM62");
+
+ MatrixI pairwise = sm.computePairwiseScores(seqs);
+
+ /*
+ * should be NxN where N = number of sequences
+ */
+ assertEquals(pairwise.height(), 4);
+ assertEquals(pairwise.width(), 4);
+
+ /*
+ * should be symmetrical (because BLOSUM62 is)
+ */
+ for (int i = 0; i < pairwise.height(); i++)
+ {
+ for (int j = 0; j < pairwise.width(); j++)
+ {
+ assertEquals(pairwise.getValue(i, j), pairwise.getValue(j, i),
+ "Not symmetric");
+ }
+ }
+ /*
+ * verify expected BLOSUM dot product scores
+ */
+ // F.F + K.K + L.L = 6 + 5 + 4 = 15
+ assertEquals(pairwise.getValue(0, 0), 15d);
+ // R.R + -.- + D.D = 5 + 1 + 6 = 12
+ assertEquals(pairwise.getValue(1, 1), 12d);
+ // Q.Q + I.I + A.A = 5 + 4 + 4 = 13
+ assertEquals(pairwise.getValue(2, 2), 13d);
+ // G.G + W.W + C.C = 6 + 11 + 9 = 26
+ assertEquals(pairwise.getValue(3, 3), 26d);
+ // F.R + K.- + L.D = -3 + -4 + -4 = -11
+ assertEquals(pairwise.getValue(0, 1), -11d);
+ // F.Q + K.I + L.A = -3 + -3 + -1 = -7
+ assertEquals(pairwise.getValue(0, 2), -7d);
+ // F.G + K.W + L.C = -3 + -3 + -1 = -7
+ assertEquals(pairwise.getValue(0, 3), -7d);
+ // R.Q + -.I + D.A = 1 + -4 + -2 = -5
+ assertEquals(pairwise.getValue(1, 2), -5d);
+ // R.G + -.W + D.C = -2 + -4 + -3 = -9
+ assertEquals(pairwise.getValue(1, 3), -9d);
+ // Q.G + I.W + A.C = -2 + -3 + 0 = -5
+ assertEquals(pairwise.getValue(2, 3), -5d);
+ }
+}
package jalview.schemes;
import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertSame;
import jalview.gui.JvOptionPane;
}
@Test(groups = "Functional")
- public void testGetColourFromString()
+ public void testParseAppletParameter()
{
- /*
- * by colour name - if known to AWT, and included in
- *
- * @see ColourSchemeProperty.getAWTColorFromName()
- */
- assertSame(Color.RED, UserColourScheme.getColourFromString("red"));
- assertSame(Color.RED, UserColourScheme.getColourFromString("Red"));
- assertSame(Color.RED, UserColourScheme.getColourFromString(" RED "));
+ UserColourScheme cs = new UserColourScheme("white");
+ cs.parseAppletParameter("D,E=red; K,R,H=0022FF; c=10 , 20,30");
+ assertEquals(Color.RED, cs.findColour('D'));
+ assertEquals(Color.RED, cs.findColour('d'));
+ assertEquals(Color.RED, cs.findColour('E'));
+ assertEquals(Color.RED, cs.findColour('e'));
+ Color c1 = new Color(0x0022ff);
+ assertEquals(c1, cs.findColour('K'));
+ assertEquals(c1, cs.findColour('R'));
+ assertEquals(c1, cs.findColour('h'));
+ Color c2 = new Color(10, 20, 30);
+ assertEquals(c2, cs.findColour('c'));
- /*
- * by RGB hex code
- */
- String hexColour = Integer.toHexString(Color.RED.getRGB() & 0xffffff);
- assertEquals(Color.RED, UserColourScheme.getColourFromString(hexColour));
- // 'hex' prefixes _not_ wanted here
- assertNull(UserColourScheme.getColourFromString("0x" + hexColour));
- assertNull(UserColourScheme.getColourFromString("#" + hexColour));
-
- /*
- * by RGB triplet
- */
- String rgb = String.format("%d,%d,%d", Color.red.getRed(),
- Color.red.getGreen(), Color.red.getBlue());
- assertEquals(Color.RED, UserColourScheme.getColourFromString(rgb));
+ cs = new UserColourScheme("white");
+ cs.parseAppletParameter("D,E=red; K,R,H=0022FF; c=10 , 20,30;t=orange;lowercase=blue;s=pink");
+ assertEquals(Color.RED, cs.findColour('D'));
+ assertEquals(Color.blue, cs.findColour('d'));
+ assertEquals(Color.RED, cs.findColour('E'));
+ assertEquals(Color.blue, cs.findColour('e'));
+ assertEquals(c1, cs.findColour('K'));
+ assertEquals(c1, cs.findColour('R'));
+ assertEquals(Color.blue, cs.findColour('h'));
+ assertEquals(c2, cs.findColour('c'));
+ // 'lowercase' sets all lower-case not already set to the given colour
+ assertEquals(Color.orange, cs.findColour('t'));
+ assertEquals(Color.blue, cs.findColour('k'));
+ assertEquals(Color.blue, cs.findColour('a'));
+ assertEquals(Color.pink, cs.findColour('s'));
+ }
- /*
- * odds and ends
- */
- assertNull(UserColourScheme.getColourFromString(null));
- assertNull(UserColourScheme.getColourFromString("rubbish"));
- assertEquals(Color.WHITE, UserColourScheme.getColourFromString("-1"));
- assertNull(UserColourScheme.getColourFromString(String
- .valueOf(Integer.MAX_VALUE)));
+ @Test(groups = "Functional")
+ public void testToAppletParameter()
+ {
+ UserColourScheme cs = new UserColourScheme(
+ "E,D=red; K,R,H=0022FF; c=10 , 20,30");
+ String param = cs.toAppletParameter();
+ assertEquals("D,E=ff0000;H,K,R=0022ff;c=0a141e", param);
}
}
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureRenderer;
+import jalview.api.SequenceRenderer;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.PDBEntry.Type;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.gui.JvOptionPane;
import jalview.io.DataSourceType;
+import jalview.schemes.ColourSchemeI;
import jalview.structure.AtomSpec;
+import jalview.structure.StructureMappingcommandSet;
import jalview.structure.StructureSelectionManager;
import jalview.structures.models.AAStructureBindingModel.SuperposeData;
+import java.awt.Color;
import java.util.Arrays;
import java.util.List;
{
return null;
}
+
+ @Override
+ public void setJalviewColourScheme(ColourSchemeI cs)
+ {
+ }
+
+ @Override
+ public void superposeStructures(AlignmentI[] als, int[] alm,
+ ColumnSelection[] alc)
+ {
+ }
+
+ @Override
+ public void setBackgroundColour(Color col)
+ {
+ }
+
+ @Override
+ protected StructureMappingcommandSet[] getColourBySequenceCommands(
+ String[] files, SequenceRenderer sr, FeatureRenderer fr,
+ AlignmentI alignment)
+ {
+ return null;
+ }
+
+ @Override
+ public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
+ {
+ return null;
+ }
+
+ @Override
+ public SequenceRenderer getSequenceRenderer(
+ AlignmentViewPanel alignment)
+ {
+ return null;
+ }
+
+ @Override
+ protected void colourBySequence(
+ StructureMappingcommandSet[] colourBySequenceCommands)
+ {
+ }
+
+ @Override
+ public void colourByChain()
+ {
+ }
+
+ @Override
+ public void colourByCharge()
+ {
+ }
};
}
assertFalse(matched[4]); // superposable, but hidden, column
assertTrue(matched[5]);
}
+
+ public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
+ {
+ return null;
+ }
+
+ public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
+ {
+ return null;
+ }
}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.urls;
+
+import jalview.urls.api.UrlProviderFactoryI;
+import jalview.urls.api.UrlProviderI;
+import jalview.urls.applet.AppletUrlProviderFactory;
+import jalview.util.UrlConstants;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class AppletUrlProviderFactoryTest {
+
+ @Test(groups = { "Functional" })
+ public void testCreateUrlProvider()
+ {
+ final String defaultUrl = UrlConstants.DEFAULT_STRING.substring(
+ UrlConstants.DEFAULT_STRING.indexOf(UrlConstants.SEP) + 1,
+ UrlConstants.DEFAULT_STRING.length());
+ Map<String, String> urlList = new HashMap<String, String>()
+ {
+ {
+ put("Test1", "http://identifiers.org/uniprot/$DB_ACCESSION$");
+ put("Test2", defaultUrl);
+ }
+ };
+
+ UrlProviderFactoryI factory = new AppletUrlProviderFactory("Test2",
+ urlList);
+ UrlProviderI prov = factory.createUrlProvider();
+
+ // default url correctly set
+ Assert.assertEquals(prov.getPrimaryUrlId(), "Test2");
+ Assert.assertEquals(prov.getPrimaryUrl("FER_CAPAN"),
+ defaultUrl.replace("$SEQUENCE_ID$",
+ "FER_CAPAN"));
+
+ List<UrlLinkDisplay> allLinks = prov.getLinksForTable();
+
+ // 2 links in provider
+ Assert.assertEquals(allLinks.size(), 2);
+
+ // first link set correctly
+ Assert.assertEquals(allLinks.get(0).getId(), "Test1");
+ Assert.assertEquals(allLinks.get(0).getDescription(), "Test1");
+ Assert.assertEquals(allLinks.get(0).getUrl(),
+ "http://identifiers.org/uniprot/$DB_ACCESSION$");
+ Assert.assertFalse(allLinks.get(0).getIsPrimary());
+ Assert.assertTrue(allLinks.get(0).getIsSelected());
+
+ // second link set correctly
+ Assert.assertEquals(allLinks.get(1).getId(), "Test2");
+ Assert.assertEquals(allLinks.get(1).getDescription(), "Test2");
+ Assert.assertEquals(allLinks.get(1).getUrl(), defaultUrl);
+ Assert.assertTrue(allLinks.get(1).getIsPrimary());
+ Assert.assertTrue(allLinks.get(1).getIsSelected());
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.urls;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+import jalview.urls.api.UrlProviderI;
+import jalview.util.UrlConstants;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Vector;
+
+import org.testng.annotations.Test;
+
+public class CustomUrlProviderTest
+{
+
+ private static final String cachedList = "TEST|http://someurl.blah/$DB_ACCESSION$|"
+ + "ANOTHER|http://test/t$SEQUENCE_ID$|"
+ + "TEST2|http://address/$SEQUENCE_ID$|SRS|"
+ + "http://theSRSlink/$SEQUENCE_ID$";
+
+ private static final String unselectedList = "NON1|http://x/y/$DB_ACCESSION$|"
+ + "NON2|http://a/b/c/$DB_ACCESSION";
+
+ private static final HashMap<String, String> urlMap = new HashMap<String, String>()
+ {
+ {
+ put("TEST","http://someurl.blah/$DB_ACCESSION$");
+ put("ANOTHER","http://test/t$SEQUENCE_ID$");
+ put("TEST2", "http://address/$SEQUENCE_ID$");
+ put("SRS", "http://theSRSlink/$SEQUENCE_ID$");
+ }
+ };
+
+ private static final HashMap<String, String> unselUrlMap = new HashMap<String, String>()
+ {
+ {
+ put("NON1", "http://x/y/$DB_ACCESSION$");
+ put("NON2", "http://a/b/c/$DB_ACCESSION");
+ }
+ };
+
+ private static final String[] dlinks = {
+ "TEST|http://someurl.blah/$DB_ACCESSION$",
+ "ANOTHER|http://test/t$SEQUENCE_ID$",
+ "TEST2|http://address/$SEQUENCE_ID$",
+ UrlConstants.DEFAULT_STRING };
+
+ private static final String[] unselDlinks = {
+ "NON1|http://x/y/$DB_ACCESSION$", "NON2|http://a/b/c/$DB_ACCESSION" };
+
+ private static final Vector<String> displayLinks = new Vector<String>(
+ Arrays.asList(dlinks));
+
+ private static final Vector<String> unselDisplayLinks = new Vector<String>(
+ Arrays.asList(unselDlinks));
+
+ private static final String[] dlinks2 = { "a|http://x.y.z/$SEQUENCE_ID$" };
+
+ private static final Vector<String> displayLinks2 = new Vector<String>(
+ Arrays.asList(dlinks2));
+
+ private static final String[] list1 = { "a" };
+
+ private static final String[] list2 = { "http://x.y.z/$SEQUENCE_ID$" };
+
+ private static final Vector<String> names = new Vector<String>(
+ Arrays.asList(list1));
+
+ private static final Vector<String> urls = new Vector<String>(
+ Arrays.asList(list2));
+
+ /*
+ * Test default url is set and returned correctly
+ */
+ @Test(groups = { "Functional" })
+ public void testDefaultUrl()
+ {
+ UrlProviderI customProv = new CustomUrlProvider(cachedList,
+ unselectedList);
+
+ // default url can be set
+ assertTrue(customProv.setPrimaryUrl("ANOTHER"));
+
+ // supplied replacement id must be more than 4 chars
+ String result = customProv.getPrimaryUrl("123");
+ assertEquals(null, result);
+
+ // default url can be retrieved given a sequence id
+ result = customProv.getPrimaryUrl("seqid");
+ assertEquals("http://test/tseqid", result);
+
+ // if there is no default url it sets the default to null
+ assertFalse(customProv.setPrimaryUrl("No default"));
+ result = customProv.getPrimaryUrl("testid");
+ assertEquals(null, result);
+
+ // choosing the default picks the DEFAULT_STRING option
+ customProv.choosePrimaryUrl();
+ result = customProv.getPrimaryUrl("seqid");
+ assertEquals(
+ UrlConstants.DEFAULT_STRING.split("\\|")[1].split("\\$")[0]
+ + "seqid",
+ result);
+ }
+
+ /*
+ * Test urls are set and returned correctly
+ */
+ @Test(groups = { "Functional" })
+ public void testUrlLinks()
+ {
+ // creation from cached url list works + old links upgraded
+ UrlProviderI customProv = new CustomUrlProvider(cachedList,
+ unselectedList);
+ assertTrue(displayLinks.containsAll(customProv.getLinksForMenu()));
+
+ // creation from map works + old links upgraded
+ UrlProviderI customProv2 = new CustomUrlProvider(urlMap, unselUrlMap);
+ assertTrue(displayLinks.containsAll(customProv2.getLinksForMenu()));
+
+ // writing url links as a string works
+ // because UrlProvider does not guarantee order of links, we can't just
+ // compare the output of writeUrlsAsString to a string, hence the hoops here
+ String result = customProv.writeUrlsAsString(true);
+ UrlProviderI up = new CustomUrlProvider(result, "");
+ assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
+
+ result = customProv.writeUrlsAsString(false);
+ up = new CustomUrlProvider("", result);
+ assertTrue(unselDisplayLinks.containsAll(up.getLinksForMenu()));
+
+ result = customProv2.writeUrlsAsString(true);
+ UrlProviderI up2 = new CustomUrlProvider(result, "");
+ assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));
+
+ result = customProv2.writeUrlsAsString(false);
+ up2 = new CustomUrlProvider("", result);
+ assertTrue(displayLinks.containsAll(up2.getLinksForMenu()));
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.urls;
+
+import jalview.urls.api.UrlProviderI;
+import jalview.urls.desktop.DesktopUrlProviderFactory;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class DesktopUrlProviderFactoryTest
+{
+ private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
+ + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
+ + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
+ + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\","
+ + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
+ + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
+ + "\"url\":\"http://identifiers.org/interpro\"},"
+ + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
+ + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
+
+ @BeforeMethod(alwaysRun = true)
+ public void setup()
+ {
+ // make a dummy identifiers.org download file
+ File temp = null;
+
+ try
+ {
+ temp = File.createTempFile("tempfile", ".tmp");
+ temp.deleteOnExit();
+ BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
+ bw.write(testIdOrgString);
+ bw.close();
+ } catch (IOException e)
+ {
+ System.out
+ .println("Error initialising DesktopUrlProviderFactoryTest test: "
+ + e.getMessage());
+ }
+
+ IdOrgSettings.setDownloadLocation(temp.getPath());
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreateUrlProvider()
+ {
+ String defaultUrlString = "Test1";
+ String defaultUrl = "http://blah.blah/$SEQUENCE_ID$";
+ String cachedUrlList = "MIR:00000005|MIR:00000011|Test1|http://blah.blah/$SEQUENCE_ID$|"
+ + "Test2|http://test2/$DB_ACCESSION$|Test3|http://test3/$SEQUENCE_ID$";
+ String userUrlList = "MIR:00000372|Test4|httpL//another.url/$SEQUENCE_ID$";
+
+ DesktopUrlProviderFactory factory = new DesktopUrlProviderFactory(
+ defaultUrlString, cachedUrlList, userUrlList);
+ UrlProviderI prov = factory.createUrlProvider();
+
+ // default url correctly set
+ Assert.assertEquals(prov.getPrimaryUrlId(), "Test1");
+ Assert.assertEquals(prov.getPrimaryUrl("FER_CAPAN"),
+ defaultUrl.replace("$SEQUENCE_ID$", "FER_CAPAN"));
+
+ List<String> menulinks = prov.getLinksForMenu();
+ List<UrlLinkDisplay> allLinks = prov.getLinksForTable();
+
+ // 8 links in provider - 4 from id file, 4 custom links
+ Assert.assertEquals(allLinks.size(), 8);
+
+ // 5 links in menu (cachedUrlList)
+ Assert.assertEquals(menulinks.size(), 5);
+
+ Assert.assertTrue(menulinks
+ .contains("Test1|http://blah.blah/$SEQUENCE_ID$"));
+ Assert.assertTrue(menulinks
+ .contains("Test2|http://test2/$DB_ACCESSION$"));
+ Assert.assertTrue(menulinks
+ .contains("Test3|http://test3/$SEQUENCE_ID$"));
+ Assert.assertTrue(menulinks
+ .contains("UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$|uniprot"));
+ Assert.assertTrue(menulinks
+ .contains("InterPro|http://identifiers.org/interpro/$DB_ACCESSION$|interpro"));
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.urls;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+import jalview.urls.api.UrlProviderI;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Vector;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class IdentifiersUrlProviderTest
+{
+ private static final String testIdOrgFile = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
+ + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
+ + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
+ + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\","
+ + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
+ + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
+ + "\"url\":\"http://identifiers.org/interpro\"},"
+ + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
+ + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
+
+ private static final String[] dlinks = {
+ "UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$|uniprot",
+ "InterPro|http://identifiers.org/interpro/$DB_ACCESSION$|interpro",
+ "ENA|http://identifiers.org/ena.embl/$DB_ACCESSION$|ena.embl" };
+
+ private static final String[] dlinks1 = {
+ "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$",
+ "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$" };
+
+ private static final String[] dlinks2 = {
+ "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$",
+ "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$" };
+
+ private static final String stringLinks = "MIR:00000005|http://identifiers.org/uniprot/$DB_ACCESSION$"
+ + "MIR:00000011|http://identifiers.org/interpro/$DB_ACCESSION$"
+ + "MIR:00000372|http://identifiers.org/ena.embl/$DB_ACCESSION$";
+
+ private static final String[] unselDlinks = { "ChEBI|http://identifiers.org/chebi/$DB_ACCESSION$" };
+
+ private static final Vector<String> displayLinks = new Vector<String>(
+ Arrays.asList(dlinks));
+
+ private static final Vector<String> unselDisplayLinks = new Vector<String>(
+ Arrays.asList(unselDlinks));
+
+ private static final Vector<String> displayLinks1 = new Vector<String>(
+ Arrays.asList(dlinks1));
+
+ private static final Vector<String> displayLinks2 = new Vector<String>(
+ Arrays.asList(dlinks2));
+
+ private static final HashMap<String, String> urlMap = new HashMap<String, String>()
+ {
+ {
+ put("MIR:00000005", "http://identifiers.org/uniprot/$DB_ACCESSION$");
+ put("MIR:00000011", "http://identifiers.org/interpro/$DB_ACCESSION$");
+ put("MIR:00000372", "http://identifiers.org/ena.embl/$DB_ACCESSION$");
+ }
+ };
+
+ private String testfile = "";
+
+
+ @BeforeClass(alwaysRun = true)
+ public void setup()
+ {
+ // setup test ids in a file
+ File outFile = null;
+ try
+ {
+ outFile = File.createTempFile("testidsfile", "txt");
+ outFile.deleteOnExit();
+
+ FileWriter fw = new FileWriter(outFile);
+ fw.write(testIdOrgFile);
+ fw.close();
+
+ testfile = outFile.getAbsolutePath();
+
+ } catch (Exception ex)
+ {
+ System.err.println(ex);
+ }
+
+ IdOrgSettings.setDownloadLocation(testfile);
+ }
+
+ /*
+ * Test urls are set and returned correctly
+ */
+ @Test(groups = { "Functional" })
+ public void testUrlLinks()
+ {
+ // creation from cached id list
+ String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
+ UrlProviderI idProv = new IdentifiersUrlProvider(idList);
+
+ assertTrue(displayLinks.containsAll(idProv.getLinksForMenu()));
+
+ // because UrlProvider does not guarantee order of links, we can't just
+ // compare the output of writeUrlsAsString to a string, hence the hoops here
+ String result = idProv.writeUrlsAsString(true);
+ UrlProviderI up = new IdentifiersUrlProvider(result);
+ assertTrue(displayLinks.containsAll(up.getLinksForMenu()));
+
+ result = idProv.writeUrlsAsString(false);
+ up = new IdentifiersUrlProvider(result);
+ assertTrue(unselDisplayLinks.containsAll(up.getLinksForMenu()));
+
+ }
+
+ /*
+ * Test default is set and returned correctly
+ */
+ @Test(groups = { "Functional" })
+ public void testDefaultUrl()
+ {
+ // creation from cached id list
+ String idList = "MIR:00000005|MIR:00000011|MIR:00000372";
+ UrlProviderI idProv = new IdentifiersUrlProvider(idList);
+
+ // initially no default
+ assertEquals(null, idProv.getPrimaryUrl("seqid"));
+
+ // set and then retrieve default
+ assertTrue(idProv.setPrimaryUrl("MIR:00000005"));
+ assertEquals("http://identifiers.org/uniprot/seqid",
+ idProv.getPrimaryUrl("seqid"));
+
+ // ids less than length 4 return null
+ assertEquals(null,
+ idProv.getPrimaryUrl("123"));
+
+ // attempt to set bad default
+ assertFalse(idProv.setPrimaryUrl("MIR:00001234"));
+ // default set to null (as default should have been set elsewhere)
+ assertEquals(null, idProv.getPrimaryUrl("seqid"));
+
+ // chooseDefaultUrl not implemented for IdentifiersUrlProvider
+ assertEquals(null, idProv.choosePrimaryUrl());
+ }
+}
--- /dev/null
+package jalview.urls;
+
+import jalview.util.UrlLink;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class UrlLinkDisplayTest {
+
+ @Test(groups = { "Functional" })
+ public void testDisplayColumnNames()
+ {
+ // 5 column names returned although 6 names internal to UrlLinkDisplay
+ List<String> names = UrlLinkDisplay.getDisplayColumnNames();
+ Assert.assertEquals(names.size(), 5);
+ }
+
+ @Test(groups = { "Functional" })
+ public void getValue()
+ {
+ UrlLink link = new UrlLink("Test Name",
+ "http://identifiers.org/$DB_ACCESSION$", "TestDB");
+ UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
+
+ Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.PRIMARY));
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "Test");
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "TestDB");
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "Test Name");
+ Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.SELECTED));
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.URL),
+ "http://identifiers.org/$DB_ACCESSION$");
+ }
+
+ @Test(groups = { "Functional" })
+ public void testIsEditable()
+ {
+ // only default and selected columns are editable ever
+ // default only editable if link contains $SEQUENCE_ID$
+
+ UrlLink link = new UrlLink("Test Url",
+ "http://identifiers.org/$DB_ACCESSION$",
+ "TestName");
+ UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
+
+ Assert.assertFalse(u.isEditable(UrlLinkDisplay.PRIMARY));
+ Assert.assertTrue(u.isEditable(UrlLinkDisplay.SELECTED));
+ Assert.assertFalse(u.isEditable(UrlLinkDisplay.ID));
+ Assert.assertFalse(u.isEditable(UrlLinkDisplay.URL));
+ Assert.assertFalse(u.isEditable(UrlLinkDisplay.NAME));
+ Assert.assertFalse(u.isEditable(UrlLinkDisplay.DATABASE));
+
+ UrlLink vlink = new UrlLink("Test Sequence ID Url",
+ "http://myurl/$SEQUENCE_ID$", "TestName");
+ UrlLinkDisplay v = new UrlLinkDisplay("Test", vlink, false, false);
+
+ Assert.assertTrue(v.isEditable(UrlLinkDisplay.PRIMARY));
+ Assert.assertTrue(v.isEditable(UrlLinkDisplay.SELECTED));
+ Assert.assertFalse(v.isEditable(UrlLinkDisplay.ID));
+ Assert.assertFalse(v.isEditable(UrlLinkDisplay.URL));
+ Assert.assertFalse(v.isEditable(UrlLinkDisplay.NAME));
+ Assert.assertFalse(v.isEditable(UrlLinkDisplay.DATABASE));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testName()
+ {
+ UrlLink link = new UrlLink("Test Url",
+ "http://identifiers.org/$DB_ACCESSION$", "TestName");
+ UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
+
+ // Name initially as input in link
+ Assert.assertEquals(u.getDBName(), "TestName");
+
+ // Setting updates name
+ u.setDBName("NewName");
+ Assert.assertEquals(u.getDBName(), "NewName");
+ }
+
+ @Test(groups = { "Functional" })
+ public void testDescription()
+ {
+ UrlLink link = new UrlLink("Test Name",
+ "http://identifiers.org/$DB_ACCESSION$", "TestDB");
+ UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
+
+ // Desc initially as input in link
+ Assert.assertEquals(u.getDescription(), "Test Name");
+
+ // Setting updates name
+ u.setDescription("New Desc");
+ Assert.assertEquals(u.getDescription(), "New Desc");
+ }
+
+ @Test(groups = { "Functional" })
+ public void testUrl()
+ {
+ UrlLink link = new UrlLink("Test Name",
+ "http://identifiers.org/$DB_ACCESSION$", "TestDB");
+ UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
+
+ // Url initially as input in link
+ Assert.assertEquals(u.getUrl(), "http://identifiers.org/$DB_ACCESSION$");
+
+ // Setting updates url
+ u.setUrl("http://something.new/$SEQUENCE_ID$");
+ Assert.assertEquals(u.getUrl(), "http://something.new/$SEQUENCE_ID$");
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetSetValue()
+ {
+ UrlLink link = new UrlLink("Test Name",
+ "http://identifiers.org/$DB_ACCESSION$", "TestDB");
+ UrlLinkDisplay u = new UrlLinkDisplay("Test", link, false, false);
+
+ Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.PRIMARY));
+ Assert.assertFalse((boolean) u.getValue(UrlLinkDisplay.SELECTED));
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "TestDB");
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "Test Name");
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "Test");
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.URL),
+ "http://identifiers.org/$DB_ACCESSION$");
+
+ u.setValue(UrlLinkDisplay.PRIMARY, true);
+ Assert.assertTrue((boolean) u.getValue(UrlLinkDisplay.PRIMARY));
+
+ u.setValue(UrlLinkDisplay.SELECTED, true);
+ Assert.assertTrue((boolean) u.getValue(UrlLinkDisplay.SELECTED));
+
+ u.setValue(UrlLinkDisplay.NAME, "New Desc");
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.NAME), "New Desc");
+
+ u.setValue(UrlLinkDisplay.DATABASE, "NewName");
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.DATABASE), "NewName");
+
+ u.setValue(UrlLinkDisplay.ID, "New ID");
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.ID), "New ID");
+
+ u.setValue(UrlLinkDisplay.URL, "http://something.new/$SEQUENCE_ID$");
+ Assert.assertEquals(u.getValue(UrlLinkDisplay.URL),
+ "http://something.new/$SEQUENCE_ID$");
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.urls;
+
+import static jalview.util.UrlConstants.DELIM;
+import static jalview.util.UrlConstants.SEP;
+import static jalview.util.UrlConstants.SEQUENCE_ID;
+
+import jalview.urls.api.UrlProviderI;
+import jalview.util.MessageManager;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.event.TableModelListener;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class UrlLinkTableModelTest {
+
+ private static final String inmenu = "TEST|http://someurl.blah/$DB_ACCESSION$|"
+ + "ANOTHER|http://test/t$SEQUENCE_ID$|"
+ + "TEST2|http://address/$SEQUENCE_ID$|SRS|"
+ + "http://theSRSlink/$SEQUENCE_ID$|"
+ + "MIR:00000005|MIR:00000011|MIR:00000372";
+
+ private static final String notinmenu = "Not1|http://not.in.menu/$DB_ACCESSION$|"
+ + "Not2|http://not.in.menu.either/$DB_ACCESSION$";
+
+ private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
+ + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
+ + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
+ + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\","
+ + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
+ + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
+ + "\"url\":\"http://identifiers.org/interpro\"},"
+ + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
+ + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
+
+ private UrlProviderI prov;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setup()
+ {
+ // set up UrlProvider data as the source for the TableModel
+ // the data gets updated by the TableModel, so needs to be reinitialised for
+ // each test
+
+ // make a dummy identifiers.org download file
+ File temp = null;
+ try
+ {
+ temp = File.createTempFile("tempfile", ".tmp");
+ temp.deleteOnExit();
+ BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
+ bw.write(testIdOrgString);
+ bw.close();
+ } catch (IOException e)
+ {
+ System.out.println("Error initialising UrlLinkTableModel test: "
+ + e.getMessage());
+ }
+
+ // set up custom and identifiers.org url providers
+ IdOrgSettings.setDownloadLocation(temp.getPath());
+ IdentifiersUrlProvider idprov = new IdentifiersUrlProvider(inmenu);
+ CustomUrlProvider cprov = new CustomUrlProvider(inmenu, notinmenu);
+ List<UrlProviderI> provlist = new ArrayList<UrlProviderI>();
+ provlist.add(idprov);
+ provlist.add(cprov);
+
+ prov = new UrlProvider("TEST2", provlist);
+ }
+
+ /*
+ * Test that the table model is correctly initialised
+ * Display columns and default row are set; data provider listening event set up
+ */
+ @Test(groups = { "Functional" })
+ public void testInitialisation()
+ {
+ int defaultCol = 4;
+ int dbCol = 0;
+ int descCol = 1;
+
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ // exactly one table model listener
+ TableModelListener[] listeners = m
+ .getListeners(TableModelListener.class);
+ Assert.assertEquals(listeners.length, 1);
+
+ // default row exists, there is exactly 1, and it matches the supplied
+ // default
+ int count = 0;
+ for (int row = 0; row < m.getRowCount(); row++)
+ {
+ boolean isDefault = (boolean) m.getValueAt(row, defaultCol);
+ if (isDefault)
+ {
+ count++;
+ String defaultDBName = (String) m.getValueAt(row, dbCol);
+ Assert.assertEquals(defaultDBName, "TEST2");
+
+ String defaultDesc = (String) m.getValueAt(row, descCol);
+ Assert.assertEquals(defaultDesc, "TEST2");
+ }
+ }
+ Assert.assertEquals(count, 1);
+ }
+
+ /*
+ * Test row and column counts
+ */
+ @Test(groups = { "Functional" })
+ public void testCounts()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ // correct numbers of column and rows
+ Assert.assertEquals(m.getColumnCount(), 5);
+ Assert.assertEquals(m.getRowCount(), 10);
+ }
+
+ /*
+ * Test column access
+ */
+ @Test(groups = { "Functional" })
+ public void testColumns()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ // check column names
+ Assert.assertEquals(m.getColumnName(0),
+ MessageManager.formatMessage("label.database"));
+ Assert.assertEquals(m.getColumnName(1),
+ MessageManager.formatMessage("label.name"));
+ Assert.assertEquals(m.getColumnName(2),
+ MessageManager.formatMessage("label.url"));
+ Assert.assertEquals(m.getColumnName(3),
+ MessageManager.formatMessage("label.inmenu"));
+ Assert.assertEquals(m.getColumnName(4),
+ MessageManager.formatMessage("label.primary"));
+
+ // check column classes
+ Assert.assertEquals(m.getColumnClass(0), String.class);
+ Assert.assertEquals(m.getColumnClass(1), String.class);
+ Assert.assertEquals(m.getColumnClass(2), String.class);
+ Assert.assertEquals(m.getColumnClass(3), Boolean.class);
+ Assert.assertEquals(m.getColumnClass(4), Boolean.class);
+ }
+
+ /*
+ * Test row insertion
+ */
+ @Test(groups = { "Functional" })
+ public void testRowInsert()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ m.insertRow("newname", "newurl");
+
+ // check table has new row inserted
+ Assert.assertEquals(m.getValueAt(10, 0), "newname");
+ Assert.assertEquals(m.getValueAt(10, 1), "newname");
+ Assert.assertEquals(m.getValueAt(10, 2), "newurl");
+ Assert.assertEquals(m.getValueAt(10, 3), true);
+ Assert.assertEquals(m.getValueAt(10, 4), false);
+
+ // check data source has new row insrte
+ Assert.assertTrue(prov.getLinksForMenu().contains(
+ "newname" + SEP + "newurl"));
+ }
+
+ /*
+ * Test row deletion
+ */
+ @Test(groups = { "Functional" })
+ public void testRowDelete()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ // get name and url at row 0
+ String name = (String) m.getValueAt(0, 0);
+ String url = (String) m.getValueAt(0, 1);
+
+ m.removeRow(0);
+
+ // check table no longer has row 0 elements in it
+ for (int row = 0; row < m.getRowCount(); row++)
+ {
+ Assert.assertNotEquals(m.getValueAt(row, 0), name);
+ }
+
+ // check data source likewise
+ Assert.assertFalse(prov.getLinksForMenu().contains(name + SEP + url));
+ }
+
+ /*
+ * Test value setting and getting
+ */
+ @Test(groups = { "Functional" })
+ public void testValues()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ // get original default
+ int olddefault;
+ boolean isDefault = false;
+ for (olddefault = 0; olddefault < m.getRowCount() && !isDefault; olddefault++)
+ {
+ isDefault = (boolean) m.getValueAt(olddefault, 3);
+ }
+
+ // set new values, one in each row
+ m.setValueAt("dbnamechanged", 6, 0);
+ m.setValueAt("descchanged", 6, 1);
+ m.setValueAt("urlchanged", 7, 2);
+ m.setValueAt(false, 8, 3);
+ m.setValueAt(true, 6, 4);
+
+ m.setValueAt("dbnamechanged", 5, 0);
+
+ // check values updated in table
+ Assert.assertEquals(m.getValueAt(6, 0), "descchanged"); // custom url can't
+ // change db name
+ Assert.assertEquals(m.getValueAt(6, 1), "descchanged");
+ Assert.assertEquals(m.getValueAt(7, 2), "urlchanged");
+ Assert.assertFalse((boolean) m.getValueAt(8, 3));
+ Assert.assertTrue((boolean) m.getValueAt(6, 4));
+ Assert.assertFalse((boolean) m.getValueAt(olddefault, 4));
+
+ Assert.assertEquals(m.getValueAt(5, 0), "dbnamechanged");
+
+ // check default row is exactly one row still
+ for (int row = 0; row < m.getRowCount(); row++)
+ {
+ isDefault = (boolean) m.getValueAt(row, 4);
+
+ // if isDefault is true, row is 9
+ // if isDefault is false, row is not 9
+ Assert.assertFalse(isDefault && !(row == 6));
+ }
+
+ // check table updated
+ Assert.assertTrue(prov.writeUrlsAsString(true).contains(
+ "descchanged" + SEP + m.getValueAt(6, 2)));
+ Assert.assertTrue(prov.writeUrlsAsString(true).contains(
+ m.getValueAt(7, 1) + SEP + "urlchanged"));
+ Assert.assertTrue(prov.writeUrlsAsString(false).contains(
+ (String) m.getValueAt(8, 1)));
+ Assert.assertEquals(prov.getPrimaryUrl("seqid"), m.getValueAt(6, 2)
+ .toString().replace(DELIM + SEQUENCE_ID + DELIM, "seqid"));
+ }
+
+ /*
+ * Test cell editability
+ */
+ @Test(groups = { "Functional" })
+ public void testEditable()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ for (int row = 0; row < m.getRowCount(); row++)
+ {
+ Assert.assertFalse(m.isCellEditable(row, 0));
+ Assert.assertFalse(m.isCellEditable(row, 1));
+ Assert.assertFalse(m.isCellEditable(row, 2));
+ Assert.assertTrue(m.isCellEditable(row, 3));
+
+ if ((row == 4) || (row == 6) || (row == 7))
+ {
+ Assert.assertTrue(m.isCellEditable(row, 4));
+ }
+ else
+ {
+ Assert.assertFalse(m.isCellEditable(row, 4));
+ }
+ }
+ }
+
+ /*
+ * Test row 'deletability'
+ */
+ @Test(groups = { "Functional" })
+ public void testDeletable()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ for (int row = 0; row < m.getRowCount(); row++)
+ {
+ if (row > 4)
+ {
+ Assert.assertTrue(m.isRowDeletable(row));
+ }
+ else
+ {
+ Assert.assertFalse(m.isRowDeletable(row));
+ }
+ }
+ }
+
+ /*
+ * Test indirect row editability
+ */
+ @Test(groups = { "Functional" })
+ public void testRowEditable()
+ {
+ UrlLinkTableModel m = new UrlLinkTableModel(prov);
+
+ for (int row = 0; row < m.getRowCount(); row++)
+ {
+ if (row > 3)
+ {
+ Assert.assertTrue(m.isRowEditable(row));
+ }
+ else
+ {
+ Assert.assertFalse(m.isRowEditable(row));
+ }
+ }
+ }
+}
--- /dev/null
+package jalview.urls;
+
+import jalview.urls.api.UrlProviderI;
+import jalview.urls.desktop.DesktopUrlProviderFactory;
+import jalview.util.UrlConstants;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+
+public class UrlProviderTest {
+
+ // Test identifiers.org download file
+ private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
+ + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
+ + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
+ + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\","
+ + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"},"
+ + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
+ + "\"url\":\"http://identifiers.org/interpro\"},"
+ + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
+ + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
+
+ private UrlProviderI prov;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setup()
+ {
+ // make a dummy identifiers.org download file
+ File temp = null;
+
+ try
+ {
+ temp = File.createTempFile("tempfile", ".tmp");
+ temp.deleteOnExit();
+ BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
+ bw.write(testIdOrgString);
+ bw.close();
+ } catch (IOException e)
+ {
+ System.out.println("Error initialising UrlProviderTest test: "
+ + e.getMessage());
+ }
+
+ IdOrgSettings.setDownloadLocation(temp.getPath());
+
+ String defaultUrlString = "No default";
+ String cachedUrlList = "MIR:00000005|MIR:00000011|Test1|http://blah.blah/$SEQUENCE_ID$|"
+ + "Test2|http://test2/$DB_ACCESSION$|Test3|http://test3/$SEQUENCE_ID$";
+ String userUrlList = "MIR:00000372|Test4|httpL//another.url/$SEQUENCE_ID$";
+
+ DesktopUrlProviderFactory factory = new DesktopUrlProviderFactory(
+ defaultUrlString, cachedUrlList, userUrlList);
+ prov = factory.createUrlProvider();
+ }
+
+ @Test(groups = { "Functional" })
+ public void testInitUrlProvider()
+ {
+ String emblUrl = UrlConstants.DEFAULT_STRING.substring(
+ UrlConstants.DEFAULT_STRING.indexOf(UrlConstants.SEP) + 1,
+ UrlConstants.DEFAULT_STRING.length());
+
+ // chooses EMBL url when default Url id does not exist in provided url lists
+ Assert.assertEquals(prov.getPrimaryUrlId(), UrlConstants.DEFAULT_LABEL);
+ Assert.assertEquals(prov.getPrimaryUrl("FER_CAPAN"),
+ emblUrl.replace("$SEQUENCE_ID$", "FER_CAPAN"));
+
+ List<String> menulinks = prov.getLinksForMenu();
+ List<UrlLinkDisplay> allLinks = prov.getLinksForTable();
+
+ // 9 links in provider - 4 from id file, 4 custom links, 1 additional
+ // default
+ Assert.assertEquals(allLinks.size(), 9);
+
+ // 6 links in menu (cachedUrlList) + new default
+ Assert.assertEquals(menulinks.size(), 6);
+
+ Assert.assertTrue(menulinks
+ .contains("Test1|http://blah.blah/$SEQUENCE_ID$"));
+ Assert.assertTrue(menulinks
+ .contains("Test2|http://test2/$DB_ACCESSION$"));
+ Assert.assertTrue(menulinks
+ .contains("Test3|http://test3/$SEQUENCE_ID$"));
+ Assert.assertTrue(menulinks
+ .contains("UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$|uniprot"));
+ Assert.assertTrue(menulinks
+ .contains("InterPro|http://identifiers.org/interpro/$DB_ACCESSION$|interpro"));
+ Assert.assertTrue(menulinks.contains(UrlConstants.DEFAULT_LABEL
+ + UrlConstants.SEP + emblUrl));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testSetDefaultUrl()
+ {
+ // set custom url as default
+ Assert.assertTrue(prov.setPrimaryUrl("Test1"));
+ Assert.assertEquals(prov.getPrimaryUrlId(), "Test1");
+
+ // set identifiers url as default
+ Assert.assertTrue(prov.setPrimaryUrl("MIR:00000011"));
+ Assert.assertEquals(prov.getPrimaryUrlId(), "MIR:00000011");
+ }
+
+ @Test(
+ groups = { "Functional" },
+ expectedExceptions = { IllegalArgumentException.class })
+ public void testSetDefaultUrlWrongly()
+ {
+ // don't allow default to be a non-key
+ prov.setPrimaryUrl("not-a-key");
+ }
+}
assertEquals(new Color(46, 31, 16), // with rounding down
ColorUtils.bleachColour(colour, -0.7f));
}
+
+ @Test(groups = "Functional")
+ public void testParseColourString()
+ {
+ /*
+ * by colour name - if known to AWT, and included in
+ *
+ * @see ColourSchemeProperty.getAWTColorFromName()
+ */
+ assertSame(Color.RED, ColorUtils.parseColourString("red"));
+ assertSame(Color.RED, ColorUtils.parseColourString("Red"));
+ assertSame(Color.RED, ColorUtils.parseColourString(" RED "));
+
+ /*
+ * by RGB hex code
+ */
+ String hexColour = Integer.toHexString(Color.RED.getRGB() & 0xffffff);
+ assertEquals("ff0000", hexColour);
+ assertEquals(Color.RED, ColorUtils.parseColourString(hexColour));
+ // 'hex' prefixes _not_ wanted here
+ assertNull(ColorUtils.parseColourString("0x" + hexColour));
+ assertNull(ColorUtils.parseColourString("#" + hexColour));
+ // out of range, but Color constructor just or's the rgb value with 0
+ assertEquals(Color.black, ColorUtils.parseColourString("1000000"));
+
+ /*
+ * by RGB triplet
+ */
+ Color c = Color.pink;
+ String rgb = String.format("%d,%d,%d", c.getRed(), c.getGreen(),
+ c.getBlue());
+ assertEquals("255,175,175", rgb);
+ assertEquals(c, ColorUtils.parseColourString(rgb));
+ assertEquals(c, ColorUtils.parseColourString("255, 175 , 175"));
+
+ /*
+ * odds and ends
+ */
+ assertNull(ColorUtils.parseColourString(null));
+ assertNull(ColorUtils.parseColourString("rubbish"));
+ assertEquals(Color.WHITE, ColorUtils.parseColourString("-1"));
+ assertNull(ColorUtils.parseColourString(String
+ .valueOf(Integer.MAX_VALUE)));
+ assertNull(ColorUtils.parseColourString("100,200,300")); // out of range
+ assertNull(ColorUtils.parseColourString("100,200")); // too few
+ assertNull(ColorUtils.parseColourString("100,200,100,200")); // too many
+ }
+
+ @Test(groups = "Functional")
+ public void testGetAWTColorFromName() {
+ assertEquals(Color.white, ColorUtils.getAWTColorFromName("white"));
+ assertEquals(Color.white, ColorUtils.getAWTColorFromName("White"));
+ assertEquals(Color.white, ColorUtils.getAWTColorFromName("WHITE"));
+ assertEquals(Color.pink, ColorUtils.getAWTColorFromName("pink"));
+ assertNull(ColorUtils.getAWTColorFromName("mauve")); // no such name
+ assertNull(ColorUtils.getAWTColorFromName(""));
+ assertNull(ColorUtils.getAWTColorFromName(null));
+ }
+
+ @Test(groups = "Functional")
+ public void testCreateColourFromName()
+ {
+ assertEquals(Color.white, ColorUtils.createColourFromName(null));
+ assertEquals(new Color(20, 20, 20), ColorUtils.createColourFromName(""));
+ assertEquals(new Color(98, 131, 171),
+ ColorUtils.createColourFromName("None")); // no special treatment!
+ assertEquals(new Color(123, 211, 122),
+ ColorUtils.createColourFromName("hello world"));
+ assertEquals(new Color(27, 147, 112),
+ ColorUtils.createColourFromName("HELLO WORLD"));
+ /*
+ * the algorithm makes the same values for r,g,b if
+ * the string consists of 3 repeating substrings
+ */
+ assertEquals(new Color(184, 184, 184),
+ ColorUtils.createColourFromName("HELLO HELLO HELLO "));
+ }
}
+ DELIM + URL_SUFFIX);
assertEquals(DB, ul.getTarget());
assertEquals(DB, ul.getLabel());
- assertEquals(URL_PREFIX, ul.getUrl_prefix());
- assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertEquals(URL_PREFIX, ul.getUrlPrefix());
+ assertEquals(URL_SUFFIX, ul.getUrlSuffix());
assertTrue(ul.isDynamic());
assertFalse(ul.usesDBAccession());
assertNull(ul.getRegexReplace());
+ URL_SUFFIX);
assertEquals(DB, ul.getTarget());
assertEquals(DB, ul.getLabel());
- assertEquals(URL_PREFIX, ul.getUrl_prefix());
- assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertEquals(URL_PREFIX, ul.getUrlPrefix());
+ assertEquals(URL_SUFFIX, ul.getUrlSuffix());
assertTrue(ul.isDynamic());
assertTrue(ul.usesDBAccession());
assertNull(ul.getRegexReplace());
ul = new UrlLink(DB + SEP + URL_PREFIX + URL_SUFFIX.substring(1));
assertEquals(DB, ul.getTarget());
assertEquals(DB, ul.getLabel());
- assertEquals(URL_PREFIX + URL_SUFFIX.substring(1), ul.getUrl_prefix());
+ assertEquals(URL_PREFIX + URL_SUFFIX.substring(1), ul.getUrlPrefix());
assertFalse(ul.isDynamic());
assertFalse(ul.usesDBAccession());
assertNull(ul.getRegexReplace());
+ REGEX_NESTED + DELIM + URL_SUFFIX);
assertEquals(DB, ul.getTarget());
assertEquals(DB, ul.getLabel());
- assertEquals(URL_PREFIX, ul.getUrl_prefix());
- assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertEquals(URL_PREFIX, ul.getUrlPrefix());
+ assertEquals(URL_SUFFIX, ul.getUrlSuffix());
assertTrue(ul.isDynamic());
assertFalse(ul.usesDBAccession());
assertEquals(REGEX_NESTED.substring(2, REGEX_NESTED.length() - 2),
+ REGEX_NESTED + DELIM + URL_SUFFIX);
assertEquals(DB, ul.getTarget());
assertEquals(DB, ul.getLabel());
- assertEquals(URL_PREFIX, ul.getUrl_prefix());
- assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertEquals(URL_PREFIX, ul.getUrlPrefix());
+ assertEquals(URL_SUFFIX, ul.getUrlSuffix());
assertTrue(ul.isDynamic());
assertTrue(ul.usesDBAccession());
assertEquals(REGEX_NESTED.substring(2, REGEX_NESTED.length() - 2),
+ REGEX_RUBBISH + DELIM + URL_SUFFIX);
assertEquals(DB, ul.getTarget());
assertEquals(DB, ul.getLabel());
- assertEquals(URL_PREFIX, ul.getUrl_prefix());
- assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertEquals(URL_PREFIX, ul.getUrlPrefix());
+ assertEquals(URL_SUFFIX, ul.getUrlSuffix());
assertTrue(ul.isDynamic());
assertTrue(ul.usesDBAccession());
assertEquals(REGEX_RUBBISH.substring(2, REGEX_RUBBISH.length() - 2),
String key = DB + SEP + URL_PREFIX;
assertEquals(1, linkset.size());
assertTrue(linkset.containsKey(key));
- assertEquals(linkset.get(key).get(0), DB);
- assertEquals(linkset.get(key).get(1), DB);
- assertEquals(linkset.get(key).get(2), null);
- assertEquals(linkset.get(key).get(3), URL_PREFIX);
+ assertEquals(DB, linkset.get(key).get(0));
+ assertEquals(DB, linkset.get(key).get(1));
+ assertEquals(null, linkset.get(key).get(2));
+ assertEquals(URL_PREFIX, linkset.get(key).get(3));
}
/**
String key = DB + SEP + URL_PREFIX + URL_SUFFIX;
assertEquals(1, linkset.size());
assertTrue(linkset.containsKey(key));
- assertEquals(linkset.get(key).get(0), DB);
- assertEquals(linkset.get(key).get(1), DB);
- assertEquals(linkset.get(key).get(2), null);
- assertEquals(linkset.get(key).get(3), URL_PREFIX + URL_SUFFIX);
+ assertEquals(DB, linkset.get(key).get(0));
+ assertEquals(DB, linkset.get(key).get(1));
+ assertEquals(null, linkset.get(key).get(2));
+ assertEquals(URL_PREFIX + URL_SUFFIX, linkset.get(key).get(3));
}
/**
+ URL_SUFFIX;
assertEquals(1, linkset.size());
assertTrue(linkset.containsKey(key));
- assertEquals(linkset.get(key).get(0), DB);
- assertEquals(linkset.get(key).get(1), DB);
- assertEquals(linkset.get(key).get(2), seq0.getName());
- assertEquals(linkset.get(key).get(3), URL_PREFIX + seq0.getName()
- + URL_SUFFIX);
+ assertEquals(DB, linkset.get(key).get(0));
+ assertEquals(DB, linkset.get(key).get(1));
+ assertEquals(seq0.getName(), linkset.get(key).get(2));
+ assertEquals(URL_PREFIX + seq0.getName() + URL_SUFFIX, linkset.get(key)
+ .get(3));
// Test where link takes a db annotation id and only has one dbref
ul = new UrlLink(links.get(1));
ul.createLinksFromSeq(seq0, linkset);
key = "P83527|http://www.uniprot.org/uniprot/P83527";
- assertEquals(1, linkset.size());
+ assertEquals(linkset.size(), 1);
assertTrue(linkset.containsKey(key));
- assertEquals(linkset.get(key).get(0), DBRefSource.UNIPROT);
- assertEquals(linkset.get(key).get(1), DBRefSource.UNIPROT + SEP
- + "P83527");
- assertEquals(linkset.get(key).get(2), "P83527");
- assertEquals(linkset.get(key).get(3),
- "http://www.uniprot.org/uniprot/P83527");
+ assertEquals(DBRefSource.UNIPROT, linkset.get(key).get(0));
+ assertEquals(DBRefSource.UNIPROT + SEP + "P83527", linkset.get(key)
+ .get(1));
+ assertEquals("P83527", linkset.get(key).get(2));
+ assertEquals("http://www.uniprot.org/uniprot/P83527", linkset.get(key)
+ .get(3));
// Test where link takes a db annotation id and has multiple dbrefs
ul = new UrlLink(links.get(2));
// check each link made it in correctly
key = "IPR001041|http://www.ebi.ac.uk/interpro/entry/IPR001041";
assertTrue(linkset.containsKey(key));
- assertEquals(linkset.get(key).get(0), "INTERPRO");
- assertEquals(linkset.get(key).get(1), "INTERPRO" + SEP + "IPR001041");
- assertEquals(linkset.get(key).get(2), "IPR001041");
- assertEquals(linkset.get(key).get(3),
- "http://www.ebi.ac.uk/interpro/entry/IPR001041");
+ assertEquals("INTERPRO", linkset.get(key).get(0));
+ assertEquals("INTERPRO" + SEP + "IPR001041", linkset.get(key).get(1));
+ assertEquals("IPR001041", linkset.get(key).get(2));
+ assertEquals("http://www.ebi.ac.uk/interpro/entry/IPR001041", linkset
+ .get(key).get(3));
key = "IPR006058|http://www.ebi.ac.uk/interpro/entry/IPR006058";
assertTrue(linkset.containsKey(key));
- assertEquals(linkset.get(key).get(0), "INTERPRO");
- assertEquals(linkset.get(key).get(1), "INTERPRO" + SEP + "IPR006058");
- assertEquals(linkset.get(key).get(2), "IPR006058");
- assertEquals(linkset.get(key).get(3),
- "http://www.ebi.ac.uk/interpro/entry/IPR006058");
+ assertEquals("INTERPRO", linkset.get(key).get(0));
+ assertEquals("INTERPRO" + SEP + "IPR006058", linkset.get(key).get(1));
+ assertEquals("IPR006058", linkset.get(key).get(2));
+ assertEquals("http://www.ebi.ac.uk/interpro/entry/IPR006058", linkset
+ .get(key).get(3));
key = "IPR012675|http://www.ebi.ac.uk/interpro/entry/IPR012675";
assertTrue(linkset.containsKey(key));
- assertEquals(linkset.get(key).get(0), "INTERPRO");
- assertEquals(linkset.get(key).get(1), "INTERPRO" + SEP + "IPR012675");
- assertEquals(linkset.get(key).get(2), "IPR012675");
- assertEquals(linkset.get(key).get(3),
- "http://www.ebi.ac.uk/interpro/entry/IPR012675");
+ assertEquals("INTERPRO", linkset.get(key).get(0));
+ assertEquals("INTERPRO" + SEP + "IPR012675", linkset.get(key).get(1));
+ assertEquals("IPR012675", linkset.get(key).get(2));
+ assertEquals("http://www.ebi.ac.uk/interpro/entry/IPR012675", linkset
+ .get(key).get(3));
// Test where there are no matching dbrefs for the link
ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + DB_ACCESSION + DELIM
assertTrue(linkset.isEmpty());
}
+ /**
+ * Test links where label and target are both included
+ */
+ @Test(groups = { "Functional" })
+ public void testLinksWithTargets()
+ {
+ UrlLink ul = new UrlLink(
+ "Protein Data Bank | http://www.identifiers.org/pdb/$"
+ + DB_ACCESSION + "$" + " | pdb");
+
+ assertEquals("Protein Data Bank", ul.getLabel());
+ assertEquals("pdb", ul.getTarget());
+ assertEquals("http://www.identifiers.org/pdb/$" + DB_ACCESSION + "$",
+ ul.getUrlWithToken());
+
+ assertEquals("Protein Data Bank|http://www.identifiers.org/pdb/$"
+ + DB_ACCESSION + "$" + "|pdb", ul.toStringWithTarget());
+
+ ul = new UrlLink("Protein Data Bank",
+ "http://www.identifiers.org/pdb/$" + DB_ACCESSION + "$", "pdb");
+
+ assertEquals("Protein Data Bank", ul.getLabel());
+ assertEquals("pdb", ul.getTarget());
+ assertEquals("http://www.identifiers.org/pdb/$" + DB_ACCESSION + "$",
+ ul.getUrlWithToken());
+
+ assertEquals("Protein Data Bank|http://www.identifiers.org/pdb/$"
+ + DB_ACCESSION + "$" + "|pdb", ul.toStringWithTarget());
+
+ }
+
}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.ws.utils;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class UrlDownloadClientTest {
+
+ /**
+ * Test that url is successfully loaded into download file
+ */
+ @Test(groups = { "Network" }, enabled = true)
+ public void UrlDownloadTest()
+ {
+ UrlDownloadClient client = new UrlDownloadClient();
+ String urlstring = "http://identifiers.org/rest/collections/";
+ String outfile = "testfile.tmp";
+
+ try
+ {
+ client.download(urlstring, outfile);
+ } catch (IOException e)
+ {
+ Assert.fail("Exception was thrown from UrlDownloadClient download: "
+ + e.getMessage());
+ File f = new File(outfile);
+ if (f.exists())
+ {
+ f.delete();
+ }
+ }
+
+ // download file exists
+ File f = new File(outfile);
+ Assert.assertTrue(f.exists());
+
+ // download file has a believable size
+ // identifiers.org file typically at least 250K
+ Assert.assertTrue(f.length() > 250000);
+
+ if (f.exists())
+ {
+ f.delete();
+ }
+
+ }
+
+ /**
+ * Test that garbage in results in IOException
+ */
+ @Test(
+ groups = { "Network" },
+ enabled = true,
+ expectedExceptions = { IOException.class })
+ public void DownloadGarbageUrlTest() throws IOException
+ {
+ UrlDownloadClient client = new UrlDownloadClient();
+ String urlstring = "identifiers.org/rest/collections/";
+ String outfile = "testfile.tmp";
+
+ client.download(urlstring, outfile);
+ }
+}