Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Analyse an array and join only some elements of it

by Cristoforo (Deacon)
on Jun 16, 2012 at 15:54 UTC ( #976580=note: print w/ replies, xml ) Need Help??


in reply to Analyse an array and join only some elements of it

From your description, it sounds like you are parsing a 'fasta' format file line by line and, if it is evenly divisible by 3, join that to a string of sequences passing that test. I'm not sure, but if a single line of the sequence is divisible by 3, the entire sequence may not. The method below reads in an entire sequence at a time, and checks for mod 3 == 0, (evenly divisible by 3).

#!/usr/bin/perl use strict; use warnings; use Bio::SeqIO; my $in = Bio::SeqIO->new( -file => "input1.txt" , -format => 'fasta'); my ($string, $valid, $invalid) = ('', 0, 0); while ( my $seq = $in->next_seq() ) { if ($seq->length % 3 == 0) { $string .= $seq->seq; ++$valid; } else { ++$invalid; } } open LOGFILE, ">", 'somefile' or die "Unable to open 'somefile' for wr +iting. $!"; print LOGFILE "Found ", $valid + $invalid, " blocks, joined $valid of +them and left out $invalid.\n"; close LOGFILE or die $!;

Chris


Comment on Re: Analyse an array and join only some elements of it
Download Code
Re^2: Analyse an array and join only some elements of it
by Istirion (Initiate) on Jun 18, 2012 at 16:02 UTC
    Hi again! Thank you very much for all of your help and really good ideas. I will try all of them and see which works best in my programm. Christoforo, you're completely right: the input file is an annotated fasta file, which I have to read line by line and analyse for Codon Usage and so on. I didn't use Bioperl for creating a seqobject but instead did all the work by myself. :-) Your wellthought objection can be clearly answered, I think. If all parts are divisible by three the entire sequenz should be also divisible by three, because it consists of parts which are divisible by three. Thanks again, Markus

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://976580]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2014-09-18 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (113 votes), past polls