#!/usr/bin/perl use strict; use warnings; use NEURO qw(load_study); use Data::Dump qw(dump); use File::Find::Rule; my $study = "mopead"; my %std = load_study($study); my $src_dir = '/nas/corachan/MOPEAD/'; my $conv_file = $std{'DATA'}.'/converted_t2.csv'; my $ids_file = $std{'DATA'}.'/ids.csv'; my $names_file =$std{'DATA'}.'/ni_names.csv'; my $proj_file = $std{'DATA'}.'/mopead.csv'; my @other_exts = ("nii.gz","json"); my $series = 6; my $tag = "t2_space_dark-fluid_sag_p2_iso"; #Leo la DB my %idsinfo; open IDS, "<$ids_file" or die $!; while(){ chomp; my ($key, $value) = split(/,\s?/); $idsinfo{$key} = $value; } close IDS; #Leo los que ya he descomprimido my @orig_str = qx/ls $src_dir/; chomp @orig_str; #Leo los que se han convertido my @conv_str; open CONV, "<$conv_file" or die $!; chomp (@conv_str = ); close CONV; #Y a ver cuantos faltan por convertir! my %conv_str = map { $_ => 1 } @conv_str; my @not_conv = grep !$conv_str{$_}, @orig_str; # y a convertirlos! foreach my $guy (@not_conv){ if(exists($idsinfo{$guy})){ my @conv_files = find(file => 'name' => "*$tag*.nii.gz", in => $std{'DATA'}.'/niftis/'.$guy.'/'); my $count = $series; foreach my $nii_file (@conv_files){ my $order = 'fslval '.$nii_file.' dim1'; my $xinfo = qx/$order/; if ($xinfo == '192'){ my $file_name = $nii_file; foreach my $ext (@other_exts){ ($file_name = $nii_file) =~ s/nii.gz$/$ext/; my $order = sprintf "cp %s %s/mop%04ds%04d.%s", $file_name, $std{'MRI2'}, $idsinfo{$guy}, $count, $ext; print "$order\n"; system($order); } $count++; } } } } #actualizo los convertidos push(@conv_str, @not_conv); open CONV, ">$conv_file" or die $!; print CONV "$_\n" foreach @conv_str; close CONV;