Renyulb28 has asked for the wisdom of the Perl Monks concerning the following question:
I have a column of ID's that go by the format of 'rs#####', but occasionally I get 'rsundefined' if that ID is missing. In order to do the analyses I desire every ID must be unique, which means that it reads all of the ID's 'rsundefined' as duplicate entries. Thus, I need sort of a find and replace script, except everything it find the word undefined I would like it to add on a different integer to the end of it (ie rsundefined1, rsundefined2, etc etc) so that every ID is unique. Thanks for any help.
Re: I need a perl script to make every instance of a repeated word unique
by GrandFather (Saint) on Jan 28, 2011 at 22:23 UTC
|
I would like it to add on a different integer to the end
So do that. As you haven't shown us any code or data what further advice are you expecting? What is the problem you are having implementing the "search and replace script"? What have you tried?
True laziness is hard work
| [reply] |
Re: I need a perl script to make every instance of a repeated word unique
by tilly (Archbishop) on Jan 28, 2011 at 23:57 UTC
|
The substitution that you will need is s/\bundefined\b/"undefined" . ++$count/eg.
perlop has instructions for how to use such substitutions (look for "s/PATTERN/REPLACEMENT"), and perlrun documents the -p and -e flags which are likely to prove very useful for you. | [reply] [d/l] |
Re: I need a perl script to make every instance of a repeated word unique
by biohisham (Priest) on Jan 29, 2011 at 17:50 UTC
|
From 'rs#####' I suspect you're dealing with biology-related stuff, what is the file format if any, better still, show how the template looks like and how you want your output looking like, show your attempts, and then it will only be possible to provide you better guidance. The key is, clearly worded question with efforts displayed yield more accurate responses from the generous monks out here..
Go through How do I post a question effectively? and Perl and Bioinformatics ...
Excellence is an Endeavor of Persistence.
A Year-Old Monk :D .
| [reply] [d/l] |
Re: I need a perl script to make every instance of a repeated word unique
by jeffa (Bishop) on Jan 28, 2011 at 21:37 UTC
|
If the ID is missing, then maybe you should not insert it into your table. I presume you are talking about a database here ...are you? Another alternative would be to add an auto incremented column and let your database insert the unique IDs for you.
| [reply] [d/l] [select] |
|
While the ID is missing, each entry is still important to keep in the file since it is a reference file associated with another data file. Thus, the analysis program will read the undefined ID as missing, but it still needs it there to keep the two files consistent. I have the reference file as a text file right now with tab delimited formate, and would like to know if there is a simple solution to making each rsundefined unique as that would solve the problem by itself
| [reply] |
|