Sponsored Content
Top Forums Shell Programming and Scripting Two variables in output file name nested for loops Post 302646011 by aminards on Thursday 24th of May 2012 11:33:23 AM
Old 05-24-2012
Question Two variables in output file name nested for loops

I am trying to use two nested for loops to process some files and then create a new file using both variables in the output file name. I have several files in this naming style:
Code:
S1_L3_all_R1.fastq
S1_L3_all_R2.fastq
S1_L4_all_R1.fastq
S1_L4_all_R2.fastq
.
.
S1_L8_all_R1.fastq
S1_L8_all_R1.fastq

I need to apply a process to each file and rename the files like this:
Code:
S1_L3_all_R1.fasta
S1_L3_all_R2.fasta
.
.
S1_L8_all_R1.fasta
S1_L8_all_R2.fasta

I am using BASH. Here is what I have tried:

Code:
for((n=3;n<=8;n++))
do 
for((k=1;k<=2;k++))
do 
for f  in S1_L$n_all_filt_R*.fastq
do 
echo $f
cat $f | perl -e my file processing > S1_L$n_all_filt_R$k.fasta
done
done
done


This runs through the file processing for each file but the file name is S1_L1.fasta and this file name is recycled for each of my original files. It seems to me that everything after the first variable in my output file name is ignored.

How can I use two variables in a file name to get the output file names I am looking for?

Last edited by Scrutinizer; 05-24-2012 at 04:41 PM.. Reason: Removed times roman formatting
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk formatting of a data file - nested for loops?

Hello - is there any way in awk I can do... 4861 x(1) y(1) z(1) 4959 x(1) y(1) z(1) 5007 x(1) y(1) z(1) 4861 x(2) y(2) z(2) 4959 x(2) y(2) z(2) 5007 x(2) y(2) z(2) 4861 x(3) y(3) z(3) 4959 x(3) y(3) z(3) 5007 x(3) y(3) z(3) to become... 4861 x(1) y(1) z(1) 4861 x(2) y(2) z(2)... (3 Replies)
Discussion started by: catwoman
3 Replies

2. Shell Programming and Scripting

Grepping within nested for loops

Good morning - I have publication lists from 34 different faculty members. I need to end up with the numbers of publications in common across all 34 faculty. I need to grep person1 (last name) in list2, person1 in list3, person1 in list 4, etc., then person2 in list3, person 2 in list4, etc.,... (2 Replies)
Discussion started by: Peggy White
2 Replies

3. Shell Programming and Scripting

file reading in nested loops

