【发布时间】:2015-02-21 19:23:49
【问题描述】:
我有以下代码:
use warnings;
use strict;
my %hash;
open TRADUCTOR, $ARGV[0];
open GTF, $ARGV[1];
while (my $line = <TRADUCTOR>) {
chomp $line;
my @chompline = split(/\t/, $line);
$hash{$chompline[2]} = $chompline[1];
}
while (my $line = <GTF>) {
my @chompline1 = split(/\t/, $line);
my @chompline2 = split(/ /, $chompline1[8]);
my @chompline3 = split(/;/, $chompline2[2]);
my $transcript = $chompline3[0];
$transcript =~ s/"//g;
$transcript =~ s/PAC://g;
my $transcript2 = $transcript;
$transcript2 =~ s/(_[jox])/&&&$1/g;
my @chompline4 = split(/&&&/, $transcript2);
my $coletilla = $chompline4[1];
my $transl = $hash{$chompline4[0]};
if (defined $chompline4[1]) {
$line =~ s/PAC:$transcript;/$transl.$coletilla;/ee;
} else {
$line =~ s/PAC:$transcript;/$hash{$chompline4[0]};/ee;
}
print $line;
}
第一个参数是以下文件(前十行):
Sb01g017490 Sb01g017490.1 1951419
Sb02g039360 Sb02g039360.1 1959410
Sb01g037620 Sb01g037620.1 1953645
Sb03g003880 Sb03g003880.1 1960464
Sb01g001330 Sb01g001330.1 1949441
Sb01g049890 Sb01g049890.1 1955138
Sb09g030646 Sb09g030646.1 1982110
Sb02g011950 Sb02g011950.1 1956744
Sb04g008540 Sb04g008540.1 1965938
第二个参数是以下文件(前十行):
A01 greenc1.0 exon 5409 5518 . - . gene_id "Bra.XLOC_002074";transcript_id "Bra.TCONS_00002741";transcript_biotype "protein_coding"
A01 greenc1.0 exon 5616 5654 . - . gene_id "Bra.XLOC_002074";transcript_id "Bra.TCONS_00002741";transcript_biotype "protein_coding"
A01 greenc1.0 exon 8307 8530 . - . gene_id "Bra011902";transcript_id "PAC:22703627_j.1";transcript_biotype "protein_coding"
A01 greenc1.0 exon 8426 8530 . - . gene_id "Bra011902";transcript_id "PAC:22703627";transcript_biotype "protein_coding"
A01 greenc1.0 exon 8599 8844 . - . gene_id "Bra011902";transcript_id "PAC:22703627_j.1";transcript_biotype "protein_coding"
A01 greenc1.0 exon 8599 8823 . - . gene_id "Bra011902";transcript_id "PAC:22703627";transcript_biotype "protein_coding"
A01 greenc1.0 exon 8919 9056 . - . gene_id "Bra011902";transcript_id "PAC:22703627_j.1";transcript_biotype "protein_coding"
A01 greenc1.0 exon 8919 9056 . - . gene_id "Bra011902";transcript_id "PAC:22703627";transcript_biotype "protein_coding"
A01 greenc1.0 exon 9151 9413 . - . gene_id "Bra011902";transcript_id "PAC:22703627_j.1";transcript_biotype "protein_coding"
A01 greenc1.0 exon 9151 9413 . - . gene_id "Bra011902";transcript_id "PAC:22703627";transcript_biotype "protein_coding"
我想将文件 2 中的字符串替换为来自文件 1 的另一个字符串。但是,文本替换不起作用...没有任何内容被替换。怎么回事?
这是有问题的代码:
if (defined $chompline4[1]) {
$line =~ s/PAC:$transcript;/$transl.$coletilla;/ee;
} else {
$line =~ s/PAC:$transcript;/$hash{$chompline4[0]};/ee;
}
【问题讨论】:
-
Sb01g017490 Sb01g017490.1 1951419中有实际的标签吗? -
关于
/ee双重评估的使用,看这个问题有一个可怕的例子:stackoverflow.com/q/9591658/725418