PHP网页导出Word文档的方法
file:///home/wanguan2000/%E6%A1%8C%E9%9D%A2/n-1930.html
一般,有2种方法可以导出doc文档,一种是使用com,并且作为php的一个扩展库安装到服务器上,然后创建一个com,调用它的方法。安装过office的服务器可以调用一个叫word.application 的com,可以生成word文档,不过这种方式我不推荐,因为执行效率比较低(我测试了一下,在执行代码的时候,服务器会真的去打开一个word客户端)。理想的com应该是没有界面的,在后台进行数据转换,这样效果会比较好,但是这些扩展一般需要收费。
ja6M2}2s!h/H 第2种方法,就是用PHP将我们的doc文档内容直接写入一个后缀为doc的文件中即可。使用这种方法不需要依赖第三方扩展,而且执行效率较高。
,J*e*K ha]+X9o word本身的功能还是很强大的,它可以打开html格式的文件,并且能够保留格式,即使后缀为doc,它也能识别正常打开。这就为我们提供了方便。但是有一个问题,html格式的文件中的图片只有一个地址,真正的图片是保存在其他地方的,也就是说,如果将HTML格式写入doc中,那么doc中将不能包含图片。那我们如何创建包含图片的doc文档呢?我们可以使用和html很接近的mht格式。
/Af7h7]$} mht格式和html很类似,只不过在mht格式中,外部链接进来的文件,比如图片、Javascript、CSS会被base64进行编码存储。因此,单个mht文件就可以保存一个网页中的所有资源,当然,相比html,它的尺寸也会比较大。BSD爱好者乐园e3O-QJ$P9@
mht格式能被word识别吗?我将一个网页保存成mht,然后修改后缀名为doc,再用word打开,OK,word也可以识别mht文件,并且可以显示图片。BSD爱好者乐园8yyJj(jZ];Q)Q
好了,既然doc可以识别mht,下面就是考虑如何将图片放入mht了。由于html代码中的图片的地址都是写在img标签的src属性中,因此,只要提取html代码中的src属性值,就可以获得图片地址。当然,有可能您获取到的是相对路径,没关系,加上URL的前缀,改成绝对路径就可以了。有了图片地址,我们就可以通过file_get_content函数获取到图片文件的具体内容,然后调用base64_encode函数将文件内容编码成 base64编码,最后插入到mht文件的合适位置即可。
W-m Bo(D_jx s 最后,我们有两种方法将文件发送给客户端,一种是先在服务器端生成一个doc文档,然后将这个doc文档的地址记录下来,最后,通过header(”location:xx.doc”);就可以让客户端下载这个doc。还有一种是直接发送html请求,修改HTML协议的header部分,将它的content-type设置为 application/doc,将content-disposition设置为attachment,后面跟上文件名,发送完html协议以后,直接将文件内容发送给客户端,也可以让客户端下载到这个doc文档。
9~(x.rO%E7P
Zy$I@’hB\1X9F,\BSD爱好者乐园�Xt4JW Z,m
实现
IHL+G/M!q`
#Z|,cLS$U f pBSD爱好者乐园\)o.^vj K
通过以上的原理介绍,相信大家应该对实现的过程有个初步的了解了,下面我给出一个导出函数,这个函数可以将HTML代码导出成一个mht文档,参数有3个,其中后2个为可选参数BSD爱好者乐园w$jY6ThP5r
content:要转换的HTML代码
h)y@2V+c absolutePath: 如果HTML代码中的图片地址都是相对路径,那么这个参数就是HTML代码中缺少的绝对路径。
8dJnCjc8h isEraseLink:是否去掉HTML代码中的超链接BSD爱好者乐园&[c6y^t2yWu C)e:z
McN]SD1T�B,|g 返回值为mht的文件内容,您可以通过file_put_content将它保存成后缀名为doc的文件
9U’g?.c(H5fQ@P
6D-w7C^+A;] 这个函数的主要功能其实就是分析HTML代码中的所有图片地址,并且依次下载下来。获取到了图片的内容以后,调用MhtFileMaker类,将图片添加到mht文件中。具体的添加细节,封装在MhtFileMaker类中了。
9p%L)Mio~’i vOP
5^?srF0o
6k#rQz w:\.C3qJ ^;j3EBSD爱好者乐园R%H/zzZ’Uv.H1Lq
/**
E6n8y6tf4\ * 根据HTML代码获取word文档内容BSD爱好者乐园)tb$J ^_`mG
* 创建一个本质为mht的文档,该函数会分析文件内容并从远程下载页面中的图片资源
/{Bq qY * 该函数依赖于类MhtFileMaker
4V:q#p7T,Un9Q * 该函数会分析img标签,提取src的属性值。但是,src的属性值必须被引号包围,否则不能提取
:BHM$h%K+Eyj *
2|,]#h/RC^G!d)}0| * @param string $content HTML内容
3qQ3V6`S#Gh] * @param string $absolutePath 网页的绝对路径。如果HTML内容里的图片路径为相对路径,那么就需要填写这个参数,来让该函数自动填补成绝对路径。这个参数最后需要以/结束BSD爱好者乐园 Vi,G}#Y!X0nQD9l
* @param bool $isEraseLink 是否去掉HTML内容中的链接BSD爱好者乐园/O$p,\�X!Uy1sIU
*/
(e1~[a%SvU]function getWordDocument( $content , $absolutePath = “” , $isEraseLink = true )BSD爱好者乐园r4SRHo)p4`A/T
{BSD爱好者乐园W2jm(hbeN
$mht = new MhtFileMaker();
]#lM;CE3?!f$S*nH’L if ($isEraseLink)
-XKq�@,t#f $content = preg_replace(’/(\s*.*?\s*)/i’ , ‘$1′ , $content); //去掉链接
t[nY'W!Z7t#@s@$h S(FBSD爱好者乐园.k'nK"t1y#pD-i;s
$images = array();
QMzk4P:c4yt $files = array();
0^#[J Vnv3Dp)U7l $matches = array();BSD爱好者乐园hU4G q2M"j'{
//这个算法要求src后的属性值必须使用引号括起来BSD爱好者乐园/biX Aorw Z
if ( preg_match_all('//i',$content ,$matches ) )
a~3yE"[$Q+A {BSD爱好者乐园)uHt,s]#j
$arrPath = $matches[1];
LP~’_/k6} for ( $i=0;$iAddContents(”tmp.html”,$mht->GetMimeType(”tmp.html”),$content);BSD爱好者乐园9rys:U7sy”HeRPVI
BSD爱好者乐园 p,Q z~ Kw]8{}
for ( $i=0;$iAddContents($files[$i],$mht->GetMimeType($image),$imgcontent);
s(dra.C2qp5W }
^’K4i?#x$^\6g else
N1b-t%Bek {
*zWM5l-m echo “file:”.$image.” not exist!
“;
:I(V.ViH2ip-Hu| }
:vg”A%z _!A`C1k }BSD爱好者乐园0rc[ O9{QH ^Fvm%x
.xW$W?"}{-Hb.O return $mht->GetFile();
*n1c ~/r(d x CF�U_"v}BSD爱好者乐园 p+|]D)s f/S xq}
P0k%\ ?Puvpw#? DBSD爱好者乐园”ud;o;}4A!y Q~+d
kvv|Ou”L!eBSD爱好者乐园*R#Hs!w-Qyq
使用方法:
“vJu8rU f)e8fUBSD爱好者乐园’P6IiEH5?B`w
$fileContent = getWordDocument($content,”http://www.yoursite.com/Music/etc/”);
NI,c^,c:r$fp = fopen(”test.doc”, ‘w’);
8Q:{g wcffwrite($fp, $fileContent);BSD爱好者乐园%Ih’N!K`_2\6M)s/g
fclose($fp);
U,L-{ LNv7e5c
IL_ ^{ T jGb其中,$content变量应该是HTML源代码,后面的链接应该是能填补HTML代码中图片相对路径的URL地址
9E+{ Y][U}fBSD爱好者乐园8LTi| rU7y
注意,在使用这个函数之前,您需要先包含类MhtFileMaker,这个类可以帮助我们生成Mht文档。
gnuplot
对于在Linux下工作的人,如果你经常要画一些二维图和简单的三维图的话,那么,gnuplot 无疑是一个非常好的选择,不仅图形漂亮,而且操作简单。当然如果需要质量更高的三维图,请用其他的一些专业绘图软件。建议大家学会使用gnuplot。这个小软件通常都是Redhat Linux自带的,但自带的版本是3.7的,建议将其升级到4.0,新版本具有很多新功能。最新版本可以到 http://www.gnuplot.info下载。
一些最基本的操作请大家看说明书。这里总结一下我在使用过程中遇到的一些问题以及解决的办法,目的是让那些以前不会的或不熟练的能快速入门,会画自己想要的图,因为原来的说明书很长,较难有针对性地很快找到自己想要的信息。这里简单的总结不可能面面俱到,所以大家不要抱怨我写的不全,更全面的了解还是请看说明书,网上的资料也多的是。其实这也是我们从网上一点一点搜集和摸索出来的。我相信看完后,应该平时最常见的问题基本上都能在这里找到答案。如果大家在使用过程中摸索到了我没有写到的技巧和体会,或有其它建议,请大家提告诉我,以不断完善这篇总结,谢谢!
一、 基础篇:
在linux命令提示符下运行gnuplot命令启动,输入quit或q或exit退出。
1、plot命令
gnuplot> plot sin(x) with line linetype 3 linewidth 2 或
gnuplot> plot sin(x) w l lt 3 lw 2 %用线画,线的类型(包括颜色与虚线的类型)是3,线的宽度是2,对函数sin(x)作图
gnuplot> plot sin(x) with point pointtype 3 pointsize 2 或
gnuplot> plot sin(x) w p pt 3 ps 2 %用点画,点的类型(包括颜色与点的类型)是3,点的大小是2
gnuplot> plot sin(x) title ‘f(x)’ w lp lt 3 lw 2 pt 3 ps 2 %同时用点和线画,这里title ‘f(x)’表示图例上标’f(x)’,如果不用则用默认选项
gnuplot> plot sin(x) %此时所有选项均用默认值。如果缺某一项则将用默认值
gnuplot> plot ‘a.dat’ u 2:3 w l lt 3 lw 2 %利用数据文件a.dat中的第二和第三列作图
顺便提一下,如这里最前面的两个例子所示,在gnuplot中,如果某两个词,按字母先后顺序,前面某几个字母相同,后面的不同,那么只要写到第一个不同的字母就可以了。如with,由于没有其它以w开头的词,因此可以用 w 代替,line也可以用 l 代替。
2、同时画多条曲线
gnuplot> plot sin(x) title ‘sin(x)’ w l lt 1 lw 2, cos(x) title ‘cos(x)’ w l lt 2 lw 2 %两条曲线是用逗号隔开的。画多条曲线时,各曲线间均用逗号隔开就可以了。
以上例子中是对函数作图,如果对数据文件作图,将函数名称换为数据文件名即可,但要用单引号引起来。
3、关于图例的位置
默认位置在右上方。
gnuplot> set key left %放在左边,有left 和right两个选项
gnuplot> set key bottom %放在下边,只有这一个选项;默认在上边
gnuplot> set key outside %放在外边,但只能在右面的外边
以上三个选项可以进行组合。如:
gnuplot> set key left bottom %表示左下边
还可以直接用坐标精确表示图例的位置,如
gnuplot> set key 0.5,0.6 %将图例放在0.5,0.6的位置处
4、关于坐标轴
gnuplot> set xlabel ‘x’ %x轴标为‘x’
gnuplot> set ylabel ‘y’ %y轴标为’y’
gnuplot> set ylabel ‘DOS’ tc lt 3 %其中的tc lt 3表示’DOS’的颜色用第三种颜色。
gnuplot> set xtics 1.0 %x轴的主刻度的宽度为1.0,同样可以为y轴定义ytics
gnuplot> set mxtics 3 %x轴上每个主刻度中画3个分刻度,同样可以为y轴定义mytics
gnuplot> set border 3 lt 3 lw 2 %设为第三种边界,颜色类型为3,线宽为2
同样可以为上边的x轴(称为x2)和右边y(称为y2)轴进行设置,即x2tics,mx2tics,y2tics,my2tics。
gnuplot> set xtics nomirror
gnuplot> unset x2tics %以上两条命令去掉上边x2轴的刻度
gnuplot> set ytics nomirror
gnuplot> unset y2tics %以上两条命令去掉右边y轴的刻度
5、在图中插入文字
gnuplot> set label ‘sin(x)’ at 0.5,0.5 %在坐标(0.5,0.5)处加入字符串’sin(x)’。
在输出为.ps或.eps文件时,如果在set term 的语句中加入了enhanced选现,则可以插入上下标、希腊字母和特殊符号。上下标的插入和latex中的方法是一样的。
6、在图中添加直线和箭头
gnuplot> set arrow from 0.0,0.0 to 0.6,0.8 %从(0.0,0.0)到(0.6,0.8)画一个箭头
gnuplot> set arrow from 0.0,0.0 to 0.6,0.8 lt 3 lw 2 %这个箭头颜色类型为3,线宽类型为2
gnuplot> set arrow from 0.0,0.0 to 0.6,0.8 nohead lt 3 lw 2 %利用nohead可以去掉箭头的头部,这就是添加直线的方法。
注意,在gnuplot中,对于插入多个的label和arrow等等,系统会默认按先后顺序分别对各个label或arrow进行编号,从1开始。如果以后要去掉某个label或arrow,那么只要用unset命令将相应的去掉即可。如:
gnuplot> unset arrow 2
将去掉第二个箭头。
7、图的大小和位置
gnuplot>set size 0.5,0.5 %长宽均为默认宽度的一半,建议用这个取值,尤其是画成ps或eps图形的时候
gnuplot>set origin 0.0,0.5 %设定图的最左下角的那一点在图形面板中的位置。这里图将出现在左上角。
8、画三维图
gnuplot>splot ‘文件名’ u 2:4:5 %以第二和第四列作为x和y坐标,第五列为z坐标。
二、提高篇:
1、如何在同一张图里同时画多个图
gnuplot>set multiplot %设置为多图模式
gnuplot>set origin 0.0,0.0 %设置第一个图的原点的位置
gnuplot>set size 0.5,0.5 %设置第一个图的大小
gnuplot>plot “a1.dat”
gnuplot>set origin 0.0,0.5 %设置第二个图的原点的位置
gnuplot>set size 0.5,0.5 %设置第二个图的大小
gnuplot>plot “a2.dat”
gnuplot>set origin 0.0,0.0 %设置第三个图的原点的位置
gnuplot>set size 0.5,0.5 %设置第三个图的大小
gnuplot>plot “a3.dat”
gnuplot>set origin 0.0,0.0 %设置第四个图的原点的位置
gnuplot>set size 0.5,0.5 %设置第四个图的大小
gnuplot>plot “a4.dat”
当然,如果后一个图中的某个量的设置和前一个的相同,那么后一个中的这个量的设置可以省略。例如上面对第二、第三和第四个图的大小的设置。前一个图中对某个量的设置也会在后一个图中起作用。如果要取消在后面图中的作用,必须用如下命令,如取消label,用
gnuplot>unset label
2、作二维图时,如何使两边坐标轴的单位长度等长
gnuplot> set size square %使图形是方的
gnuplot> set size 0.5,0.5 %使图形是你要的大小
gnuplot> set xrange[-a:a]
gnuplot> set yrange[-a:a] %两坐标轴刻度范围一样
gnuplot> plot ‘a.dat’
3、如何在同一张图里利用左右两边的y轴分别画图
gnuplot> set xtics nomirror %去掉上面坐标轴x2的刻度
gnuplot> set ytics nomirror %去掉右边坐标轴y2的刻度
gnuplot> set x2tics %让上面坐标轴x2刻度自动产生
gnuplot> set y2tics %让右边坐标轴y2的刻度自动产生
gnuplot> plot sin(x),cos(x) axes x1y2 %cos(x)用x1y2坐标,axes x1y2表示用x1y2坐标轴
gnuplot> plot sin(x),cos(x) axes x2y2 %cos(x)用x2y2坐标,axes x2y2表示用x2y2坐标轴
gnuplot> set x2range[-20:20] %设定x2坐标的范围
gnuplot> replot
gnuplot> set xrange[-5:5] %设定x坐标的范围
gnuplot> replot
gnuplot> set xlabel ‘x’
gnuplot> set x2label ‘t’
gnuplot> set ylabel ‘y’
gnuplot> set y2label ’s’
gnuplot> replot
gnuplot> set title ‘The figure’
gnuplot> replot
gnuplot> set x2label ‘t’ textcolor lt 3 %textcolor lt 3或tc lt 3设置坐标轴名称的颜色
4、如何插入希腊字母和特殊符号
一般只能在ps和eps图中,且必须指定enhanced选项。在X11终端(即显示器)中无法显示。
gnuplot> set terminal postscript enhanced
然后希腊字母就可以通过{/Symbol a}输入。例如
gnuplot> set label ‘{/Symbol a}’
各种希腊字母与特殊符号的输入方法请见安装包中gnuplot-4.0.0/docs/psdoc目录下的ps_guide.ps文件。
另外还可参见:
http://t16web.lanl.gov/Kawano/gnuplot/label-e.html#4.3
5、gnuplot中如何插入Angstrom(埃)这个符号(A上面一个小圆圈)
脚本中在插入前先加入
gnuplot>set encoding iso_8859_1
这个命令,然后就可以通过“{305}”加入了。如横坐标要标上“k(1/Å)”:
gnuplot>set xlabel ‘k(1/{305})
如果是multiplot模式,则这个命令必须放在
gnuplot>set multiplot
的前面。
如果后面还要插入别的转义字符,那么还要在插入字符后加入如下命令:
set encoding default
安装包中gnuplot-4.0.0/docs/psdoc/ps_guide.ps文件中的表中的‘E’代表那一列的所有符号都用这个方法输入。
6、gnuplot画等高线图
gnuplot>splot ‘文件名.dat’ u 1:2:3 w l %做三维图
gnuplot>set dgrid3d 100,100 %设置三维图表面的网格的数目
gnuplot>replot
gnuplot>set contour %设置画等高线
gnuplot>set cntrparam levels incremental -0.2,0.01,0.2 %设置等高线的疏密和范围,数据从 -0.2到0.2中间每隔0.01画一条线
gnuplot>unset surface 去掉上面的三维图形
最后用鼠标拽动图形,选择合理的角度即可。或者直接设置(0,0)的视角也可以:
gnuplot>set view 0,0
gnuplot>replot
这里注意,画三维图的数据文件必须是分块的,也就是x每变换一个值,y在其变化范围内变化一周,这样作为一块,然后再取一个x值,y再变化一周,作为下一数据块,等等。块与块之间用一空行格开。
7、输出为ps或eps图时,以下几个选项值得特别注意
gnuplot>set term postscript eps enh solid color
其中eps选项表示输出为eps格式,去掉则表示用默认的ps格式;enh选项表示图中可以插入上下标、希腊字母及其它特殊符号,如果去掉则不能插入;solid选项表示图中所有的曲线都用实线,去掉则将用不同的虚线;color选项表示在图中全部曲线用彩色,去掉则将用黑白。
8、如何画漂亮的pm3d图
gnuplot> set pm3d %设置pm3d模式
gnuplot> set isosamples 50,50 %设置网格点
gnuplot> splot x**2+y**2 %画三维图
gnuplot> splot x**2+y**2 w pm3d %画成pm3d模式,注意比较变化
gnuplot> set view 0,0 %设置视角,(0,0)将投影到底面上去
gnuplot> splot x**2+y**2 w pm3d %重画,注意看变化
gnuplot> unset ztics %把z轴上的数字给去掉
gnuplot> set isosamples 200,200 %使网格变细
gnuplot> replot %重画,注意看变化,主要是过渡更光滑
9、利用脚本文件避免重复输入
有时候对某个数据文件做好一张图后,下次可能还要利用这个数据文件作图,但某个或某些设置要作些细微变化。这时候,可以把第一次作图时的命令全部写到一个文件里,如a.plt,下次只要将相应的设置做修改后,用下面的命令就会自动运行文件所有的命令而最后得到你要的图:
gnuplot>load ‘a.plt’
作为一个例子,假设文件名为a.plt,里面的内容为:
set pm3d
set view 0,0
unset ztics
set isosamples 200,200
splot x**2+y**2 w pm3d
set term post color
set output ‘a.ps’
replot
那么启动gnuplot后,只要运行如下命令就可以了:
gnuplot>load ‘a.plt’
如果我们要得到的仅仅是.ps或.eps图,那也可以在linux命令提示符下直接运行如下命令:
[zxh@theory zxh]$gnuplot a.plt
10、在gnuplot模式下运行linux命令
在gnuplot提示符下也可以运行linux命令,但必须在相应的命令前面加上 ! 号。例如,假设很多参量都已经设置好了,但需要对某个数据文件a.dat进行修改后再画图,则可以用如下方式
gnuplot>!vi a.dat
通过这种方式,所有的linux命令都可以在gnuplot环境里运行。
另外,也可以在gnuplot的提示符后输入shell,暂时性退出gnuplot,进入linux环境,做完要做的事情后,运行exit命令,又回到gnuplot环境下。
gnuplot>shell
[zxh@theory zxh]$vi a.f
[zxh@theory zxh]$f77 a.f
[zxh@theory zxh]$a.out (假设生成a.dat数据文件)
[zxh@theory zxh]$exit
gnuplot>plot ‘a.dat’ w l
开源合辑-(科学工程->人工智能)之(Python)
http://www.10pig.cn/
http://www.10pig.cn/package/869/index.aspx
1. Natural Language Toolkit 2. Vega Strike 3. Feed-forward neural network for python 4. Python Knowledge Engine (PyKE)
5. Gamera 6. Presage 7. Go-Mo-Cult 8. Python Neural Genetic Algorithm Hybrids
9. PyML 10. virtual laboratory environment 11. XML enabled Communication Framework 12. RISO: distributed belief networks
13. Febrl 14. Robot Operating System 15. Evolving Objects 16. Fast Artificial Neural Network Library
17. monte python 18. PyCLIPS Python Module 19. JBoost 20. MegaHAL
21. PyAIML 22. Howie 23. Recognition of Playing Cards with webcam 24. AINT
25. RoboCup F180 26. SmartGRAPE 27. MSTParser 28. Discrete Event Calculus Reasoner
29. TADM 30. Reasonable Python 31. Evolution of Artificial Neural Networks 32. LExAu
33. General Hidden Markov Model Library 34. URBI contrib 35. Java rapid genetic programming 36. FramerD
37. PyWordNet 38. VFML 39. Pointrel Data Repository Code 40. Flexible Embodied Agent aRchitecture
41. PyOntoMap 42. RebeccaAIML, Enterprise AIML platform 43. PyLife 44. PyCV
45. AdvaS Advanced Search 46. Conway\’s Game of Life 47. Python Lib Neural 48. Freeway Traffic Smoothing Neural Network
49. Charlemagne 50. Mocapy 51. millosh’s workshop 52. Traduki
53. AKIRA 54. Reverend 55. Neural Net Lab 56. Alive!
57. pyfdupes 58. Deduce 59. pystats 60. Gaze at the landscape
61. dione 62. Stock Monkey Stock Selector 63. Pytalk 64. ftw. Text Modeller
65. pyPal – chatterbot, commandbot, palbot 66. MooBot 67. R2D3 Robotic Development 3nvironment 68. Simple AI in a 2D world
69. Decision Analysis 70. PyGenAlg 71. AMORI 72. The NetP Message Passing Library
73. Zbots- Battling breeding robots 74. Chloe – the digital goddess 75. Galileo: a Distributed Genetic Algorithm 76. The tre project
77. The A.I.V.I.S system 78. ch0 chesszero scalable;w/ rubber to road 79. pyDATR 80. RL-Glue
81. VisualCCG 82. wordnet2sql 83. PyANN 84. Tobacconist – Fresnel in Python
85. Mental 86. Excors Natural Language Interpreter 87. roboteks
Fast Artificial Neural Network Library (FANN)
http://leenissen.dk/fann/index.php
FANN Features:
* Multilayer Artificial Neural Network Library in C
* Backpropagation training (RPROP, Quickprop, Batch, Incremental)
* Evolving topology training which dynamically builds and trains the ANN (Cascade2)
* Easy to use (create, train and run an ANN with just three function calls)
* Fast (up to 150 times faster execution than other libraries)
* Versatile (possible to adjust many parameters and features on-the-fly)
* Well documented (An easy to use reference manual, a 50+ page university report describing the implementation considerations etc. and an introduction article)
* Cross-platform (configure script for linux and unix, dll files for windows, project files for MSVC++ and Borland compilers are also reported to work)
* Several different activation functions implemented (including stepwise linear functions for that extra bit of speed)
* Easy to save and load entire ANNs
* Several easy to use examples (simple train example and simple test example)
* Can use both floating point and fixed point numbers (actually both float, double and int are available)
* Cache optimized (for that extra bit of speed)
* Open source (licenced under LGPL)
* Framework for easy handling of training data sets
http://fann.sourceforge.net/fann.html#intro.start
http://ruby-fann.rubyforge.org/rdoc/
Requirements
FANN 2.1 or greater (preferably in /usr/local/lib)
Ruby 1.8.6 or greater.
gnu make tools or equiv for native code in ext
核苷酸特异性分析
@name = "fan"
@frag = "GCGTCCATTAAAGGGCGCCCATAGATCAGCACTGGAGTTTAT"
@frag = @frag.upcase
@frag = @frag.gsub(/[^A-Z]/,"")
fan = @frag.reverse
fan = fan.gsub(/A/,"1")
fan = fan.gsub(/T/,"2")
fan = fan.gsub(/C/,"3")
fan = fan.gsub(/G/,"4")
fan = fan.gsub(/1/,"T")
fan = fan.gsub(/2/,"A")
fan = fan.gsub(/3/,"G")
fan = fan.gsub(/4/,"C")
@fragok = fan
refile = File.new("lishi.txt","w")
len=@fragok.length
len -= 25
len.to_i
(0..len).each{|f| refile.puts ">#{@name}start#{f}\n#{@fragok[f,25]}\n"}
refile.close
system "blastall -p blastn -d silkcds.fa -F F -e 3 -W 7 -S 2 -i lishi.txt -o result.txt"
reblast = Array.new
fileblast = File.open("result.txt")
while lineblast = fileblast.gets
if lineblast =~ /^Query\= /
#Query= gi16950633start397
pname = lineblast.chomp.sub(/.*start/,"")
pname = pname.to_i
while lineblast = fileblast.gets
if lineblast =~ /No hits found/
blastscore = "0"
reblast[pname] = blastscore
break
end
if lineblast =~ /^Sequences producing significant alignments/
fileblast.gets
fileblast.gets
lineblast = fileblast.gets
if lineblast =~ /^\n/
blastscore = "0"
reblast[pname] = blastscore
break
else
blastscore = "1"
reblast[pname] = blastscore
lineblast = fileblast.gets
if lineblast =~ /^\n/
# blastscore = 44
# puts blastscore
break
else
blastscore = "2"
reblast[pname] = blastscore
end
end
end
break if lineblast =~ /^Reference/
end
end
end
fileblast.close
puts @frag.to_s
reblast.each{|ss| print ss.to_s}
github
github
sudo gem install mysql –with-mysql-config
/usr/lib/ruby/gems/1.8/gems
sudo gem install mysql -with-mysql-config=/usr/bin/mysql_config
ubuntu下安装mysql找不到mysql_config
2008-03-13 17:30
安装“libmysqlclient15-dev”包就可以了
1. clone from github: git clone git://github.com/knewter/ansuz.git
2. create database config in config/database.yml (see config/database.yml.example if you need help)
3. run: gem sources -a http://gems.github.com
4. install gems: rake gems:install
5. run: gem install haml –no-ri –no-rdoc
6. run plugin migrations: rake db:migrate:plugins
7. create databases: rake db:create:all
8. run migrations: rake db:migrate
9. run tests: rake spec
10. create a new user (do not use this in production): rake utils:createadmin
11. create the folder at public/uploads (This is for fckeditor’s resource browser / uploader)
12. start server: script/server -p 3000
13. goto: http://localhost:3000/admin
14. login with admin/admin
* Extract sources to a folder
* Create a database.yml file in the config directory. You can copy the database.yml.example
* Create your databases: rake db:create:all
* Migrate your database: rake db:migrate
* Start the server in production mode : ruby script/server -e production
rails 开源项目
http://www.opensourcerails.com/
非常棒的rails开源项目。
Online Examination System
Online Examination System
http://www.safeexambrowser.org
http://down.chinaz.com/query.asp?q=%BF%BC%CA%D4&search_code=0
http://download.it168.com/283/288/47157/index.shtml
http://down.chinaz.com/
Tioga: Plotting using Ruby, PDF, and TeX
Tioga: Plotting using Ruby, PDF, and TeX
http://www.itp.ucsb.edu/~paxton/tioga.html
http://tioga.rubyforge.org/
Here are a few examples made using Tioga. The tutorial has lots more, with discussions of the code that makes them.
And just as an appetizer, here is an MPEG4 movie made using Tioga plots from EZ, my stellar evolution program: Entropy Profile (7MB) If you need to get a viewer for MPEG4 on Linux, Michael Richmond tells me that “mplayer” works well for him. It can be downloaded here.
ruby 每次迭代了两个怎么写?
[1,2,3,4,5,6].each_slice(2) do |slice|
print slice[0] , “,” , slice[1] , “\n”
end
在:ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux]报错
undefined method `each_slice’ for :Array
加上这个就可以了:require ‘enumerator’
但是在ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]下没有问题
a = [1,1,1,2,2,2,3,3,3]
a.each(3) do |x,y,z|
print x,y,z,”\n”
end
