| 1 | package TFBS::ConservationProfilescip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/; |
| 2 | |
| 3 | use strictscip-perl cpan TFBS v0.5.0 strict/; |
| 4 | |
| 5 | use Bio::Root::Rootscip-perl cpan TFBS v0.5.0 Bio/Root/Root/; |
| 6 | |
| 7 | use varsscip-perl cpan TFBS v0.5.0 vars/ qw'@ISA'; |
| 8 | @ISAscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`@ISA`. = qw'Bio::Root::Root'; |
| 9 | |
| 10 | sub newscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/new(). { |
| 11 | my ($caller, %args) = @_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`@_`.; |
| 12 | my $self = blessscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/bless(). {parameters=>{}, |
| 13 | alignment => undef, |
| 14 | ref_sequence => undef, |
| 15 | %args |
| 16 | } ,refscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/ref(). $caller || $caller; |
| 17 | |
| 18 | if (!definedscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/defined().($self->{conservation}) or refscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/ref().($self->{conservation}) ne "ARRAY") { |
| 19 | $self->throwscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/throw().("conservation: argument missing or wrong object type"); |
| 20 | } |
| 21 | |
| 22 | return $self; |
| 23 | |
| 24 | } |
| 25 | |
| 26 | sub paramscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/param(). { |
| 27 | my ($self, $param, $value) = @_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`@_`.; |
| 28 | if (!definedscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/defined(). $param) { |
| 29 | return keysscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/keys(). %{$self->{parameters}}; |
| 30 | } |
| 31 | elsif (definedscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/defined(). $value) { |
| 32 | $self->{parameters}->{$param} = $value; |
| 33 | } |
| 34 | return $self->{parameters}->{$param}; |
| 35 | |
| 36 | } |
| 37 | |
| 38 | sub alignmentscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/alignment(). { |
| 39 | $_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`@_`.[0]->{alignment} |
| 40 | } |
| 41 | |
| 42 | sub ref_sequencescip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/ref_sequence(). { |
| 43 | $_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`@_`.[0]->{ref_sequence} |
| 44 | } |
| 45 | |
| 46 | sub conserved_regions_as_gffscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/conserved_regions_as_gff(). { |
| 47 | my ($self, %args) = @_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`@_`.; |
| 48 | my @features = $self->conserved_regions_as_featuresscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/conserved_regions_as_features().; |
| 49 | my $output = ""; |
| 50 | foreach my $f (@features) { |
| 51 | $output .= $f->gff_stringscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/gff_string().."\n"; |
| 52 | } |
| 53 | return $output; |
| 54 | } |
| 55 | |
| 56 | sub conserved_regions_as_featuresscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/conserved_regions_as_features(). { |
| 57 | my ($self, %args) = @_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`@_`.; |
| 58 | my ($excl_feature_ref, $cutoff) = |
| 59 | $self->_rearrangescip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/_rearrange().([qw(exclude_features cutoff)], %args); |
| 60 | $cutoff = ($cutoff or $self->paramscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/param().("cutoff") or 0.7); |
| 61 | |
| 62 | print STDERR "CURRENT CUTOFF $cutoff\n"; |
| 63 | |
| 64 | my @conservation = $self->conservationscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/conservation().; |
| 65 | my ($START, $END); |
| 66 | if ($self->ref_sequencescip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/ref_sequence(). and $self->ref_sequencescip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/ref_sequence().->isascip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/isa().("Bio::LocatableSeq")) { |
| 67 | $START = $self->ref_sequencescip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/ref_sequence().->startscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/start().; |
| 68 | $END = $self->ref_sequencescip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/ref_sequence().->endscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/end().; |
| 69 | } |
| 70 | else { |
| 71 | $START = $self->alignment->get_seq_by_pos($self->param("ref_seq_nr" or 1))->start; |
| 72 | $END = $self->alignment->get_seq_by_pos($self->param("ref_seq_nr" or 1))->end; |
| 73 | } |
| 74 | if ($excl_feature_ref and refscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/ref().($excl_feature_ref) eq "ARRAY") { |
| 75 | foreach my $f (@$excl_feature_ref) { |
| 76 | my ($s, $e) = ($f->startscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/start()., $f->endscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/end().); |
| 77 | next if ($e<$START or $s>$END); |
| 78 | $s = $START if $s<$START; |
| 79 | $e = $END if $e>$END; |
| 80 | mapscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/map(). { $conservation[$_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/$_.] = 0 } ($s-$START..$e-$START); |
| 81 | } |
| 82 | } |
| 83 | # obtain a list of positions with threshold |
| 84 | my @cons_positions = ( (grepscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/grep(). {$conservation[$_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/$_.-$START]>=$cutoff} ($START..$#conservationscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`$#conservation`.+$START)), $END+1000); |
| 85 | # $END+1000 is a dummy position that simplifies the procedure |
| 86 | |
| 87 | my @features; |
| 88 | my $region_start = $cons_positions[0]; |
| 89 | my $counter = 0; |
| 90 | foreach my $i (0..$#cons_positionsscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`$#cons_positions`. ) { |
| 91 | if ($cons_positions[$i+1]-$cons_positions[$i]>10) { # 10 can be changed to max allowed gap in a conserved region |
| 92 | $counter++; |
| 93 | my $f = Bio::SeqFeature::Generic->newscip-perl cpan TFBS v0.5.0 Bio/SeqFeature/Generic/new().(-start=>$region_start, |
| 94 | -end =>$cons_positions[$i], |
| 95 | -primary => "CR$counter", |
| 96 | -score => $cons_positions[$i]-$region_start+1 |
| 97 | ); |
| 98 | |
| 99 | pushscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/push(). @features, $f; |
| 100 | print STDERR $features[-1]->gff_stringscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/gff_string().."\n"; |
| 101 | $region_start = $cons_positions[$i+1]; |
| 102 | } |
| 103 | } |
| 104 | return @features; |
| 105 | } |
| 106 | |
| 107 | sub conserved_regions_as_feature_pairsscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/conserved_regions_as_feature_pairs(). { |
| 108 | |
| 109 | |
| 110 | } |
| 111 | |
| 112 | sub conservationscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/conservation(). { |
| 113 | my ($self, $start, $end) = @_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`@_`.; |
| 114 | |
| 115 | if (!definedscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/defined(). $start) { |
| 116 | return @{$self->{conservation}} |
| 117 | } |
| 118 | else { |
| 119 | my ($START, $END); |
| 120 | if ($self->alignmentscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/alignment().) { |
| 121 | my $ref_seq_nr = ($self->paramscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/param().("ref_seq_nr") or 1); |
| 122 | $START = $self->alignmentscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/alignment().->get_seq_by_posscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/get_seq_by_pos().($ref_seq_nr)->startscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/start().; |
| 123 | $END = $self->alignmentscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/alignment().->get_seq_by_posscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/get_seq_by_pos().($ref_seq_nr)->endscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/end().; |
| 124 | } |
| 125 | else { |
| 126 | $START = 1; |
| 127 | } |
| 128 | if (definedscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/defined(). $end) { |
| 129 | my ($pad_start, $pad_end) = (0, 0); |
| 130 | if ($start < $START) { $pad_start = $START-$start; $start = $START; } |
| 131 | if ($end > $END) { $pad_end = $end-$END; $end = $END } |
| 132 | return (_blank_arrayscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/_blank_array().($pad_start), |
| 133 | @{$self->{conservation}}[$start-$START, $end-$START], |
| 134 | _blank_arrayscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/_blank_array().($pad_end) |
| 135 | ); |
| 136 | } |
| 137 | elsif ($start< $START) { |
| 138 | return undef; |
| 139 | } |
| 140 | else { |
| 141 | return $self->{conservation}->[$start-$START]; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | |
| 147 | sub _blank_arrayscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/_blank_array(). { |
| 148 | my ($length) = @_scip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/`@_`.; |
| 149 | my @arr = mapscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/map(). {undefscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/undef().} (0..$length); |
| 150 | popscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/pop(). @arr; |
| 151 | return @arr |
| 152 | } |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | sub conserved_sequencesscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/conserved_sequences(). { |
| 158 | |
| 159 | } |
| 160 | |
| 161 | sub conserved_subalignmentsscip-perl cpan TFBS v0.5.0 TFBS/ConservationProfile/conserved_subalignments(). { |
| 162 | |
| 163 | } |
| 164 | |
| 165 | 1; |