[BiO BB] A problem about a subroutin in my code

Alex Zhang mayagao1999 at yahoo.com
Thu Aug 4 15:26:02 EDT 2005


Dear Felipe,

Thank you very much! Yes, it was an error for
'$origin[$y]'. 

Besides that, there was some other problem
with my code I think. It was supposed to produce
200 outputs but it produced only 100 outputs. 

Regards,
   Alex


--- Felipe Albrecht <felipe.albrecht at gmail.com> wrote:

> A just single comment, 
> 
> why in :
>     my @Motif = split(//,'$origin[$y]');     # This
> is a loop to get
> the motif template from origin8
> the variable $origin[$y] is under quotes?
> The correct isnt : " my @Motif =
> split(//,$origin[$y]); " ?
> 
> Felipe Albrecht
> 
> 2005/7/29, Alex Zhang <mayagao1999 at yahoo.com>:
> > Dear all, 
> >   
> > Sorry to bother you. I need some help on my code.
> I have an input file named
> > "origin8.txt" which holds 200 short sequences of
> width 8. My code is to use
> > each 
> > short sequence from "origin8.txt" as a template to
> generate 100 short
> > sequences of the same
> > width and store them in a txt file A. 
> > 
> > Then the code will read 100 short sequences from
> the txt file A and 100 long
> > sequences of width 200 from a txt file B , and
> then replaced a substring of
> > each long sequence using each short sequence. This
> code will lead to two txt
> > files C and D. File C will hold 100 replaced long
> sequences. 
> > 
> > In other words, I want to input "origin8.txt" to
> get 200 File D. 
> > 
> > My code can generates 200 File D but each of them
> holds nothing. So I guess
> > the problem is caused by a failure of passing the
> data to a subroutine named
> > "make_file". 
> > 
> > Can anybody suggest me how to modify that? Thank
> you very much in advance! 
> > 
> > Sincerely, 
> > 
> >      Alex 
> > 
> >   
> > 
> >   
> > 
> >   
> > 
> > My code: 
> > 
> >   
> > 
> >
>
*******************************************************************
> > 
> >  #!/usr/bin/perl
> > use strict;
> > use warnings;
> > my (@origin, $y);
> > my $N_Sequences = 100; 
> > my @Alphabet = split(//,'ACGT');      
> > my $P_Consensus = 0.85;               # This is
> the probability of dominant
> > letter
> > # ====== Globals ==========================
> > my @Probabilities;                    # Stores the
> > probability of each character
> > 
> > 
> > # ====== Program ==========================
> > 
> > open (ORIGIN, "< origin8.txt");       # This file
> holds 200 sequences used
> > for motif template
> > chomp (@origin = <ORIGIN>);
> > close ORIGIN;
> > 
> > for ($y=0; $y<=$#origin; $y++) {
> >   
> > 
> >      my @Motif = split(//,'$origin[$y]');     #
> This is a loop to get the
> > motif template from origin8
> >     open (OUT_NORM, ">short_sequences8_[$y].txt")
> or die "Unable to open
> > file :$!";
> >         for (my $i=0; $i < $N_Sequences; $i++) {
> >             for (my $j=0; $j < scalar(@Motif);
> $j++) {
> >                 
> loadConsensusCharacter($Motif[$j]);    
> >                  addNoiseToDistribution();        
>     
> >                  convertToIntervals();
> >                  print OUT_NORM
> (getRandomCharacter(rand(1.0)));
> >                                                   
>   }
> >             print OUT_NORM "\n";
> >             make_files();
> >                                                }
> >                               }
> > 
> > exit();
> > 
> > # ====== Subroutines =======================
> > #
> > sub loadConsensusCharacter {
> >     my ($char) = @_;
> >     my $Found = 'FALSE';
> > 
> >     for (my $i=0; $i < scalar(@Alphabet); $i++) {
> >         if ( $char eq $Alphabet[$i]) {
> >             $Probabilities[$i] = 1.0;
> >             $Found = 'TRUE';
> >         } else {
> >             $Probabilities[$i] = 0.0;
> >         }
> >     }
> >     if ($Found eq 'FALSE') {
> >     die("Panic: Motif-Character\"$char\" was not
> found in Alphabet.
> > Aborting.\n");
> >     }
> > 
> > return();
> > }
> > 
> > # ==========================================
> > sub addNoiseToDistribution {
> > 
> > 
> >     my $P_NonConsensus = ( 1.0-$P_Consensus) /
> (scalar(@Alphabet) - 1);
> > 
> >     for (my $i=0; $i < scalar(@Probabilities);
> $i++) {
> >         if ( $Probabilit ies[$i] == 1.0 ) {     
> >             $Probabilities[$i] = $P_Consensus;
> >         } else {
> >             $Probabilities[$i] = $P_NonConsensus;
> >         }
> >     }
> > 
> >     return();
> > }
> > 
> > # ==========================================
> > sub convertToIntervals {
> > 
> >     my $Sum = 0;
> > 
> >     for (my $i=1; $i < scalar(@Probabilities);
> $i++) {
> >         $Probabilities[$i] +=
> $Probabilities[$i-1];
> >     }
> > 
> >     return();
> > }
> > 
> > # ==========================================
> > sub getRandomCharacter {
> > 
> >     my ($RandomNumber) = @_;
> >    & nbsp;my $i=0;
> >     for ($i=0; $i < scalar(@Probabilities); $i++)
> {
> >         if ($Probabilities[$i] > $RandomNumber) {
> last; }
> >     }
> > 
> >     return($Alphabet[$i]);
> > }
> > 
> > # ==========================================
> > sub make_files {
> > my (@short, @long,$x,$r, $output_norm);
> > 
> > open (SHORT, "< short_sequences8_[$y].txt");
> > chomp (@short = <SHORT>);
> > close SHORT;
> > 
> > open (LONG, "< long_sequences.txt");
> > chomp (@long = <LONG>);
> > close LONG;
> > 
> > open (OUT_INITIAL,  "> output8_[$y]1.txt");
> > open (OUT_REPLACED, "> output8_[$y]2.txt");
> > 
> > for ($x=0; $x<=$#short; $x++) {
> >   $r=2;
> >   print OUT_INITIAL ">SeqName$x\n$long[$x]\n";
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the BBB mailing list