tutorials:perl:count_ecori_site.pl
- count_EcoRI_site.pl
# count_EcoRI_site.pl # Read a fasta file and count the number of # EcoRI restriction sites in each sequence. my $in_file = shift; my $seq_hash; # key = seq_name, value = seq; { # redefine the record separator local $/ = ">"; open IN, "<$in_file"; my $in_line = <IN>; # toss the first record while ( $in_line = <IN> ) { chomp $in_line; # remove the ">" character in the end my ( $seq_name, $seq ) = split( /\n/, $in_line, 2 ); $seq =~ tr/ \t\n\r//d; # Remove whitespace $seq_hash{$seq_name} = uc $seq; } close IN; } foreach my $seq_name ( sort keys %seq_hash ) { my @sites = $seq_hash{$seq_name} =~ /(GAATTC)/g; print "$seq_name has ", scalar @sites, " EcoRI sites\n"; }
tutorials/perl/count_ecori_site.pl.txt · Last modified: 2012/06/15 00:38 by chkuo