- public static void replaceMatchingSeqsWith(List<SequenceI> seqs, List<AlignmentAnnotation> annotations, List<SequenceI> ochains,
- AlignmentI al, String dnaOrProtein, boolean removeOldAnnots)
- {
- if (al != null && al.getHeight() > 0)
- {
- ArrayList<SequenceI> matches = new ArrayList<SequenceI>();
- ArrayList<AlignSeq> aligns = new ArrayList<AlignSeq>();
-
- for (SequenceI sq : ochains)
- {
- SequenceI bestm = null;
- AlignSeq bestaseq = null;
- int bestscore = 0;
- for (SequenceI msq : al.getSequences())
- {
- AlignSeq aseq = AlignSeq.doGlobalNWAlignment(msq, sq,
- dnaOrProtein);
- if (bestm == null || aseq.getMaxScore() > bestscore)
- {
- bestscore = aseq.getMaxScore();
- bestaseq = aseq;
- bestm = msq;
- }
- }
- System.out.println("Best Score for " + (matches.size() + 1) + " :"
- + bestscore);
- matches.add(bestm);
- aligns.add(bestaseq);
- al.deleteSequence(bestm);
- }
- for (int p = 0, pSize = seqs.size(); p < pSize; p++)
- {
- SequenceI sq, sp = seqs.get(p);
- int q;
- if ((q = ochains.indexOf(sp)) > -1)
- {
- seqs.set(p, sq = matches.get(q));
- sq.setName(sp.getName());
- sq.setDescription(sp.getDescription());
- Mapping sp2sq;
- sq.transferAnnotation(sp, sp2sq = aligns.get(q).getMappingFromS1(false));
- int inspos = -1;
- for (int ap = 0; ap < annotations.size();)
- {
- if (annotations.get(ap).sequenceRef == sp)
- {
- if (inspos == -1)
- {
- inspos = ap;
- }
- if (removeOldAnnots) {
- annotations.remove(ap);
- } else {
- AlignmentAnnotation alan = annotations.get(ap);
- alan.liftOver(sq, sp2sq);
- alan.setSequenceRef(sq);
- }
- }
- else
- {
- ap++;
- }
- }
- if (sq.getAnnotation() != null)
- {
- annotations.addAll(inspos, Arrays.asList(sq.getAnnotation()));
- }
- }
- }
- }
- }