本文整理汇总了Python中CGAT.BamTools.isPaired方法的典型用法代码示例。如果您正苦于以下问题:Python BamTools.isPaired方法的具体用法?Python BamTools.isPaired怎么用?Python BamTools.isPaired使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGAT.BamTools
的用法示例。
在下文中一共展示了BamTools.isPaired方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildGeneLevelReadCounts
# 需要导入模块: from CGAT import BamTools [as 别名]
# 或者: from CGAT.BamTools import isPaired [as 别名]
def buildGeneLevelReadCounts(infiles, outfile):
'''compute read counts and coverage of exons with reads.
'''
bamfile, exons = infiles
if BamTools.isPaired(bamfile):
counter = 'readpair-counts'
else:
counter = 'read-counts'
# ignore multi-mapping reads
statement = '''
zcat %(exons)s
| python %(scriptsdir)s/gtf2table.py
--reporter=genes
--bam-file=%(bamfile)s
--counter=length
--prefix="exons_"
--counter=%(counter)s
--prefix=""
--counter=read-coverage
--prefix=coverage_
--min-mapping-quality=%(counting_min_mapping_quality)i
--multi-mapping=ignore
--log=%(outfile)s.log
| gzip
> %(outfile)s
'''
P.run()
示例2: bamToBed
# 需要导入模块: from CGAT import BamTools [as 别名]
# 或者: from CGAT.BamTools import isPaired [as 别名]
def bamToBed(infile, outfile, min_insert_size=0, max_insert_size=1000):
"""convert bam to bed with bedtools."""
scriptsdir = "/ifs/devel/andreas/cgat/scripts"
if BamTools.isPaired(infile):
# output strand as well
statement = [
"cat %(infile)s "
"| python %(scriptsdir)s/bam2bed.py "
"--merge-pairs "
"--min-insert-size=%(min_insert_size)i "
"--max-insert-size=%(max_insert_size)i "
"--log=%(outfile)s.log "
"--bed-format=6 "
"> %(outfile)s" % locals()
]
else:
statement = "bamToBed -i %(infile)s > %(outfile)s" % locals()
E.debug("executing statement '%s'" % statement)
retcode = subprocess.call(statement, cwd=os.getcwd(), shell=True)
if retcode < 0:
raise OSError("Child was terminated by signal %i: \n%s\n" % (-retcode, statement))
return outfile
示例3: buildTranscriptLevelReadCounts
# 需要导入模块: from CGAT import BamTools [as 别名]
# 或者: from CGAT.BamTools import isPaired [as 别名]
def buildTranscriptLevelReadCounts(infiles, outfile):
'''count reads falling into transcripts of protein coding gene models.
.. note::
In paired-end data sets each mate will be counted. Thus
the actual read counts are approximately twice the fragment
counts.
'''
bamfile, geneset = infiles
if BamTools.isPaired(bamfile):
counter = 'readpair-counts'
else:
counter = 'read-counts'
statement = '''
zcat %(geneset)s
| python %(scriptsdir)s/gtf2table.py
--reporter=transcripts
--bam-file=%(bamfile)s
--counter=length
--prefix="exons_"
--counter=%(counter)s
--prefix=""
--counter=read-coverage
--prefix=coverage_
--min-mapping-quality=%(counting_min_mapping_quality)i
--multi-mapping=ignore
--log=%(outfile)s.log
| gzip
> %(outfile)s
'''
P.run()
示例4: isPaired
# 需要导入模块: from CGAT import BamTools [as 别名]
# 或者: from CGAT.BamTools import isPaired [as 别名]
def isPaired(filename):
'''return "T" if bamfile contains paired end reads.'''
if BamTools.isPaired(filename):
return "T"
else:
return "F"
示例5: countDEXSeq
# 需要导入模块: from CGAT import BamTools [as 别名]
# 或者: from CGAT.BamTools import isPaired [as 别名]
def countDEXSeq(infiles, outfile):
'''create counts for DEXSeq
Counts bam reads agains exon features in flattened gtf.
The required python script is provided by DEXSeq
and uses HTSeqCounts.
Parameters
----------
infile[0]: string
:term:`bam` file input
infile[1]: string
:term:`gff` output from buildGff function
outfile : string
A :term:`txt` file containing results
DEXSeq_strandedness : string
:term:`PARAMS`. Specifies strandedness, options
are 'yes', 'no' and 'reverse'
'''
infile, gfffile = infiles
ps = PYTHONSCRIPTSDIR
if BamTools.isPaired(infile):
paired = "yes"
else:
paired = "no"
strandedness = PARAMS["DEXSeq_strandedness"]
statement = '''python %(ps)s/dexseq_count.py
-p %(paired)s
-s %(strandedness)s
-r pos
-f bam %(gfffile)s %(infile)s %(outfile)s'''
P.run()
示例6: convertReadsToIntervals
# 需要导入模块: from CGAT import BamTools [as 别名]
# 或者: from CGAT.BamTools import isPaired [as 别名]
def convertReadsToIntervals(bamfile,
bedfile,
filtering_quality=None,
filtering_dedup=None,
filtering_dedup_method='picard'):
'''convert reads in *bamfile* to *intervals*.
This method converts read data into intervals for
counting based methods.
This method is not appropriated for RNA-Seq.
Optional steps include:
* deduplication - remove duplicate reads
* quality score filtering - remove reads below a certain quality score.
* paired ended data - merge pairs
* paired ended data - filter by insert size
'''
track = P.snip(bedfile, ".bed.gz")
is_paired = BamTools.isPaired(bamfile)
current_file = bamfile
tmpdir = P.getTempFilename()
statement = ["mkdir %(tmpdir)s"]
nfiles = 0
if filtering_quality > 0:
next_file = "%(tmpdir)s/bam_%(nfiles)i.bam" % locals()
statement.append('''samtools view
-q %(filtering_quality)i -b
%(current_file)s
2>> %%(bedfile)s.log
> %(next_file)s ''' % locals())
nfiles += 1
current_file = next_file
if filtering_dedup is not None:
# Picard's MarkDuplicates requries an explicit bam file.
next_file = "%(tmpdir)s/bam_%(nfiles)i.bam" % locals()
if filtering_dedup_method == 'samtools':
statement.append('''samtools rmdup - - ''')
elif filtering_dedup_method == 'picard':
statement.append('''MarkDuplicates
INPUT=%(current_file)s
OUTPUT=%(next_file)s
ASSUME_SORTED=TRUE
METRICS_FILE=%(bedfile)s.duplicate_metrics
REMOVE_DUPLICATES=TRUE
VALIDATION_STRINGENCY=SILENT
2>> %%(bedfile)s.log ''' % locals())
nfiles += 1
current_file = next_file
if is_paired:
statement.append('''cat %(current_file)s
| python %(scriptsdir)s/bam2bed.py
--merge-pairs
--min-insert-size=%(filtering_min_insert_size)i
--max-insert-size=%(filtering_max_insert_size)i
--log=%(bedfile)s.log
-
| python %(scriptsdir)s/bed2bed.py
--method=sanitize-genome
--genome-file=%(genome_dir)s/%(genome)s
--log=%(bedfile)s.log
| cut -f 1,2,3,4
| sort -k1,1 -k2,2n
| bgzip > %(bedfile)s''')
else:
statement.append('''cat %(current_file)s
| python %(scriptsdir)s/bam2bed.py
--log=%(bedfile)s.log
-
| python %(scriptsdir)s/bed2bed.py
--method=sanitize-genome
--genome-file=%(genome_dir)s/%(genome)s
--log=%(bedfile)s.log
| cut -f 1,2,3,4
| sort -k1,1 -k2,2n
| bgzip > %(bedfile)s''')
statement.append("tabix -p bed %(bedfile)s")
statement.append("rm -rf %(tmpdir)s")
statement = " ; ".join(statement)
P.run()
os.unlink(tmpdir)
示例7: runFeatureCounts
# 需要导入模块: from CGAT import BamTools [as 别名]
# 或者: from CGAT.BamTools import isPaired [as 别名]
def runFeatureCounts(annotations_file,
bamfile,
outfile,
nthreads=4,
strand=2,
options=""):
'''run feature counts on *annotations_file* with
*bam_file*.
If the bam-file is paired, paired-end counting
is enabled and the bam file automatically sorted.
'''
# featureCounts cannot handle gzipped in or out files
outfile = P.snip(outfile, ".gz")
tmpdir = P.getTempDir()
annotations_tmp = os.path.join(tmpdir,
'geneset.gtf')
bam_tmp = os.path.join(tmpdir,
bamfile)
# -p -B specifies count fragments rather than reads, and both
# reads must map to the feature
# for legacy reasons look at feature_counts_paired
if BamTools.isPaired(bamfile):
# select paired end mode, additional options
paired_options = "-p -B"
# remove .bam extension
bam_prefix = P.snip(bam_tmp, ".bam")
# sort by read name
paired_processing = \
"""samtools
sort [email protected] %(nthreads)i -n %(bamfile)s %(bam_prefix)s;
checkpoint; """ % locals()
bamfile = bam_tmp
else:
paired_options = ""
paired_processing = ""
job_options = "-pe dedicated %i" % nthreads
# AH: what is the -b option doing?
statement = '''mkdir %(tmpdir)s;
zcat %(annotations_file)s > %(annotations_tmp)s;
checkpoint;
%(paired_processing)s
featureCounts %(options)s
-T %(nthreads)i
-s %(strand)s
-b
-a %(annotations_tmp)s
%(paired_options)s
-o %(outfile)s
%(bamfile)s
>& %(outfile)s.log;
checkpoint;
gzip -f %(outfile)s;
checkpoint;
rm -rf %(tmpdir)s
'''
P.run()
示例8: runFeatureCounts
# 需要导入模块: from CGAT import BamTools [as 别名]
# 或者: from CGAT.BamTools import isPaired [as 别名]
def runFeatureCounts(annotations_file,
bamfile,
outfile,
job_threads=4,
strand=0,
options=""):
'''run FeatureCounts to collect read counts.
If `bamfile` is paired, paired-end counting is enabled and the bam
file automatically sorted.
Arguments
---------
annotations_file : string
Filename with gene set in :term:`gtf` format.
bamfile : string
Filename with short reads in :term:`bam` format.
outfile : string
Output filename in :term:`tsv` format.
job_threads : int
Number of threads to use.
strand : int
Strand option in FeatureCounts.
options : string
Options to pass on to FeatureCounts.
'''
# featureCounts cannot handle gzipped in or out files
outfile = P.snip(outfile, ".gz")
tmpdir = P.getTempDir()
annotations_tmp = os.path.join(tmpdir,
'geneset.gtf')
bam_tmp = os.path.join(tmpdir,
os.path.basename(bamfile))
# -p -B specifies count fragments rather than reads, and both
# reads must map to the feature
# for legacy reasons look at feature_counts_paired
if BamTools.isPaired(bamfile):
# select paired end mode, additional options
paired_options = "-p -B"
# remove .bam extension
bam_prefix = P.snip(bam_tmp, ".bam")
# sort by read name
paired_processing = \
"""samtools
sort [email protected] %(job_threads)i -n %(bamfile)s %(bam_prefix)s;
checkpoint; """ % locals()
bamfile = bam_tmp
else:
paired_options = ""
paired_processing = ""
# AH: what is the -b option doing?
statement = '''mkdir %(tmpdir)s;
zcat %(annotations_file)s > %(annotations_tmp)s;
checkpoint;
%(paired_processing)s
featureCounts %(options)s
-T %(job_threads)i
-s %(strand)s
-a %(annotations_tmp)s
%(paired_options)s
-o %(outfile)s
%(bamfile)s
>& %(outfile)s.log;
checkpoint;
gzip -f %(outfile)s;
checkpoint;
rm -rf %(tmpdir)s
'''
P.run()
示例9: convertReadsToIntervals
# 需要导入模块: from CGAT import BamTools [as 别名]
# 或者: from CGAT.BamTools import isPaired [as 别名]
def convertReadsToIntervals(bamfile,
bedfile,
filtering_quality=None,
filtering_dedup=None,
filtering_dedup_method='picard',
filtering_nonunique=False):
'''convert reads in *bamfile* to *intervals*.
This method converts read data into intervals for
counting based methods.
This method is not appropriate for RNA-Seq.
Optional steps include:
For paired end data, pairs are merged and optionally
filtered by insert size.
Arguments
---------
bamfile : string
Filename of input file in :term:`bam` format.
bedfile : string
Filename of output file in :term:`bed` format.
filtering_quality : int
If set, remove reads with a quality score below given threshold.
filtering_dedup : bool
If True, deduplicate data.
filtering_dedup_method : string
Deduplication method. Possible options are ``picard`` and
``samtools``.
filtering_nonunique : bool
If True, remove non-uniquely matching reads.
'''
track = P.snip(bedfile, ".bed.gz")
is_paired = BamTools.isPaired(bamfile)
current_file = bamfile
tmpdir = P.getTempFilename()
statement = ["mkdir %(tmpdir)s"]
nfiles = 0
if filtering_quality > 0:
next_file = "%(tmpdir)s/bam_%(nfiles)i.bam" % locals()
statement.append('''samtools view
-q %(filtering_quality)i -b
%(current_file)s
2>> %%(bedfile)s.log
> %(next_file)s ''' % locals())
nfiles += 1
current_file = next_file
if filtering_nonunique:
next_file = "%(tmpdir)s/bam_%(nfiles)i.bam" % locals()
statement.append('''cat %(current_file)s
| python %%(scriptsdir)s/bam2bam.py
--method=filter
--filter-method=unique,mapped
--log=%%(bedfile)s.log
> %(next_file)s ''' % locals())
nfiles += 1
current_file = next_file
if filtering_dedup is not None:
# Picard's MarkDuplicates requries an explicit bam file.
next_file = "%(tmpdir)s/bam_%(nfiles)i.bam" % locals()
if filtering_dedup_method == 'samtools':
statement.append('''samtools rmdup - - ''')
elif filtering_dedup_method == 'picard':
statement.append('''MarkDuplicates
INPUT=%(current_file)s
OUTPUT=%(next_file)s
ASSUME_SORTED=TRUE
METRICS_FILE=%(bedfile)s.duplicate_metrics
REMOVE_DUPLICATES=TRUE
VALIDATION_STRINGENCY=SILENT
2>> %%(bedfile)s.log ''' % locals())
nfiles += 1
current_file = next_file
if is_paired:
statement.append('''cat %(current_file)s
| python %(scriptsdir)s/bam2bed.py
--merge-pairs
--min-insert-size=%(filtering_min_insert_size)i
--max-insert-size=%(filtering_max_insert_size)i
--log=%(bedfile)s.log
-
| python %(scriptsdir)s/bed2bed.py
--method=sanitize-genome
--genome-file=%(genome_dir)s/%(genome)s
--log=%(bedfile)s.log
| cut -f 1,2,3,4
#.........这里部分代码省略.........