#!/usr/bin/perl ### ## Copyright 2020 Tomas Moyano (tcmoyano@uc.cl) , Jose Alvarez and Rodrigo Gutierrez. # # This program receives ordered files and sorts them taking into # account equal columns and collapses the different information in the last column. # usage: sort file |perl collapse.pl >file.collapse # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. use strict; my $id=$ARGV[0]; my $cuentas; my $ini=0; while( my $file = ) { chomp ($file); my @data = split(/\t/,$file); # $nid contain the columns used for the comparison in this case all minus the last. my $nid= join "\t",@data[0..($#data-1)]; if ($nid ne $id) { if($ini eq "0") { print "$nid\t$data[$#data]"; } if($ini eq "1") { print "\n$nid\t$data[$#data]"; } } $ini=1; if ($nid eq $id ) { print "|$data[$#data]"; next; } $id=join "\t",join "\t",@data[0..($#data-1)]; } print "\n";