This is a test version of Biostars. For the public version, visit https://www.biostars.org.
common between in the coloumns
s1  s2  s3  s4  s5  s6  

a    b    a   a    a     c
c    a     b   b    b    a
b    c     c   c    c    b.

in the above a,b,c in common in each coloumn. but i have s1, s2, s3, s4, s5 coloumn with lakhs of entries. how should i write a perl script to find out the entries are common in all coloumn. plsease suggest me..

perl

First of all the question is not very clear, then this is not very much related to a biological query that can be addressed here. It is more of a stackoverflow question , but still if you can reframe a bit and give a motivation as what you want to do and why and what have your tried people might still be able to help you, It is intelligible as to what entries corresponds to each column.

Hello Bulbul Ahmed!

We believe that this post does not fit the main topic of this site.

Not a bioinformatics question

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

2 answers

Just to add , am not sure if this will be accepted by the community. If you load the file in R with required memory then then each column with be acting as a vector and then you can do something like this in R:

s1<-c("a","c","b")
s2<- c("b","a","c")
s3<- c("a","b","c")
s4<- c("a","b","c")
s_com<-Reduce(intersect, list(s1,s2,s3,s4))

Something like this should work

P.S: You have to load your file in R as header=T and mention the character as string

Here's a perl solution.

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

my $file = shift @ARGV; # SUPPLY COLUMN FILE AT COMMAND LINE
my %hash;
open (FILE, $file);
while (<FILE>) {
    my $counter = 0;
    my $line = $_;
    chomp $line;
    my @columns = split("\t", $line); # ASSUMES FILE IS TAB-DELIMITED
    foreach (@columns) {
        $counter++;
        $hash{$counter}{$_} = 1; # LOGS EACH UNIQUE VALUE IN EACH COLUMN
    }
}
print Dumper(\%hash); # THIS LINE IS FOR THE BENEFIT OF THE ORIGINAL POSTER
my @shared;
for my $x (keys $hash{'5'}) {
    if (exists $hash{'1'}{$x} && $hash{'2'}{$x} && $hash{'3'}{$x} && $hash{'4'}{$x} ) {
        push(@shared, $x);
    }
}
my $output = join("\n", @shared);
print "These values are found in all columns:\n$output";

Log in to answer this question.