New answers tagged

3

You can set the molecule type on the existing annotations attribute of the record objects just before they get to SeqIO.write. There might be an even leaner way to do it, but if open the output file (so that you can do multiple writes to one file handle) and then iterate over each record from the GFF iterator, you can do it like this: with open(out_file, &...


2

Since this is not a correct PDB file, it can be interpreted differently by different PDB reading libraries. The most reliable way to change it would be to read it as plain text and change the chain ID to B in the lines that have segment ID LA0. Note: Strings RA0 and LA0 start at column 73. Columns in the PDB format correspond to characters. This is not a ...


4

I am pretty sure there would be more elegant, in-place solutions but here is a quick solution to your problem. Should be OK if your sequence dictionary is not way too large. seq_names = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples renamed_sequence = {} for i in seq_names: renamed_sequence[i[1]] = sequence[i[0]] ...


0

You posted similar question here: https://stackoverflow.com/questions/69676943/how-can-i-get-a-list-of-neighboring-hydrogen-atoms-of-an-alpha-carbon/69815509#69815509 ok got some code : from Bio.PDB import Chain, Atom, NeighborSearch, PDBParser, Selection def get_hydrogen_atoms(c_alpha_atom: Atom.Atom, po): ns = NeighborSearch(po) return [h for h in ...


0

I don't believe this is possible. So I'm answering this to close it, since I don't have enough reputation to close it myself.


0

This BioPython document should get you started. A specific example is given here.


0

I was going to write some clever code counting k-mers, but this problem can easily be solved using the handy sequentially-operating feature of python's str.replace() method. This code doesn't work if you need to look at the motif occurring on the other strand. Just the forward strand. #!/usr/bin/env python3 mystring = "...


3

ok tried a little bit, not sure is the most elegant/fastest way of doing it starting from file from : https://www.ncbi.nlm.nih.gov/nuccore/NC_004460.2?report=gbwithparts&log$=seqview {GenBank(Full)} here my code: from Bio import SeqIO from Bio.Seq import Seq from Bio.SeqRecord import SeqRecord file_name = 'CMCP6.gb' # stores all the CDS entries ...


1

The other answer is correct. But I thought I'd give a few pointers in how one can understand how to do something with a given Python module —teach a man to fish kind of thing... In a Jupyter Notebook or IPython shell (don't), you can do: help(function) print out the docstring dir(object) shows all the public and magic attributes and methods —note a class ...


1

Not sure but here https://biopython.org/docs/1.75/api/Bio.PDB.Residue.html Bio.PDB.Residue module Your can find : add(self, atom) : Add an Atom object. Checks for adding duplicate atoms, and raises a PDBConstructionException if so. Can’t try it just now but who knows it may work Googling around I found out that if you plan to add Hydrogens to PDB ...


Top 50 recent answers are included