Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Perl script to combine multiple columns from the protraits table to a single categorical traitType for FENNEC
#!/usr/bin/perl
# USAGE: perl extract_traits.pl <ProTraits_binaryIntegrated_File> <columns ...>
# EXAMPLE: perl extract_traits.pl ProTraits_binaryIntegratedPr0.90.txt 275 276 277 292 >oxygenreq.tsv
use strict;
use warnings;
my $file = shift(@ARGV);
my @columns = @ARGV;
open IN, "<$file" or die "$!";
my $header = <IN>;
chomp $header;
my @header = split(/\t/, $header);
while(<IN>){
chomp;
my @row = split(/\t/, $_);
foreach my $col (@columns){
print "$row[1]\t$header[$col-1]\t\t\t\n" if($row[$col-1] eq "1");
}
}
close IN or die "$!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment