Skip to content

NatRadzik/seqlibNaRa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

The library overview

The seqlibNaRa library provides implementation of class DNASeq that defines a new type of a data structure facilitating different operations performed on DNA sequences.

Library installation using pip

Installation of the seqlibNaRa library with pip is quite straightforward:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple seqlibNaRa

A quick example of the library usage

Learn how to use the seqlibNaRa library with examples provided below.

# Import the DNASeq class from the seqlibNaRa library
from seqlibNaRa import DNASeq
import numpy as np

sequences = DNASeq.from_file("example.fasta")
seq1 = sequences["seq1"]

# Print the first 60 characters of the sequence in FASTA format
print(seq1)

# Get a reverse complement
rev = seq1.revcmpl()
print(rev)

# Slice using GenBank-style (1-based, inclusive)
subseq = seq1[10:50]
print(subseq)

# Access a single base (1-based)
print(seq1[5]) 

# Concatenate two sequences
seq2 = sequences["seq2"]
combined = seq1 + seq2
print(combined)

The DNASeq class in details

The DNASeq class class represents a DNA sequence with support for reverse complements, indexing, slicing, and string formatting.

Initialisation

DNASeq(seqid: str, title: str, seq: str)

Methods

  • __init__(self, seqid, title, seq) Initializes a new DNASeq object.
  • __add__(self, other: DNASeq) – (DNASeq). Concatenates two DNASeq objects into one.
  • __len__(self) – (int). Returns the length of the sequence.
  • __repr__(self) – (str). Returns a compact preview of the sequence (first 10 bases + "...").
  • __str__(self) – (str). Returns the sequence formatted in FASTA style (wrapped to 60 characters per line).
  • __getitem__(self, key) Allows GenBank-style 1-based indexing or slicing. Negative indexes are not allowed. Reverse slicing returns the reverse complement.
  • copy(self) – (DNASeq). Returns a copy of the sequence.
  • revcmpl(self) – (DNASeq). Returns the reverse complement of the current sequence.
  • from_file(filename: str) – (dict[str, DNASeq]). Loads one or more sequences from a FASTA file. Each sequence must have a unique ID.

Indexing and slicing

  • Subsequence extraction: seq[100:200] returns a new DNASeq object from base 100 to 200.
  • Reverse slicing: seq[200:100] returns the reverse complement of the range 100–200.
  • Single-base access: seq[5] returns the 5th base (1-based).
  • Using steps for slicing is not allowed and will raise errors.

Adding two sequences

combined = seq1 + seq2

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages