当前位置: 首页>>代码示例>>Python>>正文


Python pysam.AlignedRead方法代码示例

本文整理汇总了Python中pysam.AlignedRead方法的典型用法代码示例。如果您正苦于以下问题:Python pysam.AlignedRead方法的具体用法?Python pysam.AlignedRead怎么用?Python pysam.AlignedRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysam的用法示例。


在下文中一共展示了pysam.AlignedRead方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import pysam [as 别名]
# 或者: from pysam import AlignedRead [as 别名]
def __init__(self, line, start=-1, end=-1, strand=1,
        file_format='', bamfile=None, info=''):
        self.info = ""
        self.file_format = file_format
        if type(line) == pysam.AlignedRead or type(line) == pysam.AlignedSegment:
            self.load_pysamread(line, bamfile)
        elif start == -1:
            self.load_line(line, file_format)
        elif end == -1:
            self.load_pos(line, start, start, strand)
        else:
            self.load_pos(line, start, end, strand)
        if len(info) > 0:
            self.info = info 
开发者ID:namphuon,项目名称:ViFi,代码行数:16,代码来源:hg19util.py

示例2: load_pysamread

# 需要导入模块: import pysam [as 别名]
# 或者: from pysam import AlignedRead [as 别名]
def load_pysamread(self, line, bamfile):
        if bamfile is None:
            raise "Interval of pysam AlignedRead without bamfile"
        self.chrom = line.reference_name
        self.start = line.reference_start
        self.end = line.reference_end
        if line.is_reverse:
            self.strand = -1
        else:
            self.strand = 1 
开发者ID:namphuon,项目名称:ViFi,代码行数:12,代码来源:hg19util.py

示例3: dropest_bc_correct

# 需要导入模块: import pysam [as 别名]
# 或者: from pysam import AlignedRead [as 别名]
def dropest_bc_correct(bamfilepath: str, dropest_out: str, corrected_output: str) -> None:
    """Using the output of DropEst:
    (1) Corrects barcodes directly in the bam file
    (2) Produces a valid barcodes list

    BAMFILEPATH - bam file with sorted reads obtained running DropEst

    DROPEST-OUT - R dump `rds` file generated by DropEst
    """

    try:
        import rpy2.robjects as ro
        from velocyto.r_interface import convert_r_obj
    except:
        ImportError("A problem was encountered importing rpy2. To run this `velocyto tools` rpy2 and R need to be installed (the use conda is recommended)")

    # bamfilepath = sys.argv[1]
    # filename = os.path.join(parentpath, f"{bamfilename.split('_')[0]}_dropEst.rds")
    parentpath, bamfilename = os.path.split(bamfilepath)
    filename = dropest_out
    logging.info(f"Loading `merge_targets` from {filename} using R / rpy2")
    mapping = convert_r_obj(ro.r(f"rds <- readRDS('{filename}'); rds$merge_targets"))  # a dict

    output_path = os.path.join(parentpath, f"barcodes_{bamfilename.split('_')[0]}.tsv")
    logging.info(f"Generating {output_path}")
    with open(output_path, "w") as fout:
        unique_bcs = set(list(mapping.values()))
        str_ = '\n'.join(list(unique_bcs))
        fout.write(str_)

    infile = pysam.AlignmentFile(bamfilepath, mode="rb")
    if corrected_output is None:
        bam_out_path = os.path.join(parentpath, f"correct_{bamfilename}")
    else:
        bam_out_path = corrected_output

    outfile = pysam.AlignmentFile(bam_out_path, mode="wb", template=infile)

    for read in infile:
        # read: pysam.AlignedRead
        cb = read.get_tag("CB")
        if cb in mapping:
            read.set_tag("CB", mapping[cb], value_type="Z")
        outfile.write(read)
    infile.close()
    outfile.close()
    logging.info("Done")

    return 
开发者ID:velocyto-team,项目名称:velocyto.py,代码行数:51,代码来源:dropest_bc_correct.py


注:本文中的pysam.AlignedRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。