2014-12-05 28 views
-1

我是一个一年级的研究生,他在计算生物学中相对较新。我最近开始使用Perl,它不是最简单的学习语言,至少不适合我。创建多个输出文件并用酶切割DNA - Perl

我需要帮助应用我的想法/逻辑正确的方法来找出解决我的问题。

我有一个dna字符串,我想分割它在特定的网站,以获得多个片段使用信息从酶文件,包含识别网站的行。一旦获得了片段,我想在输出文件中输出dna片段的列表。我想为酶文件中的每一行创建一个输出文件,我将从中提取信息,并将其应用于dna字符串。

这里就是我的意思正是:

假设的情景:

Enzyme.File包含:

ABC/at'gtct //(ABC是酶的名称(atgtct)是识别位点)

DEF/cgg'ataaa // ........

假设DNA字符串是:$ DNA =“accggtt atgtct aaacggataaagtctcggataaattt”(识别位点为粗体)

对于线1 当我提取从酶文件第一行/酶(ABC)的信息并将其应用到该字符串,输出应该是:

accggttat gtctaaacggataaagtctcggataaattt

撇号(cgg'ataaa之间的分裂)代表的切点 (注:即使有另一个gtct串中,它不分裂,因为应该在它之前。)

对于线路2 $ DNA = accggttatgtctaaa cggataaa gtct cggataaa TTT(信息被施加到相同的DNA串)从线/酶2

信息(DEF)将分裂DNA如下:

accggttatgtctaaacgg(cgg'ataaa之间拆分) ataaagtctcgg ataaattt

我想将不同行中的每个输出放在不同名称的独立文件中。 (我可以照顾分配名称)

因此,最后,这个例子会创建两个新文件,一个名称为“abc_whatever”和“def_whatever”。重要提示:如果酶文件有8行不同的酶,我会得到8个新的输出文件,其独特的DNA片段。“

这里是我试过到目前为止:

#!/usr/bin/perl; 

use warnings; 
use strict; 


open(ENZ,$ARGV[0]) || die; # ENZ(file handle for enzyme file) 

my $dna = "accggttatgtctaaacggataaagtctcggataaattt"; 

while (<ENZ>) { 
    if (match pattern etc..) { # I took care of that and created captured groups of 
     $1 = holds "abc"   # the info I needed from the line e.g. I captured 
     $2 = ..."at"    # (abc)/(at)'(gtct)//, so they are stored in $1,$2,$3 
     $3 = ..."gtct"   # respectively 

    } 
    while (<$dna>){ 
      my @fragments_array = split(/$3/, $dna); 
      open (OutFile, ">$dna"."_"."$1") 
      print OutFile shift @fragments_array,"\n"; 
      foreach (@fragments_array) { 
      print OutFile "$3$_\n"; 
      close OutFile; 
      } 
    } 

} 
close ENZ; 

FIRST 我只能仅在酶文件中的第一行创建一个输出我想创建并为所有输出文件行。

第二 我没有正确切割DNA,从其他的例子,我在网上看到的,它看起来像我要去必须使用以下功能来正确地应用在DNA酶信息。功能包括:

for循环,长度和SUBSTR(),

如果可以,请展示你最简单的形式工作(不奢华,令人印象深刻代码笑:-)因为我刚学这个语言)

在此先感谢!

回答

-1

我改变你的代码了一下,希望现在的工作

#!/usr/bin/perl 

    use warnings; 
    use strict; 

    open(ENZ, $ARGV[0]); 

    my $dna = "accggttatgtctaaacggataaagtctcggataaattt"; 
    my ($enzyme, $first, $second) = ("", "", ""); 


    for my $line (<ENZ>) { 
     chomp($line);        # remove \n at the end of string 
     my @elements = split(/\/|'/, $line);  # split string into tokens (e.g. abc/at'gtct => array(abc, at, gtct)) 
     $elements[2] = substr($elements[2], 0, -2); # remove the last "//" 
     my ($firstPart, $secondPart) = ($elements[1], $elements[2]); 
     if ($dna =~ /(.*)$firstPart$secondPart(.*)/) { 
      $first = $1 . $firstPart; 
      $second = $2 . $secondPart; 
      $enzyme = $elements[0]; 
      open(OUTPUT, ">$enzyme" . "_something"); 
      print OUTPUT "$first\n$second\n"; 
      close(OUTPUT); 
     } 
    } 

close ENZ; 

编辑:这是工作版本。我建议你学习如何使用正则表达式,如果你想使用Perl进行学习。它是Perl中最强大的工具。

+0

亲爱的朋友,我感谢您抽出宝贵的时间来帮助我但它不是很有效。我认为它与substr行有关。你能为我详细说明吗?谢谢 – 2014-12-05 05:33:14

0

FIRST我只能在Enzyme文件中为第一行创建输出。我想创建和输出所有行的文件。

那只是因为你把close OutFile;foreach (@fragments_array)循环,而不是放置close循环体之后。

SECOND我没有正确地切割DNA。

那是因为你忘了,包括$2,在split模式以及输出识别位点(的atgtct例如在at)的

问题是解决了容易,如果我们只需要插入分裂换行符到处之间:

#!/usr/bin/perl 
use warnings; 
use strict; 
open(ENZ, $ARGV[0]) || die; # ENZ (file handle for enzyme file) 
my $dna = "accggttatgtctaaacggataaagtctcggataaattt"; 
while (<ENZ>) 
{ 
    if (m-(.*)/(.*)'(.*)//-) 
    { 
     my ($head, $tail) = ($2, $3); # $2$3 is the recognition site; save it 
     open(OutFile, ">${dna}_$1"); 
     (my $fragments = $dna) =~ s/$head$tail/$head\n$tail/g; # insert NLs 
     print OutFile $fragments, "\n"; 
     close OutFile; 
    } 
} 
close ENZ; 
相关问题