Skip to main content

CD-HIT cluster parser

Project description

cdhit-parser

Python package Conda downloads

CD-HIT file reader.

Read CD-HIT .clstr file

Basic usage

input = "cluster.fa.clstr"
for cluster in read_cdhit(input):
    print(f"{cluster.name} refSequence={cluster.refname} size={len(cluster)}")

    for member in cluster.sequences:
        print(f" {member.name} ({member.length}) identity={member.identity}% {'(Reference sequence)' if member.is_ref else ''}")

Load all clusters in to a list:

# Load all clusters to a list
clusters = read_cdhit(input).read_items()

Read FASTA file

if os.path.exists(fileName):
    for seq in cdhit_reader.read_fasta(fileName, line_len=60):
        print(seq) # will be wrapped at 60 chars per line, use 0 to disable wrapping
        
        # to access individual attributes:
        # print(">" + seq.name + " " + seq.comment + "\n" + seq.sequence)

Install

pip install cdhit-reader

or via Miniconda, which will also install cd-hit

conda install -c bioconda -c conda-forge cdhit-reader

Demo applications

Cluster stats

The module ships a demo program called cdhit-reader.py.

cdhit-parser -h

Compare two fasta files

:warning: This requires cd-hit installed and available in the system path.

cdhit-compare allows to compare two fasta files and print the sequences that are in common, those which are only present in one of the files or those which are redundant.

cdhit-compare --help

Example:

cdhit-compare data/input1.faa data/input2.faa  --id 0.99

will produce:

input1  BJJOHBJ_00007
input2  BJJOHBJ_00007
input2  BJJOHBJ_00002
both    BJJOHBJ_00003:BJJOHBJ_00003
both    BJJOHBJ_00005:BJJOHBJ_00005
both    BJJOHBJ_00004:BJJOHBJ_00004
multi   input1#IBJJOHBJ_00006,input1#BBJJOHBJ_000B6,input1#CBJJOHBJ_000C6,input2#IBJJOHBJ_00006,input2#BBJJOHBJ_000B6,input2#CBJJOHBJ_000C6
dupl_input1     BJJOHBJ_00001:BJJOHBJ_000F

where records starting with file1 or file2 are only present in one of the files, records starting with both are present in both files (one per file), records starting with dupl are duplicates (two in one of the files), and records starting with multi are present multiple times in at least one of the datasets.

Author

License

This project is licensed under the MIT License.

Acknowledgments

This module was based on fasta_reader by Danilo Horta

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdhit-reader-0.1.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

cdhit_reader-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file cdhit-reader-0.1.0.tar.gz.

File metadata

  • Download URL: cdhit-reader-0.1.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for cdhit-reader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e4a074d7f094070e587b7daaae2456de66ee68db929f44af7db961f65ca13938
MD5 c3c1b94c635cd430f5dfe9537d5b2aab
BLAKE2b-256 bc08597c9463011228f424ea50e8a8dd238c93b5e2bc46d8bd35b3e724afb6c0

See more details on using hashes here.

File details

Details for the file cdhit_reader-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cdhit_reader-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for cdhit_reader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2afe30e08170eb3773fa7b8eb89110eff817cd40e3c0920c9270cb7247cf164
MD5 a573691e751105cfe4309fa1e4202a53
BLAKE2b-256 4e63ffd17ee379bd507b48746fa09f1e0efb770003124f80a7b8adb83a283295

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page