1. use strict;
2. use SAPserver;
3. use Data::Dumper;
4.
5. my ($geneID,$max_distance);
6. my $usage = "usage: server_paper_example3 GeneID MaxDistance";
7. (
8. ($geneID = shift @ARGV) &&
9. ($max_distance = shift @ARGV)
10. )
11. || die $usage;
12.
13. my $sapObject = SAPserver->new();
14. my $geneLocH = $sapObject->fid_locations(-ids => [$geneID]);
15. my $geneLoc = $geneLocH->{$geneID}->[0];
16. if ($geneLoc =~ /^(\S+)_(\d+)([+-])(\d+)/) # retrieve an encoded location
17. {
18. my($contig,$beg,$strand,$length) = ($1,$2,$3,$4);
19. my ($left,$right);
20. if ($strand eq "+")
21. {
22. ($left,$right) = ($beg, $beg + ($length-1));
23. }
24. else
25. {
26. ($left,$right) = ($beg, $beg - ($length-1));
27. }
28. my $paddedLeft = ($left > $max_distance) ? $left - $max_distance : 1;
29. my $paddedRight = $right + $max_distance;
30. my $sz = ($paddedRight + 1) - $paddedLeft;
31. my $region = $contig . "_" . $paddedLeft . "+" . $sz;
32. my $genesInRegionH = $sapObject->genes_in_region(-locations => [$region],
33. -includeLocation => 1);
34. my $genesInRegion = $genesInRegionH->{$region};
35. foreach my $geneID2 (keys(%$genesInRegion)) {
36. my $location = $genesInRegion->{$geneID2};
37. $location =~ /^(\S+)_(\d+)([+-])(\d+)/;
38. print "$geneID2\t$1\t$2\t$3\t$4\n";
39. }
40. }