Forum Moderators: coopster & phranque

Message Too Old, No Replies

confused with strings.

         

ktsirig

10:02 am on Jan 11, 2006 (gmt 0)

10+ Year Member



Hi all!
I have this assignment to give in Biology class and I am stuck.

Assignment:
I am given a sequence of letters, say:

XXXXXXABCDXXXXXXXX

and I am interested in part ABCD, which represents letters #7-#10 as you can see.

I am then given the same sequence, which now contains characters like * and!(only these 2 are allowed),
say:

XX**XXX!X**AB*!C*DXX*!XXX**XXX

and I want to find out which letters now represent the part ABCD.
If you count, you see that ABCD is now letters #14-#20 [4*and! were added prior to A and 10 prior to D]

What I think must be done is:
1) check how many (if any) * or/and! were added prior to start letter A(#7)
2) check how many (if any) * or/and! were added prior to end letter D(#10)
3) add all * and/or! to starting and ending letter of part ABCD

Has anyone got any hints to give me as to which functions of Perl will be useful for this problem?

rocknbil

10:29 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know how perl fits in biology, while it's supposed to be a natural language I didn't know it was organic. :-)

If I understand the question, something like this?

#!/usr/bin/perl

$string = 'XXXXXXABCDXXXXXXXX';
$string2 = 'XX**XXX!X**AB*!C*DXX*!XXX**XXX';

foreach $str ($string,$string2) {
print "Find positions of ABCD in $str:\n";
foreach $letter ('A','B','C','D') {
## index ([string],[substring],[start])
## Index is ZERO BASED. Hence the third letter has an index of 2, so we increment it to show it's in the third position.
$index = index($str,$letter,0) + 1;
print "$letter: $index; ";
}
print "\n";
}

This should output

Find positions of ABCD in XXXXXXABCDXXXXXXXX:
A: 7; B: 8; C: 9; D:10;
Find positions of ABCD in XX**XXX!X**AB*!C*DXX*!XXX**XXX:
A: 12; B: 13; C: 16; D:18;

Xenon001

11:09 am on Jan 11, 2006 (gmt 0)

10+ Year Member



Perl fits great into biology since O'Reilly has some nice books about Perl and bioinformatics ...

But of course this has nothing to do with CGI programming.

So perhaps you should have a look at O'Reillys online book shelf. Since my last try's studing biology was in 1998 - the books are most likely online for free reading.

perl_diver

7:15 pm on Jan 11, 2006 (gmt 0)

10+ Year Member



well, how very nice of you to do their class work assingment for them! Sure wish there was an internet back in the dark ages when I was in school!

rocknbil

1:31 am on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I didn't. Did I? No, I don't think I did. I just pointed him/her in the right direction. I think. :-)

The help we provide in these days makes up for all the bad kharma we built in those dark ages. :-D

perl_diver

2:46 am on Jan 12, 2006 (gmt 0)

10+ Year Member




he help we provide in these days makes up for all the bad kharma we built in those dark ages. :-D

Yikes! I am way behind if that's the case! Last I checked:

my bad karma = 1000000
my good karma = -2

ktsirig

3:48 pm on Jan 27, 2006 (gmt 0)

10+ Year Member



" well, how very nice of you to do their class work assingment for them! Sure wish there was an internet back in the dark ages when I was in school! "

Perl_diver, this is not a school assignment, but I wanted to make a program and gave an example of what I needed. I couldn't explain in a proggaming forum what exactly I want, and I tried to simplify it.
Rocknbil was kind enough and pointed me to some direction, my problem was greater than that.
And, I really don't see why you bother replying in a topic which seeks for help just to make fun of people who don't know as much as you do... Grow up man! We are not little children...

perl_diver

5:11 am on Jan 28, 2006 (gmt 0)

10+ Year Member



I think at 50 I am about as grown up as I will get, maybe not, my wife accuses me of acting juvenile sometimes.


I have this assignment to give in Biology class and I am stuck.

not a classroom assingment? Sorry for misunderstanding your above statement then.

You have mistaken humor with making fun of people, don't be so sensitive, it's ok to laugh at yourself as well as others. Cool? (see, who even says cool anymore?) I still think you're a wonderful person and will be gald to help you with anything, except your class work ;)

jatar_k

8:18 am on Jan 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



nuff said

ktsirig

11:24 am on Jan 28, 2006 (gmt 0)

10+ Year Member



I saw the admin locked the post, so I couldn't reply to it.
I want to say sorry to perl_diver for my nerves the other day..
In the forum it's difficult to say what I need the script for. Actually, I study Biology in Athens and in the University we don't have any classes concerning programming. In the senior year where I am, we must undertake an assignment.. In the assignment, I came up with a problem similar to what I described (it was NOT the assignment, but one small part unfortunately :( ).
Anyway, I was out of line and I apologize to you and the forum...
Thank you!

perl_diver

9:31 pm on Jan 28, 2006 (gmt 0)

10+ Year Member



glady and graciously accepted :)

jatar_k

4:55 am on Jan 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



unlocked and spliced since everyone was very adult and gracious

sorry, I'm jaded after all these years :)