I have to to read files simultaneously in two nested loops,but am getting error can anyone do the needful. useridFile=userIds.txt fname=kiran.txt exec<$useridFile while read line do echo "User IDs are..$line" USER_ID=$line REMOTE_DIR_LOCATION="/home/test/$USER_ID" SOURCE_DIR=$USER_ID... (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

4. Shell Programming and Scripting

nested for loops

I need help getting over this bump on how nested for loops work in shell. Say i was comparing files in a directory in any other language my for loop would look like so for(int i=0;to then end; i++) for(int y = i+1; to the end; y++) I can't seem to understand how i can translate that... (5 Replies)
Discussion started by: taiL
5 Replies

5. Shell Programming and Scripting

Nested while loops (ksh scripting)

You can use one while inside another? I made the following script (without really knowing if I can use two while) to get 3 numbers different from each other at random: num1=$(( $RANDOM % 10 )) num2=$num1 while do num2=$(( $RANDOM % 10 )) done num3=$num1 while do while do... (1 Reply)
Discussion started by: ale.dle
1 Replies

6. Shell Programming and Scripting

Need help with Regular Expressions and nested loops

Ok... am going slightly loopy trying to get this working (no pun intended) What I need is to modify this code which takes a string input then echo's each character on a seperate line, to do the same thing but to put DIGIT: in front of numbers and LETTER: in front of letters. I know a regular... (5 Replies)
Discussion started by: U_C_Dispatj
5 Replies

7. Shell Programming and Scripting

KSH nested loops?

KSH isn't my strong suit but it's what my company has to offer. I've got a script with two nested loops, a FOR and UNTIL, and that works fine. When I add a CASE into the mix I end up getting "Unexpected 'done' at line xx" errors. Any suggestions on this? for divi in at ce ci cm co de di fl... (9 Replies)
Discussion started by: mrice
9 Replies

8. Shell Programming and Scripting

Nested for loops

Greetings All, The following script attempts to enumerate all users in all groups in the group file(GROUP) and echo the following information: GROUP ---> USER The script is as follows: IFS="," for GROUP in `ypcat -k group | cut -d" " -f1` do for USER in `ypcat -k group... (13 Replies)
Discussion started by: jacksolm
13 Replies

9. Shell Programming and Scripting

two while nested loops

for server in $(echo `cat /tmp/ScanHosts_${USERSNAME}.TXT`) do for portnumber in $(echo `cat /tmp/ScanPorts_${USERSNAME}.TXT`) do #echo ${server} ${portnumber} ... (3 Replies)
Discussion started by: SkySmart
3 Replies

10. UNIX for Beginners Questions & Answers

Nested Loops for text file

Hi A text file containing data something likeVehicle: BMW Class checkin_note: Tyre : Four path_id : 11 vault_file_size: -1 Vehicle: Toyota Class checkin_note: Tyre : Four path_id : 11 vault_file_size: -1 Vehicle: Chevrolet Class checkin_note: Tyre : Five path_id :... (7 Replies)
Discussion started by: vipinHasija
7 Replies
Bio::Tools::Run::BWA(3pm)				User Contributed Perl Documentation				 Bio::Tools::Run::BWA(3pm)

NAME
Bio::Tools::Run::BWA - Run wrapper for the BWA short-read assembler *BETA* SYNOPSIS
# create an assembly # run BWA commands separately DESCRIPTION
This module provides a wrapper interface for Heng Li's reference-directed short read assembly suite "bwa" (see http://bio-bwa.sourceforge.net/bwa.shtml <http://bio-bwa.sourceforge.net/bwa.shtml> for manuals and downloads). Manipulating the alignments requires "samtools" (<http://sourceforge.net/projects/samtools/>) and Lincoln Stein's package "Bio-SamTools" (<http://search.cpan.org/perldoc?Bio::DB::Sam>). There are two modes of action. o Easy assembly The first is a simple pipeline through the "maq" commands, taking your read data in and squirting out an assembly object of type Bio::Assembly::IO::maq. The pipeline is based on the one performed by "maq.pl easyrun": Action maq commands ------ ------------ data conversion to fasta2bfa, fastq2bfq maq binary formats map sequence reads map to reference seq assemble, creating assemble consensus convert map & cns mapview, cns2fq files to plaintext (for B:A:IO:maq) Command-line options can be directed to the "map", "assemble", and "cns2fq" steps. See "OPTIONS" below. o BWA command mode The second mode is direct access to "bwa" commands. To run a "bwa" command, construct a run factory, specifying the desired command using the "-command" argument in the factory constructor, along with options specific to that command (see "OPTIONS"): $bwafac = Bio::Tools::Run::BWA->new( -command => 'fasta2bfa' ); To execute, use the "run_bwa" methods. Input and output files are specified in the arguments of "run_bwa" (see "FILES"): $bwafac->run_bwa( -fas => "myref.fas", -bfa => "myref.bfa" ); OPTIONS
"bwa" is complex, with many subprograms (commands) and command-line options and file specs for each. This module attempts to provide commands and options comprehensively. You can browse the choices like so: $bwafac = Bio::Tools::Run::BWA->new( -command => 'aln' ); # all maq commands @all_commands = $bwafac->available_parameters('commands'); @all_commands = $bwafac->available_commands; # alias # just for aln @aln_params = $bwafac->available_parameters('params'); @aln_switches = $bwafac->available_parameters('switches'); @aln_all_options = $bwafac->available_parameters(); Reasonably mnemonic names have been assigned to the single-letter command line options. These are the names returned by "available_parameters", and can be used in the factory constructor like typical BioPerl named parameters. See http://bio-bwa.sourceforge.net/bwa.shtml <http://bio-bwa.sourceforge.net/bwa.shtml> for the gory details. FILES
When a command requires filenames, these are provided to the "run_bwa" method, not the constructor ("new()"). To see the set of files required by a command, use "available_parameters('filespec')" or the alias "filespec()": $bwafac = Bio::Tools::Run::BWA->new( -command => 'aln' ); @filespec = $bwafac->filespec; This example returns the following array: fas faq >sai This indicates that the FASTA database (faq) and the FASTQ reads (faq) MUST be specified, and the STDOUT of this program (SA coordinates) MAY be slurped into a file specified in the "run_bwa" argument list: $bwafac->run_bwa( -fas => 'my.db.fas', -faq => 'reads.faq', -sai => 'out.sai' ); If files are not specified per the filespec, text sent to STDOUT and STDERR is saved and is accessible with "$bwafac-"stdout()> and "$bwafac-"stderr()>. FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated. bioperl-l@bioperl.org - General discussion http://bioperl.org/wiki/Mailing_lists - About the mailing lists Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web: http://redmine.open-bio.org/projects/bioperl/ AUTHOR - Mark A. Jensen Email maj -at- fortinbras -dot- us APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ new() Title : new Usage : my $obj = new Bio::Tools::Run::BWA(); Function: Builds a new Bio::Tools::Run::BWA object Returns : an instance of Bio::Tools::Run::BWA Args : run Title : run Usage : $assembly = $bwafac->run( @args ); Function: Run the bwa assembly pipeline. Returns : Assembly results (file, IO object or Assembly object) Args : - fastq file containing single-end reads - fasta file containing the reference sequence - [optional] fastq file containing paired-end reads run_bwa() Title : run_bwa Usage : $obj->run_bwa( @file_args ) Function: Run a bwa command as specified during object contruction Returns : Args : a specification of the files to operate on: stdout() Title : stdout Usage : $fac->stdout() Function: store the output from STDOUT for the run, if no file specified in run_maq() Example : Returns : scalar string Args : on set, new value (a scalar or undef, optional) stderr() Title : stderr Usage : $fac->stderr() Function: store the output from STDERR for the run, if no file is specified in run_maq() Example : Returns : scalar string Args : on set, new value (a scalar or undef, optional) Bio::Tools::Run::AssemblerBase overrides _check_sequence_input() No-op. _check_optional_quality_input() No-op. _prepare_input_sequences Convert input fastq and fasta to maq format. _collate_subcmd_args() Title : _collate_subcmd_args Usage : $args_hash = $self->_collate_subcmd_args Function: collate parameters and switches into command-specific arg lists for passing to new() Returns : hash of named argument lists Args : [optional] composite cmd prefix (scalar string) [default is 'run'] _run() Title : _run Usage : $factory->_run() Function: Run a bwa assembly pipeline Returns : a text-formatted sam alignment Args : - single end read file in maq bfq format - reference seq file in maq bfa format - [optional] paired end read file in maq bfq format available_parameters() Title : available_parameters Usage : @cmds = $fac->available_commands('commands'); Function: Use to browse available commands, params, or switches Returns : array of scalar strings Args : 'commands' : all bwa commands 'params' : parameters for this object's command 'switches' : boolean switches for this object's command 'filespec' : the filename spec for this object's command 4Geeks : Overrides Bio::ParameterBaseI via Bio::Tools::Run::AssemblerBase perl v5.12.3 2011-06-18 Bio::Tools::Run::BWA(3pm)
All times are GMT -4. The time now is 02:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy