| 1 | package TFBS::Ext::pwmsearchscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/; |
| 2 | |
| 3 | requirescip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/require(). 5.005_62; |
| 4 | use strictscip-perl cpan TFBS v0.5.0 strict/; |
| 5 | use warningsscip-perl cpan TFBS v0.5.0 warnings/; |
| 6 | use varsscip-perl cpan TFBS v0.5.0 vars/ qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); |
| 7 | use Bio::SeqIOscip-perl cpan TFBS v0.5.0 Bio/SeqIO/; |
| 8 | use File::Tempscip-perl cpan TFBS v0.5.0 File/Temp/ qw (:POSIX); |
| 9 | |
| 10 | requirescip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/require(). Exporter; |
| 11 | requirescip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/require(). DynaLoader; |
| 12 | |
| 13 | our @ISAscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/`@ISA`. = qw(Exporter DynaLoader); |
| 14 | |
| 15 | # Items to export into callers namespace by default. Note: do not export |
| 16 | # names by default without a very good reason. Use EXPORT_OK instead. |
| 17 | # Do not simply export all your public functions/methods/constants. |
| 18 | |
| 19 | # This allows declaration use TFBS::Ext::pwmsearch ':all'; |
| 20 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
| 21 | # will save memory. |
| 22 | %EXPORT_TAGSscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/`%EXPORT_TAGS`. = ( 'all' => [ qw( |
| 23 | |
| 24 | ) ] ); |
| 25 | |
| 26 | @EXPORT_OKscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/`@EXPORT_OK`. = ( @{ $EXPORT_TAGSscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/`%EXPORT_TAGS`.{'all'} } ); |
| 27 | |
| 28 | @EXPORTscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/`@EXPORT`. = qw( |
| 29 | |
| 30 | ); |
| 31 | $VERSIONscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/$VERSION. = '0.2'; |
| 32 | |
| 33 | bootstrapscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/bootstrap(). TFBS::Ext::pwmsearchscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch(). $VERSIONscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/$VERSION.; |
| 34 | |
| 35 | # Preloaded methods go here. |
| 36 | |
| 37 | sub pwmsearchscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/pwmsearch(). { |
| 38 | my ($matrixobj, $seqobj, $threshold, $start, $end) = @_scip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/`@_`.; |
| 39 | $start = 1 if !definedscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/defined().($start); |
| 40 | $end = $seqobj->lengthscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/length(). if !definedscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/defined().($end); |
| 41 | my $matrixfile = tmpnamscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/tmpnam().(); |
| 42 | openscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/open(). (MATRIX, ">$matrixfile") or diescip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/die(). ("Error opening temporary file."); |
| 43 | print MATRIX $matrixobj->rawprintscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/rawprint().(); |
| 44 | close MATRIX; |
| 45 | |
| 46 | my $outfile = tmpnamscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/tmpnam().(); |
| 47 | |
| 48 | # pwm_search is confused by long descriptions - we delete desc temporarily: |
| 49 | |
| 50 | my $save_desc = $seqobj->descscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/desc().(); |
| 51 | $seqobj->descscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/desc().(""); |
| 52 | |
| 53 | my $seqfile; |
| 54 | if ($seqobj->{_fastafile}) { |
| 55 | $seqfile = $seqobj->{_fastafile}; |
| 56 | } |
| 57 | else { |
| 58 | $seqfile = tmpnamscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/tmpnam().(); |
| 59 | my $outstream = Bio::SeqIO->newscip-perl cpan TFBS v0.5.0 Bio/SeqIO/new().(-file=>">$seqfile", -format=>"fasta"); |
| 60 | $outstream->write_seqscip-perl cpan TFBS v0.5.0 Bio/SeqIO/write_seq().(Bio::Seq->newscip-perl cpan TFBS v0.5.0 Bio/Seq/new().(-seq =>$seqobj->subseqscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/subseq().($start, $end), |
| 61 | -id =>$seqobj->idscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/id().)); |
| 62 | $outstream->closescip-perl cpan TFBS v0.5.0 Bio/SeqIO/close().(); |
| 63 | } |
| 64 | |
| 65 | $seqobj->descscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/desc().($save_desc); |
| 66 | |
| 67 | # calculate threshold |
| 68 | |
| 69 | if ($threshold) { |
| 70 | if ($threshold =~ /(.+)%/) { |
| 71 | # percentage |
| 72 | $threshold = $matrixobj->{min_score} + |
| 73 | ($matrixobj->{max_score} - $matrixobj->{min_score})* $1scip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/$1./100; |
| 74 | } |
| 75 | else { |
| 76 | # absolute value |
| 77 | # $threshold = $args{-threshold}; |
| 78 | } |
| 79 | } |
| 80 | else { |
| 81 | # no threshold given |
| 82 | $threshold = $matrixobj->{min_score} -1; |
| 83 | } |
| 84 | |
| 85 | search_xsscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/search_xs().($matrixfile, $seqfile, |
| 86 | $threshold, $matrixobj->namescip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/name().()."", |
| 87 | $matrixobj->{'class'}."", $outfile); |
| 88 | |
| 89 | unlinkscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/unlink(). $seqfile unless $seqobj->{'_fastafile'}; |
| 90 | unlinkscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/unlink(). $matrixfile; |
| 91 | |
| 92 | my $hitlist = TFBS::SiteSet->newscip-perl cpan TFBS v0.5.0 TFBS/SiteSet/new().(); |
| 93 | my ($TFname, $TFclass) = ($matrixobj->{name}, $matrixobj->{class}); |
| 94 | |
| 95 | |
| 96 | my $save_delim = $/scip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/`$/`.; # bugfix submitted |
| 97 | local $/scip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/`$/`. = "\n"; # by Michal Lapidot |
| 98 | |
| 99 | openscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/open(). (OUTFILE, $outfile) |
| 100 | or diescip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/die().("Could not read temporary outfile"); |
| 101 | while (my $line = <OUTFILE>) { |
| 102 | # print STDERR $line; |
| 103 | chompscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/chomp(). $line; |
| 104 | $line =~ s/^\s+//; |
| 105 | $line =~ s/ *\t */\t/g; |
| 106 | my ($seq_id, $factor, $class, $strand, $score, $pos, $siteseq) = |
| 107 | (splitscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/split(). /\t/, $line)[0, 2, 3, 4, 5, 7, 9]; |
| 108 | my $num_strand = ($strand eq "-")? "-1" : "1"; |
| 109 | my $site = TFBS::Site->newscip-perl cpan TFBS v0.5.0 TFBS/Site/new(). ( -seq_id => $seqobj->display_idscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/display_id().()."", |
| 110 | -seqobj => $seqobj, |
| 111 | -strand => $num_strand."", |
| 112 | -pattern => $matrixobj, |
| 113 | -siteseq => $siteseq."", |
| 114 | -score => $score."", |
| 115 | -start => $pos +$start -1, |
| 116 | -end => $pos +$start |
| 117 | +lengthscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/length().($siteseq) -2 |
| 118 | ); |
| 119 | $hitlist->add_sitescip-perl cpan TFBS v0.5.0 TFBS/SiteSet/add_site().($site); |
| 120 | } |
| 121 | close OUTFILE; |
| 122 | $/scip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/`$/`. = $save_delim; |
| 123 | unlinkscip-perl cpan TFBS v0.5.0 TFBS/Ext/pwmsearch/unlink(). $outfile; |
| 124 | return $hitlist; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | 1; |
| 129 | __END__ |
| 130 | |
| 131 | =head1 NAME |
| 132 | |
| 133 | TFBS::Ext::pwmsearch - Perl extension for scanning a DNA sequence object with a position weight matrix |
| 134 | |
| 135 | =head1 SYNOPSIS |
| 136 | |
| 137 | use TFBS::Ext::pwmsearch; |
| 138 | pwmsearch |
| 139 | |
| 140 | =head1 DESCRIPTION |
| 141 | |
| 142 | Stub documentation for TFBS::Ext::pwmsearch, created by h2xs. It looks like the |
| 143 | author of the extension was negligent enough to leave the stub |
| 144 | unedited. |
| 145 | |
| 146 | Blah blah blah. |
| 147 | |
| 148 | =head2 EXPORT |
| 149 | |
| 150 | None by default. |
| 151 | |
| 152 | |
| 153 | =head1 AUTHOR |
| 154 | |
| 155 | A. U. Thor, [email protected] |
| 156 | |
| 157 | =head1 SEE ALSO |
| 158 | |
| 159 | perl(1). |
| 160 | |
| 161 | =cut |