Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bioinfo_utils
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Blaise LI
bioinfo_utils
Commits
234a0676
Commit
234a0676
authored
4 years ago
by
Blaise Li
Browse files
Options
Downloads
Plain Diff
Add 'gtf2bed/' from commit '
1059f83a
'
git-subtree-dir: gtf2bed git-subtree-mainline:
0f82a98e
git-subtree-split:
1059f83a
parents
0f82a98e
1059f83a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
gtf2bed/ensembl_gtf2bed.hs
+45
-0
45 additions, 0 deletions
gtf2bed/ensembl_gtf2bed.hs
with
45 additions
and
0 deletions
gtf2bed/ensembl_gtf2bed.hs
0 → 100644
+
45
−
0
View file @
234a0676
-- import System.Environment (getArgs)
-- https://mail.haskell.org/pipermail/beginners/2011-October/008787.html
-- import Data.List.Utils (join, split)
-- import qualified Data.Text.Lazy as T
-- faster than Lazy
-- import qualified Data.Text as T
import
qualified
Data.ByteString.Lazy.Char8
as
C
-- import Numeric (readDec)
-- fastRead :: T.Text -> Int
-- fastRead t = case readDec (T.unpack t) of
-- [(n, "")] -> n
fastRead
::
C
.
ByteString
->
Int
fastRead
t
=
let
Just
(
n
,
_
)
=
C
.
readInt
t
in
n
splitFields
::
C
.
ByteString
->
[
C
.
ByteString
]
splitFields
=
C
.
split
'
\t
'
splitAnnots
::
C
.
ByteString
->
[
C
.
ByteString
]
-- C.init is to avoid the last ";"
-- C.dropWhile (== ' ') is to skip the spaces that followed the ';'
splitAnnots
=
map
(
C
.
dropWhile
(
==
' '
))
.
C
.
split
';'
.
C
.
init
splitAnnot
::
C
.
ByteString
->
(
C
.
ByteString
,
C
.
ByteString
)
splitAnnot
t
=
(
k
,
v
)
where
[
k
,
v
]
=
C
.
split
' '
t
notGeneId
::
(
C
.
ByteString
,
C
.
ByteString
)
->
Bool
notGeneId
p
=
fst
p
/=
C
.
pack
"gene_id"
joinFields
::
[
C
.
ByteString
]
->
C
.
ByteString
joinFields
=
C
.
intercalate
(
C
.
pack
"
\t
"
)
processLine
::
C
.
ByteString
->
C
.
ByteString
processLine
l
=
bedline
where
bedline
=
joinFields
[
chrom
,
bedStart
,
end
,
geneId
,
score
,
strand
]
bedStart
=
C
.
pack
$
show
((
fastRead
start
::
Int
)
-
1
)
geneId
=
C
.
init
.
C
.
tail
.
snd
.
head
.
dropWhile
notGeneId
$
annots
annots
=
map
splitAnnot
(
splitAnnots
annotField
)
(
chrom
:
_
:
_
:
start
:
end
:
score
:
strand
:
_
:
annotField
:
_
)
=
splitFields
l
main
::
IO
()
-- Main processing done as String to limit memory usage by strict Text
main
=
C
.
interact
(
C
.
unlines
.
map
processLine
.
C
.
lines
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment