From 75cbd01f57e64f0b2946e8b54005dadf139546ee Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 1 Nov 2005 11:32:35 +0000 Subject: [PATCH] Adjust seq limits for visual and dataset sequences --- src/jalview/gui/AlignFrame.java | 35 ++++++++---- src/jalview/gui/Desktop.java | 1 - src/jalview/io/SequenceFeatureFetcher.java | 81 ++++++++++++++++++---------- src/jalview/io/WSWUBlastClient.java | 59 +++++++++++--------- 4 files changed, 111 insertions(+), 65 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 1d408db..77396c9 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -617,7 +617,6 @@ public class AlignFrame { if (viewport.getSelectionGroup() == null) { - System.out.println("nothing selected"); return; } @@ -687,13 +686,14 @@ public class AlignFrame seqs[i].setDBRef(seq.getDBRef()); seqs[i].setSequenceFeatures(seq.getSequenceFeatures()); seqs[i].setDatasetSequence(seq.getDatasetSequence()); + } - Desktop.jalviewClipboard = new Object[]{seqs, viewport.alignment.getDataset()}; FastaFile ff = new FastaFile(); ff.addDBPrefix( viewport.showDBPrefix ); ff.addJVSuffix( viewport.showJVSuffix ); c.setContents(new StringSelection( ff.print(seqs)), this); + Desktop.jalviewClipboard = new Object[]{seqs, viewport.alignment.getDataset()}; } /** @@ -749,8 +749,9 @@ public class AlignFrame sequences = (SequenceI[])Desktop.jalviewClipboard[0]; } else + { sequences = new FormatAdapter().readFile(str, "Paste", format); - + } if (newAlignment) { @@ -782,8 +783,24 @@ public class AlignFrame { //!newAlignment for (int i = 0; i < sequences.length; i++) + { viewport.alignment.addSequence(sequences[i]); + if(sequences[i].getDatasetSequence()==null) + { + //////////////////////////// + //Datset needs extension; + ///////////////////////////// + Sequence ds = new Sequence(sequences[i].getName(), + AlignSeq.extractGaps("-. ", sequences[i].getSequence()), + sequences[i].getStart(), + sequences[i].getEnd()); + sequences[i].setDatasetSequence(ds); + viewport.alignment.getDataset().addSequence(ds); + + } + + } viewport.setEndSeq(viewport.alignment.getHeight()); viewport.alignment.getWidth(); viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); @@ -1369,13 +1386,13 @@ public class AlignFrame { viewport.showSequenceFeatures(sequenceFeatures.isSelected()); - // if (viewport.showSequenceFeatures && - // ! ( (Alignment) viewport.alignment.getDataset()).featuresAdded) + if (viewport.showSequenceFeatures && + ! ( (Alignment) viewport.alignment.getDataset()).featuresAdded) { - // System.out.println("new fetcher"); - // new SequenceFeatureFetcher(viewport. - // alignment, - // alignPanel); + System.out.println("new fetcher"); + new SequenceFeatureFetcher(viewport. + alignment, + alignPanel); } featureSettings.setEnabled(true); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index ba9d9a6..7569831 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -19,7 +19,6 @@ package jalview.gui; import jalview.io.*; -import jalview.datamodel.*; import java.awt.*; import java.awt.datatransfer.*; diff --git a/src/jalview/io/SequenceFeatureFetcher.java b/src/jalview/io/SequenceFeatureFetcher.java index 35a9a95..f3f144c 100755 --- a/src/jalview/io/SequenceFeatureFetcher.java +++ b/src/jalview/io/SequenceFeatureFetcher.java @@ -43,13 +43,12 @@ public class SequenceFeatureFetcher implements Runnable { AlignmentI align; + AlignmentI dataset; AlignmentPanel ap; ArrayList unknownSequences; CutAndPasteTransfer output = new CutAndPasteTransfer(); StringBuffer sbuffer = new StringBuffer(); - Vector localCache = new Vector(); - Vector getUniprotEntries(File file) { @@ -66,23 +65,11 @@ public class SequenceFeatureFetcher implements Runnable unmar.setIgnoreExtraElements(true); unmar.setMapping(map); uni = (UniprotFile) unmar.unmarshal(new FileReader(file)); - localCache.addAll( uni.getUniprotEntries() ); - - // 3. marshal the data with the total price back and print the XML in the console - // Marshaller marshaller = new Marshaller( - // new FileWriter(jalview.bin.Cache.getProperty("UNIPROT_CACHE")) - // ); - // marshaller.setMapping(map); - // marshaller.marshal(uni); } catch (Exception e) { System.out.println("Error getUniprotEntries() "+e); - // e.printStackTrace(); - // if(!updateLocalCache) - // file.delete(); - } return uni.getUniprotEntries(); } @@ -96,7 +83,8 @@ public class SequenceFeatureFetcher implements Runnable public SequenceFeatureFetcher(AlignmentI align, AlignmentPanel ap) { unknownSequences = new ArrayList(); - this.align = align.getDataset(); + this.align = align; + this.dataset = align.getDataset(); this.ap = ap; Thread thread = new Thread(this); @@ -111,7 +99,7 @@ public class SequenceFeatureFetcher implements Runnable try { int seqIndex = 0; - Vector sequences = align.getSequences(); + Vector sequences = dataset.getSequences(); while (seqIndex < sequences.size()) { @@ -121,8 +109,11 @@ public class SequenceFeatureFetcher implements Runnable seqIndex++, i++) { SequenceI sequence = (SequenceI) sequences.get(seqIndex); - ids.add(sequence.getName()); - unknownSequences.add(sequence.getName()); + if(!ids.contains(sequence.getName())) + { + ids.add(sequence.getName()); + unknownSequences.add(sequence.getName()); + } } /////////////////////////////////// @@ -142,7 +133,7 @@ public class SequenceFeatureFetcher implements Runnable if (file != null) { - ReadUniprotFile(file, align, ids); + ReadUniprotFile(file, ids); } } } @@ -160,6 +151,9 @@ public class SequenceFeatureFetcher implements Runnable "Save your alignment to maintain the updated id.\n\n" + sbuffer.toString()); Desktop.addInternalFrame(output, "Sequence names updated ", 600, 300); + // The above is the dataset, we must now find out the index + // of the viewed sequence + } if (unknownSequences.size() > 0) @@ -174,7 +168,7 @@ public class SequenceFeatureFetcher implements Runnable new WSWUBlastClient(ap, align, unknownSequences); } else - ((Alignment)align).featuresAdded = true; + ((Alignment)dataset).featuresAdded = true; ap.repaint(); @@ -187,7 +181,7 @@ public class SequenceFeatureFetcher implements Runnable * @param out DOCUMENT ME! * @param align DOCUMENT ME! */ - void ReadUniprotFile(File file, AlignmentI align, Vector ids) + void ReadUniprotFile(File file, Vector ids) { if(!file.exists()) return; @@ -203,14 +197,13 @@ public class SequenceFeatureFetcher implements Runnable { entry = (UniprotEntry) entries.elementAt(i); String idmatch = entry.getAccession().elementAt(0).toString(); - sequence = align.findName(idmatch); + sequence = dataset.findName(idmatch); if (sequence == null) { //Sequence maybe Name, not Accession - idmatch = entry.getName().elementAt(0).toString();; - sequence = align.findName(idmatch); + sequence = dataset.findName(idmatch); } if (sequence == null) @@ -239,17 +232,47 @@ public class SequenceFeatureFetcher implements Runnable int absEnd = absStart + nonGapped.toString().length(); absStart += 1; - if ( (absStart != sequence.getStart()) || - (absEnd != sequence.getEnd())) + sequence.setSequenceFeatures(entry.getFeatures()); + sequence.setStart(absStart); + sequence.setEnd(absEnd); + + if ( (absStart != sequence.getStart()) || (absEnd != sequence.getEnd())) { sbuffer.append("Updated: " + sequence.getName() + " " + sequence.getStart() + "/" + sequence.getEnd() + " to " + absStart + "/" + absEnd + "\n"); } - sequence.setSequenceFeatures(entry.getFeatures()); - sequence.setStart(absStart); - sequence.setEnd(absEnd); + + + int n = 0; + SequenceI seq2; + while (n < align.getHeight()) + { + //This loop enables multiple sequences with the same + //id to have features added and seq limits updated + seq2 = align.getSequenceAt(n); + if (seq2.getName().equals(idmatch)) + { + + nonGapped = AlignSeq.extractGaps("-. ", seq2.getSequence()); + + absStart = sequence.getSequence().indexOf(nonGapped); + absEnd = absStart + nonGapped.toString().length() - 1; + + sbuffer.append("Updated: VISUAL " + seq2.getName() + " " + + seq2.getStart() + "/" + seq2.getEnd() + + " to " + (absStart + sequence.getStart()) + "/" + + + (absEnd + sequence.getStart()) + "\n"); + + seq2.setStart(absStart + sequence.getStart()); + seq2.setEnd(absEnd + sequence.getStart()); + + } + + n++; + } } } } diff --git a/src/jalview/io/WSWUBlastClient.java b/src/jalview/io/WSWUBlastClient.java index 2e3ccfa..8e4532c 100755 --- a/src/jalview/io/WSWUBlastClient.java +++ b/src/jalview/io/WSWUBlastClient.java @@ -138,6 +138,38 @@ public class WSWUBlastClient void updateIds() { + int reply = JOptionPane.showConfirmDialog( + Desktop.desktop, "Automatically update suggested ids?", + "Auto replace sequence ids", JOptionPane.YES_NO_OPTION); + + if (reply == JOptionPane.YES_OPTION) + { + Enumeration keys = suggestedIds.keys(); + while(keys.hasMoreElements()) + { + String oldid = keys.nextElement().toString(); + SequenceI sequence = al.findName(oldid); + sequence.setName( suggestedIds.get(oldid).toString() ); + + sequence = sequence.getDatasetSequence(); + if(sequence!=null) + { + + sequence.setName(suggestedIds.get(oldid).toString()); + + Vector entries = sequence.getDBRef(); + if(entries!=null) + { + DBRefEntry entry = (DBRefEntry) entries.elementAt(0); + sequence.addDBRef(new jalview.datamodel.DBRefEntry("UNIPROT", + "0", + entry.getAccessionId())); + } + } + System.out.println("replace "+oldid+" with "+suggestedIds.get(oldid)); + } + } + ap.repaint(); } @@ -182,32 +214,7 @@ public class WSWUBlastClient if (jobsRunning == 0) { - int reply = JOptionPane.showConfirmDialog( - Desktop.desktop, "Automatically update suggested ids?", - "Auto replace sequence ids", JOptionPane.YES_NO_OPTION); - - if (reply == JOptionPane.YES_OPTION) - { - Enumeration keys = suggestedIds.keys(); - while(keys.hasMoreElements()) - { - String oldid = keys.nextElement().toString(); - SequenceI sequence = al.findName(oldid); - sequence.setName( suggestedIds.get(oldid).toString() ); - - sequence = al.getDataset().findName(oldid); - Vector entries = sequence.getDBRef(); - DBRefEntry entry = (DBRefEntry) entries.elementAt(0); - sequence.addDBRef(new jalview.datamodel.DBRefEntry("UNIPROT", - "0", - entry.getAccessionId())); - - sequence.setName(suggestedIds.get(oldid).toString()); - - System.out.println("replace "+oldid+" with "+suggestedIds.get(oldid)); - } - } - ap.repaint(); + updateIds(); } } } -- 1.7.10.2