<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"><br><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><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 class="HOEnZb"><font color="#888888"><div><br></div></font></span><div><span class="HOEnZb"><font color="#888888">Jordan<br></font></span><div><blockquote type="cite"><span class=""><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 class="h5"><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 class="">
_______________________________________________<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><br></div>