X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FDBRefFetcher.java;h=6d589f9df4c3c75d54639e91f0db56375ca41544;hb=cb7652a58feba83df46110a571785ce99be6da99;hp=d26ef6deb550f4e78e6b8069d2adc62da3ab65a4;hpb=0405267e16900334a4967ff8ad812174e6e25549;p=jalview.git diff --git a/src/jalview/io/DBRefFetcher.java b/src/jalview/io/DBRefFetcher.java index d26ef6d..6d589f9 100644 --- a/src/jalview/io/DBRefFetcher.java +++ b/src/jalview/io/DBRefFetcher.java @@ -1,37 +1,31 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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 -*/ + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 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.io; -import jalview.datamodel.*; - -import jalview.gui.*; - import java.io.*; - import java.util.*; -import org.exolab.castor.mapping.Mapping; - +import org.exolab.castor.mapping.*; import org.exolab.castor.xml.*; -import jalview.analysis.AlignSeq; - - +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.gui.*; /** * DOCUMENT ME! @@ -39,9 +33,10 @@ import jalview.analysis.AlignSeq; * @author $author$ * @version $Revision$ */ -public class DBRefFetcher implements Runnable +public class DBRefFetcher + implements Runnable { - AlignmentI dataset; + SequenceI [] dataset; AlignFrame af; CutAndPasteTransfer output = new CutAndPasteTransfer(); StringBuffer sbuffer = new StringBuffer(); @@ -60,7 +55,7 @@ public class DBRefFetcher implements Runnable try { // 1. Load the mapping information from the file - Mapping map = new Mapping(uni.getClass().getClassLoader()); + org.exolab.castor.mapping.Mapping map = new org.exolab.castor.mapping.Mapping(uni.getClass().getClassLoader()); java.net.URL url = getClass().getResource("/uniprot_mapping.xml"); map.loadMapping(url); @@ -73,10 +68,9 @@ public class DBRefFetcher implements Runnable } catch (Exception e) { - System.out.println("Error getUniprotEntries() "+e); + System.out.println("Error getUniprotEntries() " + e); } - return uni.getUniprotEntries(); } @@ -86,10 +80,18 @@ public class DBRefFetcher implements Runnable * @param align DOCUMENT ME! * @param ap DOCUMENT ME! */ - public DBRefFetcher(AlignmentI align, AlignFrame af) + public DBRefFetcher(SequenceI [] seqs, AlignFrame af) { this.af = af; - this.dataset = align.getDataset(); + SequenceI [] ds = new SequenceI[seqs.length]; + for (int i = 0; i < seqs.length; i++) + { + if(seqs[i].getDatasetSequence()!=null) + ds[i] = seqs[i].getDatasetSequence(); + else + ds[i] = seqs[i]; + } + this.dataset = ds; } public boolean fetchDBRefs(boolean waitTillFinished) @@ -98,13 +100,16 @@ public class DBRefFetcher implements Runnable thread.start(); running = true; - if(waitTillFinished) + if (waitTillFinished) { - while(running) + while (running) { - try{ + try + { Thread.sleep(500); - }catch(Exception ex){} + } + catch (Exception ex) + {} } } @@ -122,15 +127,15 @@ public class DBRefFetcher implements Runnable key = key.toUpperCase(); Vector seqs; - if(seqRefs.containsKey(key)) + if (seqRefs.containsKey(key)) { - seqs = (Vector)seqRefs.get(key); + seqs = (Vector) seqRefs.get(key); - if(seqs!=null && !seqs.contains(seq)) + if (seqs != null && !seqs.contains(seq)) { seqs.addElement(seq); } - else if(seqs==null) + else if (seqs == null) { seqs = new Vector(); seqs.addElement(seq); @@ -146,7 +151,6 @@ public class DBRefFetcher implements Runnable seqRefs.put(key, seqs); } - /** * DOCUMENT ME! */ @@ -161,45 +165,48 @@ public class DBRefFetcher implements Runnable try { int seqIndex = 0; - Vector sequences = dataset.getSequences(); - while (seqIndex < sequences.size()) + while (seqIndex < dataset.length) { StringBuffer queryString = new StringBuffer("uniprot:"); - for (int i = 0; (seqIndex < sequences.size()) && (i < 50); + for (int i = 0; (seqIndex < dataset.length) && (i < 50); seqIndex++, i++) { - Sequence sequence = (Sequence) sequences.get(seqIndex); - DBRefEntry [] uprefs = jalview.util.DBRefUtils.selectRefs(sequence.getDBRef(), new String[] { + SequenceI sequence = dataset[seqIndex]; + DBRefEntry[] uprefs = jalview.util.DBRefUtils.selectRefs(sequence. + getDBRef(), new String[] + { jalview.datamodel.DBRefSource.UNIPROT}); - if (uprefs!=null) + if (uprefs != null) { - if(uprefs.length+i>50) + if (uprefs.length + i > 50) + { break; + } - for(int j=0; j50) + if (st.countTokens() + i > 50) { //Dont send more than 50 id strings to dbFetch!! - seqIndex --; + seqIndex--; } else { - while(st.hasMoreTokens()) - { - String token = st.nextToken(); - addSeqId(sequence, token); - queryString.append(token+";"); - } + while (st.hasMoreTokens()) + { + String token = st.nextToken(); + addSeqId(sequence, token); + queryString.append(token + ";"); + } } } } @@ -233,13 +240,12 @@ public class DBRefFetcher implements Runnable } af.setProgressBar("DBRef search completed", startTime); - // promptBeforeBlast(); + // promptBeforeBlast(); - running = false; + running = false; } - /** * DOCUMENT ME! * @@ -250,7 +256,9 @@ public class DBRefFetcher implements Runnable void ReadUniprotFile(File file) { if (!file.exists()) + { return; + } SequenceI sequence = null; @@ -275,7 +283,9 @@ public class DBRefFetcher implements Runnable { sequence = (SequenceI) seqs.elementAt(jj); if (!sequenceMatches.contains(sequence)) + { sequenceMatches.addElement(sequence); + } } } } @@ -289,7 +299,9 @@ public class DBRefFetcher implements Runnable { sequence = (SequenceI) seqs.elementAt(jj); if (!sequenceMatches.contains(sequence)) + { sequenceMatches.addElement(sequence); + } } } } @@ -305,7 +317,8 @@ public class DBRefFetcher implements Runnable System.out.println("Adding dbref to " + sequence.getName() + " : " + entry.getAccession().elementAt(0).toString()); - String nonGapped = AlignSeq.extractGaps("-. ", sequence.getSequence()). + String nonGapped = AlignSeq.extractGaps("-. ", + sequence.getSequenceAsString()). toUpperCase(); int absStart = entry.getUniprotSequence().getContent().indexOf( @@ -352,7 +365,9 @@ public class DBRefFetcher implements Runnable { PDBEntry pdb = (PDBEntry) e.nextElement(); if (!pdb.getType().equals(DBRefSource.PDB)) + { continue; + } sequence.addDBRef(new DBRefEntry(DBRefSource.PDB, "0", @@ -370,5 +385,3 @@ public class DBRefFetcher implements Runnable } } } - -