This file is indexed.

/usr/bin/bp_oligo_count is in bioperl 1.7.2-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/perl 
#
# oligomer_freq.pl
# We use this to determine what primers are useful for frequent priming of
# nucleic acid for random labeling
# Input: Sequence file, oligomer length
# Output: Tab-delimited text file of oligomer frequencies
# Written July 2, 2001
# Charles C. Kim

###########
# MODULES #
###########
use Bio::Seq;
use Bio::SeqIO;
use Getopt::Long;

#########################
# VARIABLES & FILENAMES #
#########################

use strict;
use warnings;

my ($format, $infile, $help, $outfile, $oligomerlength) = ('fasta');
GetOptions(
           'f|format:s'            => \$format,
           'i|in|s|sequence:s'     => \$infile,
           'h|help|?'              => \$help,
           'o|out:s'               => \$outfile,
           'length:i'              => \$oligomerlength
          );

my $USAGE = "Usage:\toligo_count [-h/--help] [-l/--length OLIGOLENGTH]\n".
    "\t[-f/--format SEQFORMAT] [-i/--in/-s/--sequence SEQFILE]\n".
    "\t[-o/--out OUTFILE]\n".
    "\tDefault SEQFORMAT is fasta\n";

print $USAGE and exit if $help;

unless ($infile ) {
    print 'Enter your concatenated FASTA sequence filename: ';
    chomp ($infile=<STDIN>);
}
unless (-e $infile) { die "$infile not found\n"; }

if ($outfile) {
    if (-e $outfile) {
	print "$outfile already exists!  Overwrite (Y/N)? ";
	chomp ($_ = <STDIN>);
	while (/[^yn]/i) {
	    print 'Y or N, please: ';
	    chomp ($_ = <STDIN>);
	}
	if (/n/i) { die "$outfile not overwritten.\n"; }
    }
#} else {
#    print 'Enter an output filename: ';
#    chomp ($outfile=<STDIN>);
#    if (-e $outfile) {
#	print "$outfile already exists!  Overwrite (Y/N)? ";
#	chomp ($_ = <STDIN>);
#	while (/[^yn]/i) {
#	    print 'Y or N, please: ';
#	    chomp ($_ = <STDIN>);
#	}
#	if (/n/i) { die "$outfile not overwritten.\n"; }
#    }
}

unless ($oligomerlength) {
    while () {
	print 'Enter an oligomer length to count: ';
	chomp($oligomerlength=<STDIN>);
	if ($oligomerlength !~ /\d/) {
	    print "Value is non-numeric!\n";
	}
	else {last;}
    }
}


########
# MAIN #
########

if ($oligomerlength >= 9) {
    print "An oligomer length of $oligomerlength will generate ";
    print 4 ** $oligomerlength, " combinations,\nwhich could cause ";
    print "an out of memory error.  Proceed? (y/n) ";
    chomp($_=<STDIN>);
    if (/y/i) { ; }
    else { die "Program terminated\n"; }
}
my @oligoseqs = &generate_all_oligos($oligomerlength);
my %oligos = ();
foreach  (@oligoseqs) {
    $oligos{$_} = 0;
}

my $in = Bio::SeqIO->new( -file => $infile,
		       -format => $format);
my $seqnumber = 0;
my $oligocounts = 0;
my $exception;
while (my $seq = $in->next_seq() ) {
    my $len = $seq->length();
    my $position = 1;
    if ($position+$oligomerlength > $len) {
	$exception = 2;
	next;
    }
    $seq = uc $seq->seq; #string
    $exception = 1 if $seq =~ /[^GATC]/;

    while ($position + $oligomerlength-1 <= $len) {
	$oligos{substr $seq, $position-1, $oligomerlength}++;
	$position++;
	if ($position%250000 == 0) {print "$position\n";}
    }
    $oligocounts += $position-1;
    $seqnumber++;
}

my $OUTFILE;
if ($outfile) {
    open $OUTFILE, '>', $outfile or die "Could not open file '$outfile': $!\n";
} else {
    open $OUTFILE, '>-'; # STDOUT
}
print $OUTFILE "$seqnumber sequences analyzed\n";
print $OUTFILE "$oligocounts total $oligomerlength-mers counted\n";
print $OUTFILE "$oligomerlength-mer\tNumber\tFrequency\n";
foreach my $key (sort keys %oligos) {
    print $OUTFILE "$key\t$oligos{$key}\t", $oligos{$key}/$oligocounts, "\n";
}
close $OUTFILE;

if ($exception) {
    if ($exception == 1) {
	print "Non-standard (non-GATC) bases were found in sequence\n";
    }
    if ($exception == 2) {
	print "Oligomer length greater than sequence length\n";
    }
}

#&notify();

###############
# SUBROUTINES #
###############

sub generate_all_oligos {
    my $oligolength = $_[0];
    my $iter = 1;
    my @newarray = qw{A C G T};
    my @bases = qw{A C G T};

    while ($iter < $oligolength) {
	my @oldarray = @newarray;
	@newarray = ();
	foreach my $oligoseq (@oldarray) {
	    foreach my $newbase (@bases) {
		push @newarray, $oligoseq . $newbase;
	    }
	}
	$iter++;
    }
    return @newarray;
}

# if you wanted to be notified about status of running
#my $EMAILADDRESS = undef;
#die("Must change script to a valid email addres for notification") 
#    unless( defined $EMAILADDRESS );

#sub notify {
#    $address = $EMAILADDRESS;
#    $address = $_[0] if $_[0];
#    open(SENDMAIL, "|/usr/lib/sendmail -oi -t") or die "Can't fork for sendmail: $!\n";
#    print SENDMAIL <<"EOF";
#From: Computer
#To: $address
#Subject: Program Finished
#	
#EOF
#    close(SENDMAIL) or warn "sendmail didn't close nicely";
#}

__END__

=head1 NAME

bp_oligo_count - oligo count and frequency

=head1 SYNOPSIS

  Usage:  bp_oligo_count [-h/--help] [-l/--length OLIGOLENGTH]
          [-f/--format SEQFORMAT] [-i/--in/-s/--sequence SEQFILE]
          [-o/--out OUTFILE]

=head1 DESCRIPTION

This scripts counts occurrence and frequency for all oligonucleotides
of given length.

It can be used to determine what primers are useful for
frequent priming of nucleic acid for random labeling.

Note that this script could be run by utilizing the compseq
program which is part of EMBOSS.

=head1 OPTIONS

The default sequence format is fasta. If no outfile is given, the
results will be printed to standard out. All other options can entered
interactively.

=head1 FEEDBACK

=head2 Mailing Lists

User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list.  Your participation is much appreciated.

  bioperl-l@bioperl.org                  - General discussion
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

=head2 Reporting Bugs

Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via the
web:

  https://github.com/bioperl/bioperl-live/issues

=head1 AUTHOR - Charles C. Kim

Email cckim@stanford.edu

=head1 HISTORY

Written July 2, 2001

Submitted to bioperl scripts project 2001/08/06

E<gt>E<gt> 100 x speed optimization by Heikki Lehvaslaiho

=cut