Git Product home page Git Product logo

pafpy's Introduction

pafpy

A lightweight library for working with PAF (Pairwise mApping Format) files.

GitHub release (latest SemVer) GitHub Workflow Status codecov License Code style: black

Documentation: https://mbh.sh/pafpy

Table of Contents

Install

PyPi

PyPI PyPI - Python Version

pip install pafpy

Conda

Conda Conda (channel only)

conda install -c bioconda pafpy

Locally

If you would like to install locally, the recommended way is using poetry.

git clone https://github.com/mbhall88/pafpy.git
cd pafpy
make install
# to check the library is installed run
poetry run python -c "from pafpy import PafRecord;print(str(PafRecord()))"
# you should see a (unmapped) PAF record printed to the terminal
# you can also run the tests if you like
make test-code

Usage

For full usage, please refer to the documentation. If there is any functionality you feel is missing or would make pafpy more user-friendly, please raise an issue with a feature request.

In the below basic usage pattern, we collect the BLAST identity of all primary alignments in our PAF file into a list.

from typing import List
from pafpy import PafFile

path = "path/to/sample.paf"

identities: List[float] = []
with PafFile(path) as paf:
    for record in paf:
        if record.is_primary():
            identity = record.blast_identity()
            identities.append(identity)

Another use case might be that we want to get the identifiers of all records aligned to a specific contig, but only keep the alignments where more than 50% of the query (read) is aligned.

from typing import List
from pafpy import PafFile

path = "path/to/sample.paf"

contig = "chr1"
min_covg = 0.5
identifiers: List[str] = []
with PafFile(path) as paf:
    for record in paf:
        if record.tname == contig and record.query_coverage > min_covg:
            identifiers.append(record.qname)

Contributing

If you would like to contribute to pafpy, checkout CONTRIBUTING.md.

pafpy's People

Contributors

dependabot[bot] avatar lucventurini avatar mbhall88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pafpy's Issues

convert tags to str

How to write the full records PafRecord to file? How about mode={r,w} argument? (pafpy version: 0.1.2)

I have a PAF record like this:

$ head -n 1 demo.paf
11737-1     294     89      294     -       31171-1     292     87      292     205     205     0       NM:i:0    ms:i:410        AS:i:410        nn:i:0  tp:A:S  cm:i:37 s1:i:193        de:f:0  rl:i:91 cg:Z:205M

Do something: (filtering, ...), and the tags are messed.

# python
from pafpy import PafFile

with PafFile('demo.paf') as paf, open('demo.filtered.paf', 'wt') as w:
    for rec in paf:
        # do something
        print(str(rec), file=w)
        break

Tags values are missing in the output file:

$ cat demo.filtered.paf
11737-1     294     89      294     -       31171-1     292     87      292     205     205     0       NMms      AS      nn      tp      cm      s1      de      rl      cg

add support for gzipped paf file

Hi @mbhall88 , how about making PafFile() support for gzipped file?

I have a lot paf files, compressed in gzipped format (saving space).
How to open these files with current paf version 0.1.3?

I tried to use xopen to open the stream instead, and it works.

# file: pafpy/paffile.py

# add xopen
from xopen import xopen

# replace line-109
self._stream = xopen(self.path)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.