in reply to Removing partially duplicated lines from a file
Hi Sandy_Bio_Perl,
Try something like this:
#!/usr/bin/perl use warnings; use strict; open(my $in_fh, '<', 'input.txt') or die $!; open(my $out_fh, '>', 'output.txt') or die $!; my %seen_lines; while (<$in_fh>) { chomp; my @columns = split; if ($columns[1] and $columns[1] =~ /^HLA-A/) { my $HLA_Peptide = $columns[1] . $columns[2]; print $out_fh "$_\n" if (!exists $seen_lines{$HLA_Peptide}); $seen_lines{$HLA_Peptide} = 1; } else { print $out_fh "$_\n"; } } close $out_fh; close $in_fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Removing partially duplicated lines from a file
by Sandy_Bio_Perl (Beadle) on Jul 26, 2016 at 21:08 UTC | |
by perldigious (Priest) on Jul 26, 2016 at 21:28 UTC | |
by AnomalousMonk (Archbishop) on Jul 27, 2016 at 00:55 UTC | |
by perldigious (Priest) on Jul 27, 2016 at 13:03 UTC | |
by AnomalousMonk (Archbishop) on Jul 27, 2016 at 15:36 UTC | |
| |
by Sandy_Bio_Perl (Beadle) on Jul 26, 2016 at 21:35 UTC | |
by harangzsolt33 (Deacon) on Jul 26, 2016 at 21:44 UTC |