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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.