X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=91dded1e0636f7d87a3f9bb6e59cc2983e02e2b7;hb=9fef0746bf53cc0faff2bd45f1dbdb82398f4c62;hp=c61fe342f6f41058aaffefd0611901049e08ad99;hpb=091a66f3290c61a5c4b07358205f8757abd30cc3;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index c61fe34..91dded1 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -22,9 +22,11 @@ package jalview.gui; import java.awt.Container; import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Rectangle; +import java.io.File; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -52,6 +54,13 @@ import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; +import jalview.io.FileFormatException; +import jalview.io.FileFormatI; +import jalview.io.FileFormats; +import jalview.io.FileLoader; +import jalview.io.IdentifyFile; import jalview.renderer.ResidueShader; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; @@ -729,6 +738,53 @@ public class AlignViewport extends AlignmentViewport } /** + * Load a File into this AlignViewport attempting to detect format if not + * given or given as null. + * + * @param file + * @param format + */ + public void addFile(File file, FileFormatI format) + { + addFile(file, format, true); + } + + public void addFile(File file, FileFormatI format, boolean async) + { + DataSourceType protocol = AppletFormatAdapter.checkProtocol(file); + + if (format == null) + { + try + { + format = new IdentifyFile().identify(file, protocol); + } catch (FileFormatException e1) + { + jalview.bin.Console.error("Unknown file format for '" + file + "'"); + } + } + else if (FileFormats.getInstance().isIdentifiable(format)) + { + try + { + format = new IdentifyFile().identify(file, protocol); + } catch (FileFormatException e) + { + jalview.bin.Console.error("Unknown file format for '" + file + "'", + e); + } + } + + new FileLoader().LoadFile(this, file, DataSourceType.FILE, format, + async); + } + + public void addFile(File file) + { + addFile(file, null); + } + + /** * Show a dialog with the option to open and link (cDNA <-> protein) as a new * alignment, either as a standalone alignment or in a split frame. Returns * true if the new alignment was opened, false if not, because the user @@ -740,8 +796,13 @@ public class AlignViewport extends AlignmentViewport protected void openLinkedAlignment(AlignmentI al, String title) { String[] options = new String[] { MessageManager.getString("action.no"), - MessageManager.getString("label.split_window"), - MessageManager.getString("label.new_window"), }; + MessageManager.getString("label.split_window") + + "(update new alignment)", + MessageManager.getString("label.new_window"), + MessageManager.getString( + "label.split_window") + "(update this alignment)", + MessageManager.getString( + "label.split_window") + "(leave both unchanged)" }; final String question = JvSwingUtils.wrapTooltip(true, MessageManager.getString("label.open_split_window?")); final AlignViewport us = this; @@ -752,36 +813,36 @@ public class AlignViewport extends AlignmentViewport * in reverse order) */ JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop) - .setResponseHandler(0, new Runnable() - { - @Override - public void run() - { - addDataToAlignment(al); - } - }).setResponseHandler(1, new Runnable() - { - @Override - public void run() - { - us.openLinkedAlignmentAs(al, title, true); - } - }).setResponseHandler(2, new Runnable() - { - @Override - public void run() - { - us.openLinkedAlignmentAs(al, title, false); - } + .setResponseHandler(0, () -> { + addDataToAlignment(al); + }).setResponseHandler(1, () -> { + us.openLinkedAlignmentAs(al, title, true, 1); + }).setResponseHandler(2, () -> { + us.openLinkedAlignmentAs(al, title, false, 1); + }).setResponseHandler(3, () -> { + us.openLinkedAlignmentAs(al, title, true, 2); + }).setResponseHandler(4, () -> { + us.openLinkedAlignmentAs(al, title, true, 0); }); + dialog.setLayout(new FlowLayout(FlowLayout.CENTER)); + dialog.setPreferredSize(new Dimension(350,300)); dialog.showDialog(question, MessageManager.getString("label.open_split_window"), JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null, options, options[0]); } - protected void openLinkedAlignmentAs(AlignmentI al, String title, - boolean newWindowOrSplitPane) + /** + * link given alignment to the alignment in this viewport and open + * @param al - alignment containing sequences to link to this alignment + * @param title + * @param newWindowOrSplitPane + * @param alignAs TODO + * @param alignAs - 0 - don't modify either alignment, 1 - align al according to us, 2- align us according to al + * @return alignFrame holding al + */ + protected AlignFrame openLinkedAlignmentAs(AlignmentI al, String title, + boolean newWindowOrSplitPane, int alignAs) { /* * Identify protein and dna alignments. Make a copy of this one if opening @@ -790,18 +851,39 @@ public class AlignViewport extends AlignmentViewport AlignmentI thisAlignment = newWindowOrSplitPane ? new Alignment(getAlignment()) : getAlignment(); - AlignmentI protein = al.isNucleotide() ? thisAlignment : al; - final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment; + + + if (!al.isNucleotide() && !thisAlignment.isNucleotide()) + { + // link AA to 3di or other kind of 'alternative' 1:1 mapping alignment + if (al.getDataset()==null) + { + al.setDataset(thisAlignment.getDataset()); + } + AlignmentUtils.map3diPeptideToProteinAligment(thisAlignment,al); + if (thisAlignment.getCodonFrames().isEmpty()) {thisAlignment.getCodonFrames().addAll(al.getCodonFrames()); } + else {al.getCodonFrames().addAll(thisAlignment.getCodonFrames()); }; - /* - * Map sequences. At least one should get mapped as we have already passed - * the test for 'mappability'. Any mappings made will be added to the - * protein alignment. Note creating dataset sequences on the new alignment - * is a pre-requisite for building mappings. - */ - al.setDataset(null); - AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna); + } + else + { + // shouldn't we be merging dataset here ? + // always create dataset for imported alignment before doing anything else.. + al.setDataset(null); + // link CODON triplets to Protein + AlignmentI protein = al.isNucleotide() ? thisAlignment : al; + final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment; + + /* + * Map sequences. At least one should get mapped as we have already passed + * the test for 'mappability'. Any mappings made will be added to the + * protein alignment. Note creating dataset sequences on the new alignment + * is a pre-requisite for building mappings. + */ + AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna); + } + /* * Create the AlignFrame for the added alignment. If it is protein, mappings * are registered with StructureSelectionManager as a side-effect. @@ -835,9 +917,15 @@ public class AlignViewport extends AlignmentViewport if (newWindowOrSplitPane) { - al.alignAs(thisAlignment); - protein = openSplitFrame(newAlignFrame, thisAlignment); + if (alignAs==1) { + al.alignAs(thisAlignment); + } + if (alignAs==2) { + thisAlignment.alignAs(al); + } + AlignmentI mapped = openSplitFrame(newAlignFrame, thisAlignment); } + return newAlignFrame; } /** @@ -957,7 +1045,7 @@ public class AlignViewport extends AlignmentViewport */ protected boolean noReferencesTo(AlignedCodonFrame acf) { - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); if (frames == null) { return true; @@ -1118,4 +1206,5 @@ public class AlignViewport extends AlignmentViewport { this.viewName = viewName; } + }