Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
atacseq_analysis
Manage
Activity
Members
Labels
Plan
Issues
7
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
BICF
Astrocyte
atacseq_analysis
Commits
3b063504
Commit
3b063504
authored
6 years ago
by
Venkat Malladi
Browse files
Options
Downloads
Patches
Plain Diff
Update converstion step.
parent
4d08d4ea
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
workflow/main.nf
+4
-4
4 additions, 4 deletions
workflow/main.nf
workflow/scripts/convert_reads.py
+63
-11
63 additions, 11 deletions
workflow/scripts/convert_reads.py
with
67 additions
and
15 deletions
workflow/main.nf
+
4
−
4
View file @
3b063504
...
...
@@ -214,7 +214,7 @@ process convertReads {
output:
set sampleId, file('*.tagAlign.gz'),
file('*.bed{pe,se}.gz'),
experimentId, biosample, factor, treatment, replicate into tagReads
set sampleId, file('*.tagAlign.gz'), experimentId, biosample, factor, treatment, replicate into tagReads
script:
...
...
@@ -263,7 +263,7 @@ process crossReads {
input:
set sampleId,
seTagAlign,
tagAlign, experimentId, biosample, factor, treatment, replicate from tagReads
set sampleId, tagAlign, experimentId, biosample, factor, treatment, replicate from tagReads
output:
...
...
@@ -274,12 +274,12 @@ process crossReads {
if (pairedEnd) {
"""
python3 $baseDir/scripts/xcor.py -t $
seT
agAlign -p
python3 $baseDir/scripts/xcor.py -t $
t
agAlign -p
"""
}
else {
"""
python3 $baseDir/scripts/xcor.py -t $
seT
agAlign
python3 $baseDir/scripts/xcor.py -t $
t
agAlign
"""
}
...
...
This diff is collapsed.
Click to expand it.
workflow/scripts/convert_reads.py
+
63
−
11
View file @
3b063504
...
...
@@ -40,6 +40,16 @@ def get_args():
default
=
False
,
action
=
'
store_true
'
)
parser
.
add_argument
(
'
-m
'
,
'
--chrm
'
,
help
=
"
True/False if to remove ChrM.
"
,
default
=
True
,
action
=
'
store_true
'
)
parser
.
add_argument
(
'
-t
'
,
'
--tn5
'
help
=
'
Enable TN5 shifting for ATAC-Seq.
'
default
=
True
,
action
=
'
store_true
'
)
args
=
parser
.
parse_args
()
return
args
...
...
@@ -66,16 +76,22 @@ def check_tools():
raise
Exception
(
'
Missing samtools
'
)
def
convert_mapped
(
bam
,
tag_filename
):
def
convert_mapped
(
bam
,
tag_filename
,
chrm
):
'''
Use bedtools to convert to tagAlign.
'''
out
,
err
=
utils
.
run_pipe
(
[
steps
=
[
"
bamToBed -i %s
"
%
(
bam
),
r
"""
awk
'
BEGIN{OFS=
"
\t
"
}{$4=
"
N
"
;$5=
"
1000
"
;print $0}
'"""
,
"
gzip -nc
"
],
outfile
=
tag_filename
)
r
"""
awk
'
BEGIN{OFS=
"
\t
"
}{$4=
"
N
"
;$5=
"
1000
"
;print $0}
'"""
]
if
chrm
:
steps
.
extend
[
"
grep -v
'
chrM
'"
]
steps
.
extend
[
"
gzip -nc
"
]
def
convert_mapped_pe
(
bam
,
bam_basename
):
out
,
err
=
utils
.
run_pipe
(
steps
,
outfile
=
tag_filename
)
def
convert_mapped_pe
(
bam
,
bam_basename
,
tag_filename
,
chrm
):
'''
Use bedtools to convert to tagAlign PE data.
'''
bedpe_filename
=
bam_basename
+
"
.bedpe.gz
"
...
...
@@ -89,15 +105,42 @@ def convert_mapped_pe(bam, bam_basename):
logger
.
info
(
samtools_sort_command
)
subprocess
.
check_output
(
shlex
.
split
(
samtools_sort_command
))
out
,
err
=
utils
.
run_pipe
([
"
bamToBed -bedpe -mate1 -i %s
"
%
(
nmsrt_bam_filename
),
"
gzip -nc
"
],
outfile
=
bedpe_filename
)
steps
=
[
"
bamToBed -bedpe -mate1 -i %s
"
%
(
nmsrt_bam_filename
)]
steps
.
extend
[
"
gzip -nc
"
]
out
,
err
=
utils
.
run_pipe
(
steps
,
outfile
=
bedpe_filename
)
os
.
remove
(
nmsrt_bam_filename
)
if
chrm
:
steps
.
extend
[
"
grep -v
'
chrM
'"
]
# Convert read pairs to reads into standard tagAlign file
tag_steps
=
[
"
zcat -f %s
"
%
(
bedpe_filename
)]
tag_steps
.
extend
([
r
"""
awk
'
BEGIN{OFS=
"
\t
"
}{printf
"
%s\t%s\t%s\tN\t1000\t%s\n%s\t%s\t%s\tN\t1000\t%s\n
"
,$1,$2,$3,$9,$4,$5,$6,$10}
'"""
])
if
chrm
:
tag_steps
.
extend
[
"
grep -v
'
chrM
'"
]
tag_steps
.
extend
([
'
gzip -cn
'
])
out
,
err
=
utils
.
run_pipe
(
tag_steps
,
outfile
=
tag_filename
)
os
.
remove
(
bedpe_filename
)
def
tn5_shift_tagalign
(
tag_filename
,
shitfted_tag_filename
):
'''
Shift tagalign file for Tn5.
'''
steps
=
[
"
zcat -f %s
"
%
(
tag_filename
),
r
"""
awk
'
BEGIN{OFS=
"
\t
"
}{{if ($6 ==
"
+
"
) {{$2 = $2 + 4}; else if ($6 ==
"
-
"
) {{$3 = $3 - 5}} print $0}}}
'"""
,
"
gzip -nc
"
]
out
,
err
=
utils
.
run_pipe
(
steps
,
outfile
=
shitfted_tag_filename
)
def
main
():
args
=
get_args
()
paired
=
args
.
paired
bam
=
args
.
bam
chrm
=
args
.
chrm
tn5
=
args
.
tn5
# Create a file handler
handler
=
logging
.
FileHandler
(
'
convert_reads.log
'
)
...
...
@@ -111,14 +154,23 @@ def main():
utils
.
strip_extensions
(
bam
,
[
'
.bam
'
]))
tag_filename
=
bam_basename
+
'
.tagAlign.gz
'
convert_mapped
(
bam
,
tag_filename
)
shitfted_tag_filename
=
bam_basename
+
"
.tn5.tagAlign.gz
"
if
paired
:
# paired-end data
convert_mapped_pe
(
bam
,
bam_basename
)
else
:
bedse_filename
=
bam_basename
+
"
.bedse.gz
"
shutil
.
copy
(
tag_filename
,
bedse_filename
)
convert_mapped
(
bam
,
tag_filename
)
if
tn5
:
logger
.
info
(
"
TN5-shifting TAGALIGN...
"
)
tn5_shift_ta
(
tag_filename
,
shitfted_tag_filename
)
else
:
tn5_shift
=
[
"
cp %s %s
"
%
(
tag_filename
,
shitfted_tag_filename
)]
out
,
err
=
utils
.
run_pipe
(
tn5_shift
)
os
.
remove
(
tag_filename
)
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
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