X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=d56764b0bec5879d701a374bb6a03851f51159ee;hb=9d465da4f21e403c20b835264929906b538c0c9b;hp=30ccdbee7e9bd89a2d9d9d812ef018d59c4de5d1;hpb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 30ccdbe..d56764b 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -20,6 +20,18 @@ */ package jalview.gui; +import java.awt.Container; +import java.awt.Dimension; +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; + +import javax.swing.JInternalFrame; + import jalview.analysis.AlignmentUtils; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.api.AlignViewportI; @@ -35,11 +47,19 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.ContactMatrixI; import jalview.datamodel.HiddenColumns; 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; @@ -53,17 +73,6 @@ 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.FontMetrics; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; - -import javax.swing.JInternalFrame; - /** * DOCUMENT ME! * @@ -719,12 +728,62 @@ public class AlignViewport extends AlignmentViewport al.addSequence(seq); } } - + for (ContactMatrixI cm : toAdd.getContactMaps()) + { + al.addContactList(cm); + } ranges.setEndSeq(getAlignment().getHeight() - 1); // BH 2019.04.18 firePropertyChange("alignment", null, getAlignment().getSequences()); } /** + * 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 @@ -748,27 +807,12 @@ 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); + }).setResponseHandler(2, () -> { + us.openLinkedAlignmentAs(al, title, false); }); dialog.showDialog(question, MessageManager.getString("label.open_split_window"), @@ -786,18 +830,31 @@ 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; - - /* - * 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. - */ + + // always create dataset for imported alignment before doing anything else.. al.setDataset(null); - AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna); + + if (!al.isNucleotide() && !thisAlignment.isNucleotide()) + { + // link AA to 3di or other kind of 'alternative' 1:1 mapping alignment + AlignmentUtils.map3diPeptideToProteinAligment(thisAlignment,al); + } + else + { + // 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. @@ -832,7 +889,7 @@ public class AlignViewport extends AlignmentViewport if (newWindowOrSplitPane) { al.alignAs(thisAlignment); - protein = openSplitFrame(newAlignFrame, thisAlignment); + AlignmentI mapped = openSplitFrame(newAlignFrame, thisAlignment); } } @@ -953,7 +1010,7 @@ public class AlignViewport extends AlignmentViewport */ protected boolean noReferencesTo(AlignedCodonFrame acf) { - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); if (frames == null) { return true; @@ -1114,4 +1171,5 @@ public class AlignViewport extends AlignmentViewport { this.viewName = viewName; } + }