[Bioperl-l] deleting string fragments?

Paulo Almeida paulo.david at netvisao.pt
Thu Apr 1 05:03:45 EST 2004


I think the easiest way is to use a substitution:

while (<>){
s/-dfg//gi;
print OUT;
}

's/something/other/gi ' replaces 'something' with 'other'. The 'g' and 
'i' options make the substitution work in all instances of the string 
and in a case insensitive manner, respectively. There are some 
characters that you need to escape, like '.' and slashes, but I don't 
think you need to escape dashes, so what I wrote should work.

-Paulo Almeida

Gyoergy Abrusan wrote:

> Dear All,
>
> I would like to ask whether there is a command that deletes a certain 
> fragment of a sring.
>
> what I mean is:
> eg. I have stings like
>
> adfdfgfgg-dfgdfmgfgfgfg
>
> I would like to remove -dfg and print out only
>
> adfdfgfggdfmgfgfgfg
>
> Is there a commad (something similar to chop)that removes an arbitrary 
> substring from a string (the place of the target sequences is alvays 
> different)?
>
> eg.:
>
> open (OUT, ">RESULTS.txt")
>
> while(<>)
> {
> if ($_=~ /-dfg/g)
> {cut out -dfg ???
> print OUT "$_";}
>
> else
> {print OUT "$_";}
> }
> close OUT;
>
>
> I would greatly appreciate any help.
> Thanking you in advance.
>
> Best,
>
> Gyorgy Abrusan 




More information about the Bioperl-l mailing list