| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.io.packed; |
| 22 |
|
|
| 23 |
|
import java.io.BufferedReader; |
| 24 |
|
import java.io.IOException; |
| 25 |
|
import java.util.ArrayList; |
| 26 |
|
import java.util.HashMap; |
| 27 |
|
import java.util.List; |
| 28 |
|
import java.util.Locale; |
| 29 |
|
|
| 30 |
|
import jalview.datamodel.AlignmentI; |
| 31 |
|
import jalview.io.AppletFormatAdapter; |
| 32 |
|
import jalview.io.FileFormatI; |
| 33 |
|
import jalview.io.FileParse; |
| 34 |
|
import jalview.io.FormatAdapter; |
| 35 |
|
import jalview.io.IdentifyFile; |
| 36 |
|
import jalview.io.packed.DataProvider.JvDataType; |
| 37 |
|
|
| |
|
| 0% |
Uncovered Elements: 157 (157) |
Complexity: 36 |
Complexity Density: 0.34 |
|
| 38 |
|
public class ParsePackedSet |
| 39 |
|
{ |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
@param |
| 46 |
|
|
| 47 |
|
@param |
| 48 |
|
|
| 49 |
|
@return |
| 50 |
|
@throws |
| 51 |
|
|
| |
|
| 0% |
Uncovered Elements: 109 (109) |
Complexity: 27 |
Complexity Density: 0.38 |
|
| 52 |
0 |
public Object[] getAlignment(JalviewDataset context,... |
| 53 |
|
Iterable<DataProvider> files) throws Exception |
| 54 |
|
{ |
| 55 |
0 |
List<Object> rslt = new ArrayList<>(); |
| 56 |
0 |
if (context == null) |
| 57 |
|
{ |
| 58 |
0 |
context = new JalviewDataset(); |
| 59 |
|
} |
| 60 |
0 |
boolean deuniquify = false; |
| 61 |
0 |
for (DataProvider dta : files) |
| 62 |
|
{ |
| 63 |
0 |
Exception exerror = null; |
| 64 |
0 |
String errmsg = null; |
| 65 |
0 |
FileParse src = dta.getDataSource(); |
| 66 |
0 |
if (dta.getType().equals(DataProvider.JvDataType.ALIGNMENT)) |
| 67 |
|
{ |
| 68 |
0 |
FileFormatI fmt = null; |
| 69 |
0 |
try |
| 70 |
|
{ |
| 71 |
0 |
fmt = new IdentifyFile().identify(src, false, false); |
| 72 |
|
} catch (Exception ex) |
| 73 |
|
{ |
| 74 |
0 |
exerror = ex; |
| 75 |
0 |
errmsg = "Couldn't identify alignment format."; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
0 |
if (fmt != null) |
| 79 |
|
{ |
| 80 |
|
|
| 81 |
0 |
AlignmentI al = null; |
| 82 |
0 |
try |
| 83 |
|
{ |
| 84 |
0 |
al = new FormatAdapter().readFromFile(src, fmt); |
| 85 |
|
} catch (Exception e) |
| 86 |
|
{ |
| 87 |
0 |
errmsg = "Failed to parse alignment from result set"; |
| 88 |
0 |
exerror = e; |
| 89 |
|
} |
| 90 |
0 |
if (al != null) |
| 91 |
|
{ |
| 92 |
|
|
| 93 |
|
|
| 94 |
0 |
context.addAlignment(al); |
| 95 |
0 |
context.updateSetModified(true); |
| 96 |
0 |
rslt.add(al); |
| 97 |
0 |
deuniquify = true; |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
|
} |
| 101 |
0 |
if (dta.getType().equals(JvDataType.ANNOTATION)) |
| 102 |
|
{ |
| 103 |
0 |
if (!context.hasAlignments()) |
| 104 |
|
{ |
| 105 |
0 |
errmsg = "No alignment or sequence dataset to associate annotation with."; |
| 106 |
|
|
| 107 |
|
|
| 108 |
|
} |
| 109 |
0 |
try |
| 110 |
|
{ |
| 111 |
0 |
BufferedReader br; |
| 112 |
0 |
if (src.getReader() instanceof BufferedReader) |
| 113 |
|
{ |
| 114 |
0 |
br = (BufferedReader) src.getReader(); |
| 115 |
|
} |
| 116 |
|
else |
| 117 |
|
{ |
| 118 |
0 |
br = new BufferedReader(src.getReader()); |
| 119 |
|
} |
| 120 |
|
|
| 121 |
0 |
if (new jalview.io.AnnotationFile().parseAnnotationFrom( |
| 122 |
|
context.getLastAlignment(), null, br)) |
| 123 |
|
{ |
| 124 |
0 |
context.updateSetModified(true); |
| 125 |
|
} |
| 126 |
|
else |
| 127 |
|
{ |
| 128 |
0 |
errmsg = "Annotation file contained no data."; |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
} catch (Exception e) |
| 132 |
|
{ |
| 133 |
0 |
errmsg = ((errmsg == null) ? "" : errmsg) |
| 134 |
|
+ "Failed to parse the annotation file associated with the alignment."; |
| 135 |
0 |
exerror = e; |
| 136 |
|
} |
| 137 |
|
} |
| 138 |
0 |
if (dta.getType().equals(JvDataType.SEQASSOCATED)) |
| 139 |
|
{ |
| 140 |
0 |
if (!context.hasSequenceAssoc()) |
| 141 |
|
{ |
| 142 |
0 |
errmsg = "No sequence to associate data with."; |
| 143 |
|
|
| 144 |
|
} |
| 145 |
0 |
errmsg = "parsing of sequence associated data is not implemented"; |
| 146 |
0 |
exerror = new Exception(errmsg); |
| 147 |
|
} |
| 148 |
0 |
if (dta.getType().equals(JvDataType.FEATURES)) |
| 149 |
|
{ |
| 150 |
|
|
| 151 |
|
|
| 152 |
0 |
if (context.featureColours == null) |
| 153 |
|
{ |
| 154 |
0 |
context.featureColours = new HashMap<>(); |
| 155 |
|
} |
| 156 |
0 |
try |
| 157 |
|
{ |
| 158 |
0 |
jalview.io.FeaturesFile ff = new jalview.io.FeaturesFile(src); |
| 159 |
0 |
context.updateSetModified(ff.parse(context.getLastAlignment(), |
| 160 |
|
context.featureColours, false, |
| 161 |
|
context.relaxedIdMatching)); |
| 162 |
|
} catch (Exception e) |
| 163 |
|
{ |
| 164 |
0 |
errmsg = ("Failed to parse the Features file associated with the alignment."); |
| 165 |
0 |
exerror = e; |
| 166 |
|
} |
| 167 |
|
} |
| 168 |
0 |
if (dta.getType().equals(JvDataType.TREE)) |
| 169 |
|
{ |
| 170 |
0 |
try |
| 171 |
|
{ |
| 172 |
0 |
jalview.io.NewickFile nf = new jalview.io.NewickFile(src); |
| 173 |
0 |
if (!nf.isValid()) |
| 174 |
|
{ |
| 175 |
0 |
nf.close(); |
| 176 |
0 |
nf = null; |
| 177 |
|
} |
| 178 |
|
else |
| 179 |
|
{ |
| 180 |
|
|
| 181 |
|
|
| 182 |
0 |
context.addTreeFromFile(nf); |
| 183 |
0 |
rslt.add(nf); |
| 184 |
0 |
context.updateSetModified(true); |
| 185 |
|
} |
| 186 |
|
} catch (Exception e) |
| 187 |
|
{ |
| 188 |
0 |
errmsg = ("Failed to parse the treeFile associated with the result."); |
| 189 |
0 |
exerror = e; |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
} |
| 193 |
0 |
if (exerror != null) |
| 194 |
|
{ |
| 195 |
0 |
if (errmsg != null && errmsg.length() > 0) |
| 196 |
|
{ |
| 197 |
0 |
throw new IOException(errmsg, exerror); |
| 198 |
|
} |
| 199 |
|
else |
| 200 |
|
{ |
| 201 |
0 |
throw new IOException(errmsg, exerror); |
| 202 |
|
} |
| 203 |
|
} |
| 204 |
|
else |
| 205 |
|
{ |
| 206 |
0 |
if (errmsg != null && errmsg.length() > 0) |
| 207 |
|
{ |
| 208 |
0 |
throw new IOException(errmsg); |
| 209 |
|
} |
| 210 |
|
} |
| 211 |
|
} |
| 212 |
0 |
if (deuniquify) |
| 213 |
|
{ |
| 214 |
0 |
context.getLastAlignmentSet().deuniquifyAlignment(); |
| 215 |
|
} |
| 216 |
0 |
return rslt.toArray(); |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
|
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
|
|
| 224 |
|
|
| 225 |
|
@param |
| 226 |
|
|
| 227 |
|
|
| |
|
| 0% |
Uncovered Elements: 46 (46) |
Complexity: 9 |
Complexity Density: 0.26 |
|
| 228 |
0 |
public static void main(String args[])... |
| 229 |
|
{ |
| 230 |
|
|
| 231 |
0 |
int i = 0; |
| 232 |
0 |
List<DataProvider> dp = new ArrayList<>(); |
| 233 |
0 |
while ((i + 1) < args.length) |
| 234 |
|
{ |
| 235 |
0 |
String type = args[i++]; |
| 236 |
0 |
final String file = args[i++]; |
| 237 |
0 |
final JvDataType jtype = DataProvider.JvDataType |
| 238 |
|
.valueOf(type.toUpperCase(Locale.ROOT)); |
| 239 |
0 |
if (jtype != null) |
| 240 |
|
{ |
| 241 |
0 |
final FileParse fp; |
| 242 |
0 |
try |
| 243 |
|
{ |
| 244 |
0 |
fp = new FileParse(file, AppletFormatAdapter.checkProtocol(file)); |
| 245 |
|
} catch (Exception e) |
| 246 |
|
{ |
| 247 |
0 |
jalview.bin.Console |
| 248 |
|
.errPrintln("Couldn't handle datasource of type " + jtype |
| 249 |
|
+ " using URI " + file); |
| 250 |
0 |
e.printStackTrace(); |
| 251 |
0 |
return; |
| 252 |
|
} |
| 253 |
0 |
dp.add(new SimpleDataProvider(jtype, fp, null)); |
| 254 |
|
} |
| 255 |
|
else |
| 256 |
|
{ |
| 257 |
0 |
jalview.bin.Console.outPrintln("Couldn't parse source type token '" |
| 258 |
|
+ type.toUpperCase(Locale.ROOT) + "'"); |
| 259 |
|
} |
| 260 |
|
} |
| 261 |
0 |
if (i < args.length) |
| 262 |
|
{ |
| 263 |
0 |
System.out.print("** WARNING\nIgnoring unused arguments:\n"); |
| 264 |
0 |
while (i < args.length) |
| 265 |
|
{ |
| 266 |
0 |
System.out.print(" " + args[i]); |
| 267 |
|
} |
| 268 |
0 |
System.out.print("\n"); |
| 269 |
|
|
| 270 |
|
} |
| 271 |
0 |
jalview.bin.Console.outPrintln("Now trying to parse set:"); |
| 272 |
0 |
JalviewDataset context; |
| 273 |
0 |
Object[] newdm; |
| 274 |
0 |
ParsePackedSet pps; |
| 275 |
0 |
try |
| 276 |
|
{ |
| 277 |
0 |
newdm = (pps = new ParsePackedSet()) |
| 278 |
|
.getAlignment(context = new JalviewDataset(), dp); |
| 279 |
|
} catch (Exception e) |
| 280 |
|
{ |
| 281 |
0 |
jalview.bin.Console.outPrintln("Test failed for these arguments.\n"); |
| 282 |
0 |
e.printStackTrace(System.out); |
| 283 |
0 |
return; |
| 284 |
|
} |
| 285 |
0 |
if (newdm != null) |
| 286 |
|
{ |
| 287 |
0 |
for (Object o : newdm) |
| 288 |
|
{ |
| 289 |
0 |
jalview.bin.Console |
| 290 |
|
.outPrintln("Will need to create an " + o.getClass()); |
| 291 |
|
} |
| 292 |
|
|
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| 296 |
|
|
| 297 |
|
|
| 298 |
|
} |
| 299 |
|
else |
| 300 |
|
{ |
| 301 |
0 |
if (context.getLastAlignmentSet().isModified()) |
| 302 |
|
{ |
| 303 |
0 |
jalview.bin.Console.errPrintln( |
| 304 |
|
"Initial alignment set was modified and any associated views should be updated."); |
| 305 |
|
} |
| 306 |
|
} |
| 307 |
|
} |
| 308 |
|
} |