本文整理汇总了Python中pysam.Tabixfile方法的典型用法代码示例。如果您正苦于以下问题:Python pysam.Tabixfile方法的具体用法?Python pysam.Tabixfile怎么用?Python pysam.Tabixfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysam
的用法示例。
在下文中一共展示了pysam.Tabixfile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tabix
# 需要导入模块: import pysam [as 别名]
# 或者: from pysam import Tabixfile [as 别名]
def tabix(self):
if self._tabix is None:
self._tabix = pysam.Tabixfile(self.tabixPath)
return self._tabix
示例2: ensureIndexed
# 需要导入模块: import pysam [as 别名]
# 或者: from pysam import Tabixfile [as 别名]
def ensureIndexed(bedPath, preset="bed", trySorting=True):
if not bedPath.endswith(".gz"):
if not os.path.exists(bedPath+".gz"):
logging.info("bgzf compressing {}".format(bedPath))
pysam.tabix_compress(bedPath, bedPath+".gz")
if not os.path.exists(bedPath+".gz"):
raise Exception("Failed to create compress {preset} file for {file}; make sure the {preset} file is "
"sorted and the directory is writeable".format(preset=preset, file=bedPath))
bedPath += ".gz"
if not os.path.exists(bedPath+".tbi"):
logging.info("creating tabix index for {}".format(bedPath))
pysam.tabix_index(bedPath, preset=preset)
if not os.path.exists(bedPath+".tbi"):
raise Exception("Failed to create tabix index file for {file}; make sure the {preset} file is "
"sorted and the directory is writeable".format(preset=preset, file=bedPath))
line = next(pysam.Tabixfile(bedPath).fetch())
if len(line.strip().split("\t")) < 6 and preset == "bed":
raise AnnotationError("BED files need to have at least 6 (tab-delimited) fields (including "
"chrom, start, end, name, score, strand; score is unused)")
if len(line.strip().split("\t")) < 9 and preset == "gff":
raise AnnotationError("GFF/GTF files need to have at least 9 tab-delimited fields")
return bedPath
# def sortFile(uncompressedPath, preset):
# if preset == "bed":
# fields = {"chrom":0, "start":1, "end":2}
# elif preset == "gff":
# fields = {"chrom":0, "start":3, "end":4}
# sortCommand = "sort -k{chrom}V -k{start}n -k{end}n".format(**fields)
# tabixCommand = "{sort} {path} | bgzip > {path}.gz".format(sort=sortCommand, path=uncompressedPath)
# logging.info("Trying to sort input annotation file with command:")
# logging.info(" {}".format(tabixCommand))
# subprocess.check_call(tabixCommand, shell=True)
示例3: tabix
# 需要导入模块: import pysam [as 别名]
# 或者: from pysam import Tabixfile [as 别名]
def tabix(self):
"""Return a tabix index for this BedFile."""
if self._tabix:
return self._tabix
import pysam
self._tabix = pysam.Tabixfile(self.filename)
return self._tabix
示例4: __init__
# 需要导入模块: import pysam [as 别名]
# 或者: from pysam import Tabixfile [as 别名]
def __init__(self,bedgraph):
self.tbx = pysam.Tabixfile(bedgraph)
示例5: merge_vcfs
# 需要导入模块: import pysam [as 别名]
# 或者: from pysam import Tabixfile [as 别名]
def merge_vcfs(in_vcfs_dir, contigs, out_vcf):
logger.info("Mergings per-chromosome VCFs from %s" % in_vcfs_dir)
header_done = False
out_vcf_file = open(out_vcf, "w")
for contig in contigs:
chr_vcf = os.path.join(in_vcfs_dir, "%s.vcf.gz" % contig.name)
if os.path.isfile(chr_vcf):
chr_tabix_file = pysam.Tabixfile(chr_vcf)
if not header_done:
print_header(chr_tabix_file.header, out_vcf_file)
for entry in chr_tabix_file.fetch():
out_vcf_file.write("%s\n" % entry)
chr_tabix_file.close()
out_vcf_file.close()
pysam.tabix_index(out_vcf, force=True, preset="vcf")