Inserting IDs from a text file into a sequence alignment file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting IDs from a text file into a sequence alignment file
# 1  
Old 11-19-2014
Inserting IDs from a text file into a sequence alignment file

Hi,
I have one file with one column and several hundred entries

File1:
Code:
NA1
NA2
NA3

And now I need to run a command within a mapping aligner tool to insert these sample names into a sequence alignment file (SAM) such that they look like this

Code:
@RG    ID:Library1 SM:NA1 PL:Illumina  LB:lib_2x250 DS:hg19 
@RG    ID:Library1 SM:NA2 PL:Illumina  LB:lib_2x250 DS:hg19 
@RG    ID:Library1 SM:NA3 PL:Illumina  LB:lib_2x250 DS:hg19

What I am trying is
Code:
file=samples.txt
while IFS= read -r line
do
bwa mem -M -R "@RG\tID:Library1\tSM:$line\tPL:Illumina\tLB:lib_2x250\tDS:hg19" hg19.fasta R1.fastq.gz R2.fastq.gz > alignment.sam
done < "$file"

The output was not was I desired, it had only one sample name and I also think this just overwrites the output file and perform the same alignment several hundred times, is there any fix for this ?

Thank you
# 2  
Old 11-19-2014
Hmmm... Perhaps:

Code:
file=samples.txt
while IFS= read -r line
do
bwa mem -M -R "@RG\tID:Library1\tSM:$line\tPL:Illumina\tLB:lib_2x250\tDS:hg19" hg19.fasta R1.fastq.gz R2.fastq.gz
done < "$file" > alignment.sam

# 3  
Old 11-19-2014
Thank you, but what's happening is that, its not including all the names at once. Its iterating and as a result will perform the same alignment (bwa mem) again and again, in this cases 500 times... one iteration takes about 30-35 hours...so 500 would take days or weeks...
# 4  
Old 11-19-2014
I know nothing about your bwa utility. How would you use it to update multiple things at once?
# 5  
Old 11-19-2014
Well, usually, when we have multiple files, we put everything into a variable and that would work. For my issue above, after going through several forums I understood that I have to make $file (full of IDs) into a variable to which I append each line in the while loop and then put bwa outside of the loop.. but I have just been struggling with the code..
# 6  
Old 11-19-2014
I am mostly confused because I have no idea what bwa does. Is it necessary to this task or not?
# 7  
Old 11-19-2014
no its not necessary to this task... what I need has to be done before bwa starts
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Inserting information from old text file into a new text file

Hello, I'm trying to take information from a list of hundreds of subject ids (where each line is a new subject id), and insert each line into a new text file that contains the pathnames for each subject. To clarify, all subject have a similiar path name (e.g., C:\data\SUBJECT_ID\) that contains... (4 Replies)
Discussion started by: invisibledwarf
4 Replies

2. UNIX for Dummies Questions & Answers

Inserting text into a file with awk or sed

Hello, I've been trying to get a script working that fetches weather-data and converts it into an .ics file. The script works so far put I'm stuck at the point where I need to add specific static data. A thorough search through the forum did not point me into the right direction. #!/bin/bash... (3 Replies)
Discussion started by: Schubi
3 Replies

3. Shell Programming and Scripting

Help with sed and inserting text from another file

I need to insert text from one file into another file after specific term. I guess sed is the best method of doing this and I can insert a specified text string using this script but I am not sure how to modify it to insert text from another file: #!/bin/sh sed 's/\<VirtualHost... (17 Replies)
Discussion started by: barrydocks
17 Replies

4. Shell Programming and Scripting

fuzzy sequence match in a text file

Hi Forum: I have struggle with it and decide to use my eye ball to accomplish this. Basically I am looking for sequence of date inside a file. If one of the sequence repeat 2-3 time or skip once; it's still consider a match. input text file: Sep 6 A Sep 6 A Sep 10 A Sep 7 B Sep 8... (7 Replies)
Discussion started by: chirish
7 Replies

5. Shell Programming and Scripting

Inserting text into a new file

Hi all, I want to create a file and then insert some text into it. I'm trying to create a .sh script that will create a new python file from a template. Can someone tell me why this won't work, touch $1 | sed -e '1i\Some test code here' Sorry I'm quite new to all this! Just as a side... (3 Replies)
Discussion started by: ahodgson
3 Replies

6. UNIX for Dummies Questions & Answers

Inserting a column into a text file

I have a tab delimited text file with multiple columns (data.txt). I would like to insert a column into the text file. The column I want to insert is in a text file (column.txt). I want to insert it into the 5th column of data.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

7. Shell Programming and Scripting

Send a mail to IDs listed in a text file

I have a list of mail ids in text file and want a ksh script that reads this text file and sends a mail to all mail ids with same subject line and content. I am using UX-HP machine and KSH. Thanks for help in advance! (5 Replies)
Discussion started by: Sriranga
5 Replies

8. Shell Programming and Scripting

inserting a string to a text file

Hello Can somebody please help me with the following script? I'm trying to create a text file with 20 blank lines and then insert a string in line 2 but nothing is printed in the itxtfile. I can create the file with 20 blank lines but when I "tell" it to print something on the second line, it... (4 Replies)
Discussion started by: goude
4 Replies

9. Shell Programming and Scripting

Inserting text and modifying the file

I am in a dire need of doing this job , please help from shell script or perl script. It will be highly appreciated. Please have a look at the following INPUT file; The first 14 rows are not of interest but I want them to be included in the output file as they are. From the row 14... (3 Replies)
Discussion started by: digipak
3 Replies

10. Shell Programming and Scripting

inserting subscriber no in text file using KSH....

:confused:Dears , I have text file I need to insert the subscriber number at position 32, and need to keep the next field at position 53 (no increasing of the record lenght), I mean I just want to replace the spaces at position 32 with subscirber number . for example A B A ... (1 Reply)
Discussion started by: atiato
1 Replies
Login or Register to Ask a Question