Skip to content
Snippets Groups Projects
Commit 63c08d18 authored by Alice Brenon's avatar Alice Brenon
Browse files

Add script to make output from TXM useable

parent 34835a05
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env -S runhaskell --ghc-arg="-Wall" --ghc-arg="-i lib"
{-# LANGUAGE OverloadedStrings #-}
import Data.Text as Text
( Text, cons, drop, dropEnd, intercalate, isPrefixOf, length, lines, replace
, snoc, splitOn )
import Data.Text.IO as Text (getLine, interact, putStrLn)
import System.Exit (die)
data ColumnSelector = ColumnSelector
{ position :: Int
, name :: Text } deriving Show
newtype Header = Header [ColumnSelector] deriving Show
getColumns :: Text -> [Text]
getColumns = splitOn "\t"
getHeader :: [Text] -> IO Header
getHeader [] = die "no columns"
getHeader (first:otherColumns) = pure $
Header (ColumnSelector 0 first:foldr keepScores [] (zip [1..] otherColumns))
where
keepScores (position, name) tmp
| score `isPrefixOf` name =
ColumnSelector
{ position
, name = Text.drop (Text.length score) $ dropEnd 1 name }
: tmp
| otherwise = tmp
score = "score_:"
toTsv :: [Text] -> Text
toTsv [] = ""
toTsv (first:otherColumns) = intercalate "\t" (escape first:otherColumns)
where
escape s = '"' `cons` replace "\"" "\"\"" s `snoc` '"'
filterLine :: [Int] -> Text -> Text
filterLine positions = toTsv . extract . getColumns
where
extract columns = (columns !!) <$> positions
main :: IO ()
main = do
Header header <- getHeader.getColumns =<< Text.getLine
Text.putStrLn . toTsv $ name <$> header
Text.interact
(textUnlines . map (filterLine $ position <$> header) . Text.lines)
where
textUnlines = Text.intercalate "\n"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment