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灯, 水草

请输入看板名称,例如:WOW站内搜寻

TOP