Hi perlmonks,

I have two gene lists. One is 300 genes and second is 150 genes. I want to find out if those 150 genes fall in the 300 gene list or not or if some do if not all. Something like an intersection or commom genes in the two files.

I have tries this but it says, intersection=0 but I know that around 75 genes are present in the 300 gene list so why am I getting 0?
#!/usr/bin/perl -w use strict; #Find intersection that are the commom genes in both the list open (FIRST, "C:/Users/ABC/Desktop/list2.txt") or die; open (SECOND, "C:/Users/ABC/Desktop/list1.txt") or die; my @first = (<FIRST>); chomp (@first); my @second = (<SECOND>); chomp (@second); my @union = my @isect = my @sym_diff = (); my %union = my %isect = my %count = (); foreach my $e (@first, @second) { $count{$e}++; } foreach my $e (keys %count) { push(@union, $e); if ($count{$e} == 2) { push @isect, $e; } else { push @sym_diff, $e; } } my %seen; my @first_only; @seen{@second} = (); foreach my $item (@first) { push (@first_only, $item) unless exists $seen{$item}; } @isect = sort (@isect); print "Intersection: " . scalar(@isect) . " " . join (" ", @isect) . " +\n";

Also is there any way I can get the output file in text and not the result on the terminal since this gives result as 0 on the terminal?

Thank you

In reply to Common between two lists by perllearner007

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.