-
Notifications
You must be signed in to change notification settings - Fork 10
/
pipeline_mapping.py
2242 lines (1754 loc) · 64.4 KB
/
pipeline_mapping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""=====================
Read mapping pipeline
=====================
The read mapping pipeline imports unmapped reads from one or more
NGS experiments and maps reads against a reference genome.
This pipeline works on a single genome.
Overview
========
The pipeline implements various mappers. It can be used for
* Mapping against a genome
* Mapping RNASEQ data against a genome
* Mapping against a transcriptome
Principal targets
-----------------
mapping
perform all mappings
full
compute all mappings and QC
Optional targets
----------------
merge
merge mapped :term:`bam` formatted files, for example if reads
from different lanes were mapped separately. After merging, the
``qc`` target can be run again to get qc stats for the merged
:term:`bam` formatted files.
Usage
=====
See :ref:`PipelineSettingUp` and :ref:`PipelineRunning` on general
information how to use cgat pipelines.
Configuration
-------------
The pipeline requires a configured :file:`pipeline.yml` file.
The sphinxreport report requires a :file:`conf.py` and
:file:`sphinxreport.yml` file (see :ref:`PipelineReporting`). To start
with, use the files supplied with the Example_ data.
Input
-----
Reads
+++++
Reads are imported by placing files are linking to files in the
:term:`working directory`.
The default file format assumes the following convention:
filename.<suffix>
The ``suffix`` determines the file type. The following suffixes/file
types are possible:
sra
Short-Read Archive format. Reads will be extracted using the
:file:`fastq-dump` tool.
fastq.gz
Single-end reads in fastq format.
fastq.1.gz, fastq.2.gz
Paired-end reads in fastq format. The two fastq files must be
sorted by read-pair.
.. note::
Quality scores need to be of the same scale for all input
files. Thus it might be difficult to mix different formats.
Optional inputs
+++++++++++++++
Requirements
-------------
The pipeline requires the results from
:doc:`pipeline_annotations`. Set the configuration variable
:py:data:`annotations_database` and :py:data:`annotations_dir`.
On top of the default cgat setup, the pipeline requires the following
software to be in the path:
+---------+------------+------------------------------------------------+
|*Program*|*Version* |*Purpose* |
+---------+------------+------------------------------------------------+
|bowtie_ |>=0.12.7 |read mapping |
+---------+------------+------------------------------------------------+
|tophat_ |>=1.4.0 |read mapping |
+---------+------------+------------------------------------------------+
|gsnap_ |>=2012.07.20|read mapping |
+---------+------------+------------------------------------------------+
|samtools |>=0.1.16 |bam/sam files |
+---------+------------+------------------------------------------------+
|bedtools | |working with intervals |
+---------+------------+------------------------------------------------+
|sra-tools| |extracting reads from .sra files |
+---------+------------+------------------------------------------------+
|picard |>=1.42 |bam/sam files. The .jar files need to be in your|
| | | CLASSPATH environment variable. |
+---------+------------+------------------------------------------------+
|star_ |>=2.2.0c |read mapping |
+---------+------------+------------------------------------------------+
|bamstats_|>=1.22 |from CGR, Liverpool |
+---------+------------+------------------------------------------------+
|butter |>=0.3.2 |read mapping |
+---------+------------+------------------------------------------------+
|hisat |>0.1.5 |read mapping |
+---------+------------+------------------------------------------------+
|shortstack|>3.4 |read mapping |
+---------+------------+------------------------------------------------+
Merging bam files
-----------------
The pipeline has the ability to merge data post-mapping. This is
useful if data have been split over several lanes and have been
provide as separate fastq files.
To enable merging, set regular expression for the input and output in
the [merge] section of the configuration file.
Pipeline output
===============
The major output is in the database file :file:`csvdb`.
Example
=======
Example data is available at
http://www.cgat.org/~andreas/sample_data/pipeline_mapping.tgz. To run
the example, simply unpack and untar::
wget http://www.cgat.org/~andreas/sample_data/pipeline_mapping.tgz
tar -xvzf pipeline_mapping.tgz
cd pipeline_mapping
python <srcdir>/pipeline_mapping.py make full
.. note::
For the pipeline to run, install the :doc:`pipeline_annotations` as well.
Glossary
========
.. glossary::
tophat
tophat_ - a read mapper to detect splice-junctions
hisat
hisat_ - a read mapper for RNASEQ data (basis for tophat3)
bowtie
bowtie_ - a read mapper
star
star_ - a read mapper for RNASEQ data
star2pass
2-pass mapping for star_ read mapper. Mapping twice allows to
collect splice junctions from all samples and feed these back
to the second run for increased splice coverage. Recommended
for RNASEQ data and by the GATK pipeline. See STAR docs for
more info.
bismark
bismark_ - a read mapper for RRBS data
butter
butter_ - a read mapper for small RNA data (bowtie wrapper)
shortstack - a read mapper for small RNA data (bowtie wrapper)
that is an improvement on butter
.. _tophat: http://tophat.cbcb.umd.edu/
.. _bowtie: http://bowtie-bio.sourceforge.net/index.shtml
.. _gsnap: http://research-pub.gene.com/gmap/
.. _bamstats: http://www.agf.liv.ac.uk/454/sabkea/samStats_13-01-2011
.. _star: http://code.google.com/p/rna-star/
.. _bismark: http://www.bioinformatics.babraham.ac.uk/projects/bismark/
.. _butter: https://github.com/MikeAxtell/butter
.. _hisat: http://ccb.jhu.edu/software/hisat/manual.shtml
.. _shortstack: https://github.com/MikeAxtell/ShortStack
Code
====
"""
# load modules
from ruffus import *
import sys
import os
import re
import sqlite3
import collections
# required for 'butter' mapper
import shutil
import cgat.Sra as Sra
import cgatcore.experiment as E
from cgatcore import pipeline as P
import cgat.GTF as GTF
import cgatcore.iotools as iotools
import cgat.BamTools.bamtools as BamTools
import cgatpipelines.tasks.geneset as geneset
import cgatpipelines.tasks.mapping as mapping
import cgatpipelines.tasks.mappingqc as mappingqc
# Pipeline configuration
P.get_parameters(
["%s/pipeline.yml" % os.path.splitext(__file__)[0],
"../pipeline.yml",
"pipeline.yml"],
defaults={
'paired_end': False})
PARAMS = P.PARAMS
# Add parameters from the annotation pipeline, but
# only the interface
PARAMS.update(P.peek_parameters(
PARAMS["annotations_dir"],
"genesets",
prefix="annotations_",
update_interface=True,
restrict_interface=True))
geneset.PARAMS = PARAMS
mappingqc.PARAMS = PARAMS
# Helper functions mapping tracks to conditions, etc
# determine the location of the input files (reads).
try:
PARAMS["input"]
except NameError:
DATADIR = "."
else:
if PARAMS["input"] == 0:
DATADIR = "."
elif PARAMS["input"] == 1:
DATADIR = "data.dir"
else:
DATADIR = PARAMS["input"] # not recommended practise.
# Global flags
MAPPERS = P.as_list(PARAMS["mappers"])
SPLICED_MAPPING = ("tophat" in MAPPERS or
"gsnap" in MAPPERS or
"star" in MAPPERS or
"tophat2" in MAPPERS or
"transcriptome" in MAPPERS or
"hisat" in MAPPERS)
def connect():
'''connect to database.
This method also attaches to helper databases.
'''
dbh = sqlite3.connect(PARAMS["database_name"])
if not os.path.exists(PARAMS["annotations_database"]):
raise ValueError(
"can't find database '%s'" %
PARAMS["annotations_database"])
statement = '''ATTACH DATABASE '%s' as annotations''' % \
(PARAMS["annotations_database"])
cc = dbh.cursor()
cc.execute(statement)
cc.close()
return dbh
@active_if(SPLICED_MAPPING)
@follows(mkdir("geneset.dir"))
@merge(PARAMS["annotations_interface_geneset_all_gtf"],
"geneset.dir/reference.gtf.gz")
def buildReferenceGeneSet(infile, outfile):
''' filter full gene set and add attributes to create the reference gene set
Performs merge and filter operations:
* Merge exons separated by small introns (< 5bp).
* Remove transcripts with very long introns (`max_intron_size`)
* Remove transcripts located on contigs to be ignored (`remove_contigs`)
(usually: chrM, _random, ...)
* (Optional) Remove transcripts overlapping repetitive sequences
(`rna_file`)
This preserves all features in a gtf file (exon, CDS, ...)
Parameters
----------
infile : str
Input filename in :term:`gtf` format
outfile : str
Input filename in :term:`gtf` format
annotations_interface_rna_gff : str
:term:`PARAMS`. Filename of :term:`gtf` file containing
repetitive rna annotations
genome_dir : str
:term:`PARAMS`. Directory of :term:fasta formatted files
genome : str
:term:`PARAMS`. Genome name (e.g hg38)
'''
if "geneset_remove_repetetive_rna" in PARAMS:
rna_file = PARAMS["annotations_interface_rna_gff"]
else:
rna_file = None
mapping.mergeAndFilterGTF(
infile,
outfile,
"%s.removed.gz" % outfile,
genome=os.path.join(PARAMS["genome_dir"], PARAMS["genome"]),
max_intron_size=PARAMS["max_intron_size"],
remove_contigs=PARAMS["geneset_remove_contigs"],
rna_file=rna_file)
@active_if(SPLICED_MAPPING)
@originate("protein_coding_gene_ids.tsv")
def identifyProteinCodingGenes(outfile):
'''Output a list of proteing coding gene identifiers
Identify protein coding genes from the annotation database table
and output the gene identifiers
Parameters
----------
oufile : str
Output file of :term:`gtf` format
annotations_interface_table_gene_info : str
:term:`PARAMS`. Database table name for gene information
'''
dbh = connect()
table = os.path.basename(PARAMS["annotations_interface_table_gene_info"])
select = dbh.execute("""SELECT DISTINCT gene_id
FROM annotations.%(table)s
WHERE gene_biotype = 'protein_coding'""" % locals())
with iotools.open_file(outfile, "w") as outf:
outf.write("gene_id\n")
outf.write("\n".join((x[0] for x in select)) + "\n")
@transform(buildReferenceGeneSet,
suffix("reference.gtf.gz"),
add_inputs(identifyProteinCodingGenes),
"refcoding.gtf.gz")
def buildCodingGeneSet(infiles, outfile):
'''build a gene set with only protein coding transcripts.
Retain the genes from the gene_tsv file in the outfile geneset.
The gene set will contain all transcripts of protein coding genes,
including processed transcripts. The gene set includes UTR and
CDS.
Parameters
----------
infiles : list
infile: str
Input filename in :term:`gtf` format
genes_ts: str
Input filename in :term:`tsv` format
outfile: str
Output filename in :term:`gtf` format
'''
infile, genes_tsv = infiles
statement = '''
zcat %(infile)s
| cgat gtf2gtf
--method=filter
--filter-method=gene
--map-tsv-file=%(genes_tsv)s
--log=%(outfile)s.log
| gzip
> %(outfile)s
'''
P.run(statement)
#########################################################################
#########################################################################
#########################################################################
@active_if(SPLICED_MAPPING)
@follows(mkdir("geneset.dir"))
@transform(PARAMS["annotations_interface_geneset_flat_gtf"],
regex(".*"),
add_inputs(identifyProteinCodingGenes),
"geneset.dir/introns.gtf.gz")
def buildIntronGeneModels(infiles, outfile):
'''build protein-coding intron-transcipts
Retain the protein coding genes from the input gene set and
convert the exonic sequences to intronic sequences. 10 bp is
truncated on either end of an intron and need to have a minimum
length of 100. Introns from nested genes might overlap, but all
exons are removed.
Parameters
----------
infiles : list
infiles[0] : str
Input filename in :term:`gtf` format
infiles[1] : str
Input filename in :term:`tsv` format
outfile: str
Output filename in :term:`gtf` format
annotations_interface_geneset_exons_gtf: str, PARAMS
Filename for :term:`gtf` format file containing gene set exons
'''
filename_exons = PARAMS["annotations_interface_geneset_exons_gtf"]
infile, genes_tsv = infiles
statement = '''
zcat %(infile)s
| cgat gtf2gtf
--method=filter
--map-tsv-file=%(genes_tsv)s
--log=%(outfile)s.log
| cgat gtf2gtf
--method=sort
--sort-order=gene
| cgat gtf2gtf
--method=exons2introns
--intron-min-length=100
--intron-border=10
--log=%(outfile)s.log
| cgat gff2gff
--method=crop
--crop-gff-file=%(filename_exons)s
--log=%(outfile)s.log
| cgat gtf2gtf
--method=set-transcript-to-gene
--log=%(outfile)s.log
| awk -v OFS="\\t" -v FS="\\t" '{$3="exon"; print}'
| gzip
> %(outfile)s
'''
P.run(statement)
@P.add_doc(geneset.loadTranscript2Gene)
@active_if(SPLICED_MAPPING)
@transform(buildCodingGeneSet,
suffix(".gtf.gz"),
"_transcript2gene.load")
def loadGeneInformation(infile, outfile):
geneset.loadTranscript2Gene(infile, outfile)
@follows(mkdir("geneset.dir"))
@merge(PARAMS["annotations_interface_geneset_all_gtf"],
"geneset.dir/coding_exons.gtf.gz")
def buildCodingExons(infile, outfile):
'''compile the set of protein coding exons.
Filter protein coding transcripts
This set is used for splice-site validation
Parameters
----------
infile : str
Input filename in :term:`gtf` format
outfile: str
Output filename in :term:`gtf` format
'''
statement = '''
zcat %(infile)s
| awk '$3 == "CDS"'
| cgat gtf2gtf
--method=filter
--filter-method=proteincoding
--log=%(outfile)s.log
| awk -v OFS="\\t" -v FS="\\t" '{$3="exon"; print}'
| cgat gtf2gtf
--method=merge-exons
--log=%(outfile)s.log
| gzip
> %(outfile)s
'''
P.run(statement)
@active_if(SPLICED_MAPPING)
@transform(buildCodingGeneSet, suffix(".gtf.gz"), ".fa")
def buildReferenceTranscriptome(infile, outfile):
'''build reference transcriptome.
Extract the sequence for each transcript in a reference geneset
:term:`gtf` file from an indexed genome :term:`fasta` file and
output to a :term:`fasta` file. Transcript sequences include both
UTR and CDS.
Additionally build :term:`bowtie` indices for tophat/tophat2 as required.
Parameters
----------
infile : str
Input filename in :term:`gtf` format
outfile: str
Output filename in :term:`fasta` format
genome_dir : str
:term:`PARAMS`. Directory of :term:fasta formatted files
genome : str
:term:`PARAMS`. Genome name (e.g hg38)
'''
gtf_file = P.snip(infile, ".gz")
genome_file = os.path.abspath(
os.path.join(PARAMS["genome_dir"], PARAMS["genome"] + ".fa"))
statement = '''
zcat %(infile)s
| awk '$3 == "exon"' > %(gtf_file)s &&
gtf_to_fasta %(gtf_file)s %(genome_file)s %(outfile)s &&
samtools faidx %(outfile)s
'''
P.run(statement, job_condaenv="tophat2")
dest = P.snip(os.path.abspath(gtf_file), ".gtf") + ".gff"
if not os.path.exists(dest):
os.symlink(os.path.abspath(gtf_file), dest)
prefix = P.snip(outfile, ".fa")
if 'tophat' in MAPPERS or "transcriptome" in MAPPERS:
# build raw index
statement = '''
bowtie-build -f %(outfile)s %(prefix)s >> %(outfile)s.log 2>&1
'''
P.run(statement)
# build color space index - disabled
# statement = '''
# bowtie-build -C -f %(outfile)s %(prefix)s_cs
# >> %(outfile)s.log 2>&1
# '''
# P.run(statement)
if 'tophat2' in MAPPERS:
statement = '''
bowtie2-build -f %(outfile)s %(prefix)s >> %(outfile)s.log 2>&1
'''
P.run(statement)
#########################################################################
#########################################################################
#########################################################################
@active_if(SPLICED_MAPPING)
@transform(buildCodingGeneSet, suffix(".gtf.gz"), ".junctions")
def buildJunctions(infile, outfile):
'''build file with splice junctions from gtf file.
Identify the splice junctions from a gene set :term:`gtf`
file. A junctions file is a better option than supplying a GTF
file, as parsing the latter often fails. See:
http://seqanswers.com/forums/showthread.php?t=7563
Parameters
----------
infile : str
Input filename in :term:`gtf` format
outfile: str
Output filename
'''
outf = iotools.open_file(outfile, "w")
njunctions = 0
for gffs in GTF.transcript_iterator(
GTF.iterator(iotools.open_file(infile, "r"))):
gffs.sort(key=lambda x: x.start)
end = gffs[0].end
for gff in gffs[1:]:
# subtract one: these are not open/closed coordinates but
# the 0-based coordinates
# of first and last residue that are to be kept (i.e., within the
# exon).
outf.write("%s\t%i\t%i\t%s\n" %
(gff.contig, end - 1, gff.start, gff.strand))
end = gff.end
njunctions += 1
outf.close()
if njunctions == 0:
E.warn('no junctions found in gene set')
return
else:
E.info('found %i junctions before removing duplicates' % njunctions)
# make unique
statement = '''mv %(outfile)s %(outfile)s.tmp &&
cat < %(outfile)s.tmp | sort | uniq > %(outfile)s &&
rm -f %(outfile)s.tmp'''
P.run(statement)
@active_if(SPLICED_MAPPING)
@follows(mkdir("gsnap.dir"))
@merge(PARAMS["annotations_interface_geneset_exons_gtf"],
"gsnap.dir/splicesites.iit")
def buildGSNAPSpliceSites(infile, outfile):
'''build file with known splice sites for GSNAP from all exons
Identify the splice from a gene set :term:`gtf` file using the
GSNAP subprogram gts_splicesites.
Parameters
----------
infile : str
Input filename in :term:`gtf` format
outfile: str
Output filename
'''
outfile = P.snip(outfile, ".iit")
statement = '''zcat %(infile)s
| gtf_splicesites | iit_store -o %(outfile)s
> %(outfile)s.log
'''
P.run(statement)
#########################################################################
#########################################################################
#########################################################################
# Read mapping
#########################################################################
SEQUENCESUFFIXES = ("*.fastq.1.gz",
"*.fastq.gz",
"*.fa.gz",
"*.sra",
"*.export.txt.gz",
"*.csfasta.gz",
"*.csfasta.F3.gz",
"*.remote",
)
SEQUENCEFILES = tuple([os.path.join(DATADIR, suffix_name)
for suffix_name in SEQUENCESUFFIXES])
SEQUENCEFILES_REGEX = regex(
r".*/(\S+).(fastq.1.gz|fastq.gz|fa.gz|sra|csfasta.gz|csfasta.F3.gz|export.txt.gz|remote)")
###################################################################
###################################################################
###################################################################
# load number of reads
###################################################################
@follows(mkdir("nreads.dir"))
@transform(SEQUENCEFILES,
SEQUENCEFILES_REGEX,
r"nreads.dir/\1.nreads")
def countReads(infile, outfile):
'''Count number of reads in input files.'''
m = mapping.Counter()
statement = m.build((infile,), outfile)
P.run(statement)
#########################################################################
#########################################################################
#########################################################################
# Map reads with tophat
#########################################################################
@active_if(SPLICED_MAPPING)
@follows(mkdir("tophat.dir"))
@transform(SEQUENCEFILES,
SEQUENCEFILES_REGEX,
add_inputs(buildJunctions, buildReferenceTranscriptome),
r"tophat.dir/\1.tophat.bam")
def mapReadsWithTophat(infiles, outfile):
"""
Map reads using Tophat (spliced reads).
Parameters
----------
infiles: list
contains 3 filenames -
infiles[0]: str
filename of reads file
can be :term:`fastq`, :term:`sra`, csfasta
infiles[1]: str
:term:`fasta` filename, suffix .fa
reference transcriptome
infiles[2]: str
filename with suffix .junctions containing a list of known
splice junctions.
tophat_threads: int
:term:`PARAMS`
number of threads with which to run tophat
tophat_options: str
:term:`PARAMS`
string containing options to pass to tophat
tophat_memory: str
:term:`PARAMS`
memory required for tophat job
tophat_executable: str
:term:`PARAMS`
path to tophat executable
strandness
:term:`PARAMS`
FR, RF, F or R or empty see
http://www.ccb.jhu.edu/software/hisat/manual.shtml#options
will be converted to tophat specific option
tophat_include_reference_transcriptome: bool
:term:`PARAMS`
if set, map to reference transcriptome
strip_sequence: bool
:term:`PARAMS`
if set, strip read sequence and quality information
bowtie_index_dir: str
:term:`PARAMS`
path to directory containing bowtie indices
outfile: str
:term:`bam` filename to write the mapped reads in bam format.
.. note::
If tophat fails with an error such as::
Error: segment-based junction search failed with err =-6
what(): std::bad_alloc
it means that it ran out of memory.
"""
job_threads = PARAMS["tophat_threads"]
# convert strandness to tophat-style library type
if PARAMS["strandness"] == ("RF" or "R"):
tophat_library_type = "fr-firststrand"
elif PARAMS["strandness"] == ("FR" or "F"):
tophat_library_type = "fr-secondstrand"
else:
tophat_library_type = "fr-unstranded"
if "--butterfly-search" in PARAMS["tophat_options"]:
# for butterfly search - require insane amount of
# RAM.
job_memory = "50G"
else:
job_memory = PARAMS["tophat_memory"]
m = mapping.Tophat(
executable=P.substitute_parameters(**locals())["tophat_executable"],
strip_sequence=PARAMS["strip_sequence"],
tool_options=PARAMS["tophat_options"])
infile, reffile, transcriptfile = infiles
tophat_options = PARAMS["tophat_options"] + \
" --raw-juncs %(reffile)s " % locals()
# Nick - added the option to map to the reference transcriptome first
# (built within the pipeline)
if PARAMS["tophat_include_reference_transcriptome"]:
prefix = os.path.abspath(P.snip(transcriptfile, ".fa"))
tophat_options = tophat_options + \
" --transcriptome-index=%s -n 2" % prefix
statement = m.build((infile,), outfile)
P.run(statement, job_condaenv="tophat2")
@active_if(SPLICED_MAPPING)
@follows(mkdir("tophat2.dir"))
@transform(SEQUENCEFILES,
SEQUENCEFILES_REGEX,
add_inputs(buildJunctions, buildReferenceTranscriptome),
r"tophat2.dir/\1.tophat2.bam")
def mapReadsWithTophat2(infiles, outfile):
'''
Map reads using Tophat2 (spliced reads).
Parameters
----------
infiles: list
contains 3 filenames -
infiles[0]: str
filename of reads file
can be :term:`fastq`, :term:`sra`, csfasta
infiles[1]: str
:term:`fasta` filename, suffix .fa
reference transcriptome
infiles[2]: str
filename with suffix .junctions containing a list of known
splice junctions.
tophat2_threads: int
:term:`PARAMS`
number of threads with which to run tophat2
tophat2_options: str
:term:`PARAMS`
string containing options to pass to tophat2
tophat2_memory: str
:term:`PARAMS`
memory required for tophat2 job
tophat2_executable: str
:term:`PARAMS`
path to tophat2 executable
strandness
:term:`PARAMS`
FR, RF, F or R or empty see
http://www.ccb.jhu.edu/software/hisat/manual.shtml#options
will be converted to tophat specific option
tophat2_include_reference_transcriptome: bool
:term:`PARAMS`
if set, map to reference transcriptome
tophat2_mate_inner_dist: int
:term:`PARAMS`
insert length (2 * read length)
strip_sequence: bool
:term:`PARAMS`
if set, strip read sequence and quality information
bowtie_index_dir: str
:term:`PARAMS`
path to directory containing bowtie indices
outfile: str
:term:`bam` filename to write the mapped reads in bam format.
.. note::
If tophat fails with an error such as::
Error: segment-based junction search failed with err =-6
what(): std::bad_alloc
it means that it ran out of memory.
'''
job_threads = PARAMS["tophat2_threads"]
# convert strandness to tophat-style library type
if PARAMS["strandness"] == ("RF" or "R"):
tophat2_library_type = "fr-firststrand"
elif PARAMS["strandness"] == ("FR" or "F"):
tophat2_library_type = "fr-secondstrand"
else:
tophat2_library_type = "fr-unstranded"
if "--butterfly-search" in PARAMS["tophat2_options"]:
# for butterfly search - require insane amount of
# RAM.
job_memory = "50G"
else:
job_memory = PARAMS["tophat2_memory"]
m = mapping.Tophat2(
executable=P.substitute_parameters(**locals())["tophat2_executable"],
strip_sequence=PARAMS["strip_sequence"],
tool_options=PARAMS["tophat2_options"])
infile, reffile, transcriptfile = infiles
tophat2_options = PARAMS["tophat2_options"] + \
" --raw-juncs %(reffile)s" % locals()
# Nick - added the option to map to the reference transcriptome first
# (built within the pipeline)
if PARAMS["tophat2_include_reference_transcriptome"]:
prefix = os.path.abspath(P.snip(transcriptfile, ".fa"))
tophat2_options = tophat2_options + \
" --transcriptome-index=%s -n 2" % prefix
statement = m.build((infile,), outfile)
P.run(statement, job_condaenv="tophat2")
############################################################
############################################################
############################################################
@active_if(SPLICED_MAPPING)
@follows(mkdir("hisat.dir"))
@transform(SEQUENCEFILES,
SEQUENCEFILES_REGEX,
add_inputs(buildJunctions),
r"hisat.dir/\1.hisat.bam")
def mapReadsWithHisat(infiles, outfile):
'''
Map reads using Hisat (spliced reads).
Parameters
----------
infiles: list
contains two filenames -
infiles[0]: str
filename of reads file
can be :term:`fastq`, :term:`sra`, csfasta
infiles[1]: str
filename with suffix .junctions containing a list of known
splice junctions.
hisat_threads: int
:term:`PARAMS`
number of threads with which to run hisat
hisat_memory: str
:term:`PARAMS`
memory required for hisat job
hisat_executable: str
:term:`PARAMS`
path to hisat executable
strandness: str
:term:`PARAMS`
hisat rna-strandess parameter, see
https://ccb.jhu.edu/software/hisat/manual.shtml#command-line
hisat_options: str
options string for hisat, see
https://ccb.jhu.edu/software/hisat/manual.shtml#command-line
hisat_index_dir: str
path to directory containing hisat indices
strip_sequence: bool