String output = f.formatSequences(format,
exportData.getAlignment(), // class cast exceptions will
// occur in the distant future
- exportData.getOmitHidden(), f.getCacheSuffixDefault(format),
+ exportData.getOmitHidden(), exportData.getStartEndPostions(),
+ f.getCacheSuffixDefault(format),
viewport.getColumnSelection());
if (output == null)
cap.setText(new FormatAdapter(viewport).formatSequences(
e.getActionCommand(),
exportData.getAlignment(),
- exportData.getOmitHidden(),
+ exportData.getOmitHidden(), exportData.getStartEndPostions(),
viewport.getColumnSelection()));
Desktop.addInternalFrame(cap, MessageManager.formatMessage(
"label.alignment_output_command", new Object[]
{
AlignmentI alignmentToExport = null;
String[] omitHidden = null;
+ int[] alignmentStartEnd = new int[2];
FeatureRenderer fr = new FeatureRenderer(this.alignPanel);
viewport.setFeatureRenderer(fr);
HiddenSequences hiddenSeqs = viewport.getAlignment()
.getHiddenSequences();
+
+
+ alignmentToExport = viewport.getAlignment();
+ alignmentStartEnd = new int[]
+ { 0, alignmentToExport.getWidth() - 1 };
+
if (viewport.hasHiddenColumns() || hiddenSeqs.getSize() > 0)
{
int reply = JOptionPane
if (reply == JOptionPane.YES_OPTION)
{
+ // export only visible region
omitHidden = viewport.getViewAsString(false);
+ alignmentToExport = viewport.getAlignment();
+ alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
+ .getColumnSelection().getHiddenColumns());
}
else
{
- alignmentToExport = viewport.getAlignment().getHiddenSequences()
- .getFullAlignment();
+ // export all region including visible
+ alignmentToExport = hiddenSeqs.getFullAlignment();
}
}
- if (alignmentToExport == null)
+
+ return new ExportData(alignmentToExport, omitHidden, alignmentStartEnd);
+ }
+
+ private static int[] getStartEnd(int[] aligmentStartEnd,
+ List<int[]> hiddenCols)
+ {
+ int startPos = aligmentStartEnd[0];
+ int endPos = aligmentStartEnd[1];
+
+ int[] lowestRange = new int[2];
+ int[] higestRange = new int[2];
+
+ for (int[] hiddenCol : hiddenCols)
+ {
+ // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
+
+ lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
+ higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
+ }
+ // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
+ // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
+
+ if (lowestRange[0] == 0 && lowestRange[1] == 0)
+ {
+ startPos = aligmentStartEnd[0];
+ }
+ else
+ {
+ startPos = lowestRange[1] + 1;
+ }
+
+ if (higestRange[0] == 0 && higestRange[1] == 0)
+ {
+ endPos = aligmentStartEnd[1];
+ }
+ else
{
- alignmentToExport = viewport.getAlignment();
+ endPos = higestRange[0];
}
- return new ExportData(alignmentToExport, omitHidden);
+
+ // System.out.println("Export range : " + minPos + " - " + maxPos);
+ return new int[]
+ { startPos, endPos };
+ }
+
+ public static void main(String[] args)
+ {
+ ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
+ hiddenCols.add(new int[]
+ { 0, 4 });
+ hiddenCols.add(new int[]
+ { 6, 9 });
+ hiddenCols.add(new int[]
+ { 11, 12 });
+ hiddenCols.add(new int[]
+ { 33, 33 });
+ hiddenCols.add(new int[]
+ { 45, 50 });
+
+ int[] x = getStartEnd(new int[]
+ { 0, 50 }, hiddenCols);
+ // System.out.println("Export range : " + x[0] + " - " + x[1]);
}
/**
}
String output = new FormatAdapter().formatSequences("Fasta", seqs,
- omitHidden);
+ omitHidden, null);
StringSelection ss = new StringSelection(output);
private String[] omitHidden;
- public ExportData(AlignmentI align, String[] ommit)
+ private int[] startEnd;
+
+ public ExportData(AlignmentI align, String[] ommit, int[] startEnd)
{
this.alignment = align;
this.omitHidden = ommit;
- System.out.println();
+ this.startEnd = startEnd;
}
public AlignmentI getAlignment()
{
this.omitHidden = omitHidden;
}
+
+ public int[] getStartEndPostions()
+ {
+ return startEnd;
+ }
+
+ public void setStartEndPostions(int[] startEnd)
+ {
+ this.startEnd = startEnd;
+ }
}
@Override
}
String output = new FormatAdapter().formatSequences("Fasta", seqs,
- omitHidden);
+ omitHidden, null);
Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(new StringSelection(output), Desktop.instance);
}
public String formatSequences(String format, SequenceI[] seqs,
- String[] omitHiddenColumns)
+ String[] omitHiddenColumns, int[] exportRange)
{
- return formatSequences(format, replaceStrings(seqs, omitHiddenColumns));
+ return formatSequences(format,
+ replaceStrings(seqs, omitHiddenColumns, exportRange));
}
/**
* @return new sequences
*/
public SequenceI[] replaceStrings(SequenceI[] seqs,
- String[] omitHiddenColumns)
+ String[] omitHiddenColumns, int[] startEnd)
{
if (omitHiddenColumns != null)
{
SequenceI[] tmp = new SequenceI[seqs.length];
+
+ int startRes;
+ int endRes;
+ int startIndex;
+ int endIndex;
for (int i = 0; i < seqs.length; i++)
{
+ startRes = seqs[i].getStart();
+ endRes = seqs[i].getEnd();
+
+ startIndex = startEnd[0];
+ endIndex = startEnd[1];
+
+ if (startEnd != null)
+ {
+ // get first non-gaped residue start position
+ while (jalview.util.Comparison.isGap(seqs[i]
+ .getCharAt(startIndex)) && startIndex < endIndex)
+ {
+ startIndex++;
+ }
+
+ // get last non-gaped residue end position
+ while (jalview.util.Comparison.isGap(seqs[i].getCharAt(endIndex))
+ && endIndex > startIndex)
+ {
+ endIndex--;
+ }
+
+ startRes = seqs[i].findPosition(startIndex);
+ startRes = seqs[i].getStart() > 1 ? startRes - seqs[i].getStart()
+ : startRes;
+ endRes = seqs[i].findPosition(endIndex) - seqs[i].getStart();
+ }
+
tmp[i] = new Sequence(seqs[i].getName(), omitHiddenColumns[i],
- seqs[i].getStart(), seqs[i].getEnd());
+ startRes, endRes);
tmp[i].setDescription(seqs[i].getDescription());
}
seqs = tmp;
}
public String formatSequences(String format, AlignmentI alignment,
- String[] omitHidden, ColumnSelection colSel)
+ String[] omitHidden, int[] exportRange, ColumnSelection colSel)
{
- return formatSequences(format, alignment, omitHidden,
+ return formatSequences(format, alignment, omitHidden, exportRange,
getCacheSuffixDefault(format), colSel, null);
}
public String formatSequences(String format, AlignmentI alignment,
- String[] omitHidden, ColumnSelection colSel, SequenceGroup sgp)
+ String[] omitHidden, int[] exportRange, ColumnSelection colSel,
+ SequenceGroup sgp)
{
- return formatSequences(format, alignment, omitHidden,
+ return formatSequences(format, alignment, omitHidden, exportRange,
getCacheSuffixDefault(format), colSel, sgp);
}
* @return string representation of the alignment formatted as format
*/
public String formatSequences(String format, AlignmentI alignment,
- String[] omitHidden, boolean suffix, ColumnSelection colSel)
+ String[] omitHidden, int[] exportRange, boolean suffix,
+ ColumnSelection colSel)
{
- return formatSequences(format, alignment, omitHidden, suffix, colSel,
+ return formatSequences(format, alignment, omitHidden, exportRange,
+ suffix, colSel,
null);
}
public String formatSequences(String format, AlignmentI alignment,
- String[] omitHidden, boolean suffix, ColumnSelection colSel,
+ String[] omitHidden, int[] exportRange, boolean suffix,
+ ColumnSelection colSel,
jalview.datamodel.SequenceGroup selgp)
{
if (omitHidden != null)
// TODO: JAL-1486 - set start and end for output correctly. basically,
// AlignmentView.getVisibleContigs does this.
Alignment alv = new Alignment(replaceStrings(
- alignment.getSequencesArray(), omitHidden));
+ alignment.getSequencesArray(), omitHidden, exportRange));
AlignmentAnnotation[] ala = alignment.getAlignmentAnnotation();
if (ala != null)
{