Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:12:26 GMT
  2. Package jalview.ws.dbsources

File EmblFlatfileSource.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
59% of files have more coverage

Code metrics

8
29
9
1
142
99
16
0.55
3.22
9
1.78

Classes

Class Line # Actions
EmblFlatfileSource 45 29 16
0.00%
 

Contributing tests

No tests hitting this source file were found.

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 java.util.Locale;
24   
25    import java.io.File;
26    import java.io.IOException;
27   
28    import com.stevesoft.pat.Regex;
29   
30    import jalview.bin.Console;
31    import jalview.datamodel.Alignment;
32    import jalview.datamodel.AlignmentI;
33    import jalview.datamodel.SequenceI;
34    import jalview.io.DataSourceType;
35    import jalview.io.EmblFlatFile;
36    import jalview.io.FileParse;
37    import jalview.ws.ebi.EBIFetchClient;
38   
39    /**
40    * A class that does partial parsing of an EMBL flatfile.
41    *
42    * @author gmcarstairs
43    *
44    */
 
45    public abstract class EmblFlatfileSource extends EbiFileRetrievedProxy
46    {
47    private static final Regex ACCESSION_REGEX = new Regex("^[A-Z]+[0-9]+");
48   
 
49  0 toggle @Override
50    public String getDbVersion()
51    {
52  0 return "0";
53    }
54   
 
55  0 toggle @Override
56    public String getAccessionSeparator()
57    {
58  0 return null;
59    }
60   
 
61  0 toggle @Override
62    public Regex getAccessionValidator()
63    {
64  0 return ACCESSION_REGEX;
65    }
66   
 
67  0 toggle @Override
68    public boolean isValidReference(String accession)
69    {
70  0 if (accession == null || accession.length() < 2)
71    {
72  0 return false;
73    }
74  0 return getAccessionValidator().search(accession);
75    }
76   
 
77  0 toggle @Override
78    public AlignmentI getSequenceRecords(String queries) throws Exception
79    {
80  0 return null;
81    }
82   
 
83  0 toggle @Override
84    public int getTier()
85    {
86  0 return 0;
87    }
88   
 
89  0 toggle protected AlignmentI getEmblSequenceRecords(String dbName, String query)
90    throws Exception
91    {
92  0 startQuery();
93  0 EBIFetchClient dbFetch = new EBIFetchClient();
94  0 File reply;
95  0 try
96    {
97  0 reply = dbFetch.fetchDataAsFile(
98    dbName.toLowerCase(Locale.ROOT) + ":" + query.trim(), null,
99    "gz");
100    } catch (Exception e)
101    {
102  0 stopQuery();
103  0 throw new Exception(
104    String.format("EBI EMBL retrieval failed for %s:%s",
105    dbName.toLowerCase(Locale.ROOT), query.trim()),
106    e);
107    }
108  0 return getEmblSequenceRecords(dbName, query, reply);
109    }
110   
 
111  0 toggle private AlignmentI getEmblSequenceRecords(String dbName, String query,
112    File reply) throws IOException
113    {
114  0 AlignmentI al = null;
115   
116  0 if (reply != null && reply.exists())
117    {
118  0 file = reply.getAbsolutePath();
119  0 FileParse fp = new FileParse(file, DataSourceType.FILE);
120  0 EmblFlatFile emblParser = new EmblFlatFile(fp, getDbSource());
121  0 SequenceI[] seqs = emblParser.getSeqsAsArray();
122  0 if (seqs.length > 0)
123    {
124  0 al = new Alignment(seqs);
125    }
126   
127  0 if (al == null)
128    {
129  0 Console.error("No record found for '" + dbName + ":" + query + "'");
130    }
131    }
132   
133  0 stopQuery();
134  0 return al;
135    }
136   
 
137  0 toggle @Override
138    public boolean isDnaCoding()
139    {
140  0 return true;
141    }
142    }