Sponsored Content
Top Forums Shell Programming and Scripting Reading from file bash command Post 303003159 by nans on Friday 8th of September 2017 07:26:40 AM
Old 09-08-2017
Reading from file bash command

Hello, I have a file in the following format

Code:
id sample platform R1 R2 gene1 gene2 gene3
1       abc     llumina       R1_001.fastq.gz      R2_001.fastq.gz   apoe    prnpp    asp
2       def     llumina       R1_001.fastq.gz      R2_001.fastq.gz   apoe    prnpp    
3       ghi     llumina       R1_001.fastq.gz      R2_001.fastq.gz   apoe

The first 6 columns are always filled, the last two columns are only for some entries. So I have a main script that reads this file to process these ids further. I generally use

Code:
while id sample platform R1 R2 gene1
do
<mainscript.sh>
done < samples.txt

But how can I include the last two columns as well to run the command as many entries under the variable gene2 and gene3 are empty.

This is what i have tried so far to read all the lines in the file and if variable under gene2 and/or gene3 are empty, to move to the next line

Code:
while read  id sample platform R1 R2 gene1 gene2 gene3
do
echo "$id $sample $gene1 $gene2" | {
        read  id sample platform R1 R2 gene1 gene2
        [ -z "$gene2" ] && continue
        for i in $gene2; do eval echo "\"$i\""; done
 }
 
 done < samples.txt

I could do it for gene2 but wasnt able to implement it for gene3

any suggestions would be helpful

thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: Reading 2 arguments from a command line

If no arguments are entered I wanna be able to read 2 arguments, i have done like this but it doesnt work: x=0 until #loop starts do if ; then echo No arguments were entered, please enter 2 arguments. read $1 $2 elif || ; then echo $#... (0 Replies)
Discussion started by: Vozx
0 Replies

2. Shell Programming and Scripting

bash: reading filenames from file

Hi, I'm trying to write a script that reads filenames from a file and use these filenames in a loop. The filenames are all on one line and the problem is that these filenames have wildcards like * and braces like in them. Right now what I'm doing is something like this: echo "reading from... (0 Replies)
Discussion started by: warp17
0 Replies

3. Shell Programming and Scripting

Reading lines from a file, using bash, "at" command

Hi. I have the script shown below. If I execute it form the command line it seems to work properly, but when I fun it using the unix "at" command "at -m now < ./kill-at-job.sh" It appears to hang. Below is the script, the input file, and the execution as reported in the e-mail from the "at"... (3 Replies)
Discussion started by: jbsimon000
3 Replies

4. Shell Programming and Scripting

Problem in reading file (bash)

i get a name from user first name : last name, in this format. Now i am saving this to a file. what i want is, I do not want to save any name if I already have one entry o that same name..what should i do for example user give robert fernandez this will save in file as robert:fernandez. if... (5 Replies)
Discussion started by: Learnerabc
5 Replies

5. Shell Programming and Scripting

Help in reading a cv file in bash

Hi All, I am trying to read a .csv file which has some 6 columns. Eg: samp.csv one, two, three, four six, seven, eight, nine I used the following code, for line in `cat samp.csv` do echo "$line" done It displays every comma seperated values in each line like, one,... (1 Reply)
Discussion started by: johnwilliams.sp
1 Replies

6. Shell Programming and Scripting

Bash: Reading a file and assigning variables from file

I have a file that has four values on each line and I'd like to give each column a variable name and then use those values in each step of a loop. In bash, I believe you could use a while loop to do this or possibly a cat command, but I am super new to programming and I'm having trouble decoding... (2 Replies)
Discussion started by: ccorder22
2 Replies

7. Shell Programming and Scripting

Reading command line options from bash script

I have the following code and I am calling it using ./raytrac.bash -u and getting problems. For some reason opt_usage is still 0. opt_usage=0 iarg=0 narg=$# while (($iarg < $narg)) do (( iarg = $iarg + 1 )) arg=$argv usrInputFlag=`echo $arg | awk '/=/ {print 1}; ! /=/... (22 Replies)
Discussion started by: kristinu
22 Replies

8. Shell Programming and Scripting

Reading a text file using bash

