Skip to content

Instantly share code, notes, and snippets.

@iimog
Created April 18, 2018 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iimog/0424de0b4efbfe73ef2e9092f8969c06 to your computer and use it in GitHub Desktop.
Save iimog/0424de0b4efbfe73ef2e9092f8969c06 to your computer and use it in GitHub Desktop.
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