#!/usr/bin/perl -w ################################################# # gen_seqs.pl # Version 1 # Robert D. Cormia # UCSC Programming for Bioinformatics III # October 31, 2003 # Write a Perl program that will do the following: # Define a scalar $dna = 'CGACGTCTTCTCAGGCGA # # Create sequences which are are one character long through # 18 characters long. For example: # # 1 Char sequence: C G A C G T etc # 2 Char sequence: CG GA AC etc. and not CG CA CC etc # 3 Char sequence: CGA GAC ACG CGT etc # 16 Char sequence: CGACGTCTTCTCAGGC GACGTCTTCTCAGGCG # 17 Char sequence: CGACGTCTTCTCAGGCG GACGTCTTCTCAGGCGA # 18 Char sequence: CGACGTCTTCTCAGGCGA GACGTCTTCTCAGGCG # Do not leave smaller sequences at the end, i.e. three-characters # long should not have two or one-character sequences at the end. ################################################# use strict; print "\n"; # --------------------------------------------------------------- # Define the $dna scalar, determine the dna # --------------------------------------------------------------- my $dna = 'CGACGTCTTCTCAGGCGA'; my $dna_length = length($dna); my $position; # --------------------------------------------------------------- # Create subsequences that range from one-base long through # 18 bases long. Push them onto the array subsequences. Print # results to the screen. # --------------------------------------------------------------- for ( $position = 1 ; $position <= $dna_length ; ++$position ) { my @subsequences = (); my $skip = 0; while ( $dna =~ /.{$skip}(.{$position})/ ) { push ( @subsequences, $1 ); ++$skip; } print "$position", "-base long: @subsequences \n"; } __END__