| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.io; |
| 22 |
|
|
| 23 |
|
import jalview.datamodel.Sequence; |
| 24 |
|
import jalview.datamodel.SequenceFeature; |
| 25 |
|
import jalview.datamodel.SequenceI; |
| 26 |
|
import jalview.util.MessageManager; |
| 27 |
|
|
| 28 |
|
import java.io.BufferedReader; |
| 29 |
|
import java.io.FileNotFoundException; |
| 30 |
|
import java.io.FileReader; |
| 31 |
|
import java.io.IOException; |
| 32 |
|
import java.util.Hashtable; |
| 33 |
|
import java.util.Map; |
| 34 |
|
|
| 35 |
|
import javax.xml.parsers.DocumentBuilder; |
| 36 |
|
import javax.xml.parsers.DocumentBuilderFactory; |
| 37 |
|
import javax.xml.parsers.ParserConfigurationException; |
| 38 |
|
|
| 39 |
|
import org.w3c.dom.Document; |
| 40 |
|
import org.w3c.dom.Element; |
| 41 |
|
import org.w3c.dom.NodeList; |
| 42 |
|
import org.xml.sax.InputSource; |
| 43 |
|
import org.xml.sax.SAXException; |
| 44 |
|
|
| 45 |
|
import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax; |
| 46 |
|
import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed; |
| 47 |
|
import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
@author |
| 54 |
|
|
| 55 |
|
|
| |
|
| 68.5% |
Uncovered Elements: 29 (92) |
Complexity: 18 |
Complexity Density: 0.25 |
|
| 56 |
|
public class BSMLFile extends AlignFile |
| 57 |
|
{ |
| 58 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 59 |
0 |
public BSMLFile()... |
| 60 |
|
{ |
| 61 |
0 |
super(); |
| 62 |
|
|
| 63 |
|
} |
| 64 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
1 |
public BSMLFile(String inFile, DataSourceType type) throws IOException... |
| 66 |
|
{ |
| 67 |
1 |
super(inFile, type); |
| 68 |
|
|
| 69 |
|
} |
| 70 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 71 |
0 |
public BSMLFile(FileParse source) throws IOException... |
| 72 |
|
{ |
| 73 |
0 |
super(source); |
| 74 |
|
|
| 75 |
|
} |
| 76 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 77 |
0 |
public BufferedReader CreateReader() throws FileNotFoundException... |
| 78 |
|
{ |
| 79 |
0 |
FileReader fr = null; |
| 80 |
0 |
fr = new FileReader(inFile); |
| 81 |
|
|
| 82 |
0 |
BufferedReader r = new BufferedReader(fr); |
| 83 |
0 |
return r; |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
@see |
| 90 |
|
|
| |
|
| 18.2% |
Uncovered Elements: 9 (11) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 91 |
1 |
@Override... |
| 92 |
|
public void parse() throws IOException |
| 93 |
|
{ |
| 94 |
1 |
try |
| 95 |
|
{ |
| 96 |
1 |
_parse(); |
| 97 |
|
} catch (ExceptionPermissionDenied pdx) |
| 98 |
|
{ |
| 99 |
0 |
errormessage = MessageManager.formatMessage( |
| 100 |
|
"exception.BSML_couldnt_access_datasource", new String[] |
| 101 |
|
{ pdx.getMessage() }); |
| 102 |
0 |
throw new IOException(pdx); |
| 103 |
|
} catch (ExceptionLoadingFailed lf) |
| 104 |
|
{ |
| 105 |
0 |
errormessage = MessageManager.formatMessage( |
| 106 |
|
"exception.BSML_couldnt_process_data", new String[] |
| 107 |
|
{ lf.getMessage() }); |
| 108 |
0 |
throw new IOException(lf); |
| 109 |
|
} catch (ExceptionFileFormatOrSyntax iff) |
| 110 |
|
{ |
| 111 |
0 |
errormessage = MessageManager |
| 112 |
|
.formatMessage("exception.BSML_invalid_file", new String[] |
| 113 |
|
{ iff.getMessage() }); |
| 114 |
0 |
throw new IOException(iff); |
| 115 |
|
} catch (Exception x) |
| 116 |
|
{ |
| 117 |
0 |
error = true; |
| 118 |
0 |
errormessage = MessageManager.formatMessage( |
| 119 |
|
"exception.BSML_problem_parsing_data", new String[] |
| 120 |
|
{ x.getMessage() }); |
| 121 |
0 |
throw new IOException(errormessage, x); |
| 122 |
|
} |
| 123 |
|
} |
| 124 |
|
|
| |
|
| 86.4% |
Uncovered Elements: 9 (66) |
Complexity: 8 |
Complexity Density: 0.15 |
|
| 125 |
1 |
@SuppressWarnings("unchecked")... |
| 126 |
|
public void _parse() |
| 127 |
|
throws ExceptionPermissionDenied, ExceptionLoadingFailed, |
| 128 |
|
ExceptionFileFormatOrSyntax, ParserConfigurationException, |
| 129 |
|
SAXException, IOException |
| 130 |
|
{ |
| 131 |
|
|
| 132 |
1 |
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 133 |
|
|
| 134 |
1 |
dbf.setIgnoringElementContentWhitespace(true); |
| 135 |
1 |
dbf.setIgnoringComments(true); |
| 136 |
1 |
dbf.setValidating(true); |
| 137 |
1 |
dbf.setCoalescing(true); |
| 138 |
1 |
dbf.setNamespaceAware(true); |
| 139 |
1 |
dbf.setFeature("http://xml.org/sax/features/namespaces", false); |
| 140 |
1 |
dbf.setFeature("http://xml.org/sax/features/validation", false); |
| 141 |
1 |
dbf.setFeature( |
| 142 |
|
"http://apache.org/xml/features/nonvalidating/load-dtd-grammar", |
| 143 |
|
false); |
| 144 |
1 |
dbf.setFeature( |
| 145 |
|
"http://apache.org/xml/features/nonvalidating/load-external-dtd", |
| 146 |
|
false); |
| 147 |
|
|
| 148 |
1 |
DocumentBuilder db = dbf.newDocumentBuilder(); |
| 149 |
|
|
| 150 |
1 |
Map<String, SequenceI> htSeq = new Hashtable<>(); |
| 151 |
1 |
InputSource is = new InputSource(getReader()); |
| 152 |
1 |
Document d = db.parse(is); |
| 153 |
1 |
NodeList sequences = d.getElementsByTagName("Sequence-data"); |
| 154 |
1 |
int n = sequences.getLength(); |
| 155 |
1 |
SequenceI[] sqs = new SequenceI[n]; |
| 156 |
2 |
for (int i = 0; i < n; i++) |
| 157 |
|
{ |
| 158 |
1 |
Element e = (Element) sequences.item(i); |
| 159 |
1 |
String s = e.getTextContent(); |
| 160 |
1 |
String id = e.getAttribute("seq-name"); |
| 161 |
1 |
SequenceI seq = sqs[i] = new Sequence(id, s, 1, s.length()); |
| 162 |
1 |
htSeq.put(id, seq); |
| 163 |
|
|
| 164 |
|
} |
| 165 |
|
|
| 166 |
1 |
sequences = d.getElementsByTagName("Sequence"); |
| 167 |
1 |
n = sequences.getLength(); |
| 168 |
2 |
for (int i = 0; i < n; i++) |
| 169 |
|
{ |
| 170 |
1 |
Element e = (Element) sequences.item(i); |
| 171 |
1 |
String mol = e.getAttribute("molecule"); |
| 172 |
1 |
if (!"dna".equals(mol)) |
| 173 |
|
{ |
| 174 |
0 |
System.err.println("BSML molecule=rna not implemented"); |
| 175 |
0 |
continue; |
| 176 |
|
} |
| 177 |
1 |
String title = e.getAttribute("title"); |
| 178 |
1 |
SequenceI seq = htSeq.get(title); |
| 179 |
1 |
if (seq == null) |
| 180 |
|
{ |
| 181 |
0 |
continue; |
| 182 |
|
} |
| 183 |
1 |
NodeList features = e.getElementsByTagName("Feature"); |
| 184 |
1 |
int featureCount = features.getLength(); |
| 185 |
2 |
for (int f = 0; f < featureCount; f++) |
| 186 |
|
{ |
| 187 |
1 |
Element feature = (Element) features.item(f); |
| 188 |
|
|
| 189 |
|
|
| 190 |
|
|
| 191 |
|
|
| 192 |
1 |
Element iloc = (Element) feature |
| 193 |
|
.getElementsByTagName("Interval-loc").item(0); |
| 194 |
1 |
String complement = iloc.getAttribute("complement"); |
| 195 |
1 |
if (!"0".equals(complement)) |
| 196 |
|
{ |
| 197 |
|
|
| 198 |
|
|
| 199 |
0 |
continue; |
| 200 |
|
} |
| 201 |
1 |
String fclass = feature.getAttribute("class"); |
| 202 |
1 |
if (!"GENE".equals(fclass)) |
| 203 |
|
{ |
| 204 |
|
|
| 205 |
0 |
continue; |
| 206 |
|
} |
| 207 |
1 |
String ftitle = feature.getAttribute("title"); |
| 208 |
1 |
int start = Integer.parseInt(iloc.getAttribute("startpos")); |
| 209 |
1 |
int end = Integer.parseInt(iloc.getAttribute("endpos")); |
| 210 |
1 |
SequenceFeature sf = new SequenceFeature("GENE", ftitle, start, end, |
| 211 |
|
null); |
| 212 |
1 |
seq.addSequenceFeature(sf); |
| 213 |
|
} |
| 214 |
1 |
setSeqs(sqs); |
| 215 |
|
} |
| 216 |
|
|
| 217 |
|
} |
| 218 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 219 |
0 |
@Override... |
| 220 |
|
public String print(SequenceI[] s, boolean jvSuffix) |
| 221 |
|
{ |
| 222 |
0 |
return "not yet implemented"; |
| 223 |
|
} |
| 224 |
|
|
| 225 |
|
} |