Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.ws.dbsources

File EmblFlatfileSource.java

 

Coverage histogram

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

Code metrics

10
31
9
1
147
104
17
0.55
3.44
9
1.89

Classes

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