{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE BangPatterns #-}-- | Methods to transform a secondary structure containing pseudoknots into a-- structure which is pseudoknot-free.---- TODO Until a better name is found, this module is home to functions for-- "de-pseudoknotting" structures.---- TODO Check if there are corner-cases remaining when considering 2-diagrams.moduleBiobase.Secondary.PseudoKnotswhereimportqualifiedData.Vector.UnboxedasVUimportData.ListimportBiobase.Secondary-- | Try to removed pseudoknots from the "pairlist". This works by counting for-- each pair, how many pairs are incompatible with it. Then those with most-- incompatibilities are successively removed. This function might well remove-- more than necessary!classRemovePseudoKnotsawhereremoveByCounting::a->a-- | Remove pseudoknotted pairs from RNA secondary structures.instanceRemovePseudoKnots(VU.VectorPairIdx)whereremoveByCounting=VU.force.wrapRemovewherewrapRemove!ps|VU.nullcnts=ps-- there are no pairs|mmx==0=ps-- there are no incompatibilities|otherwise=wrapRemove$VU.takepospsVU.++VU.drop(pos+1)pswherecnts=VU.mapincomppsmmx=VU.maximumcntsJustpos=VU.elemIndexmmxcntsincomp(i,j)=VU.length$VU.filter(\(k,l)->i<k&&k<j&&j<l||k<i&&i<l&&l<j)psinstanceRemovePseudoKnots[PairIdx]whereremoveByCounting=VU.toList.removeByCounting.VU.fromList-- | Remove pseudoknotted pairs from extended RNA secondary structures.instanceRemovePseudoKnots(VU.VectorExtPairIdx)whereremoveByCounting=VU.force.wrapRemovewherewrapRemove!ps|VU.nullcnts=ps-- there are no pairs|mmx==0=ps-- there are no incompatibilities|otherwise=wrapRemove$VU.takepospsVU.++VU.drop(pos+1)pswherecnts=VU.mapincomppsmmx=VU.maximumcntsJustpos=VU.elemIndexmmxcntsincomp((i,j),_)=VU.length$VU.filter(\((k,l),_)->i<k&&k<j&&j<l||k<i&&i<l&&l<j)psinstanceRemovePseudoKnots[ExtPairIdx]whereremoveByCounting=VU.toList.removeByCounting.VU.fromList