Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts

Wednesday, October 03, 2007

FASTA, betta, more

My girlfriend's sister asked for help. But all she got was a 16.

The purpose of this script is to get a file(name) as a first argument, a regexp as a second argument and then search trough the file and print out the whole sequence where any of the possible regexp values are found, being that the searched sequence itself must be identified with "<>" symbols and then do a little basic math with the elements we've found.

To try this out, save the following as (for instance) sequences.txt:

>50c's and 50t's
cccccccccccccccccccccccccccccccccccccccccccccccccctttttttttt
tttttttttttttttttttttttttttttttttttttttt
>10G's and 90A's
GGGGGGGGGGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>A random sequence
ccagtcctgtctaaggactttggttcatgcgttaatttcggttagccagtggcgcccacg
taacaaagtgcgaccgacctgcttccatagcattgaaatgtccttgattggagattttac
gcaggaggactgataagttcgggtctgaattgatgcagcgaacgttcatccaatactcag
acttgcactcagtcg
>A second random sequence
cgcatgacggccctcctcgacggttcattaaccttgcacaccaactgttcctcaaccgat
ctggtgtctttctcacttacatagcagttgctgtaccatttgatgggaacccgagatcac
cgggttatcgcgggagtttattccgaattgttctcggaaatgtggcgtcggcttgaattg
ggaataatacggatcttgacaagcacgatttcatccacaatgcggcacgagtaatcccct
tctggaaggatgcagaaaggacatatacaatgagctagccacgtggcgcataacgcagct
tggttagaaactaaatctatacaggaagatacagaatgggaacagtgtcgctcagtctag
ccagctagatccgcctttagtcgaccttaggggtaaggca

And the below code as scripty.pl:

print "\n\n *girfriends_sister_school_id* \*girfriends_sisters_friend_school_id*\n\n";
print "filename:\n";
$filename = ;
open(TEMPFILE, $filename) or die("Cannot open the file $filename");
print "Insert the regular expression to find:\n";
chomp($regexp=);
while () {

if ( /^>/xms) {
$paragraph = "";
$paragraph_head = $_
}
if ( /^$/xms) {
push @paragraphs, $paragraph;
} else {
$paragraph .= $_;
}
}
push @paragraphs, $paragraph;
foreach (@paragraphs) {
while ( $_ =~ /($regexp)/gi) {
$expressions{$1} += 1;
}
}
foreach $key (keys %expressions) {
print "\n\nPattern = $key\n";
foreach (@paragraphs) {
if ($_ =~ /$key/) {
$paragraph_with_patterns = $_;
$total = length$paragraph_with_patterns;
$counterA = 0;
$counterC = 0;
$counterT = 0;
$counterG = 0;
if ($key =~ /a/){
while ( $paragraph_with_patterns =~ /a/gi) {
$counterA += 1;
$sum1 = ($counterA/$total);
}
}
if ($key =~ /c/){
while ( $paragraph_with_patterns =~ /c/gi) {
$counterC += 1;
$sum2 = ($counterC/$total);
}
}
if ($key =~ /t/){
while ( $paragraph_with_patterns =~ /t/gi) {
$counterT += 1;
$sum3 = ($counterT/$total);
}
}
if ($key =~ /g/){
while ( $paragraph_with_patterns =~ /g/gi) {
$counterG += 1;
$sum4 = ($counterG/$total);
}
}
$paragraph_with_patterns =~ s/($key)/\<$1\>/gi;
print "$paragraph_with_patterns\n\n";
%sum = ();
%sum1 = ();
%sum2 = ();
%sum3 = ();
%sum4 = ();
if ($counterA >0){
%sum1 = ("A", $counterA);
}
if ($counterC >0){
%sum2 = ("C", $counterC);
}
if ($counterT >0){
%sum3 = ("T", $counterT);
}
if ($counterG >0){
%sum4 = ("G", $counterG);
}
%sum = (%sum1,%sum2,%sum3,%sum4);
foreach $key_id (sort hashValueDescendingNum (keys(%sum))) {
$div = ($sum{$key_id}/$total);
print "$key_id = $sum{$key_id} \/ $total = $div\n";
}
}
}
}
sub hashValueDescendingNum{
$sum{$b} <=> $sum{$a};
}
exit;

Then run perl scripty.pl . Put sequences.txt as the file and a[c|t]g as the regexp when prompted.

I had alot of fun doing this wich is a good thing since I didn't get paid.

And no, neither bio::perl, nor any other module for that matter, were options.

Finally, a major thank you must go out to sab for the priceless (as in: he didn't get paid either) help.

Thursday, April 05, 2007

Perl Tech Meeting

Yesterday I went to my first Perl Tech Meeting and I can't stress enough how geeky those guys are.

Having lots of easy going, funny intelligent people talking about something they like is always fun, but this was actually very informative, since there were some tech talks that covered areas such as better debugging, replacing bash with perl, using C to improve Perl scripts benchmarks (dam, this guy was awesome!).

I specially enjoyed meeting Francisco Cabrita hearing Miguel Duarte and José Castro and some others whose names elude me right now.

Anyway, thanks to SAB(offline for _way_ too long) and Penantes for the invite.

May the Camel be with you!

Wednesday, April 04, 2007

Long time no see

I was forced to observe the shutdown day for over a week (not really, but i'll get back to that) because my Macbook died on me.

It's never a good experience to be away from your mac, but to deal with the Apple support around here one must be prepared for the worst.

From telling me that the customer service guy wouldn't reply my e-mails because he had personal problems (hey that's funny,i have a personal problem too! MY MAC IS BROKEN! what a coincidence) to taking some 20 phone calls to finally get some answers (I have witnesses. And they're still laughing) i've seen it all with these guys.

If we consider that a large part of Apple sales come from mac owners showing off the “superior hardware and the user experience a mac gets you” to their friends and coworkers (I myself am responsible for at least 4 switchers over the past 6 months), one should expect a better level of emphasis on customer satisfaction right?

Thankfully I still have my trusty Asus laptop that managed to deliver the daily fix of web surfing, and getting most of my work done so I really didn't had to be offline for so long. I was just too negative to write anything useful.

Anyway the XVI Jornadas de Informática an event hosted at UBI went by, and this year at least I heard something about what happened there. In Ruby in Portuguese website there are even some of the presentations given there available for download.

My humble 2 cents however would be to manage to get some more publicity before it happens.

While on the subject of great events happening in this little
fascist square of dirt by the sea, the fifth national encounter on Open Technologies will be happening in Lisbon on the 19th, and although the organization is hosted by Sybase and seems to be very professional and extremely interesting, my favorite Solaris Admin - slash -Farmer boy already managed to find a bug on the event page.

Also, today I'm going to my first Perl Mongers tech meeting and I'm hopping that I'll be able to learn something from those guys, 'cos the Perl I know wouldn't move the proverbial mountain.