package jalview.ws.dbsources; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.datamodel.xdb.embl.EmblEntry; import jalview.ws.EBIFetchClient; import java.io.File; import java.util.Iterator; import java.util.Vector; public abstract class EmblXmlSource extends EbiFileRetrievedProxy { /** * Last properly parsed embl file. */ public jalview.datamodel.xdb.embl.EmblFile efile = null; public EmblXmlSource() { super(); } /** * set this to false to *not* add protein products to alignment dataset. */ public boolean getProteinProducts=false; /** * retrieve and parse an emblxml file * @param emprefx either EMBL or EMBLCDS strings are allowed - anything else will not retrieve emblxml * @param query * @return * @throws Exception */ public AlignmentI getEmblSequenceRecords(String emprefx, String query) throws Exception { startQuery(); SequenceI seqs[] = null; Vector alseq = new Vector(); // the sequences that will actually be presented in the alignment StringBuffer result = new StringBuffer(); EBIFetchClient dbFetch = new EBIFetchClient(); File reply; try { reply = dbFetch.fetchDataAsFile( emprefx.toLowerCase() + ":" + query.trim(), "emblxml",null); } catch (Exception e) { stopQuery(); throw new Exception("EBI EMBL XML retrieval failed on "+emprefx.toLowerCase()+":"+query.trim(),e); } if (reply != null && reply.exists()) { file = reply.getAbsolutePath(); efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply); } if (efile!=null) { for (Iterator i=efile.getEntries().iterator(); i.hasNext(); ) { EmblEntry entry = (EmblEntry) i.next(); SequenceI[] seqparts = entry.getSequences(false,!getProteinProducts, emprefx); if (seqparts!=null) { SequenceI[] newseqs = null; int si=0; if (seqs==null) { newseqs = new SequenceI[seqparts.length]; } else { newseqs = new SequenceI[seqs.length+seqparts.length]; for (;si0) { al = new Alignment(seqs); result.append("# Successfully parsed the "+emprefx+" queries into an Alignment"); results = result; } stopQuery(); return al; } }