Skip to main content

Questions tagged [python]

python is a programming language, widely used in bioinformatics

Filter by
Sorted by
Tagged with
21 votes
8 answers
10k views

What is the fastest way to get the reverse complement of a DNA sequence in python?

I am writing a python script that requires a reverse complement function to be called on DNA strings of length 1 through around length 30. Line profiling programs indicate that my functions spend a ...
conchoecia's user avatar
  • 3,181
14 votes
3 answers
6k views

How do you write a .gz fastq file with Biopython?

How do you write a .gz (or .bgz) fastq file using ...
Mark Ebbert's user avatar
  • 1,354
14 votes
1 answer
2k views

Biopython Phylogenetic Tree replace branch tip labels by sequence logos

Having recently constructed a lot of phylogenetic trees with the module TreeConstruction from Phylo package from Biopython, I've been asked to replace the branch tip labels by the corresponding ...
Boris Schnider's user avatar
13 votes
3 answers
2k views

How can I do an overlapping sequence count in Biopython?

Biopython's .count() methods, like Python's str.count(), perform a non-overlapping count, how can I do an overlapping one? For ...
Chris_Rands's user avatar
  • 3,948
11 votes
1 answer
3k views

Changing the record id in a FASTA file using BioPython

I have the following FASTA file, original.fasta: >foo GCTCACACATAGTTGATGCAGATGTTGAATTCACTATGAGGTGGGAGGATGTAGGGCCA I need ...
BioGeek's user avatar
  • 496
11 votes
3 answers
7k views

Converting a VCF into a FASTA given a reference with Python, R

I am interested in converting a VCF file into a FASTA file given a reference sequence with Python or R. Samtools/BCFtools (Heng Li) provides a Perl script ...
ShanZhengYang's user avatar
10 votes
6 answers
7k views

How do I find identical sequences in a FASTA file?

I want to create a database for a proteomics study. Therefore, the mapping from a given sequence to a protein ID has to be unique. I am wondering whether there is already a built-in function in ...
Cleb's user avatar
  • 743
10 votes
2 answers
2k views

How do you generate read-length vs read-quality plot for long-read sequencing data (e.g., MinION)?

How do you generate read-length vs read-quality plot (heat map with histograms in the margin) for long-read sequencing data from the Oxford Nanopore Technologies (ONT) MinION? The MinKNOW software ...
Mark Ebbert's user avatar
  • 1,354
9 votes
3 answers
4k views

Running Snakemake in one single conda env

I have been experimenting a lot lately with Snakemake, I love it. Recently I also switched to using conda (--use-conda) in the way that is advertised. However, I have some issues with it, mostly ...
Freek's user avatar
  • 563
9 votes
3 answers
5k views

Convert R RNA-seq data object to a Python object

I have done some work in R and would like to try a Python tool. What is a good way to import the data (and its annotations etc) as a Python object? I am particularly interested in converting a ...
Peter's user avatar
  • 2,634
9 votes
1 answer
401 views

How to get the count of each kmer past 255 using khmer

I have a Fastq file and I want to get the exact count of each possible kmer from this file. On a previous post called How to use khmer to count k-mers? Daniel Standage proposed a custom script based ...
hilta007's user avatar
  • 173
9 votes
2 answers
2k views

Is there a standard way to clean a PDB file and re-number its residues?

