File: join_any.pl

package info (click to toggle)
trinityrnaseq 2.11.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 417,528 kB
  • sloc: perl: 48,420; cpp: 17,749; java: 12,695; python: 3,124; sh: 1,030; ansic: 983; makefile: 688; xml: 62
file content (51 lines) | stat: -rwxr-xr-x 828 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env perl

use strict;
use warnings;

my $usage = "\nusage: $0 token_list_file  file_to_join [-v]\n\n";

my $token_list_file = $ARGV[0] or die $usage;
my $file_to_join = $ARGV[1] or die $usage;
my $invert_selection = $ARGV[2] || 0;

my %tokens;
{ 
	open (my $fh, $token_list_file) or die "Error, cannot open file $token_list_file";
	while (<$fh>) {
		while (/(\S+)/g) {
			$tokens{$1} = 1;
		}
	}
	close $fh;
}


open (my $fh, $file_to_join) or die "Error, cannot open file $file_to_join ";
while (<$fh>) {
	my $line = $_;
	chomp;
	my @x = split (/\s+/);
	my $found_token = 0;
	foreach my $ele (@x) {
		if ($tokens{$ele}) {
			$found_token = 1;
			last;
		}
	}

	if ($found_token && !$invert_selection) {
		print $line;
	}
	elsif ($invert_selection && !$found_token) {
		print $line;
	}
	
}
close $fh;


exit(0);