From 702481fe6f87f0a418ddfec7b1d014ec2b8c22b2 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 21 Dec 2007 15:06:06 +0000 Subject: [PATCH] further bugfix and annotation transfer for dna/protein (still issues with non-codon translation mapping generation) --- src/jalview/analysis/Dna.java | 100 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 10 deletions(-) diff --git a/src/jalview/analysis/Dna.java b/src/jalview/analysis/Dna.java index 7bac46e..c6bcfda 100644 --- a/src/jalview/analysis/Dna.java +++ b/src/jalview/analysis/Dna.java @@ -350,16 +350,22 @@ public class Dna String seqstring, int[] viscontigs, AlignedCodonFrame codons, char gapCharacter, DBRefEntry product) { + 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]); - scontigs[vc] = npos; - npos += viscontigs[vc + 1]; - scontigs[vc + 1] = npos; + } else { + // hidden region + vismapping.addShift(npos, viscontigs[vc]-viscontigs[vc-1]+1); + } + scontigs[vc] = viscontigs[vc]; + scontigs[vc + 1] = viscontigs[vc+1]; } StringBuffer protein = new StringBuffer(); @@ -381,9 +387,40 @@ public class Dna String aa = ResidueProperties.codonTranslate(new String(codon)); rf = 0; if (aa == null) - aa = String.valueOf(gapCharacter); - else { + aa = String.valueOf(gapCharacter); + if (skipint==null) + { + skipint = new int[] { cdp[0],cdp[2] }; + } + skipint[1] = cdp[2]; + } 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 (resSize > 0) @@ -472,14 +511,12 @@ public class Dna if (scontigs != null) { npos = 0; - // Find sequence position for scontigs positions on the nucleotide - // sequence string we were passed. - for (vc = 0; vc < viscontigs.length; vc += 2) + // map scontigs to actual sequence positions on selection + for (vc = 0; vc < scontigs.length; vc += 2) { scontigs[vc] = selection.findPosition(scontigs[vc]); // not from 1! - npos += viscontigs[vc]; scontigs[vc + 1] = selection - .findPosition(npos + scontigs[vc + 1]); // exclusive + .findPosition(scontigs[vc + 1]); // exclusive if (scontigs[vc + 1] == selection.getEnd()) break; } @@ -490,8 +527,51 @@ public class Dna System.arraycopy(scontigs, 0, t, 0, vc + 2); 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]