X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=0e72690aa69e439df38b52b505a04662a500b007;hb=7000ea3223f2f6a390f56341ba26850d2a137ae0;hp=ec798f12725f592d5153c03674d1c840137a87a2;hpb=4851c84266e61a5be2244cb002fdd5f02f2a4140;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index ec798f1..0e72690 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -21,14 +21,17 @@ package jalview.datamodel; import java.util.*; +import jalview.analysis.*; /** - * DOCUMENT ME! + * + * Implements the SequenceI interface for a char[] based sequence object. * * @author $author$ * @version $Revision$ */ -public class Sequence implements SequenceI +public class Sequence + implements SequenceI { SequenceI datasetSequence; String name; @@ -44,21 +47,17 @@ public class Sequence implements SequenceI * positions are tied to the residues of this sequence */ Vector annotation; - /** DOCUMENT ME!! */ + /** array of seuqence features - may not be null for a valid sequence object */ public SequenceFeature[] sequenceFeatures; - /** This array holds hidden sequences - * of which this sequence is the representitive member of a group - */ - SequenceGroup hiddenSequences; /** * Creates a new Sequence object. * - * @param name DOCUMENT ME! - * @param sequence DOCUMENT ME! - * @param start DOCUMENT ME! - * @param end DOCUMENT ME! + * @param name display name string + * @param sequence string to form a possibly gapped sequence out of + * @param start first position of non-gap residue in the sequence + * @param end last position of ungapped residues (nearly always only used for display purposes) */ public Sequence(String name, String sequence, int start, int end) { @@ -132,13 +131,72 @@ public class Sequence implements SequenceI } /** - * Creates a new Sequence object. - * + * Creates a new Sequence object with new features, DBRefEntries, AlignmentAnnotations, and PDBIds + * but inherits any existing dataset sequence reference. * @param seq DOCUMENT ME! */ public Sequence(SequenceI seq) { - this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd()); + this(seq, seq.getAnnotation()); + } + /** + * Create a new sequence object with new features, DBRefEntries, and PDBIds + * but inherits any existing dataset sequence reference, and duplicate of + * any annotation that is present in the given annotation array. + * @param seq the sequence to be copied + * @param alAnnotation an array of annotation including some associated with seq + */ + public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation) + { + this(seq.getName(), + seq.getSequence(), + seq.getStart(), + seq.getEnd()); + description = seq.getDescription(); + if (seq.getSequenceFeatures()!=null) { + SequenceFeature[] sf = seq.getSequenceFeatures(); + for (int i=0; i= sequence.length) { @@ -401,16 +469,27 @@ public class Sequence implements SequenceI public SequenceI getSubSequence(int start, int end) { if (start < 0) + { start = 0; + } char [] seq = getSequence(start, end); if (seq.length == 0) + { return null; + } int nstart = findPosition(start); int nend = findPosition(end) - 1; // JBPNote - this is an incomplete copy. SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend); nseq.setDescription(description); - nseq.setDatasetSequence(getDatasetSequence()); + if (datasetSequence!=null) + { + nseq.setDatasetSequence(datasetSequence); + } + else + { + nseq.setDatasetSequence(this); + } return nseq; } @@ -454,11 +533,11 @@ public class Sequence implements SequenceI } /** - * DOCUMENT ME! + * Return the alignment position for a sequence position * - * @param pos DOCUMENT ME! + * @param pos lying from start to end * - * @return DOCUMENT ME! + * @return aligned position of residue pos */ public int findIndex(int pos) { @@ -537,14 +616,12 @@ public class Sequence implements SequenceI return map; } - /** - * DOCUMENT ME! - * - * @param i DOCUMENT ME! - * @param j DOCUMENT ME! + /* (non-Javadoc) + * @see jalview.datamodel.SequenceI#deleteChars(int, int) */ public void deleteChars(int i, int j) { + int newstart=start,newend=end; if (i >= sequence.length) { return; @@ -563,10 +640,53 @@ public class Sequence implements SequenceI System.arraycopy(sequence,0,tmp,0,i); System.arraycopy(sequence,j,tmp,i,sequence.length-j); } - + boolean createNewDs=false; + for (int s = i; s < j; s++) + { + if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23) + { + if (createNewDs) + { + newend--; + } else { + int sindex = findIndex(start)-1; + if (sindex==s) + { + // delete characters including start of sequence + newstart = findPosition(j); + break; // don't need to search for any more residue characters. + } else { + // delete characters after start. + int eindex = findIndex(end)-1; + if (eindex