Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. /data/results/
  2. TestFolder1/
  3. subfolder1/Variants/MD-14-11856_RNA_v2.vcf
  4. subfoder2/Variants/SU-16-16117_RNA_v2.vcf
  5. matrix.txt
  6. matrixkey.txt
  7.  
  8. TestFolder2/
  9. subfolder1/Variants/SU-15-2542_v2.vcf
  10. subfolder2/Variants/SU-16-16117_v2.vcf
  11. matrix.txt
  12. matrixkey.txt
  13.  
  14. Barcode SampleName
  15. barcode_003 SU-15-2542
  16. barcode-005 MD-14-11856
  17. barcode-002 SU-16-16117
  18.  
  19. #!/usr/bin/perl
  20. use warnings;
  21. use strict;
  22.  
  23. use File::Copy qw(move);
  24. use List::Util 'first';
  25. use File::Find;
  26. use File::Spec;
  27. use Data::Dumper;
  28.  
  29. use File::Basename;
  30. use File::Spec::Functions 'splitdir';
  31.  
  32. my $current_directory = "/data/results";
  33.  
  34. if (grep -d, glob("$current_directory/*")) {
  35. print "$current_directory has subfolder(s)n";
  36. }
  37. else
  38. {
  39. print "there are no foldersn";
  40.  
  41. die;
  42. }
  43.  
  44. my %files;
  45. my @dirs = grep { -d } glob '/data/results/*';
  46.  
  47. for my $dir ( @dirs ) {
  48.  
  49. print "the directory is $dirn";
  50. my $run_folder = (split '/', $dir)[3];
  51. print "the folder is $run_foldern";
  52.  
  53.  
  54. my $key2 = $run_folder;
  55.  
  56. # checks if barcode matrix and barcode summary files exist
  57.  
  58. #shortens the folder names and unzips them.
  59.  
  60. #check if each sample is present in the matrix file for each folder.
  61. my $location = "/data/results/".$run_folder;
  62.  
  63. my $matrix_key = "/data/results/".$run_folder."/matrixkey.txt";
  64.  
  65. open my $key, '<', $matrix_key or die $!; # key file
  66.  
  67. <$key>; # throw away header line in key file (first line)
  68. my @matrix_key = ();
  69.  
  70. @matrix_key = sort {length($b->[1]) <=> length($a->[1])} map [ split ], <$key>;
  71. close $key or die $!;
  72.  
  73. print Dumper(@matrix_key) . "===nn";
  74.  
  75. sub find_vcf {
  76. my $F = $File::Find::name;
  77.  
  78. if ($F =~ /vcf$/ ) {
  79. print "$Fn";
  80.  
  81. $F =~ m|([^/]+).vcf$| or die "Can't extract Sample ID";
  82. my $sample_id = $1; print "the short vcf name is: $sample_idn";
  83.  
  84. if ( my $aref = first { index($sample_id, $_->[1]) != -1 } @matrix_key ) {
  85. #the code fails to match sample_id to matrix_key eventhough it's printed out correctly
  86.  
  87. print "$sample_id t MATCHES $aref->[1]n";
  88. print "t$aref->[1]_$aref->[0]nn";
  89.  
  90. } else {
  91. # handle all other possible exceptions
  92.  
  93. #print "folder name is $run_foldern";
  94.  
  95. die("The VCF file doesn't match the Summary Barcode file: $sample_idn");
  96. }
  97.  
  98. }
  99.  
  100. }
  101.  
  102. find({ wanted => &find_vcf, no_chdir=>1}, $location);
  103.  
  104.  
  105. }
  106.  
  107. exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement