<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Ok, I will give it a try. updating chain.id = “something” should work in place. I just tested. We need to make sure those conditional statements are working while setting the id.<div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 26, 2015, at 2:59 AM, Claudia Millán Nebot <<a href="mailto:cmncri@ibmb.csic.es" class="">cmncri@ibmb.csic.es</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">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 class=""><br class=""></div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2015-11-26 9:09 GMT+00:00 Jordan Willis <span dir="ltr" class=""><<a href="mailto:jwillis0720@gmail.com" target="_blank" class="">jwillis0720@gmail.com</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">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 class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div></font></span><div class=""><span class="HOEnZb"><font color="#888888" class="">Jordan<br class=""></font></span><div class=""><blockquote type="cite" class=""><span class=""><div class="">On Nov 25, 2015, at 12:16 PM, Claudia Millán Nebot <<a href="mailto:cmncri@ibmb.csic.es" target="_blank" class="">cmncri@ibmb.csic.es</a>> wrote:</div><br class=""></span><div class=""><div class=""><div class="h5"><div dir="ltr" class=""><div class=""><div class=""><div class="">Dear all,<br class=""><br class=""></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 class=""><br class="">The current code looks like this:<br class="">def trimByContinuityLimit(pdb_file,min_size):<br class=""> parser=PDBParser()<br class=""> structure=parser.get_structure(pdb_file[:-4],pdb_file)<br class=""> residues=Selection.unfold_entities(structure,'R')<br class=""> list_id="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"<br class=""> dictio_chainid={}<br class=""> residues_to_remove=[]<br class=""> current_listres=[]<br class=""> index=0<br class=""> for i in range(len(residues)-1):<br class=""> res1=residues[i]<br class=""> res2=residues[i+1]<br class=""> id1=<a href="http://res1.id/" target="_blank" class="">res1.id</a><br class=""> id2=<a href="http://res2.id/" target="_blank" class="">res2.id</a><br class=""> check=Bioinformatics.checkContinuity(res1,res2)<br class=""> #print 'check',check<br class=""> #print 'list_id[index]',list_id[index]<br class=""> if check==True:<br class=""> #print "These two residues are consecutive",res1,res2<br class=""> if id1 not in current_listres:<br class=""> current_listres.append(id1)<br class=""> dictio_chainid[id1]=list_id[index]<br class=""> if id2 not in current_listres:<br class=""> current_listres.append(id2)<br class=""> dictio_chainid[id2]=list_id[index]<br class=""> #print 'list_id[index]',list_id[index]<br class=""> #print 'id1,dictio_chainid[id1]',dictio_chainid[id1],id1<br class=""> #print 'id2,dictio_chainid[id2]',dictio_chainid[id2],id2<br class=""> elif check==False:<br class=""> #print "These two residues are not consecutive",res1,res2<br class=""> if id1 not in current_listres:<br class=""> current_listres.append(id1)<br class=""> dictio_chainid[id1]=list_id[index]<br class=""> if len(current_listres)<min_size:<br class=""> residues_to_remove.extend(current_listres)<br class=""> 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 class=""> residues_to_remove.append(id2)<br class=""> else:<br class=""> current_listres=[]<br class=""> current_listres.append(id2)<br class=""> index=index+1<br class=""> dictio_chainid[id2]=list_id[index]<br class=""> # Remove the residues and write the pdb<br class=""> for model in structure:<br class=""> for chain in model:<br class=""> for residue in chain:<br class=""> id_res=<a href="http://residue.id/" target="_blank" class="">residue.id</a><br class=""> if id_res in residues_to_remove:<br class=""> chain.detach_child(id_res)<br class=""> else:<br class=""> <a href="http://chain.id/" target="_blank" class="">chain.id</a>=dictio_chainid[id_res]<br class=""> io=PDBIO()<br class=""> io.set_structure(structure)<br class=""> io.save(pdb_file[:-4]+'_trimmed.pdb',write_end=False)<br class=""><br class=""></div>Thanks in advance :)<br class=""><br class=""></div>Claudia<br class=""></div></div></div><span class="">
_______________________________________________<br class="">Biopython mailing list - <a href="mailto:Biopython@mailman.open-bio.org" target="_blank" class="">Biopython@mailman.open-bio.org</a><br class=""><a href="http://mailman.open-bio.org/mailman/listinfo/biopython" target="_blank" class="">http://mailman.open-bio.org/mailman/listinfo/biopython</a></span></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div>
<span id="cid:E9511E21-1627-4297-B9D5-687AB0415830@san.rr.com"><frag27A_0_0_trimmed.pdb></span><span id="cid:E08A653F-BE39-42FA-8072-95C8E678C837@san.rr.com"><frag27A_0_0.pdb></span></div></blockquote></div><br class=""></div></body></html>