Hot answers tagged

23 votes
Accepted

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

I don't know if it's the fastest, but the following provides an approximately 10x speed up over your functions: ...
user avatar
  • 19.3k
18 votes
Accepted

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

I'm not sure I'm doing it the best way, but here is an example where I read a compressed gzip fastq file and write the records in block gzip fastq: ...
user avatar
  • 2,930
18 votes
Accepted

How can I do an overlapping sequence count in Biopython?

For Biopython 1.70, there is a new Seq.count_overlap() method, which includes optional start and ...
user avatar
  • 3,462
13 votes

using python to write bioinformatics pipelines tutorial

Taking a different tack from other answers, there's lots of tools for pipelines in Python. Note: there was a time when people would use "pipeline" to refer to a shell script. I'm talking about ...
user avatar
  • 758
10 votes
Accepted

Counting number of possible alignments between two DNA sequences using python

A closed-form solution is offered in An exact formula for the number of alignments between two DNA sequences by Torres, Cabada, and Nieto: $$f(m,n)=\sum_{k=0}^{min(m,n)}2^{k}\binom{m}{k}\binom{n}{k}$$...
user avatar
10 votes
Accepted

Convert R RNA-seq data object to a Python object

A simple solution for converting Seurat objects into AnnData, as described in this vignette: ...
user avatar
  • 2,564
9 votes

How can I do an overlapping sequence count in Biopython?

I've encountered this problem before, and used python re module to solve this problem. ...
user avatar
  • 325
9 votes

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

Here's a Cython approach that might suggest a generic approach to speeding up Python work. If you're manipulating (ASCII) character strings and performance is a design consideration, then C or Perl ...
user avatar
8 votes
Accepted

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

The description field in the SeqRecord object has the information you are looking for: ...
user avatar
8 votes
Accepted

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

The first place to start is the GFF3 specification. This is the official word on what is and is not allowed in a GFF3 file. For example, users can define arbitrary attribute keys, so long as they do ...
user avatar
8 votes
Accepted

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

using a http request. if there is a DAS server, you can always use this protocol to download the xml -> fasta. see https://www.biostars.org/p/56/ ...
user avatar
  • 1,473
8 votes
Accepted

How do I find identical sequences in a FASTA file?

The trick would be to swap the key in the dictionary to be the sequence itself. Also I would recommend using a different separator that "_" since that is what the current ids have so that you can ...
user avatar
  • 2,566
8 votes
Accepted

Using Python, how to convert a pandas DataFrame into a VCF?

You will have to define the header either from an existing VCF file or hardcoded into you python script. Then write the header the the output VCF file then write the dataframe to the same file with ...
user avatar
  • 2,566
8 votes
Accepted

Biopython Phylogenetic Tree replace branch tip labels by sequence logos

To expand on my comment from yesterday. You could do this with the ETE Toolkit (I just copied one logo file rather than converting all 26 to png): ...
user avatar
  • 1,806
8 votes
Accepted

Snakemake: Cannot find first rule?

you are starting snakemake the wrong way. snakemake snakemake means "Running the pipeline in ...
user avatar
  • 1,322
8 votes
Accepted

Filtering fasta files by ID

You're assuming 2-line FASTA format, but the sequence can (and typically does) span multiple lines. You can use Biopython to build a simple parser: ...
user avatar
  • 3,462
7 votes
Accepted

Subset FASTA file by species name

Splitting into multiple files and changing the IDs can be easily done: ...
user avatar
  • 7,957
7 votes
Accepted

How to write a hash function for canonical kmers?

You can convert any string hash function to a "canonical" DNA string hash function. Given a DNA string $s$, let $\overline{s}$ be its Watson-Crick reverse complement. Suppose $h:\Sigma^*\to\mathbb{Z}$...
user avatar
  • 5,645
7 votes

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

The most reliable and simplest way is probably using Biopython: ...
user avatar
  • 3,462
7 votes
Accepted

How to do `bedtools intersection` using pandas alone?

Your setup: ...
user avatar
6 votes

Cannot install chromosomer

Chromosomer only exists for Python 2. You should thus be able to install it via pip2 install chromosomer But: Your Python installation is a bit screwed up: ...
user avatar
6 votes
Accepted

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

Using SeqIO.index rather than SeqIO.parse lets you read all the records into a dict, from ...
user avatar
  • 861
6 votes

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

I whipped this little script up using the KEGG API: ...
user avatar
  • 7,957
6 votes

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

using the REST API of togows: one can fetch a json structure of the genes associated to a kegg pathway. eg: http://togows.org/entry/kegg-pathway/hsa00010/genes.json ...
user avatar
  • 1,473
6 votes
Accepted

How to obtain clusters of hierarchical heatmap when using Python?

Clustering like this is typically done with scipy. Here's the code we use in deepTools (original context here): ...
user avatar
  • 19.3k
6 votes
Accepted

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

255 is the default maximum size of a Counttable in khmer. You want to do the following: ...
user avatar
  • 19.3k
6 votes
Accepted

How to extract the protein fasta file from a genbank file?

One can get it to work by using SeqIO.InsdcIO.GenBankCdsFeatureIterator: ...
user avatar
  • 743
6 votes

Python API for working with ENSEMBL genomes

Now there's another option, the ensembl_rest module, a thin wrapper around the Ensembl REST API to simplify its usage and make it more pythonic. You can find the ...
user avatar
  • 61
6 votes
Accepted

Biohackers Netflix - DNA to binary and video

I was quite curious when I saw that as well. I've spent more time than I'd care to admit trying the sort of things you have. I've gotten it decoded now, but I can't really claim any sort of victory, ...
user avatar
  • 176
5 votes

using python to write bioinformatics pipelines tutorial

BioPython has some good tools for processing reads and alignments. http://biopython.org/DIST/docs/tutorial/Tutorial.html There is a python library wrapping samtools so many of the samtools calls can ...
user avatar
  • 2,566

Only top scored, non community-wiki answers of a minimum length are eligible