X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FDna.java;h=30bc3786f985a86dcd1e8fbf1ebe5898460dd404;hb=ce2b9960f07e7182c7e58fa993b7ea77862f018b;hp=c6bcfdad4ddf13c2743e7687a739cf8139ae58f0;hpb=702481fe6f87f0a418ddfec7b1d014ec2b8c22b2;p=jalview.git diff --git a/src/jalview/analysis/Dna.java b/src/jalview/analysis/Dna.java index c6bcfda..30bc378 100644 --- a/src/jalview/analysis/Dna.java +++ b/src/jalview/analysis/Dna.java @@ -1,3 +1,21 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) + * Copyright (C) 2008 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ package jalview.analysis; import java.util.Enumeration; @@ -66,7 +84,8 @@ public class Dna * @param gapCharacter * @param annotations * @param aWidth - * @param dataset destination dataset for translated sequences and mappings + * @param dataset + * destination dataset for translated sequences and mappings * @return */ public static AlignmentI CdnaTranslate(SequenceI[] selection, @@ -81,7 +100,9 @@ public class Dna * * @param selection * @param seqstring - * @param product - array of DbRefEntry objects from which exon map in seqstring is derived + * @param product - + * array of DbRefEntry objects from which exon map in seqstring + * is derived * @param viscontigs * @param gapCharacter * @param annotations @@ -91,7 +112,8 @@ public class Dna */ public static AlignmentI CdnaTranslate(SequenceI[] selection, String[] seqstring, DBRefEntry[] product, int viscontigs[], - char gapCharacter, AlignmentAnnotation[] annotations, int aWidth, Alignment dataset) + char gapCharacter, AlignmentAnnotation[] annotations, int aWidth, + Alignment dataset) { AlignedCodonFrame codons = new AlignedCodonFrame(aWidth); // stores hash of // subsequent @@ -104,12 +126,14 @@ public class Dna for (s = 0; s < sSize; s++) { SequenceI newseq = translateCodingRegion(selection[s], seqstring[s], - viscontigs, codons, gapCharacter, (product!=null) ? product[s] : null); // possibly anonymous product + viscontigs, codons, gapCharacter, + (product != null) ? product[s] : null); // possibly anonymous + // product if (newseq != null) { pepseqs.addElement(newseq); SequenceI ds = newseq; - while (ds.getDatasetSequence()!=null) + while (ds.getDatasetSequence() != null) { ds = ds.getDatasetSequence(); } @@ -127,31 +151,36 @@ public class Dna al.addCodonFrame(codons); return al; } + /** - * fake the collection of DbRefs with associated exon mappings to identify - * if a translation would generate distinct product in the currently selected region. + * fake the collection of DbRefs with associated exon mappings to identify if + * a translation would generate distinct product in the currently selected + * region. + * * @param selection * @param viscontigs * @return */ - public static boolean canTranslate(SequenceI[] selection, int viscontigs[]) + public static boolean canTranslate(SequenceI[] selection, + int viscontigs[]) { - for (int gd=0; gdalwidth) + + if (sqstr.length() > alwidth) alwidth = sqstr.length(); cdnasqs.addElement(sqstr.toString()); cdnasqi.addElement(dna); @@ -237,7 +272,8 @@ public class Dna cdnasqs.copyInto(xons); cdnaprod.copyInto(prods); cdnasqi.copyInto(cdna); - return CdnaTranslate(cdna, xons, prods, viscontigs, gapCharacter, null, alwidth, dataset); + return CdnaTranslate(cdna, xons, prods, viscontigs, gapCharacter, + null, alwidth, dataset); } return null; } @@ -282,7 +318,8 @@ public class Dna if (codons.codons[a] != null && codons.codons[a][0] == (codons.codons[a][2] - 2)) { - anots[a] = getCodonAnnotation(codons.codons[a], annotations[i].annotations); + anots[a] = getCodonAnnotation(codons.codons[a], + annotations[i].annotations); } } } @@ -292,9 +329,10 @@ public class Dna aa.graph = annotations[i].graph; aa.graphGroup = annotations[i].graphGroup; aa.graphHeight = annotations[i].graphHeight; - if (annotations[i].getThreshold()!=null) + if (annotations[i].getThreshold() != null) { - aa.setThreshold(new jalview.datamodel.GraphLine(annotations[i].getThreshold())); + aa.setThreshold(new jalview.datamodel.GraphLine(annotations[i] + .getThreshold())); } if (annotations[i].hasScore) { @@ -321,13 +359,14 @@ public class Dna } } - private static Annotation getCodonAnnotation(int[] is, Annotation[] annotations) - { + private static Annotation getCodonAnnotation(int[] is, + Annotation[] annotations) + { // Have a look at all the codon positions for annotation and put the first // one found into the translated annotation pos. - for (int p=0; p<3; p++) + for (int p = 0; p < 3; p++) { - if (annotations[is[p]]!=null) + if (annotations[is[p]] != null) { return new Annotation(annotations[is[p]]); } @@ -338,10 +377,15 @@ public class Dna /** * Translate a na sequence * - * @param selection sequence displayed under viscontigs visible columns - * @param seqstring ORF read in some global alignment reference frame - * @param viscontigs mapping from global reference frame to visible seqstring ORF read - * @param codons Definition of global ORF alignment reference frame + * @param selection + * sequence displayed under viscontigs visible columns + * @param seqstring + * ORF read in some global alignment reference frame + * @param viscontigs + * mapping from global reference frame to visible seqstring ORF + * read + * @param codons + * Definition of global ORF alignment reference frame * @param gapCharacter * @param newSeq * @return sequence ready to be added to alignment. @@ -350,22 +394,25 @@ public class Dna String seqstring, int[] viscontigs, AlignedCodonFrame codons, char gapCharacter, DBRefEntry product) { - Vector skip=new Vector(); - int skipint[]=null; + Vector skip = new Vector(); + int skipint[] = null; ShiftList vismapping = new ShiftList(); // map from viscontigs to seqstring // intervals int vc, scontigs[] = new int[viscontigs.length]; int npos = 0; for (vc = 0; vc < viscontigs.length; vc += 2) { - if (vc==0) { - vismapping.addShift(npos, viscontigs[vc]); - } else { + if (vc == 0) + { + vismapping.addShift(npos, viscontigs[vc]); + } + else + { // hidden region - vismapping.addShift(npos, viscontigs[vc]-viscontigs[vc-1]+1); + vismapping.addShift(npos, viscontigs[vc] - viscontigs[vc - 1] + 1); } scontigs[vc] = viscontigs[vc]; - scontigs[vc + 1] = viscontigs[vc+1]; + scontigs[vc + 1] = viscontigs[vc + 1]; } StringBuffer protein = new StringBuffer(); @@ -389,37 +436,42 @@ public class Dna if (aa == null) { aa = String.valueOf(gapCharacter); - if (skipint==null) + if (skipint == null) { - skipint = new int[] { cdp[0],cdp[2] }; + skipint = new int[] + { cdp[0], cdp[2] }; } skipint[1] = cdp[2]; - } else { - if (skipint!=null) + } + else + { + if (skipint != null) { // edit scontigs skipint[0] = vismapping.shift(skipint[0]); skipint[1] = vismapping.shift(skipint[1]); - for (vc=0; vc= codons.aaWidth) - // codons.aaWidth = aspos + 1; + // if (aspos >= codons.aaWidth) + // codons.aaWidth = aspos + 1; break; // check the next position for alignment case 0: // codon aligns at aspos position. @@ -463,11 +515,14 @@ public class Dna codons.codons[aspos] = new int[] { cdp[0], cdp[1], cdp[2] }; } - aspos++; if (aspos >= codons.aaWidth) { - codons.aaWidth = aspos + 1; + // update maximum alignment width + // (we can do this without calling checkCodonFrameWidth because it was already done above) + codons.setAaWidth(aspos); } + // ready for next translated reading frame alignment position (if any) + aspos++; } } if (resSize > 0) @@ -515,8 +570,7 @@ public class Dna for (vc = 0; vc < scontigs.length; vc += 2) { scontigs[vc] = selection.findPosition(scontigs[vc]); // not from 1! - scontigs[vc + 1] = selection - .findPosition(scontigs[vc + 1]); // exclusive + scontigs[vc + 1] = selection.findPosition(scontigs[vc + 1]); // exclusive if (scontigs[vc + 1] == selection.getEnd()) break; } @@ -528,62 +582,35 @@ public class Dna scontigs = t; } /* - * delete intervals in scontigs which are not translated. - * 1. map skip into sequence position intervals - * 2. truncate existing ranges and add new ranges to exclude untranslated regions. - if (skip.size()>0) - { - Vector narange = new Vector(); - for (vc=0; vc=skipint[0] && iv[0]<=skipint[1]) - { - if (iv[0]==skipint[0]) - { - // delete beginning of range - } else { - // truncate range and create new one if necessary - iv = (int[]) narange.elementAt(vc+1); - if (iv[0]<=skipint[1]) - { - // truncate range - iv[0] = skipint[1]; - } else { - - } - } - } else - if (iv[0]0) { + * Vector narange = new Vector(); for (vc=0; vc=skipint[0] && iv[0]<=skipint[1]) { if (iv[0]==skipint[0]) { // + * delete beginning of range } else { // truncate range and create new + * one if necessary iv = (int[]) narange.elementAt(vc+1); if (iv[0]<=skipint[1]) { // + * truncate range iv[0] = skipint[1]; } else { + * } } } else if (iv[0]