From: Jim Procter Date: Fri, 29 May 2015 13:23:34 +0000 (+0100) Subject: Merge branch 'JAL-1755_npe_groupconsensus' into develop X-Git-Tag: Release_2_10_0~650^2^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=16bd1f9daaa35dd5b87de17a649116f9d33927b8;hp=797f8de3bc7ec7f84ac643bb1d961eae1a0b0824;p=jalview.git Merge branch 'JAL-1755_npe_groupconsensus' into develop --- diff --git a/THIRDPARTYLIBS b/THIRDPARTYLIBS index 824a604..bbef868 100644 --- a/THIRDPARTYLIBS +++ b/THIRDPARTYLIBS @@ -20,6 +20,7 @@ commons-codec-1.3.jar commons-discovery.jar commons-logging-1.1.1.jar commons-logging.jar +commons-net-3.3.jar httpclient-4.0.3.jar httpcore-4.0.1.jar httpmime-4.0.3.jar diff --git a/examples/example.json b/examples/example.json new file mode 100644 index 0000000..47ea429 --- /dev/null +++ b/examples/example.json @@ -0,0 +1 @@ +{"seqs":[{"name":"FER_CAPAN/3-34","start":3,"end":34,"id":"FER_CAPAN_1580333149","seq":"SVSATMISTSFMPRKPAVTSL-KPIPNVGE--ALF","order":1},{"name":"FER1_SOLLC/3-34","start":3,"end":34,"id":"FER1_SOLLC_1952300006","seq":"SISGTMISTSFLPRKPAVTSL-KAISNVGE--ALF","order":2},{"name":"Q93XJ9_SOLTU/3-34","start":3,"end":34,"id":"Q93XJ9_SOLTU_1274067508","seq":"SISGTMISTSFLPRKPVVTSL-KAISNVGE--ALF","order":3},{"name":"FER1_PEA/6-37","start":6,"end":37,"id":"FER1_PEA_1823806146","seq":"ALYGTAVSTSFLRTQPMPMSV-TTTKAFSN--GFL","order":4},{"name":"Q7XA98_TRIPR/6-39","start":6,"end":39,"id":"Q7XA98_TRIPR_1024982041","seq":"ALYGTAVSTSFMRRQPVPMSV-ATTTTTKAFPSGF","order":5}],"seqGroups":[{"displayText":true,"startRes":21,"groupName":"JGroup:1883305585","endRes":29,"colourText":false,"seqsHash":["FER1_SOLLC_1952300006","Q93XJ9_SOLTU_1274067508","FER1_PEA_1823806146","Q7XA98_TRIPR_1024982041"],"showNonconserved":false,"colourScheme":"Zappo","displayBoxes":true}],"alignAnnotation":[{"annotations":[{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"β","value":0,"secondaryStructure":"E"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"α","value":0,"secondaryStructure":"H"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"},{"displayCharacter":"","value":0,"secondaryStructure":"\u0000"}],"description":"New description","label":"Secondary Structure"}],"jalviewSettings":{"globalColorScheme":"foo","jalviewVersion":"Test","webStartUrl":"http://www.jalview.org/services/launchApp","showSeqFeatures":true,"wrapModeEnabled":false},"seqFeatures":[{"fillColor":"#ff0033","score":0,"sequenceRef":"Q93XJ9_SOLTU_1274067508","featureGroup":"Jalview","description":"desciption","xStart":3,"xEnd":13,"type":"feature_x"},{"fillColor":"#ff0033","score":0,"sequenceRef":"FER1_PEA_1823806146","featureGroup":"Jalview","description":"desciption","xStart":3,"xEnd":13,"type":"feature_x"},{"fillColor":"#ff0033","score":0,"sequenceRef":"Q7XA98_TRIPR_1024982041","featureGroup":"Jalview","description":"desciption","xStart":3,"xEnd":13,"type":"feature_x"}]} \ No newline at end of file diff --git a/resources/templates/BioJSTemplate.txt b/resources/biojs_templates/BioJsMSA_1.0.txt similarity index 99% rename from resources/templates/BioJSTemplate.txt rename to resources/biojs_templates/BioJsMSA_1.0.txt index bf780bb..26a483b 100644 --- a/resources/templates/BioJSTemplate.txt +++ b/resources/biojs_templates/BioJsMSA_1.0.txt @@ -44,9 +44,9 @@ function toggleMenuVisibility(){ function openJalviewUsingCurrentUrl(){ - var jalviewData = JSON.parse(document.getElementById("seqData").value) - var jalviewVersion = jalviewData['jalviewVersion']; - var url = jalviewData['webStartUrl']; + var json = JSON.parse(document.getElementById("seqData").value) + var jalviewVersion = json['jalviewSettings'].jalviewVersion; + var url = json['jalviewSettings'].webStartUrl; var myForm = document.createElement("form"); myForm.action = url; @@ -9009,12 +9009,28 @@ opts.zoomer = {alignmentHeight: 225, labelWidth: 130,labelFontsize: "13px",label // init msa var m = new msa.msa(opts); -m.g.colorscheme.set("scheme", jalviewData['globalColorScheme']); +m.g.colorscheme.set("scheme", jalviewData['jalviewSettings'].globalColorScheme); var x = 0; -jalviewData.seqs.forEach( function (seq) +//jalviewData.seqs.forEach( function (seq) +//{ +//m.seqs.at(x++).set("features", new msa.model.featurecol(seq.features)); +//}); + +//console.debug(">>>>>>>>>>>>>" + m.seqs.length); +//console.debug(">>>>>>>>>>>>> Found features : " + jalviewData.seqFeatures.length); +m.seqs.forEach( function (seq ) { -m.seqs.at(x++).set("features", new msa.model.featurecol(seq.features)); + var seqFeats = []; + for (i = 0; i < jalviewData.seqFeatures.length; i++) { + console.debug('comparing >>>>>>>> '+ seq.id) + if(jalviewData.seqFeatures[i].sequenceRef === seq.id){ + // console.debug('>>>>>>>> '+jalviewData.seqFeatures[i].sequenceRef+' | '+ seq.id) + seqFeats.push(jalviewData.seqFeatures[i]); + } + } +console.debug('matched features count : '+seqFeats.length); +seq.set("features", new msa.model.featurecol(seqFeats)); }); // the menu is independent to the MSA container @@ -9029,4 +9045,4 @@ m.render(); toggleMenuVisibility(); toggleMenuVisibility(); }); - \ No newline at end of file + diff --git a/resources/biojs_templates/BioJsMSA_1.1.txt b/resources/biojs_templates/BioJsMSA_1.1.txt new file mode 100644 index 0000000..26a483b --- /dev/null +++ b/resources/biojs_templates/BioJsMSA_1.1.txt @@ -0,0 +1,9048 @@ + +
BioJS viewer
+ + + + + + + + Jalview Logo + +
+
+ + + + +
+
+ +
press "Run with JS"
+ + + + + + + + diff --git a/resources/biojs_templates/Latest_BioJsMSA_1.2.txt b/resources/biojs_templates/Latest_BioJsMSA_1.2.txt new file mode 100644 index 0000000..26a483b --- /dev/null +++ b/resources/biojs_templates/Latest_BioJsMSA_1.2.txt @@ -0,0 +1,9048 @@ + +
BioJS viewer
+ + + + + + + + Jalview Logo + +
+
+ + + + +
+
+ +
press "Run with JS"
+ + + + + + + + diff --git a/resources/embl_mapping.xml b/resources/embl_mapping.xml index 7199354..ccbde5e 100644 --- a/resources/embl_mapping.xml +++ b/resources/embl_mapping.xml @@ -34,17 +34,16 @@ - + - + - @@ -54,7 +53,7 @@ - + @@ -64,11 +63,10 @@ - + - @@ -80,7 +78,6 @@ - @@ -95,18 +92,17 @@ - + - + - + - @@ -118,7 +114,6 @@ - @@ -130,7 +125,6 @@ - @@ -148,7 +142,6 @@ - diff --git a/resources/images/warning.gif b/resources/images/warning.gif new file mode 100644 index 0000000..3d57c8c Binary files /dev/null and b/resources/images/warning.gif differ diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index e25fb93..9cf90c7 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1,4 +1,4 @@ -action.refresh_services = Refresh Services +label.view_structureaction.refresh_services = Refresh Services action.reset_services = Reset Services action.merge_results = Merge Results action.load_scheme = Load scheme @@ -675,6 +675,8 @@ label.discover_pdb_ids = Discover PDB ids label.text_colour = Text Colour label.structure = Structure label.view_structure = View Structure +label.view_protein_structure = View Protein Structure +label.view_rna_structure = View Nucleotide Structure label.clustalx_colours = Clustalx colours label.above_identity_percentage = Above % Identity label.create_sequence_details_report_annotation_for = Annotation for {0} @@ -768,7 +770,8 @@ 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.invalid_font = Invalid Font -label.separate_multiple_accession_ids = Separate multiple accession ids with semi colon ";" +label.separate_multiple_accession_ids = Separate multiple PDB accession ids with semi colon ";" +label.separate_multiple_query_values = Separate multiple query values with semi colon ";" label.replace_commas_semicolons = Replace commas with semi-colons label.parsing_failed_syntax_errors_shown_below_param = Parsing failed. Syntax errors shown below {0} label.parsing_failed_unrecoverable_exception_thrown_param = \nParsing failed. An unrecoverable exception was thrown\:\n {0} diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index 940e27b..6ca8711 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -192,6 +192,7 @@ public class PDBfile extends jalview.io.AlignFile dataset.setName(id + "|" + dataset.getName()); PDBEntry entry = new PDBEntry(); entry.setId(id); + entry.setType(PDBEntry.Type.PDB); entry.setProperty(new Hashtable()); if (chains.elementAt(i).id != null) { diff --git a/src/com/stevesoft/pat/RegexWriter.java b/src/com/stevesoft/pat/RegexWriter.java index a8c3e50..61bcdf6 100755 --- a/src/com/stevesoft/pat/RegexWriter.java +++ b/src/com/stevesoft/pat/RegexWriter.java @@ -7,9 +7,10 @@ // package com.stevesoft.pat; -import java.io.*; +import java.io.IOException; +import java.io.Writer; -import com.stevesoft.pat.wrap.*; +import com.stevesoft.pat.wrap.WriterWrap; /** * A basic extension of FilterWriter that uses Transformer to make replacements @@ -77,6 +78,7 @@ public class RegexWriter extends Writer * * @deprecated */ + @Deprecated public char getEOLchar() { return EOLchar; @@ -87,6 +89,7 @@ public class RegexWriter extends Writer * * @deprecated */ + @Deprecated public void setEOLchar(char c) { EOLchar = c; @@ -99,6 +102,7 @@ public class RegexWriter extends Writer * * @deprecated */ + @Deprecated public int getMaxLines() { return max_lines; @@ -109,6 +113,7 @@ public class RegexWriter extends Writer * * @deprecated */ + @Deprecated public void setMaxLines(int ml) { max_lines = ml; @@ -226,51 +231,4 @@ public class RegexWriter extends Writer { bufferSize = i; } - - static void test(String re, String inp, int n) throws Exception - { - StringWriter sw = new StringWriter(); - Regex rex = Regex.perlCode(re); - String res1 = rex.replaceAll(inp); - RegexWriter rw = new RegexWriter(rex, sw); - for (int i = 0; i < inp.length(); i++) - { - rw.write(inp.charAt(i)); - } - rw.close(); - String res2 = sw.toString(); - if (!res1.equals(res2)) - { - System.out.println("nmax=" + n); - System.out.println("re=" + re); - System.out.println("inp=" + inp); - System.out.println("res1=" + res1); - System.out.println("res2=" + res2); - System.exit(255); - } - } - - public static void main(String[] args) throws Exception - { - for (int n = 1; n <= 1; n++) - { - test("s/x/y/", "-----x123456789", n); - test("s/x/y/", "x123456789", n); - test("s/x/y/", "-----x", n); - test("s/x.*?x/y/", ".xx..x..x...x...x....x....x", n); - test("s/x.*x/[$&]/", "--x........x--xx", n); - test("s/x.*x/[$&]/", "--x........x------", n); - test("s/.$/a/m", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbbbbbbbbbbbb", n); - test("s/.$/a/", "123", n); - test("s/.$/a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb", n); - test("s/^./a/", "bb\nbbb\nbbbb\nbbbbb\nbbbbbb\nbb", n); - test("s/$/a/", "bbb", n); - test("s/^/a/", "bbb", n); - test("s/^/a/", "", n); - test("s{.*}{N}", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", n); - test("s/.{0,7}/y/", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", n); - test("s/x/$&/", "xxx", n); - } - System.out.println("Success!!!"); - } } diff --git a/src/jalview/analysis/AlignmentAnnotationUtils.java b/src/jalview/analysis/AlignmentAnnotationUtils.java index 9bdbf73..e02aa9e 100644 --- a/src/jalview/analysis/AlignmentAnnotationUtils.java +++ b/src/jalview/analysis/AlignmentAnnotationUtils.java @@ -1,9 +1,5 @@ package jalview.analysis; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.SequenceI; -import jalview.renderer.AnnotationRenderer; - import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; @@ -12,6 +8,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.SequenceI; +import jalview.renderer.AnnotationRenderer; + public class AlignmentAnnotationUtils { @@ -63,6 +63,14 @@ public class AlignmentAnnotationUtils for (AlignmentAnnotation aa : annotations) { + /* + * Ignore non-positional annotations, can't render these against an + * alignment + */ + if (aa.annotations == null) + { + continue; + } if (forSequences != null && (aa.sequenceRef != null && forSequences .contains(aa.sequenceRef))) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index a4aeac7..df30234 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -77,18 +77,22 @@ public class AlignmentUtils for (SequenceI s : core.getSequences()) { SequenceI newSeq = s.deriveSequence(); - if (newSeq.getStart() > maxoffset + final int newSeqStart = newSeq.getStart() - 1; + if (newSeqStart > maxoffset && newSeq.getDatasetSequence().getStart() < s.getStart()) { - maxoffset = newSeq.getStart(); + maxoffset = newSeqStart; } sq.add(newSeq); } if (flankSize > -1) { - maxoffset = flankSize; + maxoffset = Math.min(maxoffset, flankSize); } - // now add offset to create a new expanded alignment + + /* + * now add offset left and right to create an expanded alignment + */ for (SequenceI s : sq) { SequenceI ds = s; @@ -98,8 +102,8 @@ public class AlignmentUtils } int s_end = s.findPosition(s.getStart() + s.getLength()); // find available flanking residues for sequence - int ustream_ds = s.getStart() - ds.getStart(), dstream_ds = ds - .getEnd() - s_end; + int ustream_ds = s.getStart() - ds.getStart(); + int dstream_ds = ds.getEnd() - s_end; // build new flanked sequence @@ -115,27 +119,27 @@ public class AlignmentUtils offset = maxoffset - flankSize; ustream_ds = flankSize; } - if (flankSize < dstream_ds) + if (flankSize <= dstream_ds) { - dstream_ds = flankSize; + dstream_ds = flankSize - 1; } } + // TODO use Character.toLowerCase to avoid creating String objects? char[] upstream = new String(ds.getSequence(s.getStart() - 1 - ustream_ds, s.getStart() - 1)).toLowerCase().toCharArray(); - char[] downstream = new String(ds.getSequence(s_end - 1, s_end + 1 + char[] downstream = new String(ds.getSequence(s_end - 1, s_end + dstream_ds)).toLowerCase().toCharArray(); char[] coreseq = s.getSequence(); char[] nseq = new char[offset + upstream.length + downstream.length + coreseq.length]; char c = core.getGapCharacter(); - // TODO could lowercase the flanking regions + int p = 0; for (; p < offset; p++) { nseq[p] = c; } - // s.setSequence(new String(upstream).toLowerCase()+new String(coreseq) + - // new String(downstream).toLowerCase()); + System.arraycopy(upstream, 0, nseq, p, upstream.length); System.arraycopy(coreseq, 0, nseq, p + upstream.length, coreseq.length); @@ -153,6 +157,7 @@ public class AlignmentUtils { for (AlignmentAnnotation aa : s.getAnnotation()) { + aa.adjustForAlignment(); // JAL-1712 fix newAl.addAnnotation(aa); } } diff --git a/src/jalview/analysis/ParseProperties.java b/src/jalview/analysis/ParseProperties.java index 2810ec9..3347800 100644 --- a/src/jalview/analysis/ParseProperties.java +++ b/src/jalview/analysis/ParseProperties.java @@ -22,7 +22,9 @@ package jalview.analysis; import com.stevesoft.pat.Regex; -import jalview.datamodel.*; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceI; public class ParseProperties { @@ -101,7 +103,9 @@ public class ParseProperties ScoreNames = tnames; String descrbase = ScoreDescriptions[onamelen - 1]; if (descrbase == null) + { descrbase = "Score parsed from (" + regex + ")"; + } tnames = new String[pattern.numSubs() + 1]; System.arraycopy(ScoreDescriptions, 0, tnames, 0, ScoreDescriptions.length); @@ -116,7 +120,9 @@ public class ParseProperties { String descr = seqs[i].getDescription(); if (descr == null) + { continue; + } int pos = 0; boolean added = false; int reps = 0; @@ -140,7 +146,8 @@ public class ParseProperties + ((reps > 0) ? "_" + reps : ""), ScoreDescriptions[cols], null); an.setScore(score); - System.out.println("Score: " + ScoreNames[cols] + "=" + score); // DEBUG + System.out.println(seqs[i].getName() + " score: '" + + ScoreNames[cols] + "' = " + score); // DEBUG an.setSequenceRef(seqs[i]); seqs[i].addAlignmentAnnotation(an); al.addAnnotation(an); @@ -155,29 +162,4 @@ public class ParseProperties } return count; } - - public static void main(String argv[]) - { - SequenceI[] seqs = new SequenceI[] - { new Sequence("sq1", "THISISAPLACEHOLDER"), - new Sequence("sq2", "THISISAPLACEHOLDER"), - new Sequence("sq3", "THISISAPLACEHOLDER"), - new Sequence("sq4", "THISISAPLACEHOLDER") }; - seqs[0].setDescription("1 mydescription1"); - seqs[1].setDescription("mydescription2"); - seqs[2].setDescription("2. 0.1 mydescription3"); - seqs[3].setDescription("3 0.01 mydescription4"); - // seqs[4].setDescription("5 mydescription5"); - Alignment al = new Alignment(seqs); - ParseProperties pp = new ParseProperties(al); - String regex = ".*([-0-9.+]+)"; - System.out.println("Matched " - + pp.getScoresFromDescription("my Score", - "my Score Description", regex, true) + " for " + regex); - regex = ".*([-0-9.+]+).+([-0-9.+]+).*"; - System.out.println("Matched " - + pp.getScoresFromDescription("my Score", - "my Score Description", regex, true) + " for " + regex); - System.out.println("Finished."); - } } diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index 8482f6b..b4d2592 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -20,11 +20,6 @@ */ package jalview.api; -import java.awt.Color; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; - import jalview.analysis.Conservation; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; @@ -36,6 +31,11 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.schemes.ColourSchemeI; +import java.awt.Color; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + /** * @author jimp * @@ -372,4 +372,9 @@ public interface AlignViewportI extends ViewStyleI * Set whether view should scroll to show the highlighted region of a sequence */ void setFollowHighlight(boolean b); + + public FeatureRenderer getFeatureRenderer(); + + public void setFeatureRenderer(FeatureRenderer featureRenderer); + } diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 1ed4583..ef17215 100644 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -20,10 +20,9 @@ */ package jalview.appletgui; -import java.awt.Font; - import jalview.analysis.NJTree; import jalview.api.AlignViewportI; +import jalview.api.FeatureRenderer; import jalview.bin.JalviewLite; import jalview.commands.CommandI; import jalview.datamodel.AlignmentI; @@ -40,6 +39,8 @@ import jalview.structure.StructureSelectionManager; import jalview.structure.VamsasSource; import jalview.viewmodel.AlignmentViewport; +import java.awt.Font; + public class AlignViewport extends AlignmentViewport implements SelectionSource, VamsasSource, CommandListener { @@ -57,6 +58,8 @@ public class AlignViewport extends AlignmentViewport implements private AnnotationColumnChooser annotationColumnSelectionState; + private FeatureRenderer featureRenderer; + public void finalize() { applet = null; @@ -467,4 +470,17 @@ public class AlignViewport extends AlignmentViewport implements } } + @Override + public FeatureRenderer getFeatureRenderer() + { + return featureRenderer; + } + + @Override + public void setFeatureRenderer(FeatureRenderer featureRenderer) + { + this.featureRenderer = featureRenderer; + + } + } diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java index 9751514..4536b1a 100644 --- a/src/jalview/appletgui/FeatureRenderer.java +++ b/src/jalview/appletgui/FeatureRenderer.java @@ -20,16 +20,30 @@ */ package jalview.appletgui; -import java.util.*; -import java.awt.*; -import java.awt.event.*; - -import jalview.datamodel.*; +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Choice; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.GridLayout; +import java.awt.Label; +import java.awt.Panel; +import java.awt.ScrollPane; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Hashtable; + +import jalview.datamodel.SearchResults; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; import jalview.schemes.AnnotationColourGradient; import jalview.schemes.GraduatedColor; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; -import jalview.viewmodel.seqfeatures.FeaturesDisplayed; /** * DOCUMENT ME! @@ -37,7 +51,8 @@ import jalview.viewmodel.seqfeatures.FeaturesDisplayed; * @author $author$ * @version $Revision$ */ -public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRenderer +public class FeatureRenderer extends + jalview.renderer.seqfeatures.FeatureRenderer { // Holds web links for feature groups and feature types @@ -55,7 +70,8 @@ public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRendere super(); this.av = av; - setTransparencyAvailable(!System.getProperty("java.version").startsWith("1.1")); + setTransparencyAvailable(!System.getProperty("java.version") + .startsWith("1.1")); } static String lastFeatureAdded; @@ -101,7 +117,9 @@ public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRendere } else { - throw new Error(MessageManager.getString("error.invalid_colour_for_mycheckbox")); + throw new Error( + MessageManager + .getString("error.invalid_colour_for_mycheckbox")); } if (col != null) { @@ -198,7 +216,9 @@ public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRendere + "-" + features[i].getEnd(); if (features[i].getFeatureGroup() != null) + { item += " (" + features[i].getFeatureGroup() + ")"; + } overlaps.addItem(item); } @@ -303,8 +323,11 @@ public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRendere } } - String title = newFeatures ? MessageManager.getString("label.create_new_sequence_features") - : MessageManager.formatMessage("label.amend_delete_features", new String[]{sequences[0].getName()}); + String title = newFeatures ? MessageManager + .getString("label.create_new_sequence_features") + : MessageManager.formatMessage("label.amend_delete_features", + new String[] + { sequences[0].getName() }); final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385, 240); @@ -377,7 +400,9 @@ public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRendere } if (lastFeatureGroupAdded != null && lastFeatureGroupAdded.length() < 1) + { lastFeatureGroupAdded = null; + } if (!newFeatures) { @@ -402,7 +427,8 @@ public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRendere } ffile.parseDescriptionHTML(sf, false); - setVisible(lastFeatureAdded); // if user edited name then make sure new type is visible + setVisible(lastFeatureAdded); // if user edited name then make sure new + // type is visible } if (deleteFeature) { @@ -423,16 +449,16 @@ public class FeatureRenderer extends jalview.renderer.seqfeatures.FeatureRendere ffile.parseDescriptionHTML(features[i], false); } - col = colourPanel.getBackground(); + Color newColour = colourPanel.getBackground(); // setColour(lastFeatureAdded, fcol); if (lastFeatureGroupAdded != null) { setGroupVisibility(lastFeatureGroupAdded, true); } - setColour(lastFeatureAdded, fcol); + setColour(lastFeatureAdded, newColour); // was fcol setVisible(lastFeatureAdded); - findAllFeatures(false); // different to original applet behaviour ? + findAllFeatures(false); // different to original applet behaviour ? // findAllFeatures(); } else diff --git a/src/jalview/appletgui/UserDefinedColours.java b/src/jalview/appletgui/UserDefinedColours.java index 342c065..277bd55 100644 --- a/src/jalview/appletgui/UserDefinedColours.java +++ b/src/jalview/appletgui/UserDefinedColours.java @@ -20,13 +20,6 @@ */ package jalview.appletgui; -import jalview.datamodel.SequenceGroup; -import jalview.schemes.ColourSchemeI; -import jalview.schemes.GraduatedColor; -import jalview.schemes.ResidueProperties; -import jalview.schemes.UserColourScheme; -import jalview.util.MessageManager; - import java.awt.Button; import java.awt.Color; import java.awt.Component; @@ -44,11 +37,20 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.awt.event.MouseEvent; import java.util.Vector; +import jalview.datamodel.SequenceGroup; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.GraduatedColor; +import jalview.schemes.ResidueProperties; +import jalview.schemes.UserColourScheme; +import jalview.util.MessageManager; + public class UserDefinedColours extends Panel implements ActionListener, - AdjustmentListener + AdjustmentListener, FocusListener { AlignmentPanel ap; @@ -225,27 +227,28 @@ public class UserDefinedColours extends Panel implements ActionListener, public void actionPerformed(ActionEvent evt) { - if (evt.getSource() == okButton) + final Object source = evt.getSource(); + if (source == okButton) { okButton_actionPerformed(); } - else if (evt.getSource() == applyButton) + else if (source == applyButton) { applyButton_actionPerformed(); } - else if (evt.getSource() == cancelButton) + else if (source == cancelButton) { cancelButton_actionPerformed(); } - else if (evt.getSource() == rText) + else if (source == rText) { rText_actionPerformed(); } - else if (evt.getSource() == gText) + else if (source == gText) { gText_actionPerformed(); } - else if (evt.getSource() == bText) + else if (source == bText) { bText_actionPerformed(); } @@ -664,6 +667,7 @@ public class UserDefinedColours extends Panel implements ActionListener, rText.setText("0 "); rText.setBounds(new Rectangle(156, 27, 53, 19)); rText.addActionListener(this); + rText.addFocusListener(this); label4.setAlignment(Label.RIGHT); label4.setText("G"); label4.setBounds(new Rectangle(15, 56, 20, 15)); @@ -678,6 +682,7 @@ public class UserDefinedColours extends Panel implements ActionListener, gText.setText("0 "); gText.setBounds(new Rectangle(156, 52, 53, 20)); gText.addActionListener(this); + gText.addFocusListener(this); label5.setAlignment(Label.RIGHT); label5.setText("B"); label5.setBounds(new Rectangle(14, 82, 20, 15)); @@ -692,12 +697,16 @@ public class UserDefinedColours extends Panel implements ActionListener, bText.setText("0 "); bText.setBounds(new Rectangle(157, 78, 52, 20)); bText.addActionListener(this); + bText.addFocusListener(this); target.setBackground(Color.black); target.setBounds(new Rectangle(229, 26, 134, 79)); this.add(okcancelPanel, null); okcancelPanel.add(okButton, null); okcancelPanel.add(applyButton, null); okcancelPanel.add(cancelButton, null); + this.add(rText); + this.add(gText); + this.add(bText); this.add(buttonPanel, null); this.add(target, null); this.add(gScroller); @@ -706,9 +715,40 @@ public class UserDefinedColours extends Panel implements ActionListener, this.add(label5); this.add(label4); this.add(label1); - this.add(gText); - this.add(rText); - this.add(bText); + } + + @Override + public void focusGained(FocusEvent e) + { + // noop + } + + /** + * This method applies any change to an RGB value if the user tabs out of the + * field instead of pressing Enter + */ + @Override + public void focusLost(FocusEvent e) + { + Component c = e.getComponent(); + if (c == rText) + { + rText_actionPerformed(); + } + else + { + if (c == gText) + { + gText_actionPerformed(); + } + else + { + if (c == bText) + { + bText_actionPerformed(); + } + } + } } } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 0fe1664..e184db7 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -20,6 +20,14 @@ */ package jalview.bin; +import jalview.gui.AlignFrame; +import jalview.gui.Desktop; +import jalview.io.BioJsHTMLOutput; +import jalview.io.HtmlSvgOutput; +import jalview.util.MessageManager; +import jalview.util.Platform; +import jalview.ws.jws2.Jws2Discoverer; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; @@ -45,13 +53,6 @@ import java.util.Vector; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; -import jalview.gui.AlignFrame; -import jalview.gui.Desktop; -import jalview.io.HtmlSvgOutput; -import jalview.util.MessageManager; -import jalview.util.Platform; -import jalview.ws.jws2.Jws2Discoverer; - /** * Main class for Jalview Application
*
@@ -93,23 +94,6 @@ public class Jalview System.out.println(System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version")); - // if (new Platform().isAMac()) - // { - // // System.setProperty("com.apple.mrj.application.apple.menu.about.name", - // // "Jalview"); - // // System.setProperty("apple.laf.useScreenMenuBar", "true"); - // try - // { - // UIManager.setLookAndFeel(ch.randelshofer.quaqua.QuaquaManager - // .getLookAndFeel()); - // System.out - // .println("--------------------------------------------> in here"); - // } catch (UnsupportedLookAndFeelException e) - // { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - // } ArgsParser aparser = new ArgsParser(args); boolean headless = false; @@ -241,6 +225,9 @@ public class Jalview desktop.checkForNews(); } + BioJsHTMLOutput bjs = new BioJsHTMLOutput(null, null); + bjs.updateBioJS(); + String file = null, protocol = null, format = null, data = null; jalview.io.FileLoader fileLoader = new jalview.io.FileLoader(); Vector getFeatures = null; // vector of das source nicknames to fetch diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 1bbe81e..b608139 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -20,10 +20,6 @@ */ package jalview.datamodel; -import jalview.analysis.Rna; -import jalview.analysis.SecStrConsensus.SimpleBP; -import jalview.analysis.WUSSParseException; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -32,6 +28,10 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import jalview.analysis.Rna; +import jalview.analysis.SecStrConsensus.SimpleBP; +import jalview.analysis.WUSSParseException; + /** * DOCUMENT ME! * @@ -1359,8 +1359,21 @@ public class AlignmentAnnotation { if (properties == null) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } return properties.keySet(); } + + /** + * Returns the Annotation for the given sequence position (base 1) if any, + * else null + * + * @param position + * @return + */ + public Annotation getAnnotationForPosition(int position) + { + return sequenceMapping == null ? null : sequenceMapping.get(position); + + } } diff --git a/src/jalview/datamodel/Mapping.java b/src/jalview/datamodel/Mapping.java index 559ae4c..d7b7eb9 100644 --- a/src/jalview/datamodel/Mapping.java +++ b/src/jalview/datamodel/Mapping.java @@ -20,12 +20,12 @@ */ package jalview.datamodel; -import jalview.util.MapList; - import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Vector; +import jalview.util.MapList; + public class Mapping { /** @@ -663,24 +663,6 @@ public class Mapping return copy; } - public static void main(String[] args) - { - /** - * trite test of the intersectVisContigs method for a simple DNA -> Protein - * exon map and a range of visContigs - */ - MapList fk = new MapList(new int[] - { 1, 6, 8, 13, 15, 23 }, new int[] - { 1, 7 }, 3, 1); - Mapping m = new Mapping(fk); - Mapping m_1 = m.intersectVisContigs(new int[] - { fk.getFromLowest(), fk.getFromHighest() }); - Mapping m_2 = m.intersectVisContigs(new int[] - { 1, 7, 11, 20 }); - System.out.println("" + m_1.map.getFromRanges()); - - } - /** * get the sequence being mapped to - if any * diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index 0050666..db792e2 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -55,10 +55,7 @@ public class PDBEntry return true; } PDBEntry o = (PDBEntry) obj; - return /* - * (file == o.file || (file != null && o.file != null && o.file - * .equals(file))) && - */ + return (type == o.type || (type != null && o.type != null && o.type .equals(type))) && (id == o.id || (id != null && o.id != null && o.id @@ -69,6 +66,7 @@ public class PDBEntry && (properties == o.properties || (properties != null && o.properties != null && properties .equals(o.properties))); + } /** @@ -94,7 +92,7 @@ public class PDBEntry { this.id = pdbId; this.chainCode = chain; - this.type = type.toString(); + this.type = type == null ? null : type.toString(); this.file = filePath; } @@ -125,9 +123,13 @@ public class PDBEntry return file; } + public void setType(String t) + { + this.type = t; + } public void setType(PDBEntry.Type type) { - this.type = type.toString(); + this.type = type == null ? null : type.toString(); } public String getType() diff --git a/src/jalview/datamodel/SeqCigar.java b/src/jalview/datamodel/SeqCigar.java index 090d216..09b2e89 100644 --- a/src/jalview/datamodel/SeqCigar.java +++ b/src/jalview/datamodel/SeqCigar.java @@ -23,8 +23,10 @@ package jalview.datamodel; import java.util.Enumeration; import java.util.Hashtable; -import jalview.analysis.*; -import jalview.util.*; +import jalview.analysis.AlignSeq; +import jalview.analysis.SeqsetUtils; +import jalview.util.MessageManager; +import jalview.util.ShiftList; public class SeqCigar extends CigarSimple { @@ -538,157 +540,6 @@ public class SeqCigar extends CigarSimple } /** - * non rigorous testing - */ - /** - * - * @param seq - * Sequence - * @param ex_cs_gapped - * String - * @return String - */ - public static String testCigar_string(Sequence seq, String ex_cs_gapped) - { - SeqCigar c_sgapped = new SeqCigar(seq); - String cs_gapped = c_sgapped.getCigarstring(); - if (!cs_gapped.equals(ex_cs_gapped)) - { - System.err.println("Failed getCigarstring: incorect string '" - + cs_gapped + "' != " + ex_cs_gapped); - } - return cs_gapped; - } - - public static boolean testSeqRecovery(SeqCigar gen_sgapped, - SequenceI s_gapped) - { - // this is non-rigorous - start and end recovery is not tested. - SequenceI gen_sgapped_s = gen_sgapped.getSeq('-'); - if (!gen_sgapped_s.getSequence().equals(s_gapped.getSequence())) - { - System.err.println("Couldn't reconstruct sequence.\n" - + gen_sgapped_s.getSequenceAsString() + "\n" - + s_gapped.getSequenceAsString()); - return false; - } - return true; - } - - public static void main(String argv[]) throws Exception - { - String o_seq; - Sequence s = new Sequence("MySeq", - o_seq = "asdfktryasdtqwrtsaslldddptyipqqwaslchvhttt", 39, 80); - String orig_gapped; - Sequence s_gapped = new Sequence( - "MySeq", - orig_gapped = "----asdf------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhttt", - 39, 80); - String ex_cs_gapped = "4I4M6I6M3I11M4I12M4I9M"; - s_gapped.setDatasetSequence(s); - String sub_gapped_s; - Sequence s_subsequence_gapped = new Sequence( - "MySeq", - sub_gapped_s = "------ktryas---dtqwrtsasll----dddptyipqqwa----slchvh", - 43, 77); - - s_subsequence_gapped.setDatasetSequence(s); - SeqCigar c_null = new SeqCigar(s); - String cs_null = c_null.getCigarstring(); - if (!cs_null.equals("42M")) - { - System.err - .println("Failed to recover ungapped sequence cigar operations:" - + ((cs_null == "") ? "empty string" : cs_null)); - } - testCigar_string(s_gapped, ex_cs_gapped); - SeqCigar gen_sgapped = SeqCigar.parseCigar(s, ex_cs_gapped); - if (!gen_sgapped.getCigarstring().equals(ex_cs_gapped)) - { - System.err.println("Failed parseCigar(" + ex_cs_gapped - + ")->getCigarString()->'" + gen_sgapped.getCigarstring() - + "'"); - } - testSeqRecovery(gen_sgapped, s_gapped); - // Test dataset resolution - SeqCigar sub_gapped = new SeqCigar(s_subsequence_gapped); - if (!testSeqRecovery(sub_gapped, s_subsequence_gapped)) - { - System.err - .println("Failed recovery for subsequence of dataset sequence"); - } - // width functions - if (sub_gapped.getWidth() != sub_gapped_s.length()) - { - System.err.println("Failed getWidth()"); - } - - sub_gapped.getFullWidth(); - if (sub_gapped.hasDeletedRegions()) - { - System.err.println("hasDeletedRegions is incorrect."); - } - // Test start-end region SeqCigar - SeqCigar sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48); - if (sub_se_gp.getWidth() != 41) - { - System.err - .println("SeqCigar(seq, start, end) not properly clipped alignsequence."); - } - System.out.println("Original sequence align:\n" + sub_gapped_s - + "\nReconstructed window from 8 to 48\n" + "XXXXXXXX" - + sub_se_gp.getSequenceString('-') + "..." + "\nCigar String:" - + sub_se_gp.getCigarstring() + "\n"); - SequenceI ssgp = sub_se_gp.getSeq('-'); - System.out.println("\t " + ssgp.getSequenceAsString()); - for (int r = 0; r < 10; r++) - { - sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48); - int sl = sub_se_gp.getWidth(); - int st = sl - 1 - r; - for (int rs = 0; rs < 10; rs++) - { - int e = st + rs; - sub_se_gp.deleteRange(st, e); - String ssgapedseq = sub_se_gp.getSeq('-').getSequenceAsString(); - System.out.println(st + "," + e + "\t:" + ssgapedseq); - st -= 3; - } - } - { - SeqCigar[] set = new SeqCigar[] - { new SeqCigar(s), new SeqCigar(s_subsequence_gapped, 8, 48), - new SeqCigar(s_gapped) }; - Alignment al = new Alignment(set); - for (int i = 0; i < al.getHeight(); i++) - { - System.out.println("" + al.getSequenceAt(i).getName() + "\t" - + al.getSequenceAt(i).getStart() + "\t" - + al.getSequenceAt(i).getEnd() + "\t" - + al.getSequenceAt(i).getSequenceAsString()); - } - } - { - System.out.println("Gapped."); - SeqCigar[] set = new SeqCigar[] - { new SeqCigar(s), new SeqCigar(s_subsequence_gapped, 8, 48), - new SeqCigar(s_gapped) }; - set[0].deleteRange(20, 25); - Alignment al = new Alignment(set); - for (int i = 0; i < al.getHeight(); i++) - { - System.out.println("" + al.getSequenceAt(i).getName() + "\t" - + al.getSequenceAt(i).getStart() + "\t" - + al.getSequenceAt(i).getEnd() + "\t" - + al.getSequenceAt(i).getSequenceAsString()); - } - } - // if (!ssgapedseq.equals("ryas---dtqqwa----slchvh")) - // System.err.println("Subseqgaped\n------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhryas---dtqwrtsasll--qwa----slchvh\n"+ssgapedseq+"\n"+sub_se_gp.getCigarstring()); - } - - /** * references to entities that this sequence cigar is associated with. */ private Hashtable selGroups = null; diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 9cec370..cab1ac7 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -20,9 +20,6 @@ */ package jalview.datamodel; -import jalview.analysis.AlignSeq; -import jalview.util.StringUtils; - import java.util.ArrayList; import java.util.Enumeration; import java.util.List; @@ -30,6 +27,9 @@ import java.util.Vector; import fr.orsay.lri.varna.models.rna.RNA; +import jalview.analysis.AlignSeq; +import jalview.util.StringUtils; + /** * * Implements the SequenceI interface for a char[] based sequence object. @@ -121,7 +121,7 @@ public class Sequence implements SequenceI .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor."); name = ""; } - // Does sequence have the /start-end signiature? + // Does sequence have the /start-end signature? if (limitrx.search(name)) { name = limitrx.left(); @@ -379,7 +379,8 @@ public class Sequence implements SequenceI * @param id * DOCUMENT ME! */ - public void setPDBId(Vector id) + @Override + public void setPDBId(Vector id) { pdbIds = id; } @@ -389,7 +390,8 @@ public class Sequence implements SequenceI * * @return DOCUMENT ME! */ - public Vector getPDBId() + @Override + public Vector getPDBId() { return pdbIds; } @@ -947,7 +949,7 @@ public class Sequence implements SequenceI { if (this.annotation == null) { - this.annotation = new Vector(); + this.annotation = new Vector(); } if (!this.annotation.contains(annotation)) { diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 04f3588..38ae372 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -134,12 +134,13 @@ public interface SequenceI public char[] getSequence(int start, int end); /** - * create a new sequence object from start to end of this sequence + * create a new sequence object with a subsequence of this one but sharing the + * same dataset sequence * * @param start - * int index for start position + * int index for start position (base 0, inclusive) * @param end - * int index for end position + * int index for end position (base 0, exclusive) * * @return SequenceI * @note implementations may use getSequence to get the sequence data diff --git a/src/jalview/datamodel/UniprotEntry.java b/src/jalview/datamodel/UniprotEntry.java index 90702a2..4cf0f13 100755 --- a/src/jalview/datamodel/UniprotEntry.java +++ b/src/jalview/datamodel/UniprotEntry.java @@ -20,39 +20,44 @@ */ package jalview.datamodel; -import java.util.*; +import java.util.Vector; +/** + * Data model for an entry returned from a Uniprot query + * + * @see uniprot_mapping.xml + */ public class UniprotEntry { UniprotSequence sequence; - Vector name; + Vector name; - Vector accession; + Vector accession; - Vector feature; + Vector feature; - Vector dbrefs; + Vector dbrefs; UniprotProteinName protName; - public void setAccession(Vector items) + public void setAccession(Vector items) { accession = items; } - public void setFeature(Vector items) + public void setFeature(Vector items) { feature = items; } - public Vector getFeature() + public Vector getFeature() { return feature; } - public Vector getAccession() + public Vector getAccession() { return accession; } @@ -67,12 +72,12 @@ public class UniprotEntry return protName; } - public void setName(Vector na) + public void setName(Vector na) { name = na; } - public Vector getName() + public Vector getName() { return name; } @@ -87,12 +92,12 @@ public class UniprotEntry sequence = seq; } - public Vector getDbReference() + public Vector getDbReference() { return dbrefs; } - public void setDbReference(Vector dbref) + public void setDbReference(Vector dbref) { this.dbrefs = dbref; } diff --git a/src/jalview/datamodel/UniprotFile.java b/src/jalview/datamodel/UniprotFile.java index 44506a6..f0e38d8 100755 --- a/src/jalview/datamodel/UniprotFile.java +++ b/src/jalview/datamodel/UniprotFile.java @@ -20,18 +20,22 @@ */ package jalview.datamodel; -import java.util.*; +import java.util.Vector; +/** + * Data model of a retrieved Uniprot entry, as unmarshalled by Castor using a + * binding file (uniprot_mapping.xml) + */ public class UniprotFile { - Vector _items; + Vector _items; - public void setUniprotEntries(Vector items) + public void setUniprotEntries(Vector items) { _items = items; } - public Vector getUniprotEntries() + public Vector getUniprotEntries() { return _items; } diff --git a/src/jalview/datamodel/UniprotProteinName.java b/src/jalview/datamodel/UniprotProteinName.java index eb353aa..0a317e6 100755 --- a/src/jalview/datamodel/UniprotProteinName.java +++ b/src/jalview/datamodel/UniprotProteinName.java @@ -20,19 +20,26 @@ */ package jalview.datamodel; +import java.util.Vector; + +/** + * Data model for protein name returned from a Uniprot query + * + * Protein names are read from the Uniprot XML element + * uniprot/entry/protein/recommendedName/fullName + * + * @see uniprot_mapping.xml + */ public class UniprotProteinName { - /** - * internal content storage - */ - private java.util.Vector names; + private Vector names; - public void setName(java.util.Vector names) + public void setName(Vector names) { this.names = names; } - public java.util.Vector getName() + public Vector getName() { return names; } diff --git a/src/jalview/datamodel/UniprotSequence.java b/src/jalview/datamodel/UniprotSequence.java index 6ce751e..1150f1e 100755 --- a/src/jalview/datamodel/UniprotSequence.java +++ b/src/jalview/datamodel/UniprotSequence.java @@ -20,24 +20,34 @@ */ package jalview.datamodel; +/** + * Data model for the sequence returned by a Uniprot query + * + * @see uniprot_mapping.xml + */ public class UniprotSequence { + private String _content = ""; + /** - * internal content storage + * Sets the content string, omitting any space characters + * + * @param seq */ - private java.lang.String _content = ""; - public void setContent(String seq) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < seq.length(); i++) + if (seq != null) { - if (seq.charAt(i) != ' ') + StringBuilder sb = new StringBuilder(seq.length()); + for (int i = 0; i < seq.length(); i++) { - sb.append(seq.charAt(i)); + if (seq.charAt(i) != ' ') + { + sb.append(seq.charAt(i)); + } } + _content = sb.toString(); } - _content = sb.toString(); } public String getContent() diff --git a/src/jalview/datamodel/xdb/embl/BasePosition.java b/src/jalview/datamodel/xdb/embl/BasePosition.java index 070958a..3737adc 100644 --- a/src/jalview/datamodel/xdb/embl/BasePosition.java +++ b/src/jalview/datamodel/xdb/embl/BasePosition.java @@ -20,6 +20,12 @@ */ package jalview.datamodel.xdb.embl; +/** + * Data model for a feature/location/locationElement/basePosition read from an + * EMBL query reply + * + * @see embl_mapping.xml + */ public class BasePosition { String type; diff --git a/src/jalview/datamodel/xdb/embl/EmblEntry.java b/src/jalview/datamodel/xdb/embl/EmblEntry.java index fc57b27..3f890ba 100644 --- a/src/jalview/datamodel/xdb/embl/EmblEntry.java +++ b/src/jalview/datamodel/xdb/embl/EmblEntry.java @@ -20,6 +20,11 @@ */ package jalview.datamodel.xdb.embl; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; + import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; import jalview.datamodel.FeatureProperties; @@ -28,11 +33,14 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Vector; - +/** + * Data model for one entry returned from an EMBL query, as marshalled by a + * Castor binding file + * + * For example: http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/x53828/emblxml + * + * @see embl_mapping.xml + */ public class EmblEntry { String accession; @@ -49,13 +57,11 @@ public class EmblEntry String lastUpdated; - Vector keywords; - - Vector refs; + Vector keywords; - Vector dbRefs; + Vector dbRefs; - Vector features; + Vector features; EmblSequence sequence; @@ -79,7 +85,7 @@ public class EmblEntry /** * @return the dbRefs */ - public Vector getDbRefs() + public Vector getDbRefs() { return dbRefs; } @@ -88,7 +94,7 @@ public class EmblEntry * @param dbRefs * the dbRefs to set */ - public void setDbRefs(Vector dbRefs) + public void setDbRefs(Vector dbRefs) { this.dbRefs = dbRefs; } @@ -113,7 +119,7 @@ public class EmblEntry /** * @return the features */ - public Vector getFeatures() + public Vector getFeatures() { return features; } @@ -122,7 +128,7 @@ public class EmblEntry * @param features * the features to set */ - public void setFeatures(Vector features) + public void setFeatures(Vector features) { this.features = features; } @@ -130,7 +136,7 @@ public class EmblEntry /** * @return the keywords */ - public Vector getKeywords() + public Vector getKeywords() { return keywords; } @@ -139,7 +145,7 @@ public class EmblEntry * @param keywords * the keywords to set */ - public void setKeywords(Vector keywords) + public void setKeywords(Vector keywords) { this.keywords = keywords; } @@ -162,23 +168,6 @@ public class EmblEntry } /** - * @return the refs - */ - public Vector getRefs() - { - return refs; - } - - /** - * @param refs - * the refs to set - */ - public void setRefs(Vector refs) - { - this.refs = refs; - } - - /** * @return the releaseCreated */ public String getRCreated() @@ -190,7 +179,7 @@ public class EmblEntry * @param releaseCreated * the releaseCreated to set */ - public void setRcreated(String releaseCreated) + public void setRCreated(String releaseCreated) { this.rCreated = releaseCreated; } diff --git a/src/jalview/datamodel/xdb/embl/EmblError.java b/src/jalview/datamodel/xdb/embl/EmblError.java index e781a7e..94de28f 100644 --- a/src/jalview/datamodel/xdb/embl/EmblError.java +++ b/src/jalview/datamodel/xdb/embl/EmblError.java @@ -20,6 +20,11 @@ */ package jalview.datamodel.xdb.embl; +/** + * Data model mapped from any <error> elements returned from an EMBL query + * + * @see embl_mapping.xml + */ public class EmblError { String accession; diff --git a/src/jalview/datamodel/xdb/embl/EmblFeature.java b/src/jalview/datamodel/xdb/embl/EmblFeature.java index 077788c..7f53eb3 100644 --- a/src/jalview/datamodel/xdb/embl/EmblFeature.java +++ b/src/jalview/datamodel/xdb/embl/EmblFeature.java @@ -22,20 +22,27 @@ package jalview.datamodel.xdb.embl; import java.util.Vector; +import jalview.datamodel.DBRefEntry; + +/** + * Data model for a <feature> element returned from an EMBL query reply + * + * @see embl_mapping.xml + */ public class EmblFeature { String name; - Vector dbRefs; + Vector dbRefs; - Vector qualifiers; + Vector qualifiers; - Vector locations; + Vector locations; /** * @return the dbRefs */ - public Vector getDbRefs() + public Vector getDbRefs() { return dbRefs; } @@ -44,7 +51,7 @@ public class EmblFeature * @param dbRefs * the dbRefs to set */ - public void setDbRefs(Vector dbRefs) + public void setDbRefs(Vector dbRefs) { this.dbRefs = dbRefs; } @@ -52,7 +59,7 @@ public class EmblFeature /** * @return the locations */ - public Vector getLocations() + public Vector getLocations() { return locations; } @@ -61,7 +68,7 @@ public class EmblFeature * @param locations * the locations to set */ - public void setLocations(Vector locations) + public void setLocations(Vector locations) { this.locations = locations; } @@ -86,7 +93,7 @@ public class EmblFeature /** * @return the qualifiers */ - public Vector getQualifiers() + public Vector getQualifiers() { return qualifiers; } @@ -95,7 +102,7 @@ public class EmblFeature * @param qualifiers * the qualifiers to set */ - public void setQualifiers(Vector qualifiers) + public void setQualifiers(Vector qualifiers) { this.qualifiers = qualifiers; } diff --git a/src/jalview/datamodel/xdb/embl/EmblFeatureLocElement.java b/src/jalview/datamodel/xdb/embl/EmblFeatureLocElement.java index 10c3634..134ce9e 100644 --- a/src/jalview/datamodel/xdb/embl/EmblFeatureLocElement.java +++ b/src/jalview/datamodel/xdb/embl/EmblFeatureLocElement.java @@ -20,6 +20,12 @@ */ package jalview.datamodel.xdb.embl; +/** + * Data model for a feature/location/locationElement read from an EMBL query + * reply + * + * @see embl_mapping.xml + */ public class EmblFeatureLocElement { String type; diff --git a/src/jalview/datamodel/xdb/embl/EmblFeatureLocations.java b/src/jalview/datamodel/xdb/embl/EmblFeatureLocations.java index 41ba739..eb0bee7 100644 --- a/src/jalview/datamodel/xdb/embl/EmblFeatureLocations.java +++ b/src/jalview/datamodel/xdb/embl/EmblFeatureLocations.java @@ -20,12 +20,17 @@ */ package jalview.datamodel.xdb.embl; -import java.util.Enumeration; import java.util.Vector; +/** + * Data model for a <loctaion> child element of a <feature> read + * from an EMBL query reply + * + * @see embl_mapping.xml + */ public class EmblFeatureLocations { - Vector locElements; + Vector locElements; String locationType; @@ -68,7 +73,7 @@ public class EmblFeatureLocations /** * @return the locElements */ - public Vector getLocElements() + public Vector getLocElements() { return locElements; } @@ -77,7 +82,7 @@ public class EmblFeatureLocations * @param locElements * the locElements to set */ - public void setLocElements(Vector locElements) + public void setLocElements(Vector locElements) { this.locElements = locElements; } @@ -110,12 +115,10 @@ public class EmblFeatureLocations { int sepos = 0; int[] se = new int[locElements.size() * 2]; - if (locationType.equalsIgnoreCase("single")) + if (locationType.equalsIgnoreCase("single")) // TODO: or "simple" ? { - for (Enumeration le = locElements.elements(); le.hasMoreElements();) + for (EmblFeatureLocElement loce : locElements) { - EmblFeatureLocElement loce = (EmblFeatureLocElement) le - .nextElement(); if (accession == null || loce.accession != null && accession.equals(loce.accession)) { @@ -130,10 +133,8 @@ public class EmblFeatureLocations } else if (locationType.equalsIgnoreCase("join")) { - for (Enumeration le = locElements.elements(); le.hasMoreElements();) + for (EmblFeatureLocElement loce : locElements) { - EmblFeatureLocElement loce = (EmblFeatureLocElement) le - .nextElement(); if (accession == null || loce.accession != null && accession.equals(loce.accession)) { @@ -150,13 +151,17 @@ public class EmblFeatureLocations else if (locationType != null) { if (jalview.bin.Cache.log != null) + { jalview.bin.Cache.log .error("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='" + locationType + "'"); + } else + { System.err .println("EmbleFeatureLocations.getElementRanges cannot deal with locationType=='" + locationType + "'"); + } } // trim range if necessary. if (se != null && sepos != se.length) diff --git a/src/jalview/datamodel/xdb/embl/EmblFile.java b/src/jalview/datamodel/xdb/embl/EmblFile.java index 3ca3755..2129054 100644 --- a/src/jalview/datamodel/xdb/embl/EmblFile.java +++ b/src/jalview/datamodel/xdb/embl/EmblFile.java @@ -22,22 +22,31 @@ package jalview.datamodel.xdb.embl; import java.io.File; import java.io.FileReader; +import java.io.PrintWriter; import java.io.Reader; import java.util.Vector; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.xml.Unmarshaller; +/** + * Data model for entries returned from an EMBL query, as marshalled by a Castor + * binding file + * + * For example: http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/embl/x53828/emblxml + * + * @see embl_mapping.xml + */ public class EmblFile { - Vector entries; + Vector entries; - Vector errors; + Vector errors; /** * @return the entries */ - public Vector getEntries() + public Vector getEntries() { return entries; } @@ -46,7 +55,7 @@ public class EmblFile * @param entries * the entries to set */ - public void setEntries(Vector entries) + public void setEntries(Vector entries) { this.entries = entries; } @@ -54,7 +63,7 @@ public class EmblFile /** * @return the errors */ - public Vector getErrors() + public Vector getErrors() { return errors; } @@ -63,7 +72,7 @@ public class EmblFile * @param errors * the errors to set */ - public void setErrors(Vector errors) + public void setErrors(Vector errors) { this.errors = errors; } @@ -77,7 +86,9 @@ public class EmblFile public static EmblFile getEmblFile(File file) { if (file == null) + { return null; + } try { return EmblFile.getEmblFile(new FileReader(file)); @@ -96,6 +107,7 @@ public class EmblFile { // 1. Load the mapping information from the file Mapping map = new Mapping(record.getClass().getClassLoader()); + java.net.URL url = record.getClass().getResource("/embl_mapping.xml"); map.loadMapping(url); @@ -104,17 +116,19 @@ public class EmblFile try { // uncomment to DEBUG EMBLFile reading - if (((String) jalview.bin.Cache.getDefault( - jalview.bin.Cache.CASTORLOGLEVEL, "debug")) + if (jalview.bin.Cache.getDefault( + jalview.bin.Cache.CASTORLOGLEVEL, "debug") .equalsIgnoreCase("DEBUG")) + { unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled()); + } } catch (Exception e) { } - ; unmar.setIgnoreExtraElements(true); + unmar.setIgnoreExtraAttributes(true); unmar.setMapping(map); - + unmar.setLogWriter(new PrintWriter(System.out)); record = (EmblFile) unmar.unmarshal(file); } catch (Exception e) { @@ -124,23 +138,4 @@ public class EmblFile return record; } - - public static void main(String args[]) - { - File mf = null; - if (args.length == 1) - { - mf = new File(args[0]); - } - if (!mf.exists()) - { - mf = new File( - "C:\\Documents and Settings\\JimP\\workspace-3.2\\Jalview Release\\schemas\\embleRecordV1.1.xml"); - } - EmblFile myfile = EmblFile.getEmblFile(mf); - if (myfile != null && myfile.entries != null - && myfile.entries.size() > 0) - System.out.println(myfile.entries.size() + " Records read. (" + mf - + ")"); - } } diff --git a/src/jalview/datamodel/xdb/embl/EmblSequence.java b/src/jalview/datamodel/xdb/embl/EmblSequence.java index 406ef2e..2a6fa84 100644 --- a/src/jalview/datamodel/xdb/embl/EmblSequence.java +++ b/src/jalview/datamodel/xdb/embl/EmblSequence.java @@ -20,6 +20,11 @@ */ package jalview.datamodel.xdb.embl; +/** + * Data model for the sequence extracted from an EMBL query reply + * + * @see embl_mapping.xml + */ public class EmblSequence { String version; diff --git a/src/jalview/datamodel/xdb/embl/Qualifier.java b/src/jalview/datamodel/xdb/embl/Qualifier.java index 9ab7f38..851dd48 100644 --- a/src/jalview/datamodel/xdb/embl/Qualifier.java +++ b/src/jalview/datamodel/xdb/embl/Qualifier.java @@ -20,6 +20,12 @@ */ package jalview.datamodel.xdb.embl; +/** + * Data model for a <qualifier> child element of a <feature> read + * from an EMBL query reply + * + * @see embl_mapping.xml + */ public class Qualifier { String name; @@ -64,6 +70,7 @@ public class Qualifier public void addEvidence(String qevidence) { + // TODO - not used? can remove? if (evidence == null) { evidence = new String[1]; @@ -79,6 +86,7 @@ public class Qualifier public void addValues(String value) { + // TODO - not used? can remove? if (values == null) { values = new String[1]; diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 68cc792..45fc378 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -20,22 +20,6 @@ */ package jalview.ext.jmol; -import jalview.api.AlignmentViewPanel; -import jalview.api.FeatureRenderer; -import jalview.api.SequenceRenderer; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; -import jalview.schemes.ColourSchemeI; -import jalview.schemes.ResidueProperties; -import jalview.structure.StructureMapping; -import jalview.structure.StructureMappingcommandSet; -import jalview.structure.StructureSelectionManager; -import jalview.structures.models.AAStructureBindingModel; -import jalview.util.MessageManager; - import java.awt.Color; import java.awt.Container; import java.awt.event.ComponentEvent; @@ -44,6 +28,7 @@ import java.io.File; import java.net.URL; import java.security.AccessControlException; import java.util.Hashtable; +import java.util.List; import java.util.Map; import java.util.Vector; @@ -55,6 +40,22 @@ import org.jmol.api.JmolViewer; import org.jmol.constant.EnumCallback; import org.jmol.popup.JmolPopup; +import jalview.api.AlignmentViewPanel; +import jalview.api.FeatureRenderer; +import jalview.api.SequenceRenderer; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.ResidueProperties; +import jalview.structure.StructureMapping; +import jalview.structure.StructureMappingcommandSet; +import jalview.structure.StructureSelectionManager; +import jalview.structures.models.AAStructureBindingModel; +import jalview.util.MessageManager; + public abstract class JalviewJmolBinding extends AAStructureBindingModel implements JmolStatusListener, JmolSelectionListener, ComponentListener @@ -1327,22 +1328,14 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel return; } - int index; - Color col; jmolHistory(false); - // TODO: Switch between nucleotide or aa selection expressions StringBuilder command = new StringBuilder(128); command.append("select *;color white;"); - for (String res : ResidueProperties.aa3Hash.keySet()) + List residueSet = ResidueProperties.getResidues(isNucleotide(), + false); + for (String res : residueSet) { - index = ResidueProperties.aa3Hash.get(res).intValue(); - if (index > 20) - { - continue; - } - - col = cs.findColour(ResidueProperties.aa[index].charAt(0)); - + Color col = cs.findColour(res.charAt(0)); command.append("select " + res + ";color[" + col.getRed() + "," + col.getGreen() + "," + col.getBlue() + "];"); } diff --git a/src/jalview/ext/jmol/PDBFileWithJmol.java b/src/jalview/ext/jmol/PDBFileWithJmol.java index bbf90ac..3df8957 100644 --- a/src/jalview/ext/jmol/PDBFileWithJmol.java +++ b/src/jalview/ext/jmol/PDBFileWithJmol.java @@ -177,10 +177,10 @@ public class PDBFileWithJmol extends AlignFile implements PDBEntry pdbe = new PDBEntry(); pdbe.setFile(getDataName()); pdbe.setId(getDataName()); - sq.addPDBId(pdbe); pdbe.setProperty(new Hashtable()); // pdbe.getProperty().put("CHAIN", "" + _lastChainId); pdbe.setChainCode(String.valueOf(_lastChainId)); + sq.addPDBId(pdbe); // JAL-1533 // Need to put the number of models for this polymer somewhere for Chimera/others to grab // pdbe.getProperty().put("PDBMODELS", biopoly.) diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 543cad4..b649a64 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -1018,23 +1018,16 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel return; } - int index; - Color col; // Chimera expects RBG values in the range 0-1 final double normalise = 255D; viewerCommandHistory(false); - // TODO: Switch between nucleotide or aa selection expressions StringBuilder command = new StringBuilder(128); - command.append("color white;"); - for (String res : ResidueProperties.aa3Hash.keySet()) - { - index = ResidueProperties.aa3Hash.get(res).intValue(); - if (index > 20) - { - continue; - } - col = cs.findColour(ResidueProperties.aa[index].charAt(0)); + List residueSet = ResidueProperties.getResidues(isNucleotide(), + false); + for (String res : residueSet) + { + Color col = cs.findColour(res.charAt(0)); command.append("color " + col.getRed() / normalise + "," + col.getGreen() / normalise + "," + col.getBlue() / normalise + " ::" + res + ";"); diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 80838e2..c659233 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -22,7 +22,6 @@ package jalview.gui; import java.awt.BorderLayout; import java.awt.Component; -import java.awt.GridLayout; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; @@ -56,17 +55,13 @@ import java.util.List; import java.util.Set; import java.util.Vector; -import javax.swing.JButton; import javax.swing.JCheckBoxMenuItem; import javax.swing.JEditorPane; import javax.swing.JInternalFrame; -import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JProgressBar; import javax.swing.JRadioButtonMenuItem; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; @@ -315,6 +310,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ void init() { + progressBar = new ProgressBar(this.statusPanel, this.statusBar); + avc = new jalview.controller.AlignViewController(this, viewport, alignPanel); if (viewport.getAlignmentConservationAnnotation() == null) @@ -875,7 +872,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // methods for implementing IProgressIndicator // need to refactor to a reusable stub class - Hashtable progressBars, progressBarHandlers; + // Map progressBars; + // + // Map progressBarHandlers; + private ProgressBar progressBar; /* * (non-Javadoc) @@ -885,78 +885,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void setProgressBar(String message, long id) { - if (progressBars == null) - { - progressBars = new Hashtable(); - progressBarHandlers = new Hashtable(); - } - - JPanel progressPanel; - Long lId = new Long(id); - GridLayout layout = (GridLayout) statusPanel.getLayout(); - if (progressBars.get(lId) != null) - { - progressPanel = (JPanel) progressBars.get(new Long(id)); - statusPanel.remove(progressPanel); - progressBars.remove(lId); - progressPanel = null; - if (message != null) - { - statusBar.setText(message); - } - if (progressBarHandlers.contains(lId)) - { - progressBarHandlers.remove(lId); - } - layout.setRows(layout.getRows() - 1); - } - else - { - progressPanel = new JPanel(new BorderLayout(10, 5)); - - JProgressBar progressBar = new JProgressBar(); - progressBar.setIndeterminate(true); - - progressPanel.add(new JLabel(message), BorderLayout.WEST); - progressPanel.add(progressBar, BorderLayout.CENTER); - - layout.setRows(layout.getRows() + 1); - statusPanel.add(progressPanel); - - progressBars.put(lId, progressPanel); - } - // update GUI - // setMenusForViewport(); - validate(); + progressBar.setProgressBar(message, id); } @Override public void registerHandler(final long id, final IProgressIndicatorHandler handler) { - if (progressBarHandlers == null || !progressBars.contains(new Long(id))) - { - throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler")); - } - progressBarHandlers.put(new Long(id), handler); - final JPanel progressPanel = (JPanel) progressBars.get(new Long(id)); - if (handler.canCancel()) - { - JButton cancel = new JButton( - MessageManager.getString("action.cancel")); - final IProgressIndicator us = this; - cancel.addActionListener(new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent e) - { - handler.cancelActivity(id); - us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", new Object[]{((JLabel) progressPanel.getComponent(0)).getText()}), id); - } - }); - progressPanel.add(cancel, BorderLayout.EAST); - } + progressBar.registerHandler(id, handler); } /** @@ -966,18 +902,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public boolean operationInProgress() { - if (progressBars != null && progressBars.size() > 0) - { - return true; - } - return false; + return progressBar.operationInProgress(); } @Override public void setStatus(String text) { statusBar.setText(text); - }; + } /* * Added so Castor Mapping file can obtain Jalview Version @@ -1212,7 +1144,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, omitHidden = viewport.getViewAsString(false); } } - FormatAdapter f = new FormatAdapter(); + FeatureRenderer fr = new FeatureRenderer(this.alignPanel); + viewport.setFeatureRenderer(fr); + FormatAdapter f = new FormatAdapter(viewport); String output = f.formatSequences(format, viewport.getAlignment(), // class cast exceptions will // occur in the distant future @@ -1282,7 +1216,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void outputText_actionPerformed(ActionEvent e) { String[] omitHidden = null; - + FeatureRenderer fr = new FeatureRenderer(this.alignPanel); + viewport.setFeatureRenderer(fr); if (viewport.hasHiddenColumns()) { int reply = JOptionPane @@ -1306,7 +1241,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, try { - cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(), + cap.setText(new FormatAdapter(viewport).formatSequences( + e.getActionCommand(), viewport.getAlignment(), omitHidden, viewport.getColumnSelection())); Desktop.addInternalFrame(cap, MessageManager.formatMessage( @@ -1338,8 +1274,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void bioJSMenuItem_actionPerformed(ActionEvent e) { - new BioJsHTMLOutput(alignPanel, + BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()); + bjs.exportJalviewAlignmentAsBioJsHtmlFile(); } public void createImageMap(File file, String image) { @@ -5787,8 +5724,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void setShowSeqFeatures(boolean b) { - showSeqFeatures.setSelected(true); - viewport.setShowSequenceFeatures(true); + showSeqFeatures.setSelected(b); + viewport.setShowSequenceFeatures(b); } /* @@ -5960,6 +5897,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, for (AlignmentAnnotation aa : alignPanel.getAlignment() .getAlignmentAnnotation()) { + /* + * don't display non-positional annotations on an alignment + */ + if (aa.annotations == null) + { + continue; + } boolean apply = (aa.sequenceRef == null && forAlignment) || (aa.sequenceRef != null && forSequences); if (apply) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index a54fa99..e32e910 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -38,22 +38,11 @@ */ package jalview.gui; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Set; -import java.util.Vector; - -import javax.swing.JInternalFrame; -import javax.swing.JOptionPane; - import jalview.analysis.AlignmentUtils; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.NJTree; import jalview.api.AlignViewportI; +import jalview.api.FeatureRenderer; import jalview.api.ViewStyleI; import jalview.bin.Cache; import jalview.commands.CommandI; @@ -76,6 +65,18 @@ import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; import jalview.ws.params.AutoCalcSetting; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Set; +import java.util.Vector; + +import javax.swing.JInternalFrame; +import javax.swing.JOptionPane; + /** * DOCUMENT ME! * @@ -95,6 +96,8 @@ public class AlignViewport extends AlignmentViewport implements private Rectangle explodedGeometry; + private FeatureRenderer featureRenderer; + String viewName; /* @@ -1038,4 +1041,16 @@ public class AlignViewport extends AlignmentViewport implements complementPanel.scrollToCentre(sr, seqOffset); } } + + @Override + public FeatureRenderer getFeatureRenderer() + { + return featureRenderer; + } + + @Override + public void setFeatureRenderer(FeatureRenderer featureRenderer) + { + this.featureRenderer = featureRenderer; + } } diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index 22f0a59..1981488 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -21,8 +21,11 @@ package jalview.gui; import jalview.datamodel.Alignment; +import jalview.io.FileParse; import jalview.io.FormatAdapter; +import jalview.io.HtmlFile; import jalview.io.IdentifyFile; +import jalview.io.JSONFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.jbgui.GCutAndPasteTransfer; @@ -53,6 +56,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer AlignViewport viewport; + FileParse source = null; public CutAndPasteTransfer() { SwingUtilities.invokeLater(new Runnable() @@ -188,7 +192,10 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer { try { - al = new FormatAdapter().readFile(getText(), "Paste", format); + FormatAdapter fa = new FormatAdapter(viewport); + al = fa.readFile(getText(), "Paste", format); + source = fa.getAlignFile(); + } catch (java.io.IOException ex) { JOptionPane.showInternalMessageDialog(Desktop.desktop, @@ -219,6 +226,16 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer af.statusBar.setText(MessageManager .getString("label.successfully_pasted_alignment_file")); + if (source instanceof HtmlFile) + { + ((HtmlFile) source).applySettingsToAlignFrame(af); + } + else if (source instanceof JSONFile) + { + ((JSONFile) source).applySettingsToAlignFrame(af); + } + + try { af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", @@ -230,6 +247,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer } } + /** * DOCUMENT ME! * diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 5f45dc1..1228965 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -20,6 +20,22 @@ */ package jalview.gui; +import jalview.api.AlignViewportI; +import jalview.api.AlignmentViewPanel; +import jalview.bin.Cache; +import jalview.io.FileLoader; +import jalview.io.FormatAdapter; +import jalview.io.IdentifyFile; +import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; +import jalview.jbgui.GSplitFrame; +import jalview.jbgui.GStructureViewer; +import jalview.structure.StructureSelectionManager; +import jalview.util.ImageMaker; +import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; +import jalview.ws.params.ParamManager; + import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -84,22 +100,6 @@ import javax.swing.event.HyperlinkEvent.EventType; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; -import jalview.api.AlignViewportI; -import jalview.api.AlignmentViewPanel; -import jalview.bin.Cache; -import jalview.io.FileLoader; -import jalview.io.FormatAdapter; -import jalview.io.IdentifyFile; -import jalview.io.JalviewFileChooser; -import jalview.io.JalviewFileView; -import jalview.jbgui.GSplitFrame; -import jalview.jbgui.GStructureViewer; -import jalview.structure.StructureSelectionManager; -import jalview.util.ImageMaker; -import jalview.util.MessageManager; -import jalview.viewmodel.AlignmentViewport; -import jalview.ws.params.ParamManager; - /** * Jalview Desktop * @@ -169,6 +169,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements private static final int THREE = 3; + private static AlignFrame currentAlignFrame; + public static jalview.ws.jws1.Discoverer discoverer; public static Object[] jalviewClipboard; @@ -1022,6 +1024,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements { new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format); + // viewport.setShowSequenceFeatures(JSONFile.isSeqFeaturesEnabled()); + // AlignFrame af = viewport.getAlignPanel().alignFrame; + // if (af != null) + // { + // af.changeColour(JSONFile.getColourScheme()); + // af.setMenusForViewport(); + // } } else { @@ -3073,4 +3082,16 @@ public class Desktop extends jalview.jbgui.GDesktop implements myTopFrame.setDisplayedView(myTopFrame.alignPanel); } + + // public static AlignFrame getCurrentAlignFrame() + // { + // return currentAlignFrame; + // } + // + // public static void setCurrentAlignFrame(AlignFrame currentAlignFrame) + // { + // Desktop.currentAlignFrame = currentAlignFrame; + // } + + } diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 3cce82c..5d07562 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -20,21 +20,25 @@ */ package jalview.gui; -import jalview.datamodel.SearchResults; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceI; -import jalview.jbgui.GFinder; -import jalview.util.MessageManager; -import jalview.viewmodel.AlignmentViewport; - import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; import java.util.Vector; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import javax.swing.AbstractAction; +import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; import javax.swing.JOptionPane; +import javax.swing.KeyStroke; + +import jalview.datamodel.SearchResults; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; +import jalview.jbgui.GFinder; +import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; /** * Performs the menu option for searching the alignment, for the next or all @@ -89,6 +93,7 @@ public class Finder extends GFinder frame = new JInternalFrame(); frame.setContentPane(this); frame.setLayer(JLayeredPane.PALETTE_LAYER); + addEscapeHandler(); Desktop.addInternalFrame(frame, MessageManager.getString("label.find"), WIDTH, HEIGHT); @@ -96,6 +101,31 @@ public class Finder extends GFinder } /** + * Add a handler for the Escape key when the window has focus + */ + private void addEscapeHandler() + { + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Cancel"); + getRootPane().getActionMap().put("Cancel", new AbstractAction() + { + public void actionPerformed(ActionEvent e) + { + escapeActionPerformed(); + } + }); + } + + /** + * Close the panel on Escape key press + */ + protected void escapeActionPerformed() + { + setVisible(false); + frame.dispose(); + } + + /** * Performs the 'Find Next' action. * * @param e diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index a0bc7c9..e4cbf61 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -59,6 +59,7 @@ public final class JvSwingUtils */ public static String wrapTooltip(boolean enclose, String ttext) { + ttext = ttext.trim(); if (ttext.length() < 60) { return enclose ? "" + ttext + "" : ttext; diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 2674617..cff9104 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -20,40 +20,34 @@ */ package jalview.gui; -import jalview.datamodel.Alignment; -import jalview.datamodel.AlignmentView; -import jalview.datamodel.ColumnSelection; -import jalview.datamodel.SeqCigar; -import jalview.datamodel.SequenceI; -import jalview.jbgui.GPCAPanel; -import jalview.schemes.ResidueProperties; -import jalview.util.MessageManager; -import jalview.viewmodel.AlignmentViewport; -import jalview.viewmodel.PCAModel; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Graphics; -import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; -import java.util.Hashtable; import javax.swing.ButtonGroup; -import javax.swing.JButton; import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; -import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JProgressBar; import javax.swing.JRadioButtonMenuItem; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentView; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SeqCigar; +import jalview.datamodel.SequenceI; +import jalview.jbgui.GPCAPanel; +import jalview.schemes.ResidueProperties; +import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.PCAModel; + /** * DOCUMENT ME! * @@ -64,6 +58,8 @@ public class PCAPanel extends GPCAPanel implements Runnable, IProgressIndicator { + private ProgressBar progressBar; + RotatableCanvas rc; AlignmentPanel ap; @@ -87,6 +83,8 @@ public class PCAPanel extends GPCAPanel implements Runnable, this.av = ap.av; this.ap = ap; + progressBar = new ProgressBar(statusPanel, statusBar); + boolean sameLength = true; boolean selected = av.getSelectionGroup() != null && av.getSelectionGroup().getSize() > 0; @@ -632,11 +630,6 @@ public class PCAPanel extends GPCAPanel implements Runnable, cap.dispose(); } } - - // methods for implementing IProgressIndicator - // need to refactor to a reusable stub class - Hashtable progressBars, progressBarHandlers; - /* * (non-Javadoc) * @@ -645,78 +638,82 @@ public class PCAPanel extends GPCAPanel implements Runnable, @Override public void setProgressBar(String message, long id) { - if (progressBars == null) - { - progressBars = new Hashtable(); - progressBarHandlers = new Hashtable(); - } - - JPanel progressPanel; - Long lId = new Long(id); - GridLayout layout = (GridLayout) statusPanel.getLayout(); - if (progressBars.get(lId) != null) - { - progressPanel = (JPanel) progressBars.get(new Long(id)); - statusPanel.remove(progressPanel); - progressBars.remove(lId); - progressPanel = null; - if (message != null) - { - statusBar.setText(message); - } - if (progressBarHandlers.contains(lId)) - { - progressBarHandlers.remove(lId); - } - layout.setRows(layout.getRows() - 1); - } - else - { - progressPanel = new JPanel(new BorderLayout(10, 5)); - - JProgressBar progressBar = new JProgressBar(); - progressBar.setIndeterminate(true); - - progressPanel.add(new JLabel(message), BorderLayout.WEST); - progressPanel.add(progressBar, BorderLayout.CENTER); - - layout.setRows(layout.getRows() + 1); - statusPanel.add(progressPanel); - - progressBars.put(lId, progressPanel); - } - // update GUI - // setMenusForViewport(); - validate(); + progressBar.setProgressBar(message, id); + // if (progressBars == null) + // { + // progressBars = new Hashtable(); + // progressBarHandlers = new Hashtable(); + // } + // + // JPanel progressPanel; + // Long lId = new Long(id); + // GridLayout layout = (GridLayout) statusPanel.getLayout(); + // if (progressBars.get(lId) != null) + // { + // progressPanel = (JPanel) progressBars.get(new Long(id)); + // statusPanel.remove(progressPanel); + // progressBars.remove(lId); + // progressPanel = null; + // if (message != null) + // { + // statusBar.setText(message); + // } + // if (progressBarHandlers.contains(lId)) + // { + // progressBarHandlers.remove(lId); + // } + // layout.setRows(layout.getRows() - 1); + // } + // else + // { + // progressPanel = new JPanel(new BorderLayout(10, 5)); + // + // JProgressBar progressBar = new JProgressBar(); + // progressBar.setIndeterminate(true); + // + // progressPanel.add(new JLabel(message), BorderLayout.WEST); + // progressPanel.add(progressBar, BorderLayout.CENTER); + // + // layout.setRows(layout.getRows() + 1); + // statusPanel.add(progressPanel); + // + // progressBars.put(lId, progressPanel); + // } + // // update GUI + // // setMenusForViewport(); + // validate(); } @Override public void registerHandler(final long id, final IProgressIndicatorHandler handler) { - if (progressBarHandlers == null || !progressBars.contains(new Long(id))) - { - throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler")); - } - progressBarHandlers.put(new Long(id), handler); - final JPanel progressPanel = (JPanel) progressBars.get(new Long(id)); - if (handler.canCancel()) - { - JButton cancel = new JButton( - MessageManager.getString("action.cancel")); - final IProgressIndicator us = this; - cancel.addActionListener(new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent e) - { - handler.cancelActivity(id); - us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", new String[]{((JLabel) progressPanel.getComponent(0)).getText()}), id); - } - }); - progressPanel.add(cancel, BorderLayout.EAST); - } + progressBar.registerHandler(id, handler); + // if (progressBarHandlers == null || !progressBars.contains(new Long(id))) + // { + // throw new + // Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler")); + // } + // progressBarHandlers.put(new Long(id), handler); + // final JPanel progressPanel = (JPanel) progressBars.get(new Long(id)); + // if (handler.canCancel()) + // { + // JButton cancel = new JButton( + // MessageManager.getString("action.cancel")); + // final IProgressIndicator us = this; + // cancel.addActionListener(new ActionListener() + // { + // + // @Override + // public void actionPerformed(ActionEvent e) + // { + // handler.cancelActivity(id); + // us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", + // new String[]{((JLabel) progressPanel.getComponent(0)).getText()}), id); + // } + // }); + // progressPanel.add(cancel, BorderLayout.EAST); + // } } /** @@ -726,11 +723,7 @@ public class PCAPanel extends GPCAPanel implements Runnable, @Override public boolean operationInProgress() { - if (progressBars != null && progressBars.size() > 0) - { - return true; - } - return false; + return progressBar.operationInProgress(); } @Override diff --git a/src/jalview/gui/PDBSearchPanel.java b/src/jalview/gui/PDBSearchPanel.java index 950c6b7..3185ae2 100644 --- a/src/jalview/gui/PDBSearchPanel.java +++ b/src/jalview/gui/PDBSearchPanel.java @@ -36,7 +36,6 @@ import java.util.Comparator; import java.util.HashSet; import java.util.List; -import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel; @SuppressWarnings("serial") @@ -62,6 +61,8 @@ public class PDBSearchPanel extends GPDBSearchPanel @Override public void txt_search_ActionPerformed() { + errorWarning.setLength(0); + lbl_warning.setVisible(false); btn_ok.setEnabled(false); boolean allowEmptySequence = false; mainFrame.setTitle(MessageManager @@ -95,8 +96,10 @@ public class PDBSearchPanel extends GPDBSearchPanel } catch (Exception e) { // System.out.println(">>>>>>>>>>>>>>>" + e.getMessage()); - JOptionPane.showMessageDialog(this, e.getMessage(), - "PDB Web-service Error", JOptionPane.ERROR_MESSAGE); + // JOptionPane.showMessageDialog(this, e.getMessage(), + // "PDB Web-service Error", JOptionPane.ERROR_MESSAGE); + errorWarning.append(e.getMessage()); + checkForErrors(); return; } @@ -172,6 +175,14 @@ public class PDBSearchPanel extends GPDBSearchPanel mainFrame.dispose(); } + public void transferToSequenceFetcher(String ids) + { + mainFrame.dispose(); + seqFetcher.textArea.setText(ids); + Thread worker = new Thread(seqFetcher); + worker.start(); + } + /** * Add the discovered/selected sequences to a target alignment window */ @@ -196,7 +207,7 @@ public class PDBSearchPanel extends GPDBSearchPanel } String ids = selectedIds.toString(); - System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids); + // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids); seqFetcher.textArea.setText(ids); Thread worker = new Thread(seqFetcher); worker.start(); @@ -258,4 +269,14 @@ public class PDBSearchPanel extends GPDBSearchPanel } } + public void checkForErrors() + { + lbl_warning.setVisible(false); + if (errorWarning.length() > 0) + { + lbl_warning.setToolTipText(JvSwingUtils.wrapTooltip(true, + errorWarning.toString())); + lbl_warning.setVisible(true); + } + } } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 1263b71..0d28a70 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -20,27 +20,6 @@ */ package jalview.gui; -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Arrays; -import java.util.Collections; -import java.util.Hashtable; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -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.JOptionPane; -import javax.swing.JPopupMenu; -import javax.swing.JRadioButtonMenuItem; - import jalview.analysis.AAFrequency; import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.AlignmentUtils; @@ -80,6 +59,27 @@ import jalview.util.GroupUrlLink.UrlStringTooLongException; import jalview.util.MessageManager; import jalview.util.UrlLink; +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; +import java.util.Collections; +import java.util.Hashtable; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +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.JOptionPane; +import javax.swing.JPopupMenu; +import javax.swing.JRadioButtonMenuItem; + /** * DOCUMENT ME! * @@ -204,9 +204,9 @@ public class PopupMenu extends JPopupMenu JMenu jMenu1 = new JMenu(); - JMenuItem structureMenu = new JMenuItem(); + JMenuItem proteinStructureMenu = new JMenuItem(); - JMenu viewStructureMenu = new JMenu(); + JMenu rnaStructureMenu = new JMenu(); JMenuItem editSequence = new JMenuItem(); @@ -322,51 +322,11 @@ public class PopupMenu extends JPopupMenu makeReferenceSeq.setText("Mark as representative"); } - if (seq.getDatasetSequence().getPDBId() != null - && seq.getDatasetSequence().getPDBId().size() > 0) - { - java.util.Enumeration e = seq.getDatasetSequence().getPDBId() - .elements(); - - while (e.hasMoreElements()) - { - final PDBEntry pdb = (PDBEntry) e.nextElement(); - - menuItem = new JMenuItem(); - menuItem.setText(pdb.getId()); - menuItem.addActionListener(new ActionListener() - { - @Override - public void actionPerformed(ActionEvent e) - { - // TODO re JAL-860: optionally open dialog or provide a menu entry - // allowing user to open just one structure per sequence - // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[] - // { pdb })[0], null, ap); - new StructureViewer(ap.getStructureSelectionManager()) - .viewStructures(pdb, - ap.av.collateForPDB(new PDBEntry[] - { pdb })[0], null, ap); - } - }); - viewStructureMenu.add(menuItem); - - /* - * menuItem = new JMenuItem(); menuItem.setText(pdb.getId()); - * menuItem.addActionListener(new java.awt.event.ActionListener() { - * public void actionPerformed(ActionEvent e) { - * colourByStructure(pdb.getId()); } }); - * colStructureMenu.add(menuItem); - */ - } - } - else + if (ap.av.getAlignment().isNucleotide() == false) { - if (ap.av.getAlignment().isNucleotide() == false) - { - structureMenu.remove(viewStructureMenu); - } + remove(rnaStructureMenu); } + if (ap.av.getAlignment().isNucleotide() == true) { AlignmentAnnotation[] aa = ap.av.getAlignment() @@ -391,7 +351,7 @@ public class PopupMenu extends JPopupMenu System.out.println("end"); } }); - viewStructureMenu.add(menuItem); + rnaStructureMenu.add(menuItem); } } @@ -422,7 +382,7 @@ public class PopupMenu extends JPopupMenu ap); } }); - viewStructureMenu.add(menuItem); + rnaStructureMenu.add(menuItem); } } } @@ -638,7 +598,8 @@ public class PopupMenu extends JPopupMenu if (seq == null) { sequenceMenu.setVisible(false); - structureMenu.setVisible(false); + proteinStructureMenu.setVisible(false); + rnaStructureMenu.setVisible(false); } if (links != null && links.size() > 0) @@ -1379,8 +1340,9 @@ public class PopupMenu extends JPopupMenu } }); jMenu1.setText(MessageManager.getString("label.group")); - structureMenu.setText(MessageManager.getString("label.view_structure")); - structureMenu.addActionListener(new ActionListener() + proteinStructureMenu.setText(MessageManager + .getString("label.view_protein_structure")); + proteinStructureMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) @@ -1395,8 +1357,9 @@ public class PopupMenu extends JPopupMenu } }); - viewStructureMenu.setText(MessageManager - .getString("label.view_structure")); + rnaStructureMenu.setText(MessageManager + .getString("label.view_rna_structure")); + // colStructureMenu.setText("Colour By Structure"); editSequence.setText(MessageManager.getString("label.edit_sequence") + "..."); @@ -1439,7 +1402,8 @@ public class PopupMenu extends JPopupMenu groupMenu.add(sequenceSelDetails); add(groupMenu); add(sequenceMenu); - add(structureMenu); + add(rnaStructureMenu); + add(proteinStructureMenu); if (sequence!=null) { add(hideInsertions); diff --git a/src/jalview/gui/ProgressBar.java b/src/jalview/gui/ProgressBar.java new file mode 100644 index 0000000..8ebc98d --- /dev/null +++ b/src/jalview/gui/ProgressBar.java @@ -0,0 +1,229 @@ +package jalview.gui; + +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Hashtable; +import java.util.Map; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.SwingUtilities; + +import jalview.util.MessageManager; + +/** + * A class to manage multiple progress bars embedded in a JPanel. + */ +/* + * Refactored from code duplicated in AlignFrame, PCAPanel, WebserviceInfo. + */ +public class ProgressBar implements IProgressIndicator +{ + /* + * Progress bars in progress, keyed by any arbitrary long value + */ + Map progressBars; + + /* + * Optional handlers for the progress bars + */ + Map progressBarHandlers; + + /* + * The panel containing the progress bars - must have GridLayout + */ + private JPanel statusPanel; + + /* + * Optional label where a status update message can be written on completion + * of progress + */ + private JLabel statusBar; + + /** + * Constructor. Note that the container of the progress bars, and the status + * bar to which an optional completion message is written, should be unchanged + * for the lifetime of this object for consistent behaviour. + * + * @param container + * the panel holding the progress bars; must have GridLayout manager + * @param statusBar + * an optional place to write a message when a progress bar is + * removed + */ + public ProgressBar(JPanel container, JLabel statusBar) + { + if (container == null) + { + throw new NullPointerException(); + } + if (!GridLayout.class + .isAssignableFrom(container.getLayout().getClass())) + { + throw new IllegalArgumentException("Container must have GridLayout"); + } + this.statusPanel = container; + this.statusBar = statusBar; + this.progressBars = new Hashtable(); + this.progressBarHandlers = new Hashtable(); + + } + + /** + * Returns true if any progress bars are still active + * + * @return + */ + @Override + public boolean operationInProgress() + { + if (progressBars != null && progressBars.size() > 0) + { + return true; + } + return false; + } + + /** + * First call for a given id will show the message as a new progress bar. A + * second call with the same id will remove it. The 'removal' message is + * written to the status bar field (if neither is null). + * + * To avoid progress bars being left orphaned, ensure their removal is + * performed in a finally block if there is any risk of an error during + * execution. + */ + @Override + public void setProgressBar(String message, long id) + { + Long longId = Long.valueOf(id); + + JPanel progressPanel = progressBars.get(longId); + if (progressPanel != null) + { + /* + * Progress bar is displayed for this id - remove it now, and any handler + */ + progressBars.remove(id); + if (message != null && statusBar != null) + { + statusBar.setText(message); + } + if (progressBarHandlers.containsKey(longId)) + { + progressBarHandlers.remove(longId); + } + removeRow(progressPanel); + } + else + { + /* + * No progress bar for this id - add one now + */ + progressPanel = new JPanel(new BorderLayout(10, 5)); + + JProgressBar progressBar = new JProgressBar(); + progressBar.setIndeterminate(true); + + progressPanel.add(new JLabel(message), BorderLayout.WEST); + progressPanel.add(progressBar, BorderLayout.CENTER); + + addRow(progressPanel); + + progressBars.put(longId, progressPanel); + } + + refreshLayout(); + } + + /** + * Lays out progress bar container hierarchy + */ + protected void refreshLayout() + { + /* + * lay out progress bar container hierarchy + */ + SwingUtilities.getRoot(statusPanel).validate(); + } + + /** + * Remove one row with a progress bar, in a thread-safe manner + * + * @param progressPanel + */ + protected void removeRow(JPanel progressPanel) + { + synchronized (statusPanel) + { + statusPanel.remove(progressPanel); + GridLayout layout = (GridLayout) statusPanel.getLayout(); + layout.setRows(layout.getRows() - 1); + statusPanel.remove(progressPanel); + } + } + + /** + * Add one row with a progress bar, in a thread-safe manner + * + * @param progressPanel + */ + protected void addRow(JPanel progressPanel) + { + synchronized (statusPanel) + { + GridLayout layout = (GridLayout) statusPanel.getLayout(); + layout.setRows(layout.getRows() + 1); + statusPanel.add(progressPanel); + } + } + + /** + * Add a 'Cancel' handler for the given progress bar id. This should be called + * _after_ setProgressBar to have any effect. + */ + @Override + public void registerHandler(final long id, + final IProgressIndicatorHandler handler) + { + Long longId = Long.valueOf(id); + final JPanel progressPanel = progressBars.get(longId); + if (progressPanel == null) + { + System.err + .println("call setProgressBar before registering the progress bar's handler."); + return; + } + + /* + * Nothing useful to do if not a Cancel handler + */ + if (!handler.canCancel()) + { + return; + } + + progressBarHandlers.put(longId, handler); + JButton cancel = new JButton(MessageManager.getString("action.cancel")); + final IProgressIndicator us = this; + cancel.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + handler.cancelActivity(id); + us.setProgressBar(MessageManager.formatMessage( + "label.cancelled_params", new Object[] + { ((JLabel) progressPanel.getComponent(0)).getText() }), id); + } + }); + progressPanel.add(cancel, BorderLayout.EAST); + refreshLayout(); + } + +} diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 142028a..2f24c61 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -165,7 +165,7 @@ public class StructureChooser extends GStructureChooser && !resultList.getSearchSummary().isEmpty()) { discoveredStructuresSet.addAll(resultList.getSearchSummary()); - updateSequenceDbRef(seq, resultList.getSearchSummary()); + updateSequencePDBEntries(seq, resultList.getSearchSummary()); } } @@ -188,8 +188,8 @@ public class StructureChooser extends GStructureChooser .setTitle("Structure Chooser - Manual association"); if (errors.size() > 0) { - StringBuilder errorMsg = new StringBuilder( - "Operation was unsucessful due to the following: \n"); + StringBuilder errorMsg = new StringBuilder(); + // "Operation was unsucessful due to the following: \n"); for (String error : errors) { errorMsg.append(error).append("\n"); @@ -216,6 +216,7 @@ public class StructureChooser extends GStructureChooser { for (PDBEntry pdbEntry : seq.getDatasetSequence().getPDBId()) { + String chain = pdbEntry.getChainCode() == null ? "_" : pdbEntry .getChainCode(); String[] pdbEntryRowData = new String[] @@ -223,8 +224,11 @@ public class StructureChooser extends GStructureChooser chain, pdbEntry.getType(), pdbEntry.getFile() }; - tableModel.addRow(pdbEntryRowData); - cachedEntryMap.put(seq.getDisplayId(false) + pdbEntry.getId(), + if (pdbEntry.getFile() != null) + { + tableModel.addRow(pdbEntryRowData); + } + cachedEntryMap.put(pdbEntry.getId().toLowerCase(), pdbEntry); } } @@ -233,7 +237,7 @@ public class StructureChooser extends GStructureChooser } /** - * Update the DBRef entry for a given sequence with values retrieved from + * Update the PDBEntry for a given sequence with values retrieved from * PDBResponseSummary * * @param seq @@ -241,15 +245,20 @@ public class StructureChooser extends GStructureChooser * @param responseSummaries * a collection of PDBResponseSummary */ - public void updateSequenceDbRef(SequenceI seq, + public void updateSequencePDBEntries(SequenceI seq, Collection responseSummaries) { for (PDBResponseSummary response : responseSummaries) { - PDBEntry newEntry = new PDBEntry(); - newEntry.setId(response.getPdbId()); - newEntry.setType(PDBEntry.Type.PDB); - seq.getDatasetSequence().addPDBId(newEntry); + String pdbIdStr = response.getPdbId(); + PDBEntry pdbEntry = cachedEntryMap.get(pdbIdStr.toLowerCase()); + if (pdbEntry == null) + { + pdbEntry = new PDBEntry(); + pdbEntry.setId(pdbIdStr); + pdbEntry.setType(PDBEntry.Type.PDB); + } + seq.getDatasetSequence().addPDBId(pdbEntry); } } @@ -409,8 +418,7 @@ public class StructureChooser extends GStructureChooser + totalTime + ")"); if (errors.size() > 0) { - StringBuilder errorMsg = new StringBuilder( - "Operation unsucessful due to the following: \n"); + StringBuilder errorMsg = new StringBuilder(); for (String error : errors) { errorMsg.append(error).append("\n"); @@ -552,6 +560,21 @@ public class StructureChooser extends GStructureChooser AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel .getCmb_assSeq().getSelectedItem(); lbl_pdbManualFetchStatus.setIcon(errorImage); + lbl_pdbManualFetchStatus.setToolTipText(""); + if (txt_search.getText().length() > 0) + { + lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip( + true, "No PDB entry found for \'" + txt_search.getText() + + "\'")); + } + + if (errorWarning.length() > 0) + { + lbl_pdbManualFetchStatus.setIcon(warningImage); + lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip( + true, errorWarning.toString())); + } + if (selectedSequences.length == 1 || !assSeqOpt.getName().equalsIgnoreCase( "-Select Associated Seq-")) @@ -560,6 +583,7 @@ public class StructureChooser extends GStructureChooser if (isValidPBDEntry) { btn_view.setEnabled(true); + lbl_pdbManualFetchStatus.setToolTipText(""); lbl_pdbManualFetchStatus.setIcon(goodImage); } } @@ -644,12 +668,16 @@ public class StructureChooser extends GStructureChooser { String pdbIdStr = tbl_summary.getValueAt(summaryRow, pdbIdCol) .toString(); - PDBEntry pdbEntry = new PDBEntry(); - pdbEntry.setId(pdbIdStr); - pdbEntry.setType(PDBEntry.Type.PDB); + + PDBEntry pdbEntry = cachedEntryMap.get(pdbIdStr.toLowerCase()); + if (pdbEntry == null) + { + pdbEntry = new PDBEntry(); + pdbEntry.setId(pdbIdStr); + pdbEntry.setType(PDBEntry.Type.PDB); + } pdbEntriesToView[count++] = pdbEntry; } - launchStructureViewer(ap.getStructureSelectionManager(), pdbEntriesToView, ap, selectedSequences); } @@ -659,7 +687,8 @@ public class StructureChooser extends GStructureChooser int count = 0; for (int row : selectedRows) { - String entryKey = tbl_local_pdb.getValueAt(row, 0).toString() + tbl_local_pdb.getValueAt(row, 1).toString(); + String entryKey = tbl_local_pdb.getValueAt(row, 1).toString() + .toLowerCase(); pdbEntriesToView[count++] = cachedEntryMap.get(entryKey); } launchStructureViewer(ap.getStructureSelectionManager(), @@ -673,9 +702,16 @@ public class StructureChooser extends GStructureChooser { selectedSequence = userSelectedSeq; } - PDBEntry pdbEntry = new PDBEntry(); - pdbEntry.setId(txt_search.getText()); - pdbEntry.setType(PDBEntry.Type.PDB); + + String pdbIdStr = txt_search.getText(); + PDBEntry pdbEntry = cachedEntryMap.get(pdbIdStr.toLowerCase()); + if (pdbEntry == null) + { + pdbEntry = new PDBEntry(); + pdbEntry.setId(txt_search.getText()); + pdbEntry.setType(PDBEntry.Type.PDB); + } + selectedSequence.getDatasetSequence().addPDBId(pdbEntry); PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry }; @@ -768,6 +804,7 @@ public class StructureChooser extends GStructureChooser @Override protected void txt_search_ActionPerformed() { + errorWarning.setLength(0); isValidPBDEntry = false; if (txt_search.getText().length() > 0) { @@ -787,12 +824,13 @@ public class StructureChooser extends GStructureChooser resultList = pdbRestCleint.executeRequest(pdbRequest); } catch (Exception e) { - JOptionPane.showMessageDialog(this, e.getMessage(), - "PDB Web-service Error", JOptionPane.ERROR_MESSAGE); + // JOptionPane.showMessageDialog(this, e.getMessage(), + // "PDB Web-service Error", JOptionPane.ERROR_MESSAGE); + errorWarning.append(e.getMessage()); return; } finally { - System.out.println(">>>>> executing finally block"); + // System.out.println(">>>>> executing finally block"); validateSelections(); } if (resultList.getSearchSummary() != null diff --git a/src/jalview/gui/WebserviceInfo.java b/src/jalview/gui/WebserviceInfo.java index a50cb72..f530018 100644 --- a/src/jalview/gui/WebserviceInfo.java +++ b/src/jalview/gui/WebserviceInfo.java @@ -20,10 +20,6 @@ */ package jalview.gui; -import jalview.jbgui.GWebserviceInfo; -import jalview.util.MessageManager; -import jalview.ws.WSClientI; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; @@ -33,19 +29,14 @@ import java.awt.GridLayout; import java.awt.Image; import java.awt.MediaTracker; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.image.BufferedImage; -import java.util.Hashtable; import java.util.Vector; -import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JEditorPane; import javax.swing.JInternalFrame; -import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTextArea; @@ -54,6 +45,10 @@ import javax.swing.event.HyperlinkListener; import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.StyleSheet; +import jalview.jbgui.GWebserviceInfo; +import jalview.util.MessageManager; +import jalview.ws.WSClientI; + /** * Base class for web service client thread and gui TODO: create StAX parser to * extract html body content reliably when preparing html formatted job statuses @@ -97,6 +92,8 @@ public class WebserviceInfo extends GWebserviceInfo implements JInternalFrame frame; + private ProgressBar progressBar; + @Override public void setVisible(boolean aFlag) { @@ -326,6 +323,8 @@ public class WebserviceInfo extends GWebserviceInfo implements Desktop.addInternalFrame(frame, title, makeVisible, width, height); frame.setClosable(false); + progressBar = new ProgressBar(statusPanel, statusBar); + this.title = title; setInfoText(info); @@ -879,10 +878,6 @@ public class WebserviceInfo extends GWebserviceInfo implements Desktop.hyperlinkUpdate(e); } - // methods for implementing IProgressIndicator - // need to refactor to a reusable stub class - Hashtable progressBars, progressBarHandlers; - /* * (non-Javadoc) * @@ -891,78 +886,14 @@ public class WebserviceInfo extends GWebserviceInfo implements @Override public void setProgressBar(String message, long id) { - if (progressBars == null) - { - progressBars = new Hashtable(); - progressBarHandlers = new Hashtable(); - } - - JPanel progressPanel; - Long lId = new Long(id); - GridLayout layout = (GridLayout) statusPanel.getLayout(); - if (progressBars.get(lId) != null) - { - progressPanel = (JPanel) progressBars.get(new Long(id)); - statusPanel.remove(progressPanel); - progressBars.remove(lId); - progressPanel = null; - if (message != null) - { - statusBar.setText(message); - } - if (progressBarHandlers.contains(lId)) - { - progressBarHandlers.remove(lId); - } - layout.setRows(layout.getRows() - 1); - } - else - { - progressPanel = new JPanel(new BorderLayout(10, 5)); - - JProgressBar progressBar = new JProgressBar(); - progressBar.setIndeterminate(true); - - progressPanel.add(new JLabel(message), BorderLayout.WEST); - progressPanel.add(progressBar, BorderLayout.CENTER); - - layout.setRows(layout.getRows() + 1); - statusPanel.add(progressPanel); - - progressBars.put(lId, progressPanel); - } - // update GUI - // setMenusForViewport(); - validate(); + progressBar.setProgressBar(message, id); } @Override public void registerHandler(final long id, final IProgressIndicatorHandler handler) { - if (progressBarHandlers == null || !progressBars.contains(new Long(id))) - { - throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler")); - } - progressBarHandlers.put(new Long(id), handler); - final JPanel progressPanel = (JPanel) progressBars.get(new Long(id)); - if (handler.canCancel()) - { - JButton cancel = new JButton( - MessageManager.getString("action.cancel")); - final IProgressIndicator us = this; - cancel.addActionListener(new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent e) - { - handler.cancelActivity(id); - us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", new String[]{((JLabel) progressPanel.getComponent(0)).getText()}), id); - } - }); - progressPanel.add(cancel, BorderLayout.EAST); - } + progressBar.registerHandler(id, handler); } /** @@ -972,10 +903,6 @@ public class WebserviceInfo extends GWebserviceInfo implements @Override public boolean operationInProgress() { - if (progressBars != null && progressBars.size() > 0) - { - return true; - } - return false; + return progressBar.operationInProgress(); } } diff --git a/src/jalview/httpserver/AbstractRequestHandler.java b/src/jalview/httpserver/AbstractRequestHandler.java index 9642508..8030c1d 100644 --- a/src/jalview/httpserver/AbstractRequestHandler.java +++ b/src/jalview/httpserver/AbstractRequestHandler.java @@ -73,9 +73,10 @@ public abstract class AbstractRequestHandler extends AbstractHandler * * @param request * @param response + * @throws IOException */ protected abstract void processRequest(HttpServletRequest request, - HttpServletResponse response); + HttpServletResponse response) throws IOException; /** * For debug - writes HTTP request details to stdout diff --git a/src/jalview/httpserver/HttpServer.java b/src/jalview/httpserver/HttpServer.java index fcfefaa..34b39cd 100644 --- a/src/jalview/httpserver/HttpServer.java +++ b/src/jalview/httpserver/HttpServer.java @@ -131,7 +131,6 @@ public class HttpServer // "HttpServer started with %d threads", server.getThreadPool() // .getThreads())); contextRoot = server.getURI(); - System.out.println("Jalview endpoint " + contextRoot); } catch (Exception e) { System.err.println("Error trying to start HttpServer: " diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index e902ccf..5d8a297 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -20,17 +20,21 @@ */ package jalview.io; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.List; +import java.util.Vector; + import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; -import java.io.IOException; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - /** * DOCUMENT ME! * @@ -54,6 +58,11 @@ public abstract class AlignFile extends FileParse protected Vector annotations; /** + * SequenceGroups to be added to the alignment object + */ + protected List seqGroups; + + /** * Properties to be added to generated alignment object */ protected Hashtable properties; @@ -165,6 +174,11 @@ public abstract class AlignFile extends FileParse return seqs; } + public List getSeqGroups() + { + return seqGroups; + } + /** * Return the Sequences in the seqs Vector as an array of Sequences */ @@ -174,7 +188,7 @@ public abstract class AlignFile extends FileParse for (int i = 0; i < seqs.size(); i++) { - s[i] = (SequenceI) seqs.elementAt(i); + s[i] = seqs.elementAt(i); } return s; @@ -198,7 +212,7 @@ public abstract class AlignFile extends FileParse * Rna.GetBasePairsFromAlignmentAnnotation(annotations.elementAt(i)); * Rna.HelixMap(pairArray); */ - AlignmentAnnotation an = (AlignmentAnnotation) annotations + AlignmentAnnotation an = annotations .elementAt(i); an.validateRangeAndDisplay(); al.addAnnotation(an); @@ -206,6 +220,12 @@ public abstract class AlignFile extends FileParse } + public void addSeqGroups(AlignmentI al) + { + this.seqGroups = al.getGroups(); + + } + /** * Add any additional information extracted from the file to the alignment * properties. @@ -267,8 +287,9 @@ public abstract class AlignFile extends FileParse */ protected void initData() { - seqs = new Vector(); - annotations = new Vector(); + seqs = new Vector(); + annotations = new Vector(); + seqGroups = new ArrayList(); parseCalled=false; } @@ -280,7 +301,7 @@ public abstract class AlignFile extends FileParse */ protected void setSeqs(SequenceI[] s) { - seqs = new Vector(); + seqs = new Vector(); for (int i = 0; i < s.length; i++) { @@ -340,13 +361,13 @@ public abstract class AlignFile extends FileParse /** * vector of String[] treeName, newickString pairs */ - Vector newickStrings = null; + Vector newickStrings = null; protected void addNewickTree(String treeName, String newickString) { if (newickStrings == null) { - newickStrings = new Vector(); + newickStrings = new Vector(); } newickStrings.addElement(new String[] { treeName, newickString }); @@ -354,11 +375,7 @@ public abstract class AlignFile extends FileParse protected int getTreeCount() { - if (newickStrings == null) - { - return 0; - } - return newickStrings.size(); + return newickStrings == null ? 0 : newickStrings.size(); } } diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index c69a0c7..5601f27 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -25,6 +25,7 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; +import jalview.datamodel.SequenceGroup; import jalview.util.MessageManager; import java.io.File; @@ -42,12 +43,47 @@ import java.util.List; */ public class AppletFormatAdapter { + private AlignViewportI viewport; + + public static String FILE = "File"; + + public static String URL = "URL"; + + public static String PASTE = "Paste"; + + public static String CLASSLOADER = "ClassLoader"; + + /** + * add jalview-derived non-secondary structure annotation from PDB structure + */ + boolean annotFromStructure = false; + + /** + * add secondary structure from PDB data with built-in algorithms + */ + boolean localSecondaryStruct = false; + + /** + * process PDB data with web services + */ + boolean serviceSecondaryStruct = false; + + private AlignFile alignFile = null; + + String inFile; + + /** + * character used to write newlines + */ + protected String newline = System.getProperty("line.separator"); + /** * List of valid format strings used in the isValidFormat method */ public static final String[] READABLE_FORMATS = new String[] { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH", - "PDB", "JnetFile", "RNAML", PhylipFile.FILE_DESC, "HTML" }; + "PDB", "JnetFile", "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, + "HTML" }; /** * List of readable format file extensions by application in order @@ -55,7 +91,8 @@ public class AppletFormatAdapter */ public static final String[] READABLE_EXTENSIONS = new String[] { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, "jar,jvp", "html" }; + "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, JSONFile.FILE_EXT, + "jar,jvp", HtmlFile.FILE_EXT }; /** * List of readable formats by application in order corresponding to @@ -63,7 +100,8 @@ public class AppletFormatAdapter */ public static final String[] READABLE_FNAMES = new String[] { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm", - "RNAML", PhylipFile.FILE_DESC, "Jalview", "HTML" }; + "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview", + HtmlFile.FILE_DESC }; /** * List of valid format strings for use by callers of the formatSequences @@ -71,7 +109,7 @@ public class AppletFormatAdapter */ public static final String[] WRITEABLE_FORMATS = new String[] { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA", - "STH", PhylipFile.FILE_DESC }; + "STH", PhylipFile.FILE_DESC, JSONFile.FILE_DESC }; /** * List of extensions corresponding to file format types in WRITABLE_FNAMES @@ -79,7 +117,7 @@ public class AppletFormatAdapter */ public static final String[] WRITABLE_EXTENSIONS = new String[] { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "sto,stk", PhylipFile.FILE_EXT, "jvp" }; + "sto,stk", PhylipFile.FILE_EXT, JSONFile.FILE_EXT, "jvp" }; /** * List of writable formats by the application. Order must correspond with the @@ -87,7 +125,7 @@ public class AppletFormatAdapter */ public static final String[] WRITABLE_FNAMES = new String[] { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "STH", - PhylipFile.FILE_DESC, "Jalview" }; + PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview" }; public static String INVALID_CHARACTERS = "Contains invalid characters"; @@ -95,6 +133,15 @@ public class AppletFormatAdapter public static String SUPPORTED_FORMATS = "Formats currently supported are\n" + prettyPrint(READABLE_FORMATS); + public AppletFormatAdapter() + { + } + + public AppletFormatAdapter(AlignViewportI viewport) + { + this.viewport = viewport; + } + /** * * @param els @@ -112,37 +159,6 @@ public class AppletFormatAdapter return list.toString(); } - public static String FILE = "File"; - - public static String URL = "URL"; - - public static String PASTE = "Paste"; - - public static String CLASSLOADER = "ClassLoader"; - - /** - * add jalview-derived non-secondary structure annotation from PDB structure - */ - boolean annotFromStructure = false; - - /** - * add secondary structure from PDB data with built-in algorithms - */ - boolean localSecondaryStruct = false; - - /** - * process PDB data with web services - */ - boolean serviceSecondaryStruct = false; - - AlignFile afile = null; - - String inFile; - - /** - * character used to write newlines - */ - protected String newline = System.getProperty("line.separator"); public void setNewlineString(String nl) { @@ -213,70 +229,90 @@ public class AppletFormatAdapter this.inFile = inFile; try { + Alignment al; if (format.equals("FASTA")) { - afile = new FastaFile(inFile, type); + alignFile = new FastaFile(inFile, type); } else if (format.equals("MSF")) { - afile = new MSFfile(inFile, type); + alignFile = new MSFfile(inFile, type); } else if (format.equals("PileUp")) { - afile = new PileUpfile(inFile, type); + alignFile = new PileUpfile(inFile, type); } else if (format.equals("CLUSTAL")) { - afile = new ClustalFile(inFile, type); + alignFile = new ClustalFile(inFile, type); } else if (format.equals("BLC")) { - afile = new BLCFile(inFile, type); + alignFile = new BLCFile(inFile, type); } else if (format.equals("PIR")) { - afile = new PIRFile(inFile, type); + alignFile = new PIRFile(inFile, type); } else if (format.equals("PFAM")) { - afile = new PfamFile(inFile, type); + alignFile = new PfamFile(inFile, type); } else if (format.equals("JnetFile")) { - afile = new JPredFile(inFile, type); - ((JPredFile) afile).removeNonSequences(); + alignFile = new JPredFile(inFile, type); + ((JPredFile) alignFile).removeNonSequences(); } else if (format.equals("PDB")) { - afile = new MCview.PDBfile(annotFromStructure, + alignFile = new MCview.PDBfile(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct, inFile, type); // Uncomment to test Jmol data based PDB processing: JAL-1213 // afile = new jalview.ext.jmol.PDBFileWithJmol(inFile, type); } else if (format.equals("STH")) { - afile = new StockholmFile(inFile, type); + alignFile = new StockholmFile(inFile, type); } else if (format.equals("SimpleBLAST")) { - afile = new SimpleBlastFile(inFile, type); + alignFile = new SimpleBlastFile(inFile, type); } else if (format.equals(PhylipFile.FILE_DESC)) { - afile = new PhylipFile(inFile, type); + alignFile = new PhylipFile(inFile, type); + } + else if (format.equals(JSONFile.FILE_DESC)) + { + alignFile = new JSONFile(inFile, type); + al = new Alignment(alignFile.getSeqsAsArray()); + alignFile.addAnnotations(al); + ((JSONFile) alignFile).setViewport(viewport); + for (SequenceGroup sg : alignFile.getSeqGroups()) + { + al.addGroup(sg); + } + return al; + } + else if (format.equals(HtmlFile.FILE_DESC)) + { + alignFile = new HtmlFile(inFile, type); + al = new Alignment(alignFile.getSeqsAsArray()); + alignFile.addAnnotations(al); + for (SequenceGroup sg : alignFile.getSeqGroups()) + { + al.addGroup(sg); + } + return al; } - // else if (format.equals(HtmlFile.FILE_DESC)) - // { - // afile = new HtmlFile(inFile, type); - // } else if (format.equals("RNAML")) { - afile = new RnamlFile(inFile, type); + alignFile = new RnamlFile(inFile, type); } - Alignment al = new Alignment(afile.getSeqsAsArray()); + al = new Alignment(alignFile.getSeqsAsArray()); - afile.addAnnotations(al); + alignFile.addAnnotations(al); return al; } catch (Exception e) @@ -297,9 +333,11 @@ public class AppletFormatAdapter try { // Possible sequence is just residues with no label - afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste"); - Alignment al = new Alignment(afile.getSeqsAsArray()); - afile.addAnnotations(al); + alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste"); + Alignment al = new Alignment(alignFile.getSeqsAsArray()); + + alignFile.addSeqGroups(al); + alignFile.addAnnotations(al); return al; } catch (Exception ex) @@ -339,67 +377,76 @@ public class AppletFormatAdapter String type = source.type; try { + Alignment al; if (format.equals("FASTA")) { - afile = new FastaFile(source); + alignFile = new FastaFile(source); } else if (format.equals("MSF")) { - afile = new MSFfile(source); + alignFile = new MSFfile(source); } else if (format.equals("PileUp")) { - afile = new PileUpfile(source); + alignFile = new PileUpfile(source); } else if (format.equals("CLUSTAL")) { - afile = new ClustalFile(source); + alignFile = new ClustalFile(source); } else if (format.equals("BLC")) { - afile = new BLCFile(source); + alignFile = new BLCFile(source); } else if (format.equals("PIR")) { - afile = new PIRFile(source); + alignFile = new PIRFile(source); } else if (format.equals("PFAM")) { - afile = new PfamFile(source); + alignFile = new PfamFile(source); } else if (format.equals("JnetFile")) { - afile = new JPredFile(source); - ((JPredFile) afile).removeNonSequences(); + alignFile = new JPredFile(source); + ((JPredFile) alignFile).removeNonSequences(); } else if (format.equals("PDB")) { - afile = new MCview.PDBfile(annotFromStructure, + alignFile = new MCview.PDBfile(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct, source); } else if (format.equals("STH")) { - afile = new StockholmFile(source); + alignFile = new StockholmFile(source); } else if (format.equals("RNAML")) { - afile = new RnamlFile(source); + alignFile = new RnamlFile(source); } else if (format.equals("SimpleBLAST")) { - afile = new SimpleBlastFile(source); + alignFile = new SimpleBlastFile(source); } else if (format.equals(PhylipFile.FILE_DESC)) { - afile = new PhylipFile(source); + alignFile = new PhylipFile(source); } - // else if (format.equals(HtmlFile.FILE_DESC)) - // { - // afile = new HtmlFile(source); - // } - Alignment al = new Alignment(afile.getSeqsAsArray()); - - afile.addAnnotations(al); + else if (format.equals(JSONFile.FILE_DESC)) + { + alignFile = new JSONFile(source); + // ((JSONFile) afile).setViewport(viewport); + al = new Alignment(alignFile.getSeqsAsArray()); + alignFile.addAnnotations(al); + alignFile.addSeqGroups(al); + return al; + } + else if (format.equals(HtmlFile.FILE_DESC)) + { + alignFile = new HtmlFile(source); + } + al = new Alignment(alignFile.getSeqsAsArray()); + alignFile.addAnnotations(al); return al; } catch (Exception e) @@ -420,9 +467,10 @@ public class AppletFormatAdapter try { // Possible sequence is just residues with no label - afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste"); - Alignment al = new Alignment(afile.getSeqsAsArray()); - afile.addAnnotations(al); + alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste"); + Alignment al = new Alignment(alignFile.getSeqsAsArray()); + alignFile.addAnnotations(al); + alignFile.addSeqGroups(al); return al; } catch (Exception ex) @@ -491,7 +539,6 @@ public class AppletFormatAdapter try { AlignFile afile = null; - if (format.equalsIgnoreCase("FASTA")) { afile = new FastaFile(); @@ -532,10 +579,26 @@ public class AppletFormatAdapter { afile = new PhylipFile(); } - // else if (format.equalsIgnoreCase(HtmlFile.FILE_DESC)) - // { - // afile = new HtmlFile(); - // } + else if (format.equalsIgnoreCase(JSONFile.FILE_DESC)) + { + afile = new JSONFile(); + afile.setViewport(viewport); + // Add groups to AlignFile + afile.seqGroups = alignment.getGroups(); + + // Add non auto calculated annotation to AlignFile + for (AlignmentAnnotation annot : alignment.getAlignmentAnnotation()) + { + if (annot != null && !annot.autoCalculated) + { + if (annot.label.equals("PDB.CATempFactor")) + { + continue; + } + afile.annotations.add(annot); + } + } + } else if (format.equalsIgnoreCase("RNAML")) { afile = new RnamlFile(); @@ -550,6 +613,7 @@ public class AppletFormatAdapter afile.setSeqs(alignment.getSequencesArray()); + String afileresp = afile.print(); if (afile.hasWarningMessage()) { @@ -808,4 +872,14 @@ public class AppletFormatAdapter } return null; } + + public AlignFile getAlignFile() + { + return alignFile; + } + + public void setAlignFile(AlignFile alignFile) + { + this.alignFile = alignFile; + } } diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index d2c4a7f..3a3b665 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -1,69 +1,59 @@ package jalview.io; -import jalview.api.FeaturesDisplayedI; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceI; import jalview.exceptions.NoFileSelectedException; +import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; import jalview.gui.FeatureRenderer; -import jalview.json.binding.v1.BioJsAlignmentPojo; -import jalview.json.binding.v1.BioJsFeaturePojo; -import jalview.json.binding.v1.BioJsSeqPojo; -import jalview.schemes.ColourSchemeProperty; +import jalview.json.binding.v1.BioJSReleasePojo; +import jalview.json.binding.v1.BioJSRepositoryPojo; import jalview.util.MessageManager; -import jalview.viewmodel.AlignmentViewport; -import java.awt.Color; +import java.io.BufferedInputStream; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.net.URISyntaxException; import java.net.URL; -import java.util.ArrayList; +import java.util.Objects; +import java.util.TreeMap; -import com.json.JSONException; public class BioJsHTMLOutput { - private AlignmentViewport av; + private AlignViewport av; - private jalview.api.FeatureRenderer fr; + private static File currentBJSTemplateFile; - private String globalColorScheme; + private static TreeMap bioJsMSAVersions; - private FeaturesDisplayedI displayedFeatures; + public static final String BJS_TEMPLATES_LOCAL_DIRECTORY = jalview.bin.Cache + .getDefault("biojs_template_directory", "/biojs_templates/"); - private String jalviewVersion; - - private String webStartLaunchServletUrl = "http://www.jalview.org/services/launchApp"; + public static final String BJS_TEMPLATE_GIT_REPO = jalview.bin.Cache + .getDefault( + "biojs_template_git_repo", + "https://raw.githubusercontent.com/tcofoegbu/bjs-template/master/package.json");; public BioJsHTMLOutput(AlignmentPanel ap, FeatureRenderer fr1) { - - jalviewVersion = jalview.bin.Cache.getProperty("VERSION"); - webStartLaunchServletUrl = jalview.bin.Cache.getDefault( - "www.jalview.org", "http://www.jalview.org") - + "/services/launchApp"; if (ap != null) { this.av = ap.av; - this.globalColorScheme = ColourSchemeProperty.getColourName(av - .getGlobalColourScheme()); - this.fr = ap.cloneFeatureRenderer(); - displayedFeatures = av.getFeaturesDisplayed(); + av.setFeatureRenderer(new FeatureRenderer(ap)); } } - private void exportJalviewAlignmentAsBioJsHtmlFile() + public void exportJalviewAlignmentAsBioJsHtmlFile() { try { String outputFile = getOutputFile(); - String jalviewAlignmentJson = getJalviewAlignmentAsJsonString(av - .getAlignment()); - String bioJSTemplateString = getBioJsTemplateAsString(this); + String jalviewAlignmentJson = JSONFile.getJSONData(av); + String bioJSTemplateString = getBioJsTemplateAsString(); String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString .replaceAll( "#sequenceData#", jalviewAlignmentJson) @@ -110,72 +100,20 @@ public class BioJsHTMLOutput { throw new NoFileSelectedException("No file was selected."); } - return selectedFile; } - public String getJalviewAlignmentAsJsonString(AlignmentI alignment) - throws IOException, JSONException - { - BioJsAlignmentPojo bjsAlignment = new BioJsAlignmentPojo(); - - bjsAlignment.setGlobalColorScheme(getGlobalColorScheme()); - bjsAlignment.setJalviewVersion(jalviewVersion); - bjsAlignment.setWebStartUrl(webStartLaunchServletUrl); - - int count = 0; - for (SequenceI seq : alignment.getSequences()) - { - StringBuilder name = new StringBuilder(); - name.append(seq.getName()).append("/").append(seq.getStart()) - .append("-").append(seq.getEnd()); - - BioJsSeqPojo seqPojo = new BioJsSeqPojo(); - seqPojo.setId(String.valueOf(++count)); - seqPojo.setEnd(seq.getEnd()); - seqPojo.setStart(seq.getStart()); - seqPojo.setName(name.toString()); - seqPojo.setSeq(seq.getSequenceAsString()); - - SequenceFeature[] seqFeatures = seq.getSequenceFeatures(); - if (seqFeatures != null) - { - ArrayList bjsSeqFeatures = new ArrayList(); - for (SequenceFeature sf : seqFeatures) - { - if (displayedFeatures != null - && displayedFeatures.isVisible(sf.getType())) - { - - // TODO: translate graduated/complex colourschemes to biojs model - String featureColour = jalview.util.Format.getHexString(fr - .findFeatureColour(Color.white, seq, - seq.findIndex(sf.getBegin()))); - BioJsFeaturePojo bjsFeature = new BioJsFeaturePojo(); - bjsFeature.setFillColor(featureColour); - bjsFeature.setXstart(seq.findIndex(sf.getBegin()) - 1); - bjsFeature.setXend(seq.findIndex(sf.getEnd())); - bjsFeature.setText(sf.getType()); - bjsSeqFeatures.add(bjsFeature); - } - } - seqPojo.setFeatures(bjsSeqFeatures); - } - bjsAlignment.getSeqs().add(seqPojo); - } - return new com.json.JSONObject(bjsAlignment).toString() - .replaceAll("xstart", "xStart").replaceAll("xend", "xEnd"); - } - - public static String getBioJsTemplateAsString(Object currentObj) + public static String getBioJsTemplateAsString() throws IOException { InputStreamReader isReader = null; BufferedReader buffReader = null; StringBuilder sb = new StringBuilder(); - URL url = currentObj.getClass().getResource( - "/templates/BioJSTemplate.txt"); + Objects.requireNonNull(getCurrentBJSTemplateFile(), + "BioJsTemplate File not initialized!"); + @SuppressWarnings("deprecation") + URL url = getCurrentBJSTemplateFile().toURL(); if (url != null) { try @@ -208,14 +146,164 @@ public class BioJsHTMLOutput return sb.toString(); } - public String getGlobalColorScheme() + public void refreshBioJSVersionsInfo(String dirName) + throws URISyntaxException + { + URL url = getClass().getResource(dirName); + File directory = new File(url.toURI()); + Objects.requireNonNull(dirName, "dirName MUST not be null!"); + Objects.requireNonNull(directory, "directory MUST not be null!"); + TreeMap versionFileMap = new TreeMap(); + + for (File file : directory.listFiles()) + { + if (file.isFile()) + { + String fileName = file.getName().substring(0, + file.getName().lastIndexOf(".")); + String fileMeta[] = fileName.split("_"); + if (fileMeta.length > 2) + { + setCurrentBJSTemplateFile(file); + versionFileMap.put(fileMeta[2], file); + } + else if (fileMeta.length > 1) + { + versionFileMap.put(fileMeta[1], file); + } + } + } + if (getCurrentBJSTemplateFile() == null && versionFileMap.size() > 0) + { + setCurrentBJSTemplateFile(versionFileMap.lastEntry().getValue()); + } + setBioJsMSAVersions(versionFileMap); + } + + public void updateBioJS() + { + try + { + String gitRepoPkgJson = getURLContentAsString(BJS_TEMPLATE_GIT_REPO); + BioJSRepositoryPojo release = new BioJSRepositoryPojo(gitRepoPkgJson); + syncUpdates(BJS_TEMPLATES_LOCAL_DIRECTORY, release); + refreshBioJSVersionsInfo(BJS_TEMPLATES_LOCAL_DIRECTORY); + } catch (URISyntaxException e) + { + e.printStackTrace(); + } + } + + + public void syncUpdates(String localDir, BioJSRepositoryPojo repo) + throws URISyntaxException + { + for (BioJSReleasePojo bjsRelease : repo.getReleases()) + { + String releaseUrl = bjsRelease.getUrl(); + String releaseVersion = bjsRelease.getVersion(); + String releaseFile = "BioJsMSA_" + releaseVersion + ".txt"; + if (releaseVersion.equals(repo.getLatestReleaseVersion())) + { + releaseFile = "Latest_BioJsMSA_" + releaseVersion + ".txt"; + } + File file = null; + URL url = getClass().getResource( + BJS_TEMPLATES_LOCAL_DIRECTORY + releaseFile); + if (url == null) + { + String path = getClass().getResource(BJS_TEMPLATES_LOCAL_DIRECTORY) + .getPath(); + System.out.println("------> " + path); + file = new File(path + releaseFile); + } + else + { + file = new File(url.toURI()); + } + + if (!file.exists()) + { + PrintWriter out = null; + try + { + out = new java.io.PrintWriter(new java.io.FileWriter(file)); + out.print(getURLContentAsString(releaseUrl)); + } catch (IOException e) + { + e.printStackTrace(); + } finally + { + if (out != null) + { + out.flush(); + out.close(); + } + } + } + } + + } + + public static String getURLContentAsString(String url) + throws OutOfMemoryError + { + StringBuilder responseStrBuilder = null; + InputStream is = null; + try + { + URL resourceUrl = new URL(url); + is = new BufferedInputStream(resourceUrl.openStream()); + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + responseStrBuilder = new StringBuilder(); + String lineContent; + + while ((lineContent = br.readLine()) != null) + { + responseStrBuilder.append(lineContent).append("\n"); + } + } catch (OutOfMemoryError er) + { + er.printStackTrace(); + } catch (Exception ex) + { + ex.printStackTrace(); + } finally + { + if (is != null) + { + try + { + is.close(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + } + return responseStrBuilder == null ? null : responseStrBuilder + .toString(); + } + + public static File getCurrentBJSTemplateFile() + { + return currentBJSTemplateFile; + } + + public static void setCurrentBJSTemplateFile(File currentBJSTemplateFile) + { + BioJsHTMLOutput.currentBJSTemplateFile = currentBJSTemplateFile; + } + + public static TreeMap getBioJsMSAVersions() { - return globalColorScheme; + return bioJsMSAVersions; } - public void setGlobalColorScheme(String globalColorScheme) + public static void setBioJsMSAVersions( + TreeMap bioJsMSAVersions) { - this.globalColorScheme = globalColorScheme; + BioJsHTMLOutput.bioJsMSAVersions = bioJsMSAVersions; } } diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 3322689..6329f58 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -30,7 +30,6 @@ import jalview.gui.Jalview2XML; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; -import java.util.List; import java.util.StringTokenizer; import java.util.Vector; @@ -297,7 +296,7 @@ public class FileLoader implements Runnable // open a new source and read from it FormatAdapter fa = new FormatAdapter(); al = fa.readFile(file, protocol, format); - source = fa.afile; // keep reference for later if necessary. + source = fa.getAlignFile(); // keep reference for later if necessary. } } catch (java.io.IOException ex) { @@ -323,7 +322,7 @@ public class FileLoader implements Runnable } if (sq.getPDBId() != null) { - for (PDBEntry pdbe : (List) sq.getPDBId()) + for (PDBEntry pdbe : sq.getPDBId()) { StructureSelectionManager.getStructureSelectionManager( Desktop.instance).registerPDBEntry(pdbe); @@ -349,9 +348,13 @@ public class FileLoader implements Runnable } if (source instanceof HtmlFile) { - ((HtmlFile) source).LoadAlignmentFeatures(alignFrame); - + ((HtmlFile) source).applySettingsToAlignFrame(alignFrame); + } + else if (source instanceof JSONFile) + { + ((JSONFile) source).applySettingsToAlignFrame(alignFrame); } + if (raiseGUI) { // add the window to the GUI diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index 69c362f..f9c717d 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -20,6 +20,7 @@ */ package jalview.io; +import jalview.api.AlignViewportI; import jalview.util.MessageManager; import java.io.BufferedReader; @@ -48,6 +49,8 @@ public class FileParse public File inFile = null; + private AlignViewportI viewport; + public int index = 1; // sequence counter for FileParse object created from // same data source @@ -488,4 +491,14 @@ public class FileParse } return null; } + + public AlignViewportI getViewport() + { + return viewport; + } + + public void setViewport(AlignViewportI viewport) + { + this.viewport = viewport; + } } diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index dfbdf86..7c117b9 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -37,10 +37,20 @@ import jalview.datamodel.SequenceI; */ public class FormatAdapter extends AppletFormatAdapter { + public FormatAdapter(AlignViewportI viewport) + { + super(viewport); + init(); + } public FormatAdapter() { super(); + init(); + } + + private void init() + { if (jalview.bin.Cache.getDefault("STRUCT_FROM_PDB", true)) { annotFromStructure = jalview.bin.Cache.getDefault("ADD_TEMPFACT_ANN", @@ -58,6 +68,7 @@ public class FormatAdapter extends AppletFormatAdapter serviceSecondaryStruct = false; } } + public String formatSequences(String format, SequenceI[] seqs, String[] omitHiddenColumns) { @@ -258,35 +269,14 @@ public class FormatAdapter extends AppletFormatAdapter public Alignment readFile(String inFile, String type, String format) throws java.io.IOException { - Alignment al; - if (format.equals("HTML")) - { - afile = new HtmlFile(inFile, type); - al = new Alignment(afile.getSeqsAsArray()); - afile.addAnnotations(al); - } - else - { - al = super.readFile(inFile, type, format); - } - + Alignment al = super.readFile(inFile, type, format); return al; } public AlignmentI readFromFile(FileParse source, String format) throws java.io.IOException { - Alignment al; - if (format.equals("HTML")) - { - afile = new HtmlFile(source); - al = new Alignment(afile.getSeqsAsArray()); - afile.addAnnotations(al); - } - else - { - al = (Alignment) super.readFromFile(source, format); - } + Alignment al = (Alignment) super.readFromFile(source, format); return al; } @@ -323,4 +313,5 @@ public class FormatAdapter extends AppletFormatAdapter return formatSequences(format, getCacheSuffixDefault(format), av, selectedOnly); } + } diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index 3cb7c3f..d507362 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -1,28 +1,23 @@ package jalview.io; -import jalview.datamodel.Sequence; -import jalview.datamodel.SequenceFeature; import jalview.gui.AlignFrame; -import jalview.json.binding.v1.BioJsAlignmentPojo.JalviewBioJsColorSchemeMapper; import jalview.schemes.ColourSchemeI; import java.io.IOException; -import java.util.Iterator; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; public class HtmlFile extends AlignFile { - // public static final String FILE_EXT = "html"; - // - // public static final String FILE_DESC = "HTML"; + public static final String FILE_EXT = "html"; - private ColourSchemeI cs; + public static final String FILE_DESC = "HTML"; + + private ColourSchemeI colourScheme; + + private boolean showSeqFeatures; public HtmlFile() { @@ -39,7 +34,6 @@ public class HtmlFile extends AlignFile super(inFile, type); } - @SuppressWarnings("unchecked") @Override public void parse() throws IOException { @@ -54,99 +48,53 @@ public class HtmlFile extends AlignFile Document doc = Jsoup.parse(htmlData.toString()); Element content = doc.getElementById("seqData"); - String alignmentJsonString = content.val(); - JSONParser jsonParser = new JSONParser(); - JSONObject alignmentJsonObj = (JSONObject) jsonParser - .parse(alignmentJsonString); - JSONArray seqJsonArray = (JSONArray) alignmentJsonObj.get("seqs"); - String bioJsColourScheme = (String) alignmentJsonObj - .get("globalColorScheme"); - cs = getJalviewColorScheme(bioJsColourScheme); - - for (Iterator sequenceIter = seqJsonArray.iterator(); sequenceIter - .hasNext();) - { - JSONObject sequence = sequenceIter.next(); - String sequcenceString = sequence.get("seq").toString(); - Sequence seq = new Sequence(sequence.get("name").toString(), - sequcenceString, Integer.valueOf(sequence.get("start") - .toString()), Integer.valueOf(sequence.get("end") - .toString())); - - JSONArray jsonSeqArray = (JSONArray) sequence.get("features"); - SequenceFeature[] retrievedSeqFeatures = getJalviewSequenceFeatures( - jsonSeqArray, seq); - if (retrievedSeqFeatures != null) - { - seq.setSequenceFeatures(retrievedSeqFeatures); - } - seqs.add(seq); - } + JSONFile jsonFile = new JSONFile().parse(alignmentJsonString); + seqs = jsonFile.seqs; + seqGroups = jsonFile.seqGroups; + annotations = jsonFile.annotations; + showSeqFeatures = jsonFile.isShowSeqFeatures(); + colourScheme = jsonFile.getColourScheme(); } catch (Exception e) { e.printStackTrace(); } } - public SequenceFeature[] getJalviewSequenceFeatures( - JSONArray jsonSeqFeatures, Sequence seq) + public void applySettingsToAlignFrame(AlignFrame af) { - SequenceFeature[] seqFeatures = null; - int count = 0; - if (jsonSeqFeatures != null) - { - seqFeatures = new SequenceFeature[jsonSeqFeatures.size()]; - for (@SuppressWarnings("unchecked") - Iterator seqFeatureItr = jsonSeqFeatures.iterator(); seqFeatureItr - .hasNext();) - { + af.setShowSeqFeatures(isShowSeqFeatures()); + af.changeColour(getColourScheme()); + af.setMenusForViewport(); + } - SequenceFeature sequenceFeature = new SequenceFeature(); - JSONObject jsonFeature = seqFeatureItr.next(); - Long begin = (Long) jsonFeature.get("xStart"); - Long end = (Long) jsonFeature.get("xEnd"); - String type = (String) jsonFeature.get("text"); - // String color = (String) jsonFeature.get("fillColor"); - - sequenceFeature.setBegin(seq.findPosition(begin.intValue())); - sequenceFeature.setEnd(seq.findPosition(end.intValue()) - 1); - sequenceFeature.setType(type); - seqFeatures[count++] = sequenceFeature; - } - } - return seqFeatures; + + @Override + public String print() + { + throw new UnsupportedOperationException( + "Print method of HtmlFile is not supported!"); } - public void LoadAlignmentFeatures(AlignFrame af) + public boolean isShowSeqFeatures() { + return showSeqFeatures; + } - af.setShowSeqFeatures(true); - af.changeColour(cs); - af.setMenusForViewport(); + public void setShowSeqFeatures(boolean showSeqFeatures) + { + this.showSeqFeatures = showSeqFeatures; } - private ColourSchemeI getJalviewColorScheme(String bioJsColourSchemeName) + public ColourSchemeI getColourScheme() { - ColourSchemeI jalviewColor = null; - for (JalviewBioJsColorSchemeMapper cs : JalviewBioJsColorSchemeMapper - .values()) - { - if (cs.getBioJsName().equals(bioJsColourSchemeName)) - { - jalviewColor = cs.getJvColourScheme(); - break; - } - } - return jalviewColor; + return colourScheme; } - @Override - public String print() + public void setColourScheme(ColourSchemeI colourScheme) { - throw new UnsupportedOperationException( - "Print method of HtmlFile not yet supported!"); + this.colourScheme = colourScheme; } } diff --git a/src/jalview/io/HtmlSvgOutput.java b/src/jalview/io/HtmlSvgOutput.java index 3c9c608..db34c2f 100644 --- a/src/jalview/io/HtmlSvgOutput.java +++ b/src/jalview/io/HtmlSvgOutput.java @@ -34,6 +34,7 @@ public class HtmlSvgOutput this.av = ap.av; this.ap = ap; + av.setFeatureRenderer(new FeatureRenderer(ap)); this.annotationPanel = ap.getAnnotationPanel(); generateHtmlSvgOutput(file); } @@ -100,7 +101,8 @@ public class HtmlSvgOutput String titleSvgData = g1.getSVGDocument(); String alignSvgData = g2.getSVGDocument(); - String htmlData = getHtml(titleSvgData, alignSvgData); + String jsonData = JSONFile.getJSONData(av); + String htmlData = getHtml(titleSvgData, alignSvgData, jsonData); out.write(htmlData.getBytes()); out.flush(); @@ -257,11 +259,17 @@ public class HtmlSvgOutput return Printable.PAGE_EXISTS; } - private String getHtml(String titleSvg, String alignmentSvg) + private String getHtml(String titleSvg, String alignmentSvg, + String jsonData) { StringBuilder htmlSvg = new StringBuilder(); - htmlSvg.append("" - + "