Trimming sequences based on Reference


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trimming sequences based on Reference
# 1  
Old 07-01-2010
Trimming sequences based on Reference

My file looks something like this
Quote:
>GHL8OVD01BNNCA Freq 4
TTGATGTGCCCGTGGGTTTCCCGTCAACACCGG-------------------------------
>GHL8OVD01CMQVT Freq 15
TTGATGTCGTGGGTTTCCCGTCAACACCGGCAAATAGTAGCAGCACTACCAGGACCTTCGCCCA
>Reference1 Freq 1
TTGATGTGCCAGTTTCCCGTCTAGCAGCACTACCAGGACCTTCGCCCA----------------
>GHL8OVD01CMQVW Freq 11
TTGATGTGTCCCGTCGACACCGGCAAATAGCAGCAGCACTACCAGGACCTTCGCCCA-------
>GHL8OVD01A45V3 Freq 9
TTGATTCCCGTCGACACCGGCAAATAGCAGCAGCACTACAGGACCTTCGCCCA-----------
>GHL8OVD01B9PRR Freq 1
TTGATGTGCCAGCTTTCGCGTCGACACCGGCAAATAGTAGCAGCGCTACCAGGACCTTCGCCCA
>GHL8OVD01BL8BD Freq 1
TTGATGAGTACTTCCCCCGGTGACGTGGGTCAGCACTACCAGGACCTTCGCCCA----------
>GHL8OVD01AV2U9 Freq 17
TTGATGTGCCAGCTTTCGCGTCGACACCGGCAAATAGTAGCAGCGCTA----------------
Wnat I need is to look for the Reference sequence (">Reference1") and based on the length of that sequence trim all the entries in that file. So, the rersulting file will contain all sequences with the same length, like this
Quote:
>GHL8OVD01BNNCA Freq 4
TTGATGTGCCCGTGGGTTTCCCGTCAACACCGG---------------
>GHL8OVD01CMQVT Freq 15
TTGATGTCGTGGGTTTCCCGTCAACACCGGCAAATAGTAGCAGCACTA
>Reference1 Freq 1
TTGATGTGCCAGTTTCCCGTCTAGCAGCACTACCAGGACCTTCGCCCA
>GHL8OVD01CMQVW Freq 11
TTGATGTGTCCCGTCGACACCGGCAAATAGCAGCAGCACTACCAGGAC
>GHL8OVD01A45V3 Freq 9
TTGATTCCCGTCGACACCGGCAAATAGCAGCAGCACTACAGGACCTTC
>GHL8OVD01B9PRR Freq 1
TTGATGTGCCAGCTTTCGCGTCGACACCGGCAAATAGTAGCAGCGCTA
>GHL8OVD01BL8BD Freq 1
TTGATGAGTACTTCCCCCGGTGACGTGGGTCAGCACTACCAGGACCTT
>GHL8OVD01AV2U9 Freq 17
TTGATGTGCCAGCTTTCGCGTCGACACCGGCAAATAGTAGCAGCGCTA
Thus, all sequences will keep their identifier intact (">Identifier") and have the same length. In case of being shorter than the Reference sequence, then the dashes ("-") will be consider as characters to make the length up.
Any help will be very much appreciated.

Last edited by Xterra; 07-01-2010 at 01:04 AM..
# 2  
Old 07-01-2010
Hi

Code:
awk 'NR==FNR{if($0 ~ /Reference1/){getline; gsub("-","");x=length;}next;}{print substr($0,1,x);}' file file

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 07-01-2010
Guru

The output file is empty. Am I using your code in the right way?
Code:
$ awk 'NR==FNR{if($0 ~ /Reference1/){getline; gsub("-","");x=length;}next;}{print substr($0,1,x);}' Input > Output

# 4  
Old 07-01-2010
Hi xterra

Not like this. if you want to redirect the output to a file,

Code:
awk 'NR==FNR{if($0 ~ /Reference1/){getline; gsub("-","");x=length;}next;}{print substr($0,1,x);}' Input Input > Output

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 5  
Old 07-01-2010
My bad!

Thanks alot! It worked like a charm!
# 6  
Old 07-01-2010
guruprasadpr's code can't help you for this request:

In case of being shorter than the Reference sequence, then the dashes ("-") will be consider as characters to make the length up.

