Skip to content

Commit

Permalink
Copy SDRF functionality to output dir (#22)
Browse files Browse the repository at this point in the history
* Initial commit for copy SDRF functionality

* Complete copy part

* Missing arg for sdrf copy

* Fix issues

* Missing curly!

* Test copy of SDRF
  • Loading branch information
pcm32 committed Feb 23, 2021
1 parent 963ea06 commit f9b8677
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 4 additions & 2 deletions atlas-experiment-metadata-test.bats
Expand Up @@ -12,6 +12,7 @@ setup() {
implicit_pl_out_dir='implicit_pl'
explicit_pl_out="${explicit_pl_out_dir}/E-MTAB-6077.condensed-sdrf.tsv"
implicit_pl_out="${implicit_pl_out_dir}/E-MTAB-6077.condensed-sdrf.tsv"
implicit_pl_output_sdrf="${implicit_pl_out_dir}/${test_exp_acc}.sdrf.txt"
explicit_sc_sh_out_dir='explicit_sc_sh'
implicit_sc_sh_out_dir='implicit_sc_sh'
zooma_exclusions="test_data/zooma_exclusions.yml"
Expand All @@ -32,15 +33,16 @@ setup() {
[ -f "$explicit_pl_out" ]
}

@test "Test single-cell condense perl script with implicit IDF" {
@test "Test single-cell condense perl script with implicit IDF and SDRF copy" {
if [ -f "$implicit_pl_out" ]; then
skip "Output from implicit condense pl exists"
fi

run mkdir -p $implicit_pl_out_dir && env ATLAS_PROD=$test_data_dir $condense_pl -sc -e $test_exp_acc -o $implicit_pl_out_dir
run mkdir -p $implicit_pl_out_dir && env ATLAS_PROD=$test_data_dir $condense_pl -sc -s -e $test_exp_acc -o $implicit_pl_out_dir

[ "$status" -eq 0 ]
[ -f "$implicit_pl_out" ]
[ -f "$implicit_pl_output_sdrf" ]
}

@test "Test single-cell condense wrapper with explicit IDF" {
Expand Down
32 changes: 31 additions & 1 deletion condense_sdrf.pl
Expand Up @@ -45,6 +45,10 @@ =head1 OPTIONS
Optional. Copy IDF file from ArrayExpress load directory to output directory.
=item -s --copySDRF
Optional. Copy SDRF file from the IDF determined location to the output directory.
=item -o --outdir
Optional. Destination directory for output file(s). Will use current working
Expand Down Expand Up @@ -105,6 +109,7 @@ =head1 AUTHOR
use Atlas::ZoomaClient::MappingResult;
use Atlas::AtlasConfig::Reader qw( parseAtlasFactors );
use File::Basename;
use File::Spec;
use Data::Dumper;

$| = 1;
Expand Down Expand Up @@ -164,8 +169,13 @@ =head1 AUTHOR
ignore_datafiles => 1
});

my $magetab = $reader->parse;
my ($investigation, $magetab) = $reader->parse;
$logger->info( "Successfully read MAGETAB." );

if( $args->{ "copySDRF" } ) {
copy_sdrf_to_output_dir($investigation, $args->{ "output_directory" }, $idfFile);
}

$logger->info( "Merging technical replicates if available.") if( $args->{ "mergeTechReplicates" } );
my $atlasAssays = create_all_atlas_assays( $magetab, $args->{ "mergeTechReplicates" } );
$logger->debug( Dumper( $atlasAssays ) );
Expand Down Expand Up @@ -247,6 +257,7 @@ sub parse_args {
"z|zooma" => \$args{ "zooma" },
"x|zoomaExclusions=s" => \$args{ "zooma_exclusions_path" },
"i|idf" => \$args{ "idf" },
"s|copySDRF" => \$args{"copySDRF"},
"f|factors=s" => \$args{ "factors_file" },
"b|bioreps" => \$args{ "bioreps" },
"d|debug" => \$args{ "debug" },
Expand Down Expand Up @@ -308,6 +319,25 @@ sub copy_idf_from_ae {
}
}

sub copy_sdrf_to_output_dir {
my ( $investigation, $output_dir, $idf_abs_path ) = @_;
foreach my $sdrf ( @{ $investigation->get_sdrfs() } ) {
my $filename = $sdrf->get_uri()->file();
if( !File::Spec->file_name_is_absolute( $filename ) ) {
# append IDF path
my $dir = dirname($idf_abs_path);
$filename = File::Spec->catfile( $dir, $filename );
}
`cp $filename $output_dir`;
unless( $? ) {
$logger->info( "Successfully copied SDRF." );
}
else {
$logger->logdie( "Could not copy SDRF: $!" );
}
}
}

sub create_all_atlas_assays {
my ( $magetab, $mergeTechReplicates ) = @_;
# Create a relaxed AtlasAssayFactory.
Expand Down

0 comments on commit f9b8677

Please sign in to comment.