Hello all, Basically I have a list of gene_ids that I do not like (%empty_geneids). And I want to remove all lines in a second file ($ptt_file) that contain these gene_ids. I have tried many variations of this code, all in perl, then 'regressing' to trying to use sed. I know this last attempt using sed is VERY wrong. but I think it explains what I would like to do. I am relatively new so could use some suggestions. thank you
use strict; use warnings; my $list_file="/g/Viruses/prophage_data/emptySeqList_aa.txt"; my %empty_geneids; my @header_columns; my $gene_id; my @ptt_columns; open (IN,$list_file); ## list of 83 to remove from ptt file while(<IN>) { chomp; my ($header,$descript)=split(/\s+/,$_); $header=~ s/^>//g; @header_columns=split(/_/,$header); $gene_id=$header_columns[0]."_".$header_columns[1]; $empty_geneids{$gene_id}=1; print "empty gene_id from list file\t$gene_id\n"; } close (IN); my $ptt_file="/g/Viruses/prophage_data/prophage_region.ptt1"; my @ptt_lines; my @non_empty_lines; my $ptt_file2; open (IN,$ptt_file); @ptt_lines=<IN>; chomp(@ptt_lines); close (IN); open (OUT,">$ptt_file.noEmpties"); foreach my $k1 (keys %empty_geneids){ `sed '/$k1/d' $ptt_file > $ptt_file2`; `mv $ptt_file2 $ptt_file`; }
In reply to compare lists and delete unwanted from file by AWallBuilder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |