From: gmungoc Date: Wed, 22 Nov 2017 15:33:17 +0000 (+0000) Subject: Merge branch 'develop' into features/JAL-1793VCF X-Git-Tag: Release_2_11_0~111 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=a81d34b61544d11e146f2d5cf6558d35bf24533b;hp=-c Merge branch 'develop' into features/JAL-1793VCF --- a81d34b61544d11e146f2d5cf6558d35bf24533b diff --combined src/jalview/datamodel/Sequence.java index 9e81d81,15d1378..441d8d0 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@@ -657,10 -657,10 +657,10 @@@ public class Sequence extends ASequenc } /** - * DOCUMENT ME! + * Sets the sequence description, and also parses out any special formats of + * interest * * @param desc - * DOCUMENT ME! */ @Override public void setDescription(String desc) @@@ -668,67 -668,10 +668,67 @@@ this.description = desc; } + @Override + public void setGeneLoci(String speciesId, String assemblyId, + String chromosomeId, MapList map) + { + addDBRef(new DBRefEntry(speciesId, assemblyId, DBRefEntry.CHROMOSOME + + ":" + chromosomeId, new Mapping(map))); + } + /** - * DOCUMENT ME! + * Returns the gene loci mapping for the sequence (may be null) * - * @return DOCUMENT ME! + * @return + */ + @Override + public GeneLociI getGeneLoci() + { + DBRefEntry[] refs = getDBRefs(); + if (refs != null) + { + for (final DBRefEntry ref : refs) + { + if (ref.isChromosome()) + { + return new GeneLociI() + { + @Override + public String getSpeciesId() + { + return ref.getSource(); + } + + @Override + public String getAssemblyId() + { + return ref.getVersion(); + } + + @Override + public String getChromosomeId() + { + // strip off "chromosome:" prefix to chrId + return ref.getAccessionId().substring( + DBRefEntry.CHROMOSOME.length() + 1); + } + + @Override + public MapList getMap() + { + return ref.getMap().getMap(); + } + }; + } + } + } + return null; + } + + /** + * Answers the description + * + * @return */ @Override public String getDescription() @@@ -1217,7 -1160,7 +1217,7 @@@ } @Override - public void deleteChars(int i, int j) + public void deleteChars(final int i, final int j) { int newstart = start, newend = end; if (i >= sequence.length || i < 0) @@@ -1229,62 -1172,75 +1229,75 @@@ boolean createNewDs = false; // TODO: take a (second look) at the dataset creation validation method for // the very large sequence case - int eindex = -1, sindex = -1; - boolean ecalc = false, scalc = false; + int startIndex = findIndex(start) - 1; + int endIndex = findIndex(end) - 1; + int startDeleteColumn = -1; // for dataset sequence deletions + int deleteCount = 0; + for (int s = i; s < j; s++) { - if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23) + if (Comparison.isGap(sequence[s])) + { + continue; + } + deleteCount++; + if (startDeleteColumn == -1) + { + startDeleteColumn = findPosition(s) - start; + } + if (createNewDs) + { + newend--; + } + else { - if (createNewDs) + if (startIndex == s) { - newend--; + /* + * deleting characters from start of sequence; new start is the + * sequence position of the next column (position to the right + * if the column position is gapped) + */ + newstart = findPosition(j); + break; } else { - if (!scalc) - { - sindex = findIndex(start) - 1; - scalc = true; - } - if (sindex == s) + if (endIndex < j) { - // delete characters including start of sequence - newstart = findPosition(j); - break; // don't need to search for any more residue characters. + /* + * deleting characters at end of sequence; new end is the sequence + * position of the column before the deletion; subtract 1 if this is + * gapped since findPosition returns the next sequence position + */ + newend = findPosition(i - 1); + if (Comparison.isGap(sequence[i - 1])) + { + newend--; + } + break; } else { - // delete characters after start. - if (!ecalc) - { - eindex = findIndex(end) - 1; - ecalc = true; - } - if (eindex < j) - { - // delete characters at end of sequence - newend = findPosition(i - 1); - break; // don't need to search for any more residue characters. - } - else - { - createNewDs = true; - newend--; // decrease end position by one for the deleted residue - // and search further - } + createNewDs = true; + newend--; } } } } - // deletion occured in the middle of the sequence + if (createNewDs && this.datasetSequence != null) { - // construct a new sequence + /* + * if deletion occured in the middle of the sequence, + * construct a new dataset sequence and delete the residues + * that were deleted from the aligned sequence + */ Sequence ds = new Sequence(datasetSequence); + ds.deleteChars(startDeleteColumn, startDeleteColumn + deleteCount); + datasetSequence = ds; // TODO: remove any non-inheritable properties ? // TODO: create a sequence mapping (since there is a relation here ?) - ds.deleteChars(i, j); - datasetSequence = ds; } start = newstart; end = newend; diff --combined src/jalview/datamodel/SequenceI.java index c064373,2f3e925..fb723e6 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@@ -21,7 -21,6 +21,7 @@@ package jalview.datamodel; import jalview.datamodel.features.SequenceFeaturesI; +import jalview.util.MapList; import java.util.BitSet; import java.util.List; @@@ -193,13 -192,14 +193,14 @@@ public interface SequenceI extends ASeq public int findIndex(int pos); /** - * Returns the sequence position for an alignment position. + * Returns the sequence position for an alignment (column) position. If at a + * gap, returns the position of the next residue to the right. If beyond the + * end of the sequence, returns 1 more than the last residue position. * * @param i * column index in alignment (from 0..