Commit ffa792b8 authored by Blaise Li's avatar Blaise Li
Browse files

Added missing Haskell program.

parent a1cd92a6
import Distribution.Simple
main = defaultMain
#!/bin/bash -l
# http://linuxcommand.org/wss0150.php
PROGNAME=$(basename $0)
function error_exit
{
# ----------------------------------------------------------------
# Function for exit due to fatal program error
# Accepts 1 argument:
# string containing descriptive error message
# ----------------------------------------------------------------
echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
exit 1
}
function try_load_gmp_module
{
(module --version 2> /dev/null && module load gmp) || :
}
if [ $(id -u) = 0 ]
then
# We don't want things to be installed in root's home directory.
install="install --local-bin-path /usr/local/bin"
else
install="install"
fi
config_file="${HOME}/.stack/config.yaml"
stack --version 2> /dev/null \
|| (echo "loading stack" && module load stack/1.4.0)
if [ "${config_file}" ]
then
stack exec -- ghc --version > /dev/null \
|| (try_load_gmp_module \
&& stack setup \
&& INCLUDE_PATH=$(echo ${CMAKE_INCLUDE_PATH} | tr ":" ",") \
&& LIBRARY_PATH=$(echo ${CMAKE_LIBRARY_PATH} | tr ":" ",") \
&& include_config="extra-include-dirs: [${INCLUDE_PATH}]" \
&& libdir_config="extra-lib-dirs: [${LIBRARY_PATH}]" \
&& echo "" >> ${config_file} \
&& echo ${include_config} >> ${config_file} \
&& echo ${libdir_config} >> ${config_file}) \
|| error_exit "stack setup failed"
make_stack_options () {
stack_options=""
}
else
stack exec -- ghc --version > /dev/null \
|| (try_load_gmp_module && stack setup) \
|| error_exit "stack setup failed"
# https://unix.stackexchange.com/a/60690/55127
# Delay variable evaluation in order to adapt to loaded libraries
make_stack_options () {
INCLUDE_PATH=$(echo ${CMAKE_INCLUDE_PATH} | tr ":" ",") \
LIBRARY_PATH=$(echo ${CMAKE_LIBRARY_PATH} | tr ":" ",") \
stack_options="--extra-include-dirs=${INCLUDE_PATH} --extra-lib-dirs=${LIBRARY_PATH}"
}
fi
# cd ${HOME} to ignore local project stack config
hlint --version 2> /dev/null \
|| (try_load_gmp_module && (cd ${HOME} && make_stack_options && stack ${stack_options} ${install} hlint)) \
|| error_exit "hlint install failed"
scan --version 2> /dev/null \
|| (try_load_gmp_module && (cd ${HOME} && make_stack_options && stack ${stack_options} ${install} scan)) \
|| error_exit "scan install failed"
doctest --version 2> /dev/null \
|| (try_load_gmp_module && (cd ${HOME} && make_stack_options && stack ${stack_options} ${install} doctest)) \
|| error_exit "doctest install failed"
make_stack_options
stack ${stack_options} build --exec "hlint src/Main.hs" --exec "scan -j False src/Main.hs" --exec "doctest src/Main.hs"
stack ${install}
{-# LANGUAGE OverloadedStrings #-}
module Main where
-- For more efficient text manipulation
-- import qualified Data.ByteString.Lazy.Char8 as C
import qualified Data.ByteString.Char8 as C
-- Type synonyms for fields in a fastq record
type Name = C.ByteString
type Nucleotides = C.ByteString
type Qualities = C.ByteString
-- New type for a fastq record
data Fastq = Fastq Name Nucleotides Qualities
-- Turn a fastq record into text.
formatFastq :: Fastq -> C.ByteString
formatFastq (Fastq n s q) =
C.unlines [n, s, "+", q]
{-
Parse lines four by four, ignoring the third with "_".
We use pattern-matching and recursion to achieve this.
-}
getFastqs :: [C.ByteString] -> [Fastq]
getFastqs [] = []
getFastqs (l1 : l2 : _ : l4 : ls) =
Fastq l1 l2 l4 : getFastqs ls
trimTtails :: [Fastq] -> [Fastq]
trimTtails [] = []
trimTtails (Fastq n s q : fs) =
let (s', q') = zipTrim s q
in Fastq n s' q' : trimTtails fs
zipTrim :: Nucleotides -> Qualities -> (Nucleotides, Qualities)
{-
We don't check that the qualities have the same length
as the sequences, but they should.
-}
zipTrim s q
| C.null s = (C.empty, C.empty)
| C.head (last $ C.group s) == 'T' =
C.unzip (C.zip (C.concat $ init $ C.group s) q)
| otherwise = (s, q)
-- Compose functions into a "pipeline".
processLines :: [C.ByteString] -> [C.ByteString]
processLines =
map formatFastq . trimTtails . getFastqs
{-
C.lines decomposes the text into lines which are
processed by processLines to remove duplicates.
C.concat "flattens" the resulting list of
text-formatted fastq records into a single text.
C.interact deals with the IO interaction, i.e. taking
text from the outside world and returning text to it.
-}
main :: IO ()
main = C.interact (C.concat . processLines . C.lines)
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# http://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-7.1
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps: []
# Override default flag values for local packages and extra-deps
flags: {}
# Extra package databases containing global packages
extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.2"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
ghc-options:
"*": -O -Wall
rebuild-ghc-options:
true
name: trim-t-tail-from-fastq
version: 0.1.0.0
synopsis: Simple project template from stack
description: Please see README.md
homepage: https://github.com/blaiseli/trim-t-tail-from-fastq#readme
license: BSD3
license-file: LICENSE
author: Blaise Li
maintainer: blaise.li@normalesup.org
copyright: (CC-BY-SA) Blaise Li
category: Bioinformatics
build-type: Simple
cabal-version: >=1.10
executable trim-t-tail-from-fastq
hs-source-dirs: src
main-is: Main.hs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5, bytestring
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment