phac-nml / mob-suite

MOB-suite: Software tools for clustering, reconstruction and typing of plasmids from draft assemblies
Apache License 2.0
111 stars 31 forks source link

Results depend on the ordering of the input fasta #160

Closed jchorl closed 1 month ago

jchorl commented 3 months ago

Thanks for the great tool!

https://github.com/phac-nml/mob-suite/pull/159 addresses unstable ordering when sorting contig-link counts.

When assigning contigs to clusters, it feels the priority should be correctness, and then stability. One option is to always sort the fasta before processing begins. While that would provide stability across different-ordered-fastas, it doesn't necessarily provide correctness (what's to say whether ascending or descending sort would yield more correct results). Therefore it seems that for each method of assigning contigs to clusters, the correct ordering might be subtly different. For low linkage contigs, I think it makes sense to prioritize lower link count and use cluster score as a tie-breaker.

In the case of assigning based on high-confidence references, there can also be ties for the reference scores, which can impact cluster assignment. Here are some example reference scores:

             ('JX627737', 103233.0),                                                                                           
             ('NC_019424', 103233.0),
...
             ('JX981514', 52572.0),                            
             ('NC_022105', 52572.0),       
             ('CP011290', 52532.0), 
             ('CP011293', 52532.0),

assign_contigs_to_clusters is fairly complex, assigning contigs to clusters based on many different criteria. I'm curious if you've given thought to make assignment correct/stable, regardless of the order of the input fasta. Happy to help here!

kbessonov1984 commented 1 month ago

Hello, I am currently working on this issue and contig ordering in the input fasta file has indeed impact on final results such as different number of contigs assigned to the same cluster as the contig assignment to plasmid clusters is iterative and order of contigs matters. The simplest solution is indeed resolve ties by an alphabetical ordering but this rather a simplistic solution but would not necessarily capitalize on optimal (i.e. "correctness") of the final reconstructed plasmid. Instead we are testing now trying to order input contigs by lengths (from longest to shortest) before contig assignment to clusters. Sorry for delay as I was on vacation and it took some time to figure out the assign_contigs_to_clusters logic and write unit test functions for testing and debugging.