Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
where NC_.... is the name of files in the directory with .fq extension. I want to create a binary matrix which has all the filenames in horizontal and genes in vertical and print 1 if filename matches else print 0. My script is :(3R)-hydroxyacyl-ACP dehydratase subunit HadA NC_021192.1 (3R)-hydroxyacyl-ACP dehydratase subunit HadB NC_017026.1 (dimethylallyl)adenosine tRNA methylthiotransferase NC_009565.1 +NC_002755.2 NC_009525.1 NC_016934.1 1,4-alpha-glucan branching protein NC_021192.1 NC_017522.1 NC +_016934.1 NC_018078.1 NC_020089.1 NC_002755.2 NC_017524.1 + NC_009565.1 NC_012943.1 NC_017523.1 NC_021740.1 1,4-dihydroxy-2-naphthoate octaprenyltransferase NC_016934.1 NC_ +017026.1 NC_009525.1 1,4-dihydroxy-2-naphthoyl-CoA synthase NC_018143.2 NC_009565.1 + NC_002755.2 NC_012943.1 NC_017523.1
but this gives me incorrect output of 0's and 1's.open (FH, "p.txt"); while ($seq=<FH>) { @seq = split /\t/, $seq; print @seq[0]."\t"; opendir(DIR, "."); @files = grep(/\.fq$/,readdir(DIR)); closedir(DIR); foreach $file (@files) { @file1 = split /\./, $file; $file2 = $file1[0]; $size = @files; $file3 = $file2."\t".$file3;} for ($i = 1; $i <= $size; $i++) { @seq1 = split /\./, @seq[$i]; chomp @seq1[0]; if (@seq1[0] eq $file2) {print "1"."\t";} else {print "0"."\t";} } print "\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: create a binary matrix
by Laurent_R (Canon) on Oct 01, 2016 at 10:14 UTC | |
Re: create a binary matrix
by Random_Walk (Prior) on Oct 01, 2016 at 06:56 UTC | |
by Anonymous Monk on Oct 01, 2016 at 07:14 UTC |