rename sequences in gap4

Jonathan Manning jmanning at genome.wi.mit.edu
Wed Aug 6 09:36:09 EST 2003

Marie-Henriette.FLAMENT at biogemma.com wrote:

> Hello,
> Please could you tell me how I can process to rename sequences in gap4 once
> the alignment is validated (expertised) ?
> (I know I can rename sequences before pregap but I woul like to avoid this
> step because I have to make again the alignment)
> Thank you for your help
> Best regards
> Marie-henriette flament
> ---

Here is some sample tcl code to rename sequences in an existing gap4 
database. This runs in the stash shell that comes with gap4.

You will have to have some sort of map from the current name to the 
desired name. A few simple rules would be best (ie. add a prefix or 
suffix to each existing name), but it really depends on what you want. 
Adapting this to your needs will require some TCL programming, or at 
least familiarity with regular expressions. Use the tcl documentation 
for regsub and regexp for help.



if { $argc != 2 } {
     puts stdout "usage: $argv0 db_name version"
     exit 1
load_package gap

set db_name [lindex $argv 0]
set version [lindex $argv 1]
puts stdout "Reading $db_name..."
set io [open_db -name $db_name -version $version -access "rw"]
set number [db_info num_readings $io]
set counter 1
while { $counter <= $number } {
     set name [io_read_reading_name $io $counter]
     set newname $name

     ## RULE 1
     # Replace abcd to defg. Use full regex's here.
     if { [ regsub {abcd} $name "defg" newname ] } {
         io_write_reading_name $io $counter $newname
         puts stdout "Renamed read $counter from '$name' to '$newname'"
     ## RULE 2
     # if it begins with a digit, add a R prefix.
     if { [ regsub {^[0-9]} $name "R\0" newname ] } {
         io_write_reading_name $io $counter $newname
         puts stdout "Renamed read $counter from '$name' to '$newname'"
     ## repeat as needed - write your own rules.

     set counter [expr $counter + 1]

close_db -io $io
exit 0

More information about the Staden mailing list

Send comments to us at biosci-help [At] net.bio.net