I have two files and I want to merge the common lines as well as print the uncommon ones. I have written a code which is working but I would like to have some better way to do it.
The code I have written is :
@files = @ARGV;
$size = @files;
open (FA, ">>comp.txt");
open (FH, @ARGV[0]);
while ($seq = <FH>)
{ chomp $seq;
@seq = split ("\t", $seq);
$seqm = @seq[0];
chomp $seqm;
open (FH1, @ARGV[1]);
while ($seq2 = <FH1>)
{ chomp $seq2;
@seq2 = split ("\t", $seq2);
$seqm1 = @seq2[0];
chomp $seqm1;
if ($seqm1 =~m/$seqm/)
{$names=$names."\n".$seq."\t".@seq2[1]."\n";
$c=1;
last;}
else {$c=0;}
}
if ($c=="0")
{$names=$names."\n".$seq."\n";}
}
open (FH, @ARGV[1]);
while ($seq = <FH>)
{ chomp $seq;
@seq = split ("\t", $seq);
$seqm = @seq[0];
chomp $seqm;
open (FH1, @ARGV[2]);
while ($seq2 = <FH1>)
{ chomp $seq2;
@seq2 = split ("\t", $seq2);
$seqm1 = @seq2[0];
chomp $seqm1;
if ($seqm1 =~m/$seqm/)
{
$c=1;
last;}
else {$c=0;}
}
if ($c=="0")
{$names1=$names1."\n".$seq."\n";}
}
print FA $names."\n".$names1;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.