I've a file in linux with following text: ;ip address hostname put-location alt-put-location tftpserver 192.168.1.1 r01-lab1-net /mnt/nas1/fgbu/ /opt/fgbu/devicebackup 192.168.1.254Now I want to read these values and assign them to particular variables... (6 Replies)
Discussion started by: kashif.live
6 Replies

9. UNIX for Beginners Questions & Answers

Reading a file from a different directory in a Bash script

Hi all, Given here under a section of a script I am using. SIMDIR="/home/Ins/forces" cd $SIMDIR for file in `ls *.forces` do basename=`echo $file | sed 's/\.*$//'` extname=`echo $file | sed 's/*\(*\)\.\(.*\)/\2\1/'` echo "Processing file: "$basename python convert.py... (4 Replies)
Discussion started by: Theo Score
4 Replies

10. UNIX for Beginners Questions & Answers

Bash Variable scope - while loop while reading from a file

Cope sample1: test.sh i=0 echo " Outside loop i = $i " while do i=$(( $i + 1)) echo "Inside loop i = $i " done echo " Out of loop i is : $i " When run output : Outside loop i = 0 Inside loop i = 1 Inside loop i = 2 Inside loop i = 3 Inside loop i = 4 Inside loop i = 5 Inside... (8 Replies)
Discussion started by: Adarshreddy01
8 Replies
Bio::Tools::Run::Bowtie(3pm)				User Contributed Perl Documentation			      Bio::Tools::Run::Bowtie(3pm)

