X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=65857ce0a4ff4d5ea504446f5dfbf46f49fdfe0e;hb=2b3edc77ed89937505a6c1297b4264cd8b820b8b;hp=39d68802880f437175960b6554fac32bf2bffc96;hpb=0ebbdf07a6afe841138a9c3473697e57349bf345;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 39d6880..65857ce 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,16 +21,18 @@ 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; private char [] sequence; @@ -45,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) { @@ -88,6 +86,11 @@ public class Sequence implements SequenceI void parseId() { + if (name==null) + { + System.err.println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor."); + name = ""; + } // Does sequence have the /start-end signiature? if (limitrx.search(name)) { @@ -133,20 +136,74 @@ 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, 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()); + seq.getSequence(), + seq.getStart(), + seq.getEnd()); description = seq.getDescription(); + if (seq.getSequenceFeatures()!=null) { + SequenceFeature[] sf = seq.getSequenceFeatures(); + for (int i=0; i= sequence.length) { @@ -407,19 +474,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); if (datasetSequence!=null) + { nseq.setDatasetSequence(datasetSequence); + } else + { nseq.setDatasetSequence(this); + } return nseq; } @@ -463,11 +538,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) { @@ -546,14 +621,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; @@ -572,10 +645,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