def MergePdbFiles( pdb_ids,
                   filenames,
                   rotations = None,
                   target = None,
                   do_gunzip = None):

    current_chain = 0

    map_old2new = {}

    current_id = ord("A")
    index = 0
    coord = []

    for index in range(len(pdb_ids)):
        
        coord.append("MODEL            %i\n" % (index))

        pdb_id = pdb_ids[index]
        
        pdb = pdb_id[0:4]
        
        if len(pdb_id) > 4:
            pdb_chain = string.upper(pdb_id[4])
        else:
            pdb_chain = None

        if not os.path.exists( filenames[index] ):
            raise "pdb file for %s not found" % pdb_id
        
        if do_gunzip:
            statement = "gunzip < %s" % filenames[index]
        else:
            statement = "cat %s" % filenames[index]

        if rotations:
            if rotations[index]:
                statement += " | %s %s" % (param_cmd_rotate, rotations[index])

        lines = os.popen(statement).readlines()

        for line in lines:
            if line[:4] == "ATOM":
                chain = string.upper(line[21])
                if pdb_chain and pdb_chain != chain: continue

                key = pdb_id + chain
                
                if not map_old2new.has_key(key):
                    map_old2new[key] = chr(current_id)
                    current_id += 1

                new_chain = map_old2new[key]
                
                coord.append(line[:21] + new_chain + line[22:])

        coord.append("ENDMDL\n")

    result=["HEADER    PROTEIN STRUCTURE ALIGNMENT"]
        
    for key in map_old2new.keys():
        result.append((map_old2new[key], key) % "COMPND    (%s) %s\n")
        
    result += coord 

    if target:
        file = open(target,"w")
    else:
        file = sys.stdout

    file.write(string.join(result, "") + "\n")

    if target:
        file.close()
dataset/ETHPy150Open CGATOxford/cgat/obsolete/merge_pdb_files.py/MergePdbFiles/swapped operands of `%`