Is there a pre-existing tool which will tidy up the numbering of a PDB file? Firstly, I would like to re-number the residues on inserts to make the icode an actual residue in the chain (by that I ...
TW93's user avatar
  • 449
8 votes
4 answers
2k views

How to do `bedtools intersection` using pandas alone?

I have two pandas Dataframes, using python3.x: ...
EB2127's user avatar
  • 1,423
8 votes
2 answers
3k views

Subset FASTA file by species name

I have a problem: I've managed to download a massive fasta file of 1500 sequences, but now I want to split them into separate fasta files based on the genus. EDIT The fasta file looks like this: ...
tahunami's user avatar
  • 303
8 votes
1 answer
1k views

How GFF3 attributes (9th column) varies from one gene prediction algorithm to another

GFF3 files are in tabular format with 9 fields per line, separated by tabs. The first 8 fields share almost same data structure, but the 9th field varies a lot depending on feature type and gene ...
Arijit Panda's user avatar
8 votes
1 answer
468 views

Getting protein FASTA sequence based on keyword with python

I would like to gather proteins FASTA sequence from Entrez with python 2.7. I am looking for any proteins that have the keywords: "terminase" and "large" in their name. So far I got this code: ...
tahunami's user avatar
  • 303
7 votes
3 answers
2k views

Read PDB file, extract dihedral angles, modify dihedral angles, reconstruct Cartesian coordinates, and write PDB file

As the title summarizes, I am trying to: Read a PDB file (for example, 1enh.pdb). Extract the backbone dihedral angles (phi, psi). Modify the dihedral angles (phi, ...
epsilone's user avatar
  • 125
7 votes
3 answers
2k views

Importing GFF file with Biopython

Is there a way to import a GFF file for an organism with Biopython in the same way you can for a Genbank file? For example, ...
Alex Summers's user avatar
7 votes
2 answers
870 views

How to write a hash function for canonical kmers?

This question is a follow up from How do kmer counters determine which kmer is 'canonical'?. In that question we learned that kmer counting programs use a 2-bit hash function to internally represent ...
conchoecia's user avatar
  • 3,181
7 votes
2 answers
581 views

Is there any function in Biopython to convert a DNA sequence from ambiguous to unambiguous?

I have a project to write in Python that requires to write a function that given degenerate DNA sequence (for example: KKGTACACCAG) sequence and a molecular weight interval, returns a list of all ...
Ke Keiss's user avatar
7 votes
1 answer
768 views

Using pysam with cython: htslib/kstring.h not found

I'm trying to learn to use cython to speed up some code based on pysam. My issue is not strictly speaking about bioinformatics, but rather about building tools using a bioinformatics library. I hope ...
bli's user avatar
  • 3,130
7 votes
2 answers
252 views

What methods should I use from PythonCyc API to query metabolites in BioCyc database?

I am using PythonCyc API in order to write a query for metabolites in BioCyc. The purpose of this API is to communicate with the database software of BioCyc- Pathway Tools. Pathway Tools is in lisp ...
astridmarilyn's user avatar
7 votes
2 answers
647 views

How to get all PDB homologs from Uniprot (mapping + BLAST)?

I'd like to create a dataset consisting of all sequences which are either present in the PDB, or whose homolog is present in the PDB. In other words, any sequence in the PDB or any sequence related to ...
Zubo's user avatar
  • 179
7 votes
2 answers
3k views

Extracting the CIGAR string from a BAM via Python?

Is there a standard method in Python to extract a CIGAR string from the BAM? There are great libraries which parse the CIGAR, e.g. https://pypi.python.org/pypi/cigar/0.1 ...
ShanZhengYang's user avatar
7 votes
1 answer
914 views

Filtering bases based on phred qualities with pysam

Is there a way to filter bases in BAM files based on phred quallities through python's pysam ? I have a code here that Takes the nucleobases per position from a BAM file using pysam's pileup ...
Ammar Sabir Cheema's user avatar
7 votes
2 answers
733 views

Truncating branch length values of Phylogenetic tree with biopython

I have been using biopython 1.72 to display my phylogenetic tree files. Using the function 'Phylo.draw(pars_tree, branch_labels=lambda c: c.branch_length)' to ...
Sidra Younas's user avatar
7 votes
1 answer
640 views

Reject reads with low quality bases from a Bam file through pysam

I have a code below: ...
Ammar Sabir Cheema's user avatar
6 votes
5 answers
6k views

How to create Phylogenetic Trees from fasta files in Python or R?

I have around a hundred Fasta files (and will collect several thousand) with DNA sequences and +50x coverage. What is a recommended method to construct a phylogenetic tree? Solutions in Python or R ...
Soerendip's user avatar
  • 1,295
6 votes
4 answers
11k views

Extract residue sequence from pdb file (in biopython, but open to recommendations)

I'm new to Biopython and I'd like to extract the sequence of residues from a pdb file. My two questions are: What is the simplest way to do this? (Esp. when there is more than one sequence) and ...
mzzx's user avatar
  • 175
6 votes
3 answers
2k views

How can I extract gene names for a metabolic pathway from KEGG?

Note: this question has also been asked on Biostars I need the get the list of gene names involved in glycolysis (to put an example). Not manually, I need to do this in a script. Ideally with Python. ...
a06e's user avatar
  • 161
6 votes
3 answers
890 views

Generating the reconstructed alignment from BAM

I have a (small) BAM file with CIGAR and MD fields. Question 1: What tools exists in Python and/or R to reconstruct the alignment between the reference and the read in a BAM? Given that this is a ...
ShanZhengYang's user avatar
6 votes
2 answers
380 views

Is there any way of using biopython to write Swissprot files?

I have the following mwe for filtering a Swissprot file based on a certain feature, in this case, transmembrane regions. ...
James's user avatar
  • 409
6 votes
2 answers
248 views

BioPython internal_coords module returns different dihedral angles for the (seemingly) same protein structure

I am using the internal_coords module from BioPython in order to compare dihedral angles of two different conformations of the same protein. The conformations are ...
CubeHead's user avatar
  • 425
6 votes
2 answers
963 views

How can I edit a specific FASTQ read in place, given the read ID?

I am introducing SNVs into specific samples in order to estimate false negative rates for a variant calling pipeline. I know reads can be simulated but I would actually prefer to use the real data so ...
dkainer's user avatar
  • 128
6 votes
1 answer
450 views

Biohackers Netflix - DNA to binary and video

I'm not sponsored or anything, just interested in their challenge to decipher their DNA code. They encoded their first episode of "Biohackers" video/binary file to DNA code and said if we ...
xamax 's user avatar
  • 63
6 votes
1 answer
151 views

Getting all NNI trees of a parsimony tree

I have an aligned protein sequence file which I have been using for reconstructing a parsimonious tree. I am currently using NNITreeSearcher._get_neighbors method from Biopython 1.72 but it's way to ...
Sidra Younas's user avatar
6 votes
1 answer
1k views

How to maximize fastq parsing with FastqGeneralIterator (Bio.SeqIO.QualityIO)

I'm contributing to a python-based project that uses Biopython to analyze fastq files. It currently uses SeqIO.parse, which ...
Mark Ebbert's user avatar
  • 1,354
6 votes
1 answer
220 views

Generating random BED intervals given constraints

Problem is to generate a random BED interval given the following constraints: minimum start maximum end fixed length maximum ...
victorlin's user avatar
  • 161
6 votes
0 answers
340 views

Using dssp after chain extraction

I have a list of PDB IDs with realtive chains IDs that have to be extracted, and then run on dssp. For the single chain extraction I tried several methods, such as: ...
saiden's user avatar
  • 171
6 votes
0 answers
1k views

changing blast parameters using NCBIWWW module

I have found a blog post with a script that I would like to use for my current research project: link The script is incredibly fast and produces a smooth conservation plot. In the blog post, the ...
bluescholar1212's user avatar
5 votes
4 answers
291 views

File I/O error using nglview.show_biopython(structure)

So I have been trying to get into visualizing proteins in python, so after some research I ended up on a tutorial that was teaching you how to visualize a protein from the COVID-19 virus, so I went ...
Jeremiah Wade's user avatar
5 votes
2 answers
859 views

What does "fetching by region is not available for SAM files" mean?

I am used to gzip/biopython solutions when dealing with sequencing data, but now I wish to switch to more elegant ...
Kamil S Jaron's user avatar
5 votes
4 answers
2k views

Range overlap python error with genomic regions

I have two files s3.txt : 1 10 20 1 5 20 2 20 30 2 25 30 1 10 50 2 20 60 1 14 17 s4.txt: 1 10 20 2 20 30 I am trying to match col0 ...
novicebioinforesearcher's user avatar
5 votes
2 answers
373 views

Why does it require 4 vectors to calculate a torsion angle?

The BioPython documentation shows the following: 11.6.3 Measuring torsion angles Use the vector representation of the atomic coordinates, and the calc dihedral function from the Vector module: ...
user366312's user avatar
5 votes
3 answers
2k views

Way to get genomic sequences at given coordinates without downloading fasta files of whole chromosomes/genomes first?

So I have a list of start and stop positions along chromosomes in different species, and I'd like to get the corresponding DNA sequence for each set of coordinates. In the past, I've just download the ...
Eric Brenner's user avatar
5 votes
3 answers
5k views

How to translate amino acid sequences to Nucleotide sequences

I want to convert a list of fasta ( protein sequences) in a .text file into corresponding nucleotide sequences. A Google search gives me result of DNA to protein conversion but not vice versa. Also, I ...
user3289492's user avatar
5 votes
2 answers
422 views

Is there a Python/R package with the ability to convert an alignment and reference into a CIGAR?

I'm writing a python function from scratch to do this, but I feel like this must exist in some standard bioinformatics library already. In principle, this is a simply regex operation which many must ...
EB2127's user avatar
  • 1,423
5 votes
4 answers
3k views

How to map PDB chains to Uniprot IDs using API services

I have a lot of PDB IDs and I need to get uniprot fasta sequences of these PDB IDs special chains by API services. For example, imagine that I need to get fasta sequence of '1kf6' 'A' chain. The ...
Sara's user avatar
  • 777
5 votes
1 answer
737 views

Read and write FASTA files with more information than id and sequence

I am trying to read a fasta file, manipulate is in Python (using BioPython) and then write it back. The format of my sequences is like: ...
Leonidas Souliotis's user avatar
5 votes
2 answers
158 views

Counting letters in phylip alignment columns with Biopython

I have been using python 3.6 and biopython 1.72 to work with protein data files. I am using a protein sequence file (phylip format), for example: ...
Sidra Younas's user avatar

1
2 3 4 5
13