diff --git a/BiobaseXNA.cabal b/BiobaseXNA.cabal
--- a/BiobaseXNA.cabal
+++ b/BiobaseXNA.cabal
@@ -1,5 +1,5 @@
 name:           BiobaseXNA
-version:        0.7.0.0
+version:        0.7.0.1
 author:         Christian Hoener zu Siederdissen
 maintainer:     choener@tbi.univie.ac.at
 homepage:       http://www.tbi.univie.ac.at/~choener/
@@ -72,6 +72,14 @@
 
   ghc-options:
     -O2 -funbox-strict-fields
+
+executable SubOptDistance
+  build-depends:
+    cmdargs >= 0.10
+  main-is:
+    SubOptDistance.hs
+  ghc-options:
+    -O2
 
 source-repository head
   type: git
diff --git a/SubOptDistance.hs b/SubOptDistance.hs
new file mode 100644
--- /dev/null
+++ b/SubOptDistance.hs
@@ -0,0 +1,52 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE NoMonomorphismRestriction #-}
+
+module Main where
+
+import System.Console.CmdArgs
+import Control.Arrow
+import Data.Char (isSpace)
+import Data.List
+import Data.Ord
+import Text.Printf
+
+import Biobase.Secondary.Diagrams
+import Biobase.Secondary
+
+
+
+data Options = Options
+  { structure :: String
+  , aq :: Bool
+  , qa :: Bool
+  } deriving (Show,Data,Typeable)
+
+options = Options
+  { structure = "" &= args
+  , aq = True &= help "perform target \\\\ query calculation"
+  , qa = True &= help "perform query \\\\ target calculation"
+  } &= help helpLines
+
+helpLines = unlines
+  [ "This program reads a bunch of RNAsubopt lines on STDIN. Provide an"
+  , "additional structure as the argument line. The result will be the"
+  , "sub-optimal line with lowest base pair distance to the query line."
+  ]
+
+main = do
+  Options{..} <- cmdArgs options
+  (sqn:xs') <- fmap lines $ getContents
+  let xs = map (\(s,e) -> (s,dotBracket ["()"] s,read e)) $ map (break isSpace) xs'
+  let q = dotBracket ["()"] structure
+  let (d,x,e) = getMinimalDistance aq qa q xs
+  let distance :: Double = e - ((/100) . read $ words sqn !! 1)
+  printf "%4d %s %8.2f %8.2f\n" d x e distance
+
+getMinimalDistance :: Bool -> Bool -> [PairIdx] -> [(String,[PairIdx],Double)] -> (Int,String,Double)
+getMinimalDistance aq qa q xs = g $ minimumBy (comparing f) xs where
+  g (a,b,c) = ( fst $ f (a,b,c) , a, c)
+  f (_,a,e) = (length $ aqs ++ qas , e) where
+    aqs = if aq then a \\ q else []
+    qas = if qa then q \\ a else []
