I have the following piece of code:
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;
}
First argument is the following file (first ten lines):
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
Second argument is the following file (first ten lines):
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"
I want to replace a string in file 2 for another string coming from file 1. However, text replacement is not working... Nothing is replaced. What is going on?
This is the problematic piece of code:
if (defined $chompline4[1]) {
$line =~ s/PAC:$transcript;/$transl.$coletilla;/ee;
} else {
$line =~ s/PAC:$transcript;/$hash{$chompline4[0]};/ee;
}