<p dir="ltr">Also, instead of unfold_entities, use structure.get_residues() that returns a list (copy) of the residues that you can safely iterate and use detach_children() on. Again, on my phone, so it might not be entirely true... </p>
<br><div class="gmail_quote"><div dir="ltr">A qui, 26/11/2015, 18:36, João Rodrigues <<a href="mailto:j.p.g.l.m.rodrigues@gmail.com">j.p.g.l.m.rodrigues@gmail.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hi Claudia, you can use the build_peptides() function from the Bio.PDB.Polypeptides module. This should give you directly the fragments of the structure, based on a distance criterion. For the chain, you have to create new chains. </p>
<p dir="ltr">I'm on my phone so I can't verify it, but I'd first create a new empty structure (and model), get the fragments of the parsed structure, and then based on the fragment length add then to the new structure with a sequential chain ID. I think this is the optimal way. </p>
<p dir="ltr">What Jordan suggested works wonders if you want to filter a given structure. If you want just to remove small fragments, you could just tag these residues with a negative bfactor for example and then use this to filter with Select() and PDBIO(). </p>
<p dir="ltr">Cheers, </p>
<p dir="ltr">João </p>
<br><div class="gmail_quote"><div dir="ltr">A qui, 26/11/2015, 14:44, Claudia Millán Nebot <<a href="mailto:cmncri@ibmb.csic.es" target="_blank">cmncri@ibmb.csic.es</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Jordan, the removal of the residues is working, is the renaming of the chains that is causing trouble. I attach an example of input/output produced by the function.<div><br></div><div><br></div></div><div class="gmail_extra"><div class="gmail_quote">2015-11-26 9:09 GMT+00:00 Jordan Willis <span dir="ltr"><<a href="mailto:jwillis0720@gmail.com" target="_blank">jwillis0720@gmail.com</a>></span>:<br></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Also, the detach_child method should work in place, so I’m not sure why this is not working. Can you give an example PDB?<span><font color="#888888"><div><br></div></font></span><div><span><font color="#888888">Jordan<br></font></span><div><blockquote type="cite"><span><div>On Nov 25, 2015, at 12:16 PM, Claudia Millán Nebot <<a href="mailto:cmncri@ibmb.csic.es" target="_blank">cmncri@ibmb.csic.es</a>> wrote:</div><br></span><div><div><div><div dir="ltr"><div><div><div>Dear all,<br><br></div>I am writing a function that examines a structure, and if there are discontinuous regions that are smaller than a certain size, they will be removed from the structure. Then, I would like to write the structure as a pdb in which the chain identifiers are different for each discontinuous fragment. For that purpose, I want to change the chain id of certain residues. ¿What will be the best way to do it? Because right now it is not working, of course, because I am iterating over something that I am trying to change at the same time. Maybe I am missing something very obvious or straightforward, but I do not see what will be the best way to do it... ¿Maybe creating and empty chain and using the set_parent method?<br><br>The current code looks like this:<br>def trimByContinuityLimit(pdb_file,min_size):<br> parser=PDBParser()<br> structure=parser.get_structure(pdb_file[:-4],pdb_file)<br> residues=Selection.unfold_entities(structure,'R')<br> list_id="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"<br> dictio_chainid={}<br> residues_to_remove=[]<br> current_listres=[]<br> index=0<br> for i in range(len(residues)-1):<br> res1=residues[i]<br> res2=residues[i+1]<br> id1=<a href="http://res1.id/" target="_blank">res1.id</a><br> id2=<a href="http://res2.id/" target="_blank">res2.id</a><br> check=Bioinformatics.checkContinuity(res1,res2)<br> #print 'check',check<br> #print 'list_id[index]',list_id[index]<br> if check==True:<br> #print "These two residues are consecutive",res1,res2<br> if id1 not in current_listres:<br> current_listres.append(id1)<br> dictio_chainid[id1]=list_id[index]<br> if id2 not in current_listres:<br> current_listres.append(id2)<br> dictio_chainid[id2]=list_id[index]<br> #print 'list_id[index]',list_id[index]<br> #print 'id1,dictio_chainid[id1]',dictio_chainid[id1],id1<br> #print 'id2,dictio_chainid[id2]',dictio_chainid[id2],id2<br> elif check==False:<br> #print "These two residues are not consecutive",res1,res2<br> if id1 not in current_listres:<br> current_listres.append(id1)<br> dictio_chainid[id1]=list_id[index]<br> if len(current_listres)<min_size:<br> residues_to_remove.extend(current_listres)<br> if i==len(residues)-2 and min_size>1: # If we reach this point, then the last residue is not continuous so it is single :<br> residues_to_remove.append(id2)<br> else:<br> current_listres=[]<br> current_listres.append(id2)<br> index=index+1<br> dictio_chainid[id2]=list_id[index]<br> # Remove the residues and write the pdb<br> for model in structure:<br> for chain in model:<br> for residue in chain:<br> id_res=<a href="http://residue.id/" target="_blank">residue.id</a><br> if id_res in residues_to_remove:<br> chain.detach_child(id_res)<br> else:<br> <a href="http://chain.id/" target="_blank">chain.id</a>=dictio_chainid[id_res]<br> io=PDBIO()<br> io.set_structure(structure)<br> io.save(pdb_file[:-4]+'_trimmed.pdb',write_end=False)<br><br></div>Thanks in advance :)<br><br></div>Claudia<br></div></div></div><span>
_______________________________________________<br>Biopython mailing list - <a href="mailto:Biopython@mailman.open-bio.org" target="_blank">Biopython@mailman.open-bio.org</a><br><a href="http://mailman.open-bio.org/mailman/listinfo/biopython" target="_blank">http://mailman.open-bio.org/mailman/listinfo/biopython</a></span></div></blockquote></div><br></div></div></blockquote></div></div>
_______________________________________________<br>
Biopython mailing list - <a href="mailto:Biopython@mailman.open-bio.org" target="_blank">Biopython@mailman.open-bio.org</a><br>
<a href="http://mailman.open-bio.org/mailman/listinfo/biopython" rel="noreferrer" target="_blank">http://mailman.open-bio.org/mailman/listinfo/biopython</a></blockquote></div></blockquote></div>