+/*\r
+* Jalview - A Sequence Alignment Editor and Viewer\r
+* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+*\r
+* This program is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU General Public License\r
+* as published by the Free Software Foundation; either version 2\r
+* of the License, or (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+*/\r
+\r
package jalview.analysis;\r
\r
import jalview.datamodel.*;\r
-import jalview.io.*;\r
import jalview.util.*;\r
-\r
import java.util.*;\r
\r
public class AlignmentUtil {\r
}\r
}\r
\r
- public static Hashtable findKmers(SequenceI seq, int start, int end, Vector kmers) {\r
-\r
- Hashtable pos = new Hashtable();\r
-\r
- for (int j = 0; j < kmers.size(); j++) {\r
-\r
- String kmer = ((Sequence)kmers.elementAt(j)).getSequence();\r
- Sequence kmerseq = (Sequence)kmers.elementAt(j);\r
-\r
- if (end < seq.getLength()) {\r
-\r
- String str = seq.getSequence(start,end);\r
-\r
- int i = 0;\r
-\r
- while (str.indexOf(kmer,i) != -1) {\r
-\r
- // System.out.println("STring " + str + " " + i);\r
- int coord = str.indexOf(kmer,i);\r
-\r
- pos.put(new Integer(coord),new Integer(kmerseq.getLength()));\r
-\r
- i = coord + 1;\r
-\r
- }\r
- }\r
- }\r
- return pos;\r
- }\r
-\r
- class FeatureThread extends Thread\r
- {\r
-\r
- }\r
-\r
- public static void addUniprotFeatures(AlignmentI align)\r
- {\r
- EBIFetchClient ebi = new EBIFetchClient();\r
- int seqIndex = 0;\r
- Vector sequences = align.getSequences();\r
- SequenceI sequence;\r
-\r
- while (seqIndex < sequences.size())\r
- {\r
- StringBuffer ids = new StringBuffer("uniprot:");\r
- for (int i=0; seqIndex<sequences.size() && i<50; seqIndex++, i++)\r
- {\r
- sequence = (SequenceI) sequences.get(seqIndex);\r
- ids.append(sequence.getName() + ";");\r
- }\r
-\r
- String[] result = ebi.fetchData(ids.toString(), "xml", null);\r
- sequence = null;\r
- Vector features = null;\r
- String type, description, status, start, end, pdb = null;\r
-\r
- for (int r = 0; r < result.length; r++)\r
- {\r
- if(sequence==null && result[r].indexOf("<name>")>-1)\r
- {\r
- sequence = align.findName( parseElement( result[r], "<name>" )) ;\r
- features = new Vector();\r
- type=""; start="0"; end="0"; description=""; status=""; pdb="";\r
- }\r
-\r
- if(sequence==null)\r
- continue;\r
-\r
- if( result[r].indexOf("<property type=\"pdb accession\"")>-1)\r
- {\r
- pdb = parseValue( result[r], "value=" );\r
- sequence.setPDBId(pdb);\r
- }\r
-\r
- if(result[r].indexOf("feature type")>-1)\r
- {\r
- type = parseValue( result[r], "type=" );\r
- description = parseValue( result[r], "description=" );\r
- status = parseValue ( result[r], "status=");\r
-\r
- while( result[r].indexOf("<location>")==-1)\r
- {\r
- r++; //<location>\r
- }\r
- r++;\r
- if(result[r].indexOf("begin")>-1)\r
- {\r
- start = parseValue( result[r], "position=" );\r
- end = parseValue( result[++r], "position=" );\r
- }\r
- else\r
- {\r
- start = parseValue( result[r], "position=" );\r
- end = parseValue( result[r], "position=" );\r
- }\r
- int sstart = Integer.parseInt(start);\r
- int eend = Integer.parseInt(end);\r
-\r
- if(sstart>=sequence.getStart() && eend<=sequence.getEnd())\r
- {\r
- SequenceFeature sf = new SequenceFeature(type,\r
- sstart,\r
- eend,\r
- description,\r
- status);\r
- features.add(sf);\r
- }\r
- }\r
-\r
- if(result[r].indexOf("</entry>")>-1)\r
- {\r
- sequence.setSequenceFeatures( features );\r
- features = null;\r
- sequence = null;\r
- }\r
- }\r
- }\r
- }\r
-\r
- static String parseValue(String line, String tag)\r
- {\r
-\r
- int index = line.indexOf(tag)+tag.length()+1;\r
- if(index==tag.length())\r
- return "";\r
-\r
- return line.substring( index, line.indexOf("\"", index+1) );\r
- }\r
-\r
-\r
- static String parseElement(String line, String tag)\r
- {\r
- int index = line.indexOf(tag)+tag.length();\r
- return line.substring( index, line.indexOf("</") ) ;\r
- }\r
-\r
-\r
-\r
-\r
\r
}\r