Skip to content
Snippets Groups Projects
Select Git revision
  • f09a3cf4e46d8497428f78783ec3e463d2da5397
  • main default protected
  • ugly
  • ml-training
  • the-amazing-obj-refactoring
5 results

select.hs

Blame
  • select.hs 983 B
    #!/usr/bin/env -S runhaskell --ghc-arg="-Wall" --ghc-arg="-i lib"
    {-# LANGUAGE ExplicitNamespaces, OverloadedStrings #-}
    module Main where
    
    import Control.Monad.Except (ExceptT(..), runExceptT)
    import Data.Map ((!?))
    import Data.Maybe (catMaybes)
    import Data.Vector (Vector, toList)
    import GEODE.Metadata (Entry, Has(..), PrimaryKey, type(@), indexBy, readNamedTsv, tsvFile)
    import System.Environment (getArgs)
    import System.Exit (die)
    import System.Script (syntax)
    
    getMeta :: Vector PrimaryKey -> Vector (PrimaryKey @ Entry) -> [(PrimaryKey @ Entry)]
    getMeta coords meta = catMaybes ((indexed !?) <$> toList coords)
      where
        indexed = indexBy get meta
    
    main :: IO ()
    main = getArgs >>= run
      where
        run [keys, input, output] =
          runExceptT ( getMeta
                        <$> ExceptT (readNamedTsv keys)
                        <*> ExceptT (readNamedTsv input) )
          >>= either die (tsvFile output)
        run _ = syntax "PRIMARY_KEY.tsv INPUT_METADATA.tsv OUTPUT_METADATA.tsv"