Questions tagged [python]
python is a programming language, widely used in bioinformatics
597
questions
21
votes
8
answers
9k
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
9
votes
3
answers
4k
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 ...
9
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 ...
9
votes
1
answer
392
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 ...
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 ...
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:
...
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 ...
8
votes
1
answer
460
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:
...
7
votes
4
answers
2k
views
How to do `bedtools intersection` using pandas alone?
I have two pandas Dataframes, using python3.x:
...
7
votes
3
answers
1k
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, ...
7
votes
3
answers
1k
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,
...
7
votes
2
answers
856
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 ...
7
votes
2
answers
533
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 ...
7
votes
2
answers
245
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 ...
7
votes
2
answers
628
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 ...
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
...
7
votes
1
answer
865
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 ...
7
votes
2
answers
669
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 ...
7
votes
1
answer
616
views
Reject reads with low quality bases from a Bam file through pysam
I have a code below:
...
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 ...
6
votes
4
answers
9k
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
...
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. ...
6
votes
3
answers
850
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 ...
6
votes
2
answers
371
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.
...
6
votes
2
answers
913
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 ...
6
votes
2
answers
228
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 ...
6
votes
1
answer
441
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 ...
6
votes
1
answer
722
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 ...
6
votes
1
answer
148
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 ...
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 ...
6
votes
1
answer
214
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 ...
6
votes
0
answers
303
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:
...
6
votes
0
answers
978
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 ...
5
votes
4
answers
260
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 ...
5
votes
2
answers
825
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 ...
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 ...
5
votes
2
answers
315
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:
...
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 ...
5
votes
3
answers
4k
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 ...
5
votes
2
answers
393
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 ...
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 ...
5
votes
1
answer
731
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:
...
5
votes
2
answers
152
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:
...