use of gov.nih.nlm.ncbi.blast.HitHsps in project jvarkit by lindenb.
the class MergeSplittedBlast method merge.
private Hit merge(List<Hit> hits) {
Hit first = hits.get(0);
Split firstSplit = parse(first);
Hit newHit = new Hit();
newHit.setHitAccession(first.getHitAccession());
newHit.setHitDef(firstSplit.chrom);
newHit.setHitId(first.getHitId());
newHit.setHitNum(first.getHitNum());
newHit.setHitLen(String.valueOf(firstSplit.len));
newHit.setHitHsps(new HitHsps());
List<Hsp> hsps = new ArrayList<Hsp>();
for (Hit h0 : hits) {
/* fix hit_from/hit_to */
Split split = parse(h0);
List<Hsp> L = h0.getHitHsps().getHsp();
for (int i = 0; i < L.size(); ++i) {
Hsp newHsp = BlastHspAlignment.cloneHsp(L.get(i));
BlastHspAlignment aln = new BlastHspAlignment(newHsp);
int h_from = aln.getHitFrom1();
int h_to = aln.getHitTo1();
h_from += (split.start1 - 1);
h_to += (split.start1 - 1);
newHsp.setHspHitFrom(String.valueOf(h_from));
newHsp.setHspHitTo(String.valueOf(h_to));
hsps.add(newHsp);
}
}
boolean done = false;
while (!done) {
done = true;
for (int i = 0; i + 1 < hsps.size(); ++i) {
Hsp hsp0 = hsps.get(i);
for (int j = i + 1; j < hsps.size(); ++j) {
// debug("comparing hsp "+i+" vs "+j+" N="+hsps.size());
Hsp hsp1 = hsps.get(j);
Hsp newHitHsp = merge(hsp0, hsp1);
if (newHitHsp != null) {
hsps.set(i, newHitHsp);
hsps.remove(j);
done = false;
break;
}
}
if (!done)
break;
}
}
for (int i = 0; i < hsps.size(); ++i) hsps.get(i).setHspNum(String.valueOf(i + 1));
newHit.getHitHsps().getHsp().addAll(hsps);
return newHit;
}
Aggregations