-
Notifications
You must be signed in to change notification settings - Fork 0
/
overlap.pl
executable file
·110 lines (99 loc) · 5.5 KB
/
overlap.pl
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/perl
#
# Overlap some data with some other data
#
# Description: this script can overlap data. Provided with one file (LOOKUP.txt) it will
# lookup something in [COLUMN#] in another file [SOURCE.txt] in a certain
# [COLUMN#]. The whole line of the [SOURCE.txt] will be printed to the
# standard out
#
# Written by: Jessica van Setten & Sander W. van der Laan; UMC Utrecht, Utrecht, the
# Netherlands, [email protected] or [email protected].
# Version: 2.0.1
# Update date: 2018-08-21
#
# Usage: overlap.pl [LOOKUP.txt] [COLUMN#] [SOURCE.txt] [COLUMN#] []
#
# Starting conversion
print STDERR "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
print STDERR "+ OVERLAP DATA +\n";
print STDERR "+ V2.0.1 +\n";
print STDERR "+ 21-08-2018 +\n";
print STDERR "+ Written by: Jessica van Setten & Sander W. van der Laan +\n";
print STDERR "+ +\n";
print STDERR "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
print STDERR "\n";
print STDERR "Hello. I am starting the overlapping of the files you've provided.\n";
my $time = localtime; # scalar context
print STDERR "The current date and time is: $time.\n";
print STDERR "\n";
#use strict;
#use warnings;
# Five arguments are required:
# - the input file (IN)
# - column number in (IN)
# - the output file (SOURCE)
# - column number in (SOURCE)
# - whether the input file is zipped (GZIP/NORM)
my $file1 = $ARGV[0];
my $col1 = $ARGV[1];
my $file2 = $ARGV[2];
my $col2 = $ARGV[3];
my $neg = $ARGV[4];
###my $zipped = $ARGV[5];
my %present = ();
### IF/ELSE STATEMENTS
##if ($zipped eq "GZIP") {
## open (IN, "gunzip -c $file1 |") or die "* ERROR: Couldn't open input file: $!";
##
##} elsif ($zipped eq "NORM") {
## open (IN, $file1) or die "* ERROR: Couldn't open input file: $!";
##
##} else {
## print "* ERROR: Please, indicate the type of input file: gzipped [GZIP] or uncompressed [NORM]!\n";
## print " (Arguments are case-sensitive.)\n";
##
##}
open (F1, $file1);
while(<F1>){
chomp;
@fields = split;
$present{ $fields[$col1-1] } = 1;
}
close F1;
open (F2, $file2);
while (<F2>){
chomp;
@fields = split;
if ( ( $neg eq "-v" && ! exists $present{$fields[$col2-1]} ) || ( $neg eq "" && exists $present{$fields[$col2-1]} ) ) { print "$_\n"; }
}
close F2;
print STDERR "Wow. That was a lot of work. I'm glad it's done. Let's have beer, buddy!\n";
my $newtime = localtime; # scalar context
print STDERR "The current date and time is: $newtime.\n";
print STDERR "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
print STDERR "\n";
print STDERR "\n";
print STDERR "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
print STDERR "+ The MIT License (MIT) +\n";
print STDERR "+ Copyright (c) 2016 Jessica van Setten & Sander W. van der Laan +\n";
print STDERR "+ +\n";
print STDERR "+ Permission is hereby granted, free of charge, to any person obtaining a copy of this +\n";
print STDERR "+ software and associated documentation files (the \"Software\"), to deal in the +\n";
print STDERR "+ Software without restriction, including without limitation the rights to use, copy, +\n";
print STDERR "+ modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +\n";
print STDERR "+ and to permit persons to whom the Software is furnished to do so, subject to the +\n";
print STDERR "+ following conditions: +\n";
print STDERR "+ +\n";
print STDERR "+ The above copyright notice and this permission notice shall be included in all copies +\n";
print STDERR "+ or substantial portions of the Software. +\n";
print STDERR "+ +\n";
print STDERR "+ THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +\n";
print STDERR "+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +\n";
print STDERR "+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +\n";
print STDERR "+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +\n";
print STDERR "+ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +\n";
print STDERR "+ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\n";
print STDERR "+ +\n";
print STDERR "+ Reference: http://opensource.org. +\n";
print STDERR "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";