<s> """<STR_LIT>""" <EOL> import sys , os , getopt , re , string <EOL> param_pattern_pdb = "<STR_LIT>" <EOL> param_cmd_rotate = "<STR_LIT>" <EOL> param_gunzip = <NUM_LIT:0> <EOL> param_rotate = None <EOL> param_target = None <EOL> def MergePdbFiles ( pdb_ids , <EOL> filenames , <EOL> rotations = None , <EOL> target = None , <EOL> do_gunzip = None ) : <EOL> current_chain = <NUM_LIT:0> <EOL> map_old2new = { } <EOL> current_id = ord ( "<STR_LIT:A>" ) <EOL> index = <NUM_LIT:0> <EOL> coord = [ ] <EOL> for index in range ( len ( pdb_ids ) ) : <EOL> coord . append ( "<STR_LIT>" % ( index ) ) <EOL> pdb_id = pdb_ids [ index ] <EOL> pdb = pdb_id [ <NUM_LIT:0> : <NUM_LIT:4> ] <EOL> if len ( pdb_id ) > <NUM_LIT:4> : <EOL> pdb_chain = string . upper ( pdb_id [ <NUM_LIT:4> ] ) <EOL> else : <EOL> pdb_chain = None <EOL> if not os . path . exists ( filenames [ index ] ) : <EOL> raise "<STR_LIT>" % pdb_id <EOL> if do_gunzip : <EOL> statement = "<STR_LIT>" % filenames [ index ] <EOL> else : <EOL> statement = "<STR_LIT>" % filenames [ index ] <EOL> if rotations : <EOL> if rotations [ index ] : <EOL> statement += "<STR_LIT>" % ( param_cmd_rotate , rotations [ index ] ) <EOL> lines = os . popen ( statement ) . readlines ( ) <EOL> for line in lines : <EOL> if line [ : <NUM_LIT:4> ] == "<STR_LIT>" : <EOL> chain = string . upper ( line [ <NUM_LIT> ] ) <EOL> if pdb_chain and pdb_chain != chain : continue <EOL> key = pdb_id + chain <EOL> if not map_old2new . has_key ( key ) : <EOL> map_old2new [ key ] = chr ( current_id ) <EOL> current_id += <NUM_LIT:1> <EOL> new_chain = map_old2new [ key ] <EOL> coord . append ( line [ : <NUM_LIT> ] + new_chain + line [ <NUM_LIT> : ] ) <EOL> coord . append ( "<STR_LIT>" ) <EOL> result = [ "<STR_LIT>" ] <EOL> for key in map_old2new . keys ( ) : <EOL> result . append ( "<STR_LIT>" % ( map_old2new [ key ] , key ) ) <EOL> result += coord <EOL> if target : <EOL> file = open ( target , "<STR_LIT:w>" ) <EOL> else : <EOL> file = sys . stdout <EOL> file . write ( string . join ( result , "<STR_LIT>" ) + "<STR_LIT:\n>" ) <EOL> if target : <EOL> file . close ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> optlist , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> except getopt . error , msg : <EOL> print USAGE <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> for o , a in optlist : <EOL> if o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> param_gunzip = <NUM_LIT:1> <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> param_target = a <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> param_rotate = a <EOL> elif o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> param_filenames = string . split ( a , "<STR_LIT:U+002C>" ) <EOL> pdb_ids = [ ] <EOL> pdb_files = [ ] <EOL> for a in args : <EOL> pdb_ids . append ( a ) <EOL> pdb_files . append ( param_pattern_pdb % a [ : <NUM_LIT:4> ] ) <EOL> if param_rotate : <EOL> lines = map ( string . strip , string . split ( param_rotate , "<STR_LIT:@>" ) ) <EOL> rotations = [ ] <EOL> for line in lines : <EOL> data = re . split ( "<STR_LIT>" , line [ : - <NUM_LIT:1> ] ) <EOL> if len ( data ) == <NUM_LIT:1> : <EOL> rotations . append ( None ) <EOL> else : <EOL> if len ( data ) == <NUM_LIT:12> : <EOL> rotations . append ( string . join ( data , "<STR_LIT:U+0020>" ) ) <EOL> else : <EOL> raise "<STR_LIT>" <EOL> if len ( rotations ) != len ( pdb_ids ) : <EOL> raise "<STR_LIT>" <EOL> else : <EOL> rotations = None <EOL> if param_filenames : <EOL> pdb_files = param_filenames <EOL> MergePdbFiles ( pdb_ids , pdb_files , <EOL> rotations , <EOL> target = param_target , <EOL> do_gunzip = param_gunzip ) </s>
