| 1 |
package bin; |
| 2 |
|
| 3 |
import json.JsonObject; |
| 4 |
import shared.LineParserS2; |
| 5 |
import structures.ByteBuilder; |
| 6 |
|
| 7 |
public class SketchRecord extends BinObject { |
| 8 |
|
| 9 |
public SketchRecord(JsonObject hit) { |
| 10 |
setFrom(hit); |
| 11 |
} |
| 12 |
|
| 13 |
public void setFrom(JsonObject hit) { |
| 14 |
matches=hit.getLong("Matches").intValue(); |
| 15 |
ani=hit.getDouble("ANI").floatValue(); |
| 16 |
completeness=hit.getDouble("Complt").floatValue(); |
| 17 |
contam=hit.getDouble("Contam").floatValue(); |
| 18 |
taxid=hit.getLong("TaxID").intValue(); |
| 19 |
taxName=hit.getString("taxName"); |
| 20 |
genusTaxid=-1; |
| 21 |
} |
| 22 |
|
| 23 |
public ByteBuilder toBytes() { |
| 24 |
ByteBuilder bb=new ByteBuilder(); |
| 25 |
return appendTo(bb); |
| 26 |
} |
| 27 |
|
| 28 |
public ByteBuilder appendTo(ByteBuilder bb) { |
| 29 |
bb.append("ANI: ").append(ani, 2); |
| 30 |
bb.tab().append("Complt: ").append(completeness, 2); |
| 31 |
bb.tab().append("Contam: ").append(contam, 2); |
| 32 |
bb.tab().append("Matches: ").append(matches); |
| 33 |
bb.tab().append("TaxID: ").append(taxid); |
| 34 |
bb.tab().append("Name: ").append(shrink(taxName)); |
| 35 |
return bb; |
| 36 |
} |
| 37 |
|
| 38 |
private static String shrink(String n) { |
| 39 |
if(n==null || n.length()<40) {return n;} |
| 40 |
ByteBuilder bb=new ByteBuilder(); |
| 41 |
LineParserS2 lp=new LineParserS2(' '); |
| 42 |
lp.set(n); |
| 43 |
for(int i=0; i<4 && lp.hasMore(); i++) { |
| 44 |
if(bb.length>0) {bb.space();} |
| 45 |
bb.append(lp.parseString()); |
| 46 |
} |
| 47 |
if(lp.hasMore()) {bb.append("...");} |
| 48 |
return (bb.length()<n.length() ? bb.toString() : n); |
| 49 |
} |
| 50 |
|
| 51 |
int matches=-1; |
| 52 |
float completeness=-1; |
| 53 |
float contam=-1; |
| 54 |
float ani=-1; |
| 55 |
int taxid=-1; |
| 56 |
int genusTaxid=-1; |
| 57 |
String taxName=null; |
| 58 |
|
| 59 |
} |