From b100e1ff9a2e736a5535dda3abded2bf59144af4 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 8 Feb 2005 18:40:35 +0000 Subject: [PATCH] Looks for missing ids using BlastClient --- src/jalview/analysis/SequenceFeatureFetcher.java | 101 +++++++++++++++++++++- 1 file changed, 97 insertions(+), 4 deletions(-) diff --git a/src/jalview/analysis/SequenceFeatureFetcher.java b/src/jalview/analysis/SequenceFeatureFetcher.java index 8c550e9..e034b3f 100755 --- a/src/jalview/analysis/SequenceFeatureFetcher.java +++ b/src/jalview/analysis/SequenceFeatureFetcher.java @@ -10,9 +10,11 @@ public class SequenceFeatureFetcher implements Runnable { AlignmentI align; AlignmentPanel ap; + ArrayList unknownSequences; public SequenceFeatureFetcher(AlignmentI align, AlignmentPanel ap) { + unknownSequences = new ArrayList(); this.align = align; this.ap = ap; Thread thread = new Thread(this); @@ -78,7 +80,8 @@ public class SequenceFeatureFetcher implements Runnable remainingIds.append(ids.get(i) + ";"); EBIFetchClient ebi = new EBIFetchClient(); - String[] result = ebi.fetchData(remainingIds.toString(), "xml", null); + System.out.println(remainingIds.toString()); + String[] result = ebi.fetchData(remainingIds.toString(), "xml", null); if(result!=null) ReadUniprotFile(result, out, align); @@ -93,6 +96,13 @@ public class SequenceFeatureFetcher implements Runnable } }catch(Exception ex){ex.printStackTrace();} + ap.RefreshPanels(); + findMissingIds(align); + + if(unknownSequences.size()>0) + { + WSWUBlastClient blastClient = new WSWUBlastClient(align, unknownSequences); + } } @@ -115,10 +125,21 @@ void ReadUniprotFile(String [] result, RandomAccessFile out, AlignmentI align) out.writeBytes("\n"); }catch(Exception ex){} - sequence = align.findName( parseElement( result[r], "" , out)) ; + String seqName = parseElement( result[r], "" , out); + sequence = align.findName( seqName ) ; if(sequence==null) { - System.out.println("Couldnt find sequence id. Suggestion is "+result[r]); + sequence = align.findName( seqName.substring(0, seqName.indexOf('_'))); + if(sequence!=null) + { + System.out.println("changing "+sequence.getName()+" to "+seqName); + sequence.setName(seqName); + } + } + if(sequence==null) + { + System.out.println("UNIPROT updated suggestion is "+result[r]); + sequence = align.findName( result[r] ) ; // this entry has been suggested by ebi. // doesn't match id in alignment file @@ -180,6 +201,52 @@ void ReadUniprotFile(String [] result, RandomAccessFile out, AlignmentI align) } } + if(result[r].indexOf("-1) + { + StringBuffer seqString = new StringBuffer(); + + if(out!=null) + try { out.writeBytes(result[r]+"\n"); } catch (Exception ex){} + + while(result[++r].indexOf("")==-1) + { + seqString.append(result[r]); + if(out!=null) + try { out.writeBytes(result[r]+"\n"); } catch (Exception ex){} + } + + if(out!=null) + try { out.writeBytes(result[r]+"\n"); } catch (Exception ex){} + + StringBuffer nonGapped = new StringBuffer(); + for (int i = 0; i < sequence.getSequence().length(); i++) + { + if (!jalview.util.Comparison.isGap(sequence.getCharAt(i))) + nonGapped.append(sequence.getCharAt(i)); + } + + int absStart = seqString.toString().indexOf(nonGapped.toString()); + if(absStart==-1) + { + unknownSequences.add(sequence.getName()); + features = null; + System.out.println(sequence.getName()+ "does not match "); + continue; + } + + int absEnd = absStart + nonGapped.toString().length(); + absStart+=1; + + if(absStart!=sequence.getStart() || absEnd!=sequence.getEnd()) + System.out.println("Updated: "+sequence.getName()+" "+ + sequence.getStart()+"/"+sequence.getEnd()+" to "+ absStart+"/"+absEnd); + + + sequence.setStart(absStart); + sequence.setEnd(absEnd); + + } + if(result[r].indexOf("")>-1) { if(features!=null) @@ -191,8 +258,34 @@ void ReadUniprotFile(String [] result, RandomAccessFile out, AlignmentI align) } } +} + +void findMissingIds(AlignmentI align) +{ + String data; + ArrayList cachedIds = new ArrayList(); + + try + { + BufferedReader in = new BufferedReader( + new FileReader(jalview.bin.Cache.getProperty("UNIPROT_CACHE"))); + + while ( (data = in.readLine()) != null) + { + if (data.indexOf("name") > -1) + { + String name = parseElement(data, "", null); + cachedIds.add(name); + } + } + } + catch (Exception ex) + { ex.printStackTrace(); } + + for(int i=0; i