#!/usr/bin/perl use strict; use warnings; use NEURO qw(load_study); use File::Find::Rule; use Data::Dump qw(dump); my $study = "mopead"; my $prefix = "mop"; my %std = load_study($study); my $src_dir = '/nas/corachan/MOPEAD/'; my $conv_file = $std{'DATA'}.'/converted_dti.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","bval","bvec","json"); my @b0_exts = ("nii.gz","json"); my $tag = "DTIep2d_diff_mddw_48dir_p3_AP"; my $b0tag = "DTIep2d_diff_mddw_4b0_PA"; #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! my @newones; foreach my $guy (@not_conv){ if(exists($idsinfo{$guy})){ print "Getting DTI data A>>P\n"; my @conv_files = find(file => 'name' => "*$tag*.nii.gz", in => $std{'DATA'}.'/niftis/'.$guy.'/'); foreach my $nii_file (@conv_files){ my $order = 'fslval '.$nii_file.' dim4'; my $xinfo = qx/$order/; (my $checkv = $nii_file) =~ s/nii.gz$/bval/; my $dest = sprintf "%s/%s%04ds0020.nii.gz", $std{'DTI'}, $prefix, $idsinfo{$guy}; if($xinfo>1 && -e $checkv && ! -e $dest){ print "Choosing and moving files\n"; my $file_name = $nii_file; foreach my $ext (@other_exts){ ($file_name = $nii_file) =~ s/nii.gz$/$ext/; $order = sprintf "cp %s %s/%s%04ds0020.%s", $file_name, $std{'DTI'}, $prefix, $idsinfo{$guy}, $ext; print "$order\n"; system($order); } push @newones, $guy; } } #Convierto los B0 en sentido contrario (P>>A) print "Getting P>>A B0\n"; #system($order); @conv_files = find(file => 'name' => "*$b0tag*.nii.gz", in => $std{'DATA'}.'/niftis/'.$guy.'/'); foreach my $nii_file (@conv_files){ foreach my $ext (@b0_exts){ (my $file_name = $nii_file) =~ s/nii.gz$/$ext/; my $order = sprintf "cp %s %s/%s%04d_p2a_b0.%s", $file_name, $std{'DTI'}, $prefix, $idsinfo{$guy}, $ext; print "$order\n"; system($order); } } } } #actualizo los convertidos push(@conv_str, @newones); open CONV, ">$conv_file" or die $!; print CONV "$_\n" foreach @conv_str; close CONV;