Here is my update.
Code:
awk -F ""  'NR==FNR{if ($0~/Reference1/){getline; gsub("-","");x=length;}next;}
     {if ($0~/^>/) {print $0} else { {for (i=1;i<=x;i++) printf ($i=="")?"-":$i};printf "\n"}}' urfile urfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting sequences based on length with sed

I have this file: >ID1 AA >ID2 TTTTTT >ID-3 AAAAAAAAA >ID4 TTTTTTGGAGATCAGTAGCAGATGACAG-GGGGG-TGCACCCC Add I am trying to use this script to output sequences longer than 15 characters: sed -r '/^>/N;{/^.{,15}$/d}' The desire output would be this: >ID4... (8 Replies)
Discussion started by: Xterra
8 Replies

2. Shell Programming and Scripting

Print sequences from file2 based on match to, AND in same order as, file1

I have a list of IDs in file1 and a list of sequences in file2. I can print sequences from file2, but I'm asking for help in printing the sequences in the same order as the IDs appear in file1. file1: EN_comp12952_c0_seq3:367-1668 ES_comp17168_c1_seq6:1-864 EN_comp13395_c3_seq14:231-1088... (5 Replies)
Discussion started by: pathunkathunk
5 Replies

3. Shell Programming and Scripting

Eliminating sequences based on Distances

I have to remove sequences from a file based on the distance value. I am attaching the file containing the distances (Distance.xls) The second file looks something like this: Sequences.txt >Sample1 Freq 59 ggatatgatgatgaactggt >Sample1 Freq 54 ggatatgatgttgaactggt >Sample1 Freq 44... (2 Replies)
Discussion started by: Xterra
2 Replies

4. Shell Programming and Scripting

Selecting sequences based on scores

I have two files with thousands of sequences of different lengths. infile1 contains the actual sequences and infile2 the scores for each A, T, G and C in infile1. Something like this: infile1: >HZVJKYI01ECH5R TTGATGTGCCAGCTGCCGTTGGTGTGCCAA >HZVJKYI01AQWJ8 GGATATGATGATGAACTGGTTTGGCACACC... (4 Replies)
Discussion started by: Xterra
4 Replies

5. Shell Programming and Scripting

Extract sequences based on the list

Hi, I have a file with more than 28000 records and it looks like below.. >mm10_refflat_ABCD range=chr1:1234567-2345678 tgtgcacactacacatgactagtacatgactagac....so on >mm10_refflat_BCD range=chr1:3234567-4545678... tgtgcacactacacatgactagtatgtgcacactacacatgactagta . . . . . so on ... (2 Replies)
Discussion started by: Diya123
2 Replies

6. UNIX for Dummies Questions & Answers

Trimming a string based on delimiter.

Hi, I have a string say "whateverCluster". I need everthing apart from the string "Cluster" Input: whateverCluster Desired output: whatever (5 Replies)
Discussion started by: mohtashims
5 Replies

7. Shell Programming and Scripting

Replace character based on reference file problem asking

I got two files right now, input file (target file), reference file 1 (query file) reference file 1 (long list of data) KOLOPWMOPOPO ADASDASD ADSASDASDAD . . target file (one long liner content) ADASDASDTYUKOKOLOPWMOPOPOOPLUAADSASDASDADPOPOUYADADASDASD desired output file content ... (1 Reply)
Discussion started by: patrick87
1 Replies

8. Shell Programming and Scripting

Deleting sequences based on character frequency

This is what I would like to accomplish, I have an input file (file A) that consist of thousands of sequence elements with the same number of characters (length), each headed by a free text header starting with the chevron ‘>' character followed by the ID (all different IDs with different lenghts)... (9 Replies)
Discussion started by: Xterra
9 Replies

9. Shell Programming and Scripting

Trimming sequences based on specific pattern

My files look like this And I need to cut the sequences at the last "A" found in the following 'pattern' -highlighted for easier identification, the pattern is the actual file is not highlighted. The expected result should look like this Thus, all the sequences would end with AGCCCTA... (2 Replies)
Discussion started by: Xterra
2 Replies

10. Shell Programming and Scripting

trimming sequences

My file looks like this: But I would like to 'trim' all sequences to the same lenght 32 characters, keeping intact all the identifier (>GHXCZCC01AJ8CJ) Would it be possible to use awk to perform this task? (2 Replies)
Discussion started by: Xterra
2 Replies
Login or Register to Ask a Question