Perl 板


LINE

package Restrictionmap; use base ( "Restriction" ); # # A class to find locations of restriction enzyme recognition sites in # DNA sequence data, and to display them. # use strict; use warnings; use Carp; # Class data and methods { # A list of all attributes with default values. my %_attributes = ( # key = restriction enzyme name # value = space-separated string of recognition sites => regular expressions _rebase => { }, # A Rebase.pm object _sequence => '', # DNA sequence data in raw format (only bases) _enzyme => '', # space separated string of one or more enzyme names _map => { }, # hash: enzyme names => arrays of locations _graphictype => 'text', # one of 'text' or 'png' or some other _graphic => '', # a graphic display of the restriction map ); # Return a list of all attributes sub _all_attributes { keys %_attributes; } } sub get_graphic { my($self) = @_; # If the graphic is not stored, calculate and store it unless($self->{_graphic}) { unless($self->{_graphictype}) { croak 'Attribute graphictype not set (default is "text")'; } # if graphictype is "xyz", method that makes the graphic is "_drawmap_xyz" my $drawmapfunctionname = "_drawmap_" . $self->{_graphictype}; # Calculate and store the graphic $self->{_graphic} = $self->$drawmapfunctionname; } # Return the stored graphic return $self->{_graphic}; } # # Methods to output graphics in text format # sub _drawmap_text { my($self) = @_; my @annotation = (); push(@annotation, _initialize_annotation_text($self->get_sequence)); foreach my $enzyme ($self->get_enzyme_names) { _add_annotation_text(\@annotation, $enzyme, $self->get_enzyme_map($enzyme)); } # Format the restriction map as sequence and annotation my @output = _formatmaptext(50, $self->get_sequence, @annotation); # Return output as a string, not an array of lines return join('', @output); } # Make a blank string of the same length as the given sequence string sub _initialize_annotation_text { my($seq) = @_; return ' ' x length($seq); } # Add annotation to an annotation string sub _add_annotation_text { my($array, $enz, @pos) = @_; # $array is a reference to an array of annotations # Put the labels for the enzyme name at the correct positions in the annotation foreach my $location (@pos) { # Loop through all the annotation strings as necessary for( my $i = 0 ; $i < @$array ; ++$i ) { # If the annotation contains only space characters at that position, # insert the annotation if(substr($$array[$i], $location-1, length($enz)) eq (' ' x length($enz))){ substr($$array[$i], $location-1, length($enz)) = $enz; last; # If the annotation collides, add it to the next annotation string on the # next iteration of the "for" loop. # But first, if there is not another annotation string, make one }elsif($i == (@$array - 1)) { push(@$array, _initialize_annotation_text($$array[0])); } } } } # Sequence with annotation lines formatted for the page with line breaks sub _formatmaptext { my($line_length, $seq, @annotation) = @_; my(@output) = (); # Split strings into lines of $line_length for ( my $pos = 0 ; $pos < length($seq) ; $pos += $line_length ) { # Print annotation on top of sequence, using reverse foreach my $string ( reverse ($seq, @annotation) ) { # Discard blank lines? # if ( substr($string, $pos, $line_length) !~ /[^ \n]/ ) { # next; # } # Add line to output push(@output, substr($string, $pos, $line_length) . "\n"); } # separate the lines push(@output,"\n"); } # Return the merged annotation and sequence return @output; } # # Method to output graphics in PNG format # sub _drawmap_png { my($self) = @_; # Get text version of graphic my @maptext = split( /\n+/, $self->_drawmap_text); # Now make a PNG graphic from the text version use GD; # # Layout information: fonts, margins, image size # # Use built-in GD fixed-width font 'gdMediumBoldFont' (could use TrueType fonts) # # Font character size in pixels my ($fontwidth, $fontheight) = (gdMediumBoldFont->width, gdMediumBoldFont->height); # Margins top, bottom, right, left, and between lines my ($tmarg, $bmarg, $rmarg, $lmarg, $linemarg) = (10, 10, 10, 10, 5); # Image width is length of line times width of a character, plus margins my ($imagewidth) = (length($maptext[0]) * $fontwidth) + $lmarg + $rmarg; # Image height is height of font plus margin times number of lines, plus margins my ($imageheight) = (($fontheight + $linemarg) * (scalar @maptext)) + $tmarg + $bmarg; my $image = new GD::Image($imagewidth, $imageheight); # First one becomes background color my $white = $image->colorAllocate(255, 255, 255); my $black = $image->colorAllocate(0, 0, 0); my $red = $image->colorAllocate(255, 0, 0); # Origin at upper left hand corner my ($x, $y) = ($lmarg, $tmarg); # # Draw the lines on the image # foreach my $line (@maptext) { chomp $line; # Draw annotation in red if($line =~ / /) { #annotation has spaces $image->string(gdMediumBoldFont, $x, $y, $line, $red); # Draw sequence in black }else{ #sequence $image->string(gdMediumBoldFont, $x, $y, $line, $black); } $y += ($fontheight + $linemarg); } return $image->png; } # # Method to output graphics in JPEG format # sub _drawmap_jpg { my($self) = @_; # Get text version of graphic my @maptext = split( /\n+/, $self->_drawmap_text); # Now make a JPEG graphic from the text version use GD; # # Layout information: fonts, margins, image size # # Use built-in GD fixed-width font 'gdMediumBoldFont' (could use TrueType fonts) # # Font character size in pixels my ($fontwidth, $fontheight) = (gdMediumBoldFont->width, gdMediumBoldFont->height); # Margins top, bottom, right, left, and between lines my ($tmarg, $bmarg, $rmarg, $lmarg, $linemarg) = (10, 10, 10, 10, 5); # Image width is length of line times width of a character, plus margins my ($imagewidth) = (length($maptext[0]) * $fontwidth) + $lmarg + $rmarg; # Image height is height of font plus margin times number of lines, plus margins my ($imageheight) = (($fontheight + $linemarg) * (scalar @maptext)) + $tmarg + $bmarg; my $image = new GD::Image($imagewidth, $imageheight); # First one becomes background color my $white = $image->colorAllocate(255, 255, 255); my $black = $image->colorAllocate(0, 0, 0); my $red = $image->colorAllocate(255, 0, 0); # Origin at upper left hand corner my ($x, $y) = ($lmarg, $tmarg); # # Draw the lines on the image # foreach my $line (@maptext) { chomp $line; # Draw annotation in red if($line =~ / /) { #annotation has spaces $image->string(gdMediumBoldFont, $x, $y, $line, $red); # Draw sequence in black }else{ #sequence $image->string(gdMediumBoldFont, $x, $y, $line, $black); } $y += ($fontheight + $linemarg); } return $image->jpeg; } =head1 Restrictionmap Restrictionmap: Given a Rebase object, sequence, and list of restriction enzyme names, return the locations of the recognition sites in the sequence =head1 Synopsis use Restrictionmap; use Rebase; use strict; use warnings; my $rebase = Rebase->new( dbmfile => 'BIONET', bionetfile => 'bionet.212' ); my $restrict = Restrictionmap->new( rebase => $rebase, enzyme => 'EcoRI HindIII', sequence => 'ACGAATTCCGGAATTCG', graphictype => 'text', ); print "Locations are ", join ' ', $restrict->get_enzyme_map('EcoRI'), "\n"; print $restrict->get_graphic; =head1 AUTHOR James Tisdall =head1 COPYRIGHT Copyright (c) 2003, James Tisdall =cut 1; 以上是一個模組, 我的問題是要怎麼讓跑出來的結果, 酵素名子認到正確的位置,而且酵素名子的下一行可以加上一條線 且也是跟酵素認一樣的位置, 請問要怎麼修改模組中的程式才可以達到我要的目的 請大家幫幫我這個Perl新手 --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.128.62.181







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Boy-Girl站內搜尋

TOP