X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FCrossRef.java;h=d7a3175c8b7a1f5e75c4457b98a3be6ba4ab1ff2;hb=4e1cb9b8b058d9b633af223b1cdb7b220d5d2ccd;hp=f355d1f09c6d139e8c82344e91e46c97de635cd7;hpb=6b406c397d41a0f2d84b75f13e7ab478932bf57d;p=jalview.git diff --git a/src/jalview/analysis/CrossRef.java b/src/jalview/analysis/CrossRef.java index f355d1f..d7a3175 100644 --- a/src/jalview/analysis/CrossRef.java +++ b/src/jalview/analysis/CrossRef.java @@ -1,3 +1,21 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1) + * Copyright (C) 2009 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; @@ -86,36 +104,41 @@ public class CrossRef Vector refs = new Vector(); for (int s = 0; s < seqs.length; s++) { - SequenceI dss = seqs[s]; - while (dss.getDatasetSequence() != null) + if (seqs[s] != null) { - dss = dss.getDatasetSequence(); - } - DBRefEntry[] rfs = findXDbRefs(dna, dss.getDBRef()); - for (int r = 0; rfs != null && r < rfs.length; r++) - { - if (!refs.contains(rfs[r].getSource())) + + SequenceI dss = seqs[s]; + while (dss.getDatasetSequence() != null) { - refs.addElement(rfs[r].getSource()); + dss = dss.getDatasetSequence(); } - } - if (dataset != null) - { - // search for references to this sequence's direct references. - DBRefEntry[] lrfs = CrossRef.findXDbRefs(!dna, seqs[s].getDBRef()); - Vector rseqs = new Vector(); - CrossRef.searchDatasetXrefs(seqs[s], !dna, lrfs, dataset, rseqs, - null); // don't need to specify codon frame for mapping here - Enumeration lr = rseqs.elements(); - while (lr.hasMoreElements()) + DBRefEntry[] rfs = findXDbRefs(dna, dss.getDBRef()); + for (int r = 0; rfs != null && r < rfs.length; r++) { - SequenceI rs = (SequenceI) lr.nextElement(); - DBRefEntry[] xrs = findXDbRefs(dna, rs.getDBRef()); - for (int r = 0; rfs != null && r < rfs.length; r++) + if (!refs.contains(rfs[r].getSource())) { - if (!refs.contains(rfs[r].getSource())) + refs.addElement(rfs[r].getSource()); + } + } + if (dataset != null) + { + // search for references to this sequence's direct references. + DBRefEntry[] lrfs = CrossRef + .findXDbRefs(!dna, seqs[s].getDBRef()); + Vector rseqs = new Vector(); + CrossRef.searchDatasetXrefs(seqs[s], !dna, lrfs, dataset, rseqs, + null); // don't need to specify codon frame for mapping here + Enumeration lr = rseqs.elements(); + while (lr.hasMoreElements()) + { + SequenceI rs = (SequenceI) lr.nextElement(); + DBRefEntry[] xrs = findXDbRefs(dna, rs.getDBRef()); + for (int r = 0; rfs != null && r < rfs.length; r++) { - refs.addElement(rfs[r].getSource()); + if (!refs.contains(rfs[r].getSource())) + { + refs.addElement(rfs[r].getSource()); + } } } } @@ -158,7 +181,9 @@ public class CrossRef { if (cdna[c].getSource().equals(DBRefSource.EMBLCDS)) { - // retrieve CDS dataset sequences + System.err + .println("TODO: unimplemented sequence retrieval for coding region sequence."); + // TODO: retrieve CDS dataset sequences // need global dataset sequence retriever/resolver to reuse refs // and construct Mapping entry. // insert gaps in CDS according to peptide gaps. @@ -261,7 +286,7 @@ public class CrossRef // xrefs on this sequence. if (dataset != null) { - found |= searchDataset(dss, xrfs[r], dataset, rseqs, cf); + found |= searchDataset(dss, xrfs[r], dataset, rseqs, cf); // ,false,!dna); if (found) xrfs[r] = null; // we've recovered seqs for this one. } @@ -305,7 +330,10 @@ public class CrossRef xrfs = t; try { - retrieved = sftch.getSequences(xrfs); // problem here is we don't know which of xrfs resulted in which retrieved element + retrieved = sftch.getSequences(xrfs); // problem here is we don't + // know which of xrfs + // resulted in which + // retrieved element } catch (Exception e) { System.err @@ -318,32 +346,39 @@ public class CrossRef for (int rs = 0; rs < retrieved.length; rs++) { // TODO: examine each sequence for 'redundancy' - jalview.datamodel.DBRefEntry[] dbr = retrieved[rs].getDBRef(); + jalview.datamodel.DBRefEntry[] dbr = retrieved[rs] + .getDBRef(); if (dbr != null && dbr.length > 0) { for (int di = 0; di < dbr.length; di++) { - // find any entry where we should put in the sequence being cross-referenced into the map + // find any entry where we should put in the sequence being + // cross-referenced into the map jalview.datamodel.Mapping map = dbr[di].getMap(); if (map != null) { if (map.getTo() != null && map.getMap() != null) { - // should search the local dataset to find any existing candidates for To ! + // should search the local dataset to find any existing + // candidates for To ! try { - // compare ms with dss and replace with dss in mapping if map is congruent + // compare ms with dss and replace with dss in mapping + // if map is congruent SequenceI ms = map.getTo(); int sf = map.getMap().getToLowest(); int st = map.getMap().getToHighest(); SequenceI mappedrg = ms.getSubSequence(sf, st); SequenceI loc = dss.getSubSequence(sf, st); - if (mappedrg.getLength()>0 && mappedrg.getSequenceAsString().equals( - loc.getSequenceAsString())) + if (mappedrg.getLength() > 0 + && mappedrg.getSequenceAsString().equals( + loc.getSequenceAsString())) { System.err .println("Mapping updated for retrieved crossreference"); - // method to update all refs of existing To on retrieved sequence with dss and merge any props on To onto dss. + // method to update all refs of existing To on + // retrieved sequence with dss and merge any props + // on To onto dss. map.setTo(dss); } } catch (Exception e) @@ -444,6 +479,7 @@ public class CrossRef boolean direct, boolean dna) { boolean found = false; + SequenceI[] typer = new SequenceI[1]; if (dataset == null) return false; if (dataset.getSequences() == null) @@ -464,17 +500,28 @@ public class CrossRef } if (nxt != sequenceI && nxt != sequenceI.getDatasetSequence()) { + // check if this is the correct sequence type + { + typer[0] = nxt; + boolean isDna = jalview.util.Comparison.isNucleotide(typer); + if ((direct && isDna == dna) || (!direct && isDna != dna)) + { + // skip this sequence because it is same molecule type + continue; + } + } + // look for direct or indirect references in common - DBRefEntry[] poss = null, cands = null; + DBRefEntry[] poss = nxt.getDBRef(), cands = null; if (direct) { - cands = jalview.util.DBRefUtils.searchRefs(poss = nxt - .getDBRef(), xrf); + cands = jalview.util.DBRefUtils.searchRefs(poss , xrf); } else { - cands = jalview.util.DBRefUtils.searchRefs(poss = CrossRef - .findXDbRefs(dna, nxt.getDBRef()), xrf); + poss = CrossRef + .findXDbRefs(dna, poss); // + cands = jalview.util.DBRefUtils.searchRefs(poss, xrf); } if (cands != null) { @@ -537,16 +584,17 @@ public class CrossRef * System.out.println("Found " + ((prod == null) ? "no" : "" + * prod.length) + " products"); if (prod!=null) { for (int p=0; p