Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.ws.dbsources

File EmblXmlSource.java

 

Coverage histogram

../../../img/srcFileCovDistChart1.png
53% of files have more coverage

Code metrics

10
27
4
1
139
77
12
0.44
6.75
4
3

Classes

Class Line # Actions
EmblXmlSource 35 27 12 39
0.0487804864.9%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.ws.dbsources;
22   
23    import jalview.datamodel.Alignment;
24    import jalview.datamodel.AlignmentI;
25    import jalview.datamodel.SequenceI;
26    import jalview.datamodel.xdb.embl.EmblEntry;
27    import jalview.datamodel.xdb.embl.EmblFile;
28    import jalview.util.MessageManager;
29    import jalview.ws.ebi.EBIFetchClient;
30   
31    import java.io.File;
32    import java.util.ArrayList;
33    import java.util.List;
34   
 
35    public abstract class EmblXmlSource extends EbiFileRetrievedProxy
36    {
37    /*
38    * JAL-1856 Embl returns this text for query not found
39    */
40    private static final String EMBL_NOT_FOUND_REPLY = "ERROR 12 No entries found.";
41   
 
42  12 toggle public EmblXmlSource()
43    {
44  12 super();
45    }
46   
47    /**
48    * retrieve and parse an emblxml file
49    *
50    * @param emprefx
51    * either EMBL or EMBLCDS strings are allowed - anything else will
52    * not retrieve emblxml
53    * @param query
54    * @return
55    * @throws Exception
56    */
 
57  0 toggle public AlignmentI getEmblSequenceRecords(String emprefx, String query)
58    throws Exception
59    {
60  0 startQuery();
61  0 EBIFetchClient dbFetch = new EBIFetchClient();
62  0 File reply;
63  0 try
64    {
65  0 reply = dbFetch.fetchDataAsFile(
66    emprefx.toLowerCase() + ":" + query.trim(), "display=xml",
67    "xml");
68    } catch (Exception e)
69    {
70  0 stopQuery();
71  0 throw new Exception(MessageManager.formatMessage(
72    "exception.ebiembl_retrieval_failed_on", new String[]
73    { emprefx.toLowerCase(), query.trim() }), e);
74    }
75  0 return getEmblSequenceRecords(emprefx, query, reply);
76    }
77   
78    /**
79    * parse an emblxml file stored locally
80    *
81    * @param emprefx
82    * either EMBL or EMBLCDS strings are allowed - anything else will
83    * not retrieve emblxml
84    * @param query
85    * @param file
86    * the EMBL XML file containing the results of a query
87    * @return
88    * @throws Exception
89    */
 
90  0 toggle public AlignmentI getEmblSequenceRecords(String emprefx, String query,
91    File reply) throws Exception
92    {
93  0 EmblFile efile = null;
94  0 List<SequenceI> seqs = new ArrayList<>();
95   
96  0 if (reply != null && reply.exists())
97    {
98  0 file = reply.getAbsolutePath();
99  0 if (reply.length() > EMBL_NOT_FOUND_REPLY.length())
100    {
101  0 efile = EmblFile.getEmblFile(reply);
102    }
103    }
104   
105    /*
106    * invalid accession gets a reply with no <entry> elements, text content of
107    * EmbFile reads something like (e.g.) this ungrammatical phrase
108    * Entry: <acc> display type is either not supported or entry is not found.
109    */
110  0 List<SequenceI> peptides = new ArrayList<>();
111  0 if (efile != null && efile.getEntries() != null)
112    {
113  0 for (EmblEntry entry : efile.getEntries())
114    {
115  0 SequenceI seq = entry.getSequence(emprefx, peptides);
116  0 if (seq != null)
117    {
118  0 seqs.add(seq.deriveSequence());
119    // place DBReferences on dataset and refer
120    }
121    }
122    }
123   
124  0 AlignmentI al = null;
125  0 if (!seqs.isEmpty())
126    {
127  0 al = new Alignment(seqs.toArray(new SequenceI[seqs.size()]));
128    }
129  0 stopQuery();
130  0 return al;
131    }
132   
 
133  0 toggle @Override
134    public boolean isDnaCoding()
135    {
136  0 return true;
137    }
138   
139    }