Hi, I am encountering some problem with looping here. How do get this line "if ($line =~ m ($gene)) {" to match all $gene in the hash?
open (LIST1, "tab_delimited.txt");
while (<LIST1>) {
($id, $product, $ec) = split(/\t/, $_);
$hash{$id} = ($product, $ec);
}
close(LIST1);
open (LIST2, "tab.txt");
while (<LIST2>) {
my($line) = $_;
if ($line =~ m ($id)) {
print $line;
print "\n /product=\"$product\"";
if ($ec) {print "\n /EC_number=\"$ec\""};
print "\n"
}
else {
print $line;
}
}
close(LIST2);
the goal is to insert a few rows of info into the file tab.
this is the content for file tab
CDS /label=2494_g
/id="LAN0001"
CDS /label=2494_g
/id="LAN0002"
CDS /label=2495_g
/id="LAN0003"
and the tab_delimited file
LAN0001 ABC
LAN0002 DEF 123
LAN0003 GHI
the expected output
CDS /label=2494_g
/id="LAN0001"
/product="ABC"
CDS /label=2494_g
/id="LAN0002"
/product="DEF"
/EC_number="123"
CDS /label=2495_g
/id="LAN0003"
/product="GHI"
thanks!
open (LIST1, "tab_delimited.txt");
while (<LIST1>) {
($id, $product, $ec) = split(/\t/, $_);
$hash{$id} = ($product, $ec);
}
close(LIST1);
open (LIST2, "tab.txt");
while (<LIST2>) {
my($line) = $_;
if ($line =~ m ($id)) {
print $line;
print "\n /product=\"$product\"";
if ($ec) {print "\n /EC_number=\"$ec\""};
print "\n"
}
else {
print $line;
}
}
close(LIST2);
the goal is to insert a few rows of info into the file tab.
this is the content for file tab
CDS /label=2494_g
/id="LAN0001"
CDS /label=2494_g
/id="LAN0002"
CDS /label=2495_g
/id="LAN0003"
and the tab_delimited file
LAN0001 ABC
LAN0002 DEF 123
LAN0003 GHI
the expected output
CDS /label=2494_g
/id="LAN0001"
/product="ABC"
CDS /label=2494_g
/id="LAN0002"
/product="DEF"
/EC_number="123"
CDS /label=2495_g
/id="LAN0003"
/product="GHI"
thanks!