NAME
Bio::Tools::Run::Bowtie - Run wrapper for the Bowtie short-read assembler *BETA* SYNOPSIS
# create an index $bowtie_build = Bio::Tools::Run::Bowtie->new(); $index = $bowtie_fac->run( 'reference.fasta', 'index_base' ); # or with named args... $index = $bowtie_fac->run( -ref => 'reference.fasta', -ind => 'index_base' ); # get the base name of the last index from an index builder $index = $bowtie_fac->result; # create an assembly $bowtie_fac = Bio::Tools::Run::Bowtie->new(); $bowtie_fac->want('Bio::Assembly::Scaffold'); $bowtie_assy = $bowtie_fac->run( 'reads.fastq', 'index_base' ); # if IO::Uncompress::Gunzip is available and with named args... $bowtie_assy = $bowtie_fac->run( -seq => 'reads.fastq.gz', -ind => 'index_base' ); # paired-end $bowtie_fac = Bio::Tools::Run::Bowtie->new(-command => 'paired', -want => 'Bio::Assembly::Scaffold'); $bowtie_assy = $bowtie_fac->run( 'reads.fastq', 'index_base', 'paired-reads.fastq' ); # be more strict $bowtie_fac->set_parameters( -max_qual_mismatch => 50 ); # create a Bio::Assembly::Scaffold object $bowtie_assy = $bowtie_fac->run( 'reads.fastq', 'index_base', 'paired-reads.fastq' ); # print consensus sequences from assembly object for $contig ($bowtie_assy->all_contigs) { print $contig->get_consensus_sequence->seq," "; } # get the file object of the last assembly $io = $bowtie_fac->result( -want => 'Bio::Root::IO' ); # get a merged SeqFeature::Collection of all hits # - currently only available with SAM format $io = $bowtie_fac->result( -want => 'Bio::SeqFeature::Collection' ); #... or the file name directly $filename = $bowtie_fac->result( -want => 'raw' ); DESCRIPTION
This module provides a wrapper interface for Ben Langmead and Col Trapnell's ultrafast memory-efficient short read aligner "bowtie" (see http://bowtie-bio.sourceforge.net/ <http://bowtie-bio.sourceforge.net/> for manuals and downloads). OPTIONS
"bowtie" is complex, with many command-line options. This module attempts to provide and options comprehensively. You can browse the choices like so: $bowtiefac = Bio::Tools::Run::Bowtie->new( -command => 'single' ); # all bowtie commands @all_commands = $bowtiefac->available_parameters('commands'); @all_commands = $bowtiefac->available_commands; # alias # just for single @assemble_params = $bowtiefac->available_parameters('params'); @assemble_switches = $bowtiefac->available_parameters('switches'); @assemble_all_options = $bowtiefac->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. As a number of options are mutually exclusive, and the interpretation of intent is based on last-pass option reaching bowtie with potentially unpredicted results. This module will prevent inconsistent switches and parameters from being passed. See http://bowtie.sourceforge.net/bowtie-manpage.shtml <http://bowtie.sourceforge.net/bowtie-manpage.shtml> for details of bowtie options. FILES
When a command requires filenames, these are provided to the "run" method, not the constructor ("new()"). To see the set of files required by a command, use "available_parameters('filespec')" or the alias "filespec()": $bowtiefac = Bio::Tools::Run::Bowtie->new( -command => 'paired' ); @filespec = $bowtiefac->filespec; This example returns the following array: ind seq seq2 #out This indicates that ind ("bowtie" index file base name), seq (fasta/fastq),and seq2 (fasta/fastq) files MUST be specified, and that the out file MAY be specified. Use these in the "run" call like so: $bowtiefac->run( -ind => 'index_base', -seq => 'seq-a.fq', -seq2 => 'seq-b.fq', -out => 'align.out' ); Note that named parameters in this form allow you to specify the location of the outfile; without named parameters, the outfile is located in a tempdir and does not persist beyond the life of the object - with the exception of index creation. The object will store the programs STDOUT and STDERR output for you in the "stdout()" and "stderr()" attributes: handle_map_warning($bowtiefac) if ($bowtiefac->stderr =~ /warning/); 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 - Dan Kortschak Email dan.kortschak adelaide.edu.au CONTRIBUTORS
Mark A. Jensen (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::Bowtie(); Function: Builds a new Bio::Tools::Run::Bowtie object Returns : an instance of Bio::Tools::Run::Bowtie Args : run() Title : run Usage : $assembly = $bowtie_assembler->run($read1_fastq_file, $index_location, $read2_fastq_file); $assembly = $bowtie_assembler->run(%params); Function: Run the bowtie assembly pipeline. Returns : Assembly results (file, IO object or Assembly object) Args : - fastq file containing single-end reads - name of the base of the bowtie index - [optional] fastq file containing paired-end reads Named params are also available with args: -seq, -seq2, -ind (bowtie index), -ref (fasta reference) and -out Note : gzipped inputs are allowed if IO::Uncompress::Gunzip is available The behaviour for locating indexes follows the definition in the bowtie manual - you may use the environment variable BOWTIE_INDEXES to specify the index path or use an 'indexes' directory under the directory where the bowtie executable is located want() Title : want Usage : $bowtiefac->want( $class ) Function: make factory return $class, or raw (scalar) results in file Returns : return wanted type Args : [optional] string indicating class or raw of wanted result result() Title : result Usage : $bowtiefac->result( [-want => $type|$format] ) Function: return result in wanted format Returns : results Args : [optional] hashref of wanted type _determine_format() Title : _determine_format Usage : $bowtiefac->_determine_format Function: determine the format of output for current options Returns : format of bowtie output Args : _make_bam() Title : _make_bam Usage : $bowtiefac->_make_bam( $file, $sort ) Function: make a sorted BAM format file from SAM file Returns : sorted BAM file name Args : SAM file name and boolean flag to select sorted BAM format _validate_file_input() Title : _validate_file_input Usage : $bowtiefac->_validate_file_input( -type => $file ) Function: validate file type for file spec Returns : file type if valid type for file spec Args : hash of filespec => file_name Bio::Tools::Run::AssemblerBase overrides _assembly_format() Title : _assembly_format Usage : $bowtiefac->_determine_format Function: set the format of output for current options Returns : format of bowtie output Args : _check_sequence_input() No-op. _check_optional_quality_input() No-op. _prepare_input_sequences() Prepare and check input sequences for bowtie. set_parameters() Title : set_parameters Usage : $bowtiefac->set_parameters(%params); Function: sets the parameters listed in the hash or array, maintaining sane options. Returns : true on success Args : [optional] hash or array of parameter/values. Note : This will unset conflicts and set required options, but will not prevent non-sane requests in the arguments version() Title : version Usage : $version = $bowtiefac->version() Function: Returns the program version (if available) Returns : string representing location and version of the program perl v5.12.3 2011-06-18 Bio::Tools::Run::Bowtie(3pm)
All times are GMT -4. The time now is 06:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy