/usr/bin/bp_flanks is in bioperl 1.6.924-1.
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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | #!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
# -*-Perl-*-
#
# Heikki Lehvaslaiho <heikki-at-bioperl-dot-org>
# Finding flanking sequences for a variant.
#
#
# v. 1 16 Mar 2001
# v. 1.1 9 Aug 2001 interface change, more info in fasta header
# v. 2.0 23 Nov 2001 new code from the flanks CGI program
# support for EMBL-like positions
# v. 3.0 21 Feb 2003 new command line interface
use Bio::PrimarySeq;
use Bio::SeqIO;
use Bio::DB::EMBL;
use Bio::DB::GenBank;
use Getopt::Long;
use strict;
use warnings;
use constant VERSION => '3.0';
my $help = '';
my $flank = 100; # flank length on both sides of the region
my $in_format = 'EMBL'; # format of the file to read in
my @pos; # position(s) in the sequence
GetOptions ("help" => \$help, "flanklength=i" => \$flank,
"position=s" => \@pos );
@pos = split(/,/,join(',',@pos));
system("perldoc $0") if $help;
system("perldoc $0") unless @ARGV;
print STDERR "\nYou need to provide --position option\n" and system("perldoc $0")
unless @pos;
my $file = shift;
$file || system("perldoc $0");
my $seq = get_seq($file);
exit 0 unless $seq;
&extract($seq, \@pos, $flank);
#
## end main
#
sub get_seq {
my ($file) = @_;
my $IN_FORMAT = 'EMBL'; # format of the local file on disk
if (-e $file ) { # local file
my $in = Bio::SeqIO->new('-file' => $file,
'-format' => $IN_FORMAT);
$seq = $in->next_seq();
}
elsif ($file =~ /\./) { # sequence version from GenBank
eval {
my $gb = new Bio::DB::GenBank;
$seq = $gb->get_Seq_by_version($file);
};
} else { # plain accession mumber from more reliable EMBL
eval {
my $gb = new Bio::DB::EMBL;
$seq = $gb->get_Seq_by_acc($file);
};
}
print STDERR "Could not find sequence [$file]" && return unless $seq;
return $seq;
}
sub extract {
my ($seq, $pos, $flank) = @_;
my ($out_seq);
my $OUT_FORMAT = 'FASTA'; # output format, going into STDOUT
my $strand = 1; # default for the forward strand
my $out = Bio::SeqIO->new('-format' => $OUT_FORMAT);
my $count = 1;
foreach my $idpos (@$pos) {
my ($id, $pos_range, $start, $end, $allele_len);
my $inbetween = 0; # handle 23^24 notation as well as plain integer (24)
# but set flag and make corrections when needed
if ($idpos =~ /:/ ) { # id and position separator
($id, $pos_range) = split /:/, $idpos;
} else { # no id
$id = $count;
$count++;
$pos_range = $idpos;
}
$strand = -1 if $pos_range =~ /-$/; # opposite strand
$pos_range = $1 if $pos_range =~ /(.+)-/; # remove trailing '-'
if ($pos_range =~ /\^/) { # notation 23^24 used
($start, $end) = split /\^/, $pos_range;
print STDERR $id, ": Give adjacent nucleotides flanking '^' character, not [",
$start, "] and [", $end, "]\n" and next
unless $end == $start + 1;
$end = $start;
$inbetween = 1;
} else { # notation 23..24 used
($start, $end) = split /\.\./, $pos_range;
}
$end ||= $start; # notation 23 used
print STDERR $id, ": Start can not be larger than end. Not [",
$start, "] and [", $end, "]\n" and next
if $start > $end;
$allele_len = $end - $start;
# sanity checks
next unless defined $start && $start =~ /\d+/ && $start != 0;
print STDERR "Position '$start' not in sequence '$file'\n", and next
if $start < 1 or $start > $seq->length;
print STDERR "End position '$end' not in sequence '$file'\n", and next
if $end < 1 or $end > $seq->length;
# determine nucleotide positions
# left edge
my $five_start = $start - $flank;
$five_start = 1 if $five_start < 1; # not outside the sequence
# right edge
my $three_end = $start + $allele_len + $flank;
$three_end = $seq->length if $start + $allele_len + $flank > $seq->length;
$three_end-- if $inbetween;
# extract the sequences
my $five_prime = lc $seq->subseq($five_start , $start - 1); # left flank
my $snp = uc $seq->subseq($start, $end); # allele (always > 0 length)
$snp = lc $snp if $inbetween;
my $three_prime; # right flank
if ($end < $seq->length) { # make sure we are not beyond reference sequece
$three_prime = lc $seq->subseq($end + 1, $three_end);
} else {
$three_prime = '';
}
# allele positions in local, extracted coordinates
my $locpos = length($five_prime) + 1;
my $loc_end;
if ($allele_len) {
$loc_end = "..". ($locpos+$allele_len);
} else {
$loc_end = '';
$loc_end = '^'. ($locpos+1) if $inbetween;
}
# build FASTA id and description line
my $fastaid = uc($id). "_". uc($file).
" oripos=$pos_range strand=$strand allelepos=$locpos$loc_end";
#build BioPerl sequence objects
if ($strand == -1) {
my $five_prime_seq = new Bio::PrimarySeq(-alphabet=>'dna',-seq=>$five_prime);
my $snp_seq = new Bio::PrimarySeq(-alphabet=>'dna',-seq=>$snp);
my $three_prime_seq = new Bio::PrimarySeq(-alphabet=>'dna',-seq=>$three_prime);
my $str = $three_prime_seq->revcom->seq. " ".
$snp_seq->revcom->seq. " ". $five_prime_seq->revcom->seq;
$str =~ s/ //g;
$out_seq = new Bio::PrimarySeq (-id => $fastaid,
-alphabet=>'dna',
-seq => $str );
} else {
my $str = $five_prime. " ". $snp. " ". $three_prime;
$str =~ s/ //g;
$out_seq = new Bio::PrimarySeq (-id => $fastaid,
-alphabet=>'dna',
-seq => $str );
}
$out->write_seq($out_seq); # print sequence out
}
}
=head1 NAME
bp_flanks - finding flanking sequences for a variant in a sequence position
=head1 SYNOPSIS
bp_flanks --position POS [-p POS ...] [--flanklen INT]
accession | filename
=head1 DESCRIPTION
This script allows you to extract a subsequence around a region of
interest from an existing sequence. The output if fasta formatted
sequence entry where the header line contains additional information
about the location.
=head1 OPTIONS
The script takes one unnamed argument which be either a file name in
the local file system or a nucleotide sequence accession number.
-p Position uses simple nucleotide sequence feature table
--position notation to define the region of interest, typically a
SNP or microsatellite repeat around which the flanks are
defined.
There can be more than one position option or you can
give a comma separated list to one position option.
The format of a position is:
[id:] int | range | in-between [-]
The optional id is the name you want to call the new
sequence. If it not given in joins running number to the
entry name with an underscore.
The position is either a point (e.g. 234), a range (e.g
250..300) or insertion point between nucleotides
(e.g. 234^235)
If the position is not completely within the source
sequence the output sequence will be truncated and it
will print a warning.
The optional hyphen [-] at the end of the position
indicates that that you want the retrieved sequence to be
in the opposite strand.
-f Defaults to 100. This is the length of the nucleotides
--flanklen sequence retrieved on both sides of the given position.
If the source file does not contain
=head1 OUTPUT FORMAT
The output is a fasta formatted entry where the description file
contains tag=value pairs for information about where in the original
sequence the subsequence was taken.
The ID of the fasta entry is the name given at the command line joined
by hyphen to the filename or accesion of the source sequence. If no id
is given a series of consequtive integers is used.
The tag=value pairs are:
=over 3
=item oripos=int
position in the source file
=item strand=1|-1
strand of the sequence compared to the source sequence
=item allelepos=int
position of the region of interest in the current entry.
The tag is the same as used by dbSNP@NCBI
=back
The sequence highlights the allele variant position by showing it in
upper case and rest of the sequence in lower case characters.
=head1 EXAMPLE
% bp_flanks ~/seq/ar.embl
>1_/HOME/HEIKKI/SEQ/AR.EMBL oripos=100 strand=1 allelepos=100
taataactcagttcttatttgcacctacttcagtggacactgaatttggaaggtggagga
ttttgtttttttcttttaagatctgggcatcttttgaatCtacccttcaagtattaagag
acagactgtgagcctagcagggcagatcttgtccaccgtgtgtcttcttctgcacgagac
tttgaggctgtcagagcgct
=head1 TODO
The input files are assumed to be in EMBL format and the sequences are
retrieved only from the EMB database. Make this more generic and use
the registry.
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 lists 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
the bugs and their resolution. Bug reports can be submitted via the
web:
https://github.com/bioperl/bioperl-live/issues
=head1 AUTHOR - Heikki Lehvaslaiho
Email: E<lt>heikki-at-bioperl-dot-orgE<gt>
=cut
|