X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FDna.java;h=a10b037faaf1ba34497a33d318d1229c0565fcdd;hb=4687e1243f51bd09334792b8a7ce518a5aa07de7;hp=1d5f996b44279f5339d86474ac3f19bf364be00c;hpb=07bb0da70ad46444f5f9bc0b2fa80e9ee3805394;p=jalview.git diff --git a/src/jalview/analysis/Dna.java b/src/jalview/analysis/Dna.java index 1d5f996..a10b037 100644 --- a/src/jalview/analysis/Dna.java +++ b/src/jalview/analysis/Dna.java @@ -20,12 +20,6 @@ */ package jalview.analysis; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.Map; - import jalview.api.AlignViewportI; import jalview.datamodel.AlignedCodon; import jalview.datamodel.AlignedCodonFrame; @@ -47,9 +41,14 @@ import jalview.util.DBRefUtils; import jalview.util.MapList; import jalview.util.ShiftList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + public class Dna { - private static final String STOP_X = "X"; + private static final String STOP_ASTERIX = "*"; private static final Comparator comparator = new CodonComparator(); @@ -69,7 +68,7 @@ public class Dna final private int dnaWidth; - final private Alignment dataset; + final private AlignmentI dataset; /* * Working variables for the translation. @@ -134,7 +133,8 @@ public class Dna * @param ac2 * @return */ - private static int jalview_2_8_2compare(AlignedCodon ac1, AlignedCodon ac2) + private static int jalview_2_8_2compare(AlignedCodon ac1, + AlignedCodon ac2) { if (ac1 == null || ac2 == null || (ac1.equals(ac2))) { @@ -208,14 +208,13 @@ public class Dna for (int gd = 0; gd < selection.length; gd++) { SequenceI dna = selection[gd]; - DBRefEntry[] dnarefs = DBRefUtils - .selectRefs(dna.getDBRef(), - jalview.datamodel.DBRefSource.DNACODINGDBS); + DBRefEntry[] dnarefs = DBRefUtils.selectRefs(dna.getDBRefs(), + jalview.datamodel.DBRefSource.DNACODINGDBS); if (dnarefs != null) { // intersect with pep List mappedrefs = new ArrayList(); - DBRefEntry[] refs = dna.getDBRef(); + DBRefEntry[] refs = dna.getDBRefs(); for (int d = 0; d < refs.length; d++) { if (refs[d].getMap() != null && refs[d].getMap().getMap() != null @@ -300,8 +299,7 @@ public class Dna aa.graphHeight = annotation.graphHeight; if (annotation.getThreshold() != null) { - aa.setThreshold(new GraphLine(annotation - .getThreshold())); + aa.setThreshold(new GraphLine(annotation.getThreshold())); } if (annotation.hasScore) { @@ -437,7 +435,8 @@ public class Dna /* * Filled up a reading frame... */ - AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1], cdp[2]); + AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1], + cdp[2]); String aa = ResidueProperties.codonTranslate(new String(codon)); rf = 0; final String gapString = String.valueOf(gapChar); @@ -446,8 +445,11 @@ public class Dna aa = gapString; if (skipint == null) { - skipint = new int[] - { alignedCodon.pos1, alignedCodon.pos3 /* cdp[0], cdp[2] */}; + skipint = new int[] { alignedCodon.pos1, + alignedCodon.pos3 /* + * cdp[0], + * cdp[2] + */ }; } skipint[1] = alignedCodon.pos3; // cdp[2]; } @@ -502,8 +504,8 @@ public class Dna } if (vc + 2 < t.length) { - System.arraycopy(scontigs, vc + 2, t, vc, t.length - - vc + 2); + System.arraycopy(scontigs, vc + 2, t, vc, + t.length - vc + 2); } scontigs = t; } @@ -544,7 +546,7 @@ public class Dna } if (aa.equals("STOP")) { - aa = STOP_X; + aa = STOP_ASTERIX; } resSize++; } @@ -596,9 +598,9 @@ public class Dna } else if (!alignedCodons[aspos].equals(alignedCodon)) { - throw new IllegalStateException("Tried to coalign " - + alignedCodons[aspos].toString() + " with " - + alignedCodon.toString()); + throw new IllegalStateException( + "Tried to coalign " + alignedCodons[aspos].toString() + + " with " + alignedCodon.toString()); } if (aspos >= aaWidth) { @@ -683,10 +685,9 @@ public class Dna * range iv[0] = skipint[1]; } else { } } } else if (iv[0] proteinSeqs) + protected void insertAAGap(int pos, List proteinSeqs) { aaWidth++; for (SequenceI seq : proteinSeqs) @@ -756,26 +756,16 @@ public class Dna /** * Given a peptide newly translated from a dna sequence, copy over and set any - * features on the peptide from the DNA. If featureTypes is null, all features - * on the dna sequence are searched (rather than just the displayed ones), and - * similarly for featureGroups. + * features on the peptide from the DNA. * * @param dna * @param pep * @param map - * @param featureTypes - * hash whose keys are the displayed feature type strings - * @param featureGroups - * hash where keys are feature groups and values are Boolean objects - * indicating if they are displayed. */ private static void transferCodedFeatures(SequenceI dna, SequenceI pep, - MapList map, Map featureTypes, - Map featureGroups) + MapList map) { - SequenceFeature[] sfs = dna.getSequenceFeatures(); - Boolean fgstate; - DBRefEntry[] dnarefs = DBRefUtils.selectRefs(dna.getDBRef(), + DBRefEntry[] dnarefs = DBRefUtils.selectRefs(dna.getDBRefs(), DBRefSource.DNACODINGDBS); if (dnarefs != null) { @@ -788,24 +778,175 @@ public class Dna } } } - if (sfs != null) + for (SequenceFeature sf : dna.getFeatures().getAllFeatures()) { - for (SequenceFeature sf : sfs) - { - fgstate = (featureGroups == null) ? null : featureGroups - .get(sf.featureGroup); - if ((featureTypes == null || featureTypes.containsKey(sf.getType())) - && (fgstate == null || fgstate.booleanValue())) + if (FeatureProperties.isCodingFeature(null, sf.getType())) { - if (FeatureProperties.isCodingFeature(null, sf.getType())) + // if (map.intersectsFrom(sf[f].begin, sf[f].end)) { - // if (map.intersectsFrom(sf[f].begin, sf[f].end)) - { - } } } + } + } + + /** + * Returns an alignment consisting of the reversed (and optionally + * complemented) sequences set in this object's constructor + * + * @param complement + * @return + */ + public AlignmentI reverseCdna(boolean complement) + { + int sSize = selection.size(); + List reversed = new ArrayList(); + for (int s = 0; s < sSize; s++) + { + SequenceI newseq = reverseSequence(selection.get(s).getName(), + seqstring[s], complement); + + if (newseq != null) + { + reversed.add(newseq); } } + + SequenceI[] newseqs = reversed.toArray(new SequenceI[reversed.size()]); + AlignmentI al = new Alignment(newseqs); + ((Alignment) al).createDatasetAlignment(); + return al; + } + + /** + * Returns a reversed, and optionally complemented, sequence. The new + * sequence's name is the original name with "|rev" or "|revcomp" appended. + * aAcCgGtT and DNA ambiguity codes are complemented, any other characters are + * left unchanged. + * + * @param seq + * @param complement + * @return + */ + public static SequenceI reverseSequence(String seqName, String sequence, + boolean complement) + { + String newName = seqName + "|rev" + (complement ? "comp" : ""); + char[] originalSequence = sequence.toCharArray(); + int length = originalSequence.length; + char[] reversedSequence = new char[length]; + int bases = 0; + for (int i = 0; i < length; i++) + { + char c = complement ? getComplement(originalSequence[i]) + : originalSequence[i]; + reversedSequence[length - i - 1] = c; + if (!Comparison.isGap(c)) + { + bases++; + } + } + SequenceI reversed = new Sequence(newName, reversedSequence, 1, bases); + return reversed; + } + + /** + * Returns dna complement (preserving case) for aAcCgGtTuU. Ambiguity codes + * are treated as on http://reverse-complement.com/. Anything else is left + * unchanged. + * + * @param c + * @return + */ + public static char getComplement(char c) + { + char result = c; + switch (c) + { + case '-': + case '.': + case ' ': + break; + case 'a': + result = 't'; + break; + case 'A': + result = 'T'; + break; + case 'c': + result = 'g'; + break; + case 'C': + result = 'G'; + break; + case 'g': + result = 'c'; + break; + case 'G': + result = 'C'; + break; + case 't': + result = 'a'; + break; + case 'T': + result = 'A'; + break; + case 'u': + result = 'a'; + break; + case 'U': + result = 'A'; + break; + case 'r': + result = 'y'; + break; + case 'R': + result = 'Y'; + break; + case 'y': + result = 'r'; + break; + case 'Y': + result = 'R'; + break; + case 'k': + result = 'm'; + break; + case 'K': + result = 'M'; + break; + case 'm': + result = 'k'; + break; + case 'M': + result = 'K'; + break; + case 'b': + result = 'v'; + break; + case 'B': + result = 'V'; + break; + case 'v': + result = 'b'; + break; + case 'V': + result = 'B'; + break; + case 'd': + result = 'h'; + break; + case 'D': + result = 'H'; + break; + case 'h': + result = 'd'; + break; + case 'H': + result = 'D'; + break; + } + + return result; } }