From 25f306d64b1c6abce48f243d7929d7d9dc5f3603 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Thu, 26 Sep 2013 08:09:07 +0000 Subject: [PATCH] added prefix option to write_fasta_files and write_fastq_files git-svn-id: http://biopieces.googlecode.com/svn/trunk@2218 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/write_fasta_files | 8 +++++++- bp_bin/write_fastq_files | 8 +++++++- bp_test/out/write_fasta_files.out.4/Length_test1.fasta | 2 ++ bp_test/out/write_fasta_files.out.4/Length_test2.fasta | 2 ++ bp_test/out/write_fasta_files.out.4/Length_test3.fasta | 2 ++ bp_test/out/write_fastq_files.out.3/Name_test.fastq | 4 ++++ bp_test/out/write_fastq_files.out.3/Name_test2.fastq | 8 ++++++++ bp_test/test/test_write_fasta_files | 6 ++++++ bp_test/test/test_write_fastq_files | 6 ++++++ 9 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 bp_test/out/write_fasta_files.out.4/Length_test1.fasta create mode 100644 bp_test/out/write_fasta_files.out.4/Length_test2.fasta create mode 100644 bp_test/out/write_fasta_files.out.4/Length_test3.fasta create mode 100644 bp_test/out/write_fastq_files.out.3/Name_test.fastq create mode 100644 bp_test/out/write_fastq_files.out.3/Name_test2.fastq diff --git a/bp_bin/write_fasta_files b/bp_bin/write_fasta_files index a0e20a5..dfeabb2 100755 --- a/bp_bin/write_fasta_files +++ b/bp_bin/write_fasta_files @@ -35,6 +35,7 @@ require 'pp' casts = [] casts << {long: 'key', short: 'k', type: 'string', mandatory: true, default: nil, allowed: nil, disallowed: nil} casts << {long: 'dir', short: 'd', type: 'dir!', mandatory: true, default: nil, allowed: nil, disallowed: nil} +casts << {long: 'prefix', short: 'p', type: 'string', mandatory: false, default: nil, allowed: nil, disallowed: nil} casts << {long: 'wrap', short: 'w', type: 'uint', mandatory: false, default: nil, allowed: nil, disallowed: "0"} casts << {long: 'compress', short: 'Z', type: 'string', mandatory: false, default: nil, allowed: "gzip,bzip,bzip2", disallowed: nil} casts << {long: 'no_stream', short: 'x', type: 'flag', mandatory: false, default: nil, allowed: nil, disallowed: nil} @@ -53,7 +54,12 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| if fh_hash[record[key].to_sym] fasta_io = fh_hash[record[key].to_sym] else - fasta_file = File.join(options[:dir], record[key] + ".fasta") + if options[:prefix] + fasta_file = File.join(options[:dir], [options[:prefix], record[key]].join("_") + ".fasta") + else + fasta_file = File.join(options[:dir], record[key] + ".fasta") + end + fasta_file << ".gz" if compress == :gzip fasta_file << ".bz2" if compress == :bzip or compress == :bzip2 fasta_io = Fasta.open(fasta_file, "w", compress: compress) diff --git a/bp_bin/write_fastq_files b/bp_bin/write_fastq_files index 5e36a38..b475b12 100755 --- a/bp_bin/write_fastq_files +++ b/bp_bin/write_fastq_files @@ -37,6 +37,7 @@ allowed_enc = 'base_33,base_64' casts = [] casts << {long: 'key', short: 'k', type: 'string', mandatory: true, default: nil, allowed: nil, disallowed: nil} casts << {long: 'dir', short: 'd', type: 'dir!', mandatory: true, default: nil, allowed: nil, disallowed: nil} +casts << {long: 'prefix', short: 'p', type: 'string', mandatory: false, default: nil, allowed: nil, disallowed: nil} casts << {long: 'no_stream', short: 'x', type: 'flag', mandatory: false, default: nil, allowed: nil, disallowed: nil} casts << {long: 'compress', short: 'Z', type: 'string', mandatory: false, default: nil, allowed: "gzip,bzip,bzip2", disallowed: nil} casts << {long: 'encoding', short: 'e', type: 'string', mandatory: false, default: 'base_33', allowed: allowed_enc, disallowed: nil} @@ -59,7 +60,12 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| if fh_hash[record[key].to_sym] fastq_io = fh_hash[record[key].to_sym] else - fastq_file = File.join(options[:dir], record[key] + ".fastq") + if options[:prefix] + fastq_file = File.join(options[:dir], [options[:prefix], record[key]].join("_") + ".fastq") + else + fastq_file = File.join(options[:dir], record[key] + ".fastq") + end + fastq_file << ".gz" if compress == :gzip fastq_file << ".bz2" if compress == :bzip or compress == :bzip2 fastq_io = Fastq.open(fastq_file, "w", compress: compress) diff --git a/bp_test/out/write_fasta_files.out.4/Length_test1.fasta b/bp_test/out/write_fasta_files.out.4/Length_test1.fasta new file mode 100644 index 0000000..cb5bc10 --- /dev/null +++ b/bp_test/out/write_fasta_files.out.4/Length_test1.fasta @@ -0,0 +1,2 @@ +>test1 +GACATCGAC diff --git a/bp_test/out/write_fasta_files.out.4/Length_test2.fasta b/bp_test/out/write_fasta_files.out.4/Length_test2.fasta new file mode 100644 index 0000000..10f6659 --- /dev/null +++ b/bp_test/out/write_fasta_files.out.4/Length_test2.fasta @@ -0,0 +1,2 @@ +>test2 +ACGACTACAGT diff --git a/bp_test/out/write_fasta_files.out.4/Length_test3.fasta b/bp_test/out/write_fasta_files.out.4/Length_test3.fasta new file mode 100644 index 0000000..aa9e884 --- /dev/null +++ b/bp_test/out/write_fasta_files.out.4/Length_test3.fasta @@ -0,0 +1,2 @@ +>test3 +GCACACAGAGC diff --git a/bp_test/out/write_fastq_files.out.3/Name_test.fastq b/bp_test/out/write_fastq_files.out.3/Name_test.fastq new file mode 100644 index 0000000..56cbf76 --- /dev/null +++ b/bp_test/out/write_fastq_files.out.3/Name_test.fastq @@ -0,0 +1,4 @@ +@test +TAGGGAATCTTGCACAATGGAGGAAACTCTGATGCAGCGA ++ +CEEECC;EFFH=EGBE=CE +@test2 +TGGGGAATTTTGCGCAATGGGCGAAAGCCTGACGCAGCAA ++ +55?????B?BB<-5@BC9CFFB>+C>C>E?@B=>,>5>FE diff --git a/bp_test/test/test_write_fasta_files b/bp_test/test/test_write_fasta_files index 9332864..d7775c3 100755 --- a/bp_test/test/test_write_fasta_files +++ b/bp_test/test/test_write_fasta_files @@ -33,3 +33,9 @@ run "$bp -I $in -d $tmp_dir -k SEQ_LEN -w 4 -x" assert_no_diff_dir $tmp_dir $out.3 clean rm -rf $tmp_dir + +mkdir $tmp_dir +run "$bp -I $in -d $tmp_dir -k SEQ_NAME -p Length -x" +assert_no_diff_dir $tmp_dir $out.4 +clean +rm -rf $tmp_dir diff --git a/bp_test/test/test_write_fastq_files b/bp_test/test/test_write_fastq_files index 7babe73..8a0f386 100755 --- a/bp_test/test/test_write_fastq_files +++ b/bp_test/test/test_write_fastq_files @@ -33,3 +33,9 @@ bunzip2 $tmp_dir/*.bz2 assert_no_diff_dir $tmp_dir $out.2 clean rm -rf $tmp_dir + +mkdir $tmp_dir +run "$bp -I $in -d $tmp_dir -k SEQ_NAME -p Name -x" +assert_no_diff_dir $tmp_dir $out.3 +clean +rm -rf $tmp_dir -- 2.39.2