Help: Parsing a file to new output files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help: Parsing a file to new output files
# 1  
Old 01-10-2013
Help: Parsing a file to new output files

I have an output file similar to this

Code:
>HWI-ST766:129:D0WJDACXX:4:2308:16645:199681.1 /start=1 /end=100 /strand=+ Eukaryotic18S_rRNA
GATTAAGCCATGCATGTGTAAGTTTAAAGTCCTAGAAGGATGAAACTGCGGACGGCTCAT
TATAACAGTAATAGTTTCTTTGGTTAGTATCTATAAGGAT
>HWI-ST766:129:D0WJDACXX:4:2308:2922:199946.1 /start=1 /end=96 /strand=+ Eukaryotic:28S_rRNA
CCTAACTATACGCTCATCAGATACCACAAAAGGTGTTGATTCATCTAAACAGCAGGGCGG
TGGACATAGAAGTCGTTACCCGCTAAGGAGTGTGTC
>HWI-ST766:129:D0WJDACXX:4:2308:5144:199799.1 /start=1 /end=85 /strand=- Bacterial:16S_rRNA
GGGGAGATCTCAAAGAGTCAGGTTGCTTGGAACTGCAGCCTTAAGCGGGAGATATGAAAC
TTCCAAAGCTAAATATAGATGGGAG
>HWI-ST766:129:D0WJDACXX:4:2308:7062:199913.1 /start=2 /end=100 /strand=+ Bacterial:23S_rRNA
TTCGAGTTGGAGCACGCCTGTCGGGACCCGAAAGATGGTGAACTATGCCTGAGCGGGGCG
AAGCCAGAGGAAACTCTGGTGGAGGCTCGAAGCGATACT
>HWI-ST766:129:D0WJDACXX:4:2308:13310:199841.1 /start=10 /end=99 /strand=+ Archaeal:16S_rRNA
AACACAAACTAGCTTGGAGACATCAGCACGTGCCCTTGGAAGAGTTTTCTTTTCTTCTTA
ACATGTATGAGGCCTTGAAATTGGATTACC
>HWI-ST766:129:D0WJDACXX:4:2308:15549:199820.1 /start=1 /end=100 /strand=- Archaeal:23S_rRNA
CCTCAGGATAGCAGGAACAATATTGCAGTTTTATCAGGTAAAGCGAATGATTAGAGGTTA
CTGAGCGTTTTTTGTTTGGACCTATTCTCAAACTTTAAAT
>HWI-ST766:129:D0WJDACXX:4:2308:1510:200068.1 /start=1 /end=100 /strand=- Bacterial:23S_rRNA
GAAGCGGTGTTGACGTGCAAATCACTCGTCAAATTTGGGTATAGGGGCGAAAGACTAATC
GAACCATCTAGTAGCTGGTTCCCTCTGAAGTTTCCCTCAG
>HWI-ST766:129:D0WJDACXX:4:2308:2254:200148.1 /start=1 /end=100 /strand=- Archaeal:23S_rRNA
GATGGTGAACTATACTTGAACGGTTAGAAGCCGAAGGAAACTTTGGTGGAAGAACCACGC
AGTGTTAACGTGCAAATTACTTGTCATATTTGAGTATAGG
>HWI-ST766:129:D0WJDACXX:4:2308:4747:200053.1 /start=2 /end=96 /strand=+ Eukaryotic:28S_rRNA
AGATGACTCGCTGGACTTAAGCATATTATTAAGCGAAGGAAAAGAAATTAACAAAGATTG
CCTTAGTAAGGGCGACTGAACCGGCAATAGCTCGA
>HWI-ST766:129:D0WJDACXX:4:2308:4747:200053.1 /start=2 /end=96 /strand=+ Bacterial:16S_rRNA
AGATGACTCGCTGGACTTAAGCATATTATTAAGCGAAGGAAAAGAAATTAACAAAGATTG
CCTTAGTAAGGGCGACTGAACCGGCAATAGCTCGA
>HWI-ST766:129:D0WJDACXX:4:2308:5396:200008.1 /start=2 /end=100 /strand=+ Eukaryotic18S_rRNA
TTCTTAGTGGGCCATTTTTGGTAAGCAGAACTGGCGATGAGGGATGAACCTAACGTCGAG
TTAAGGTGCCTAACTATACGCTCATCAGATACCACAAAA

I would like to search the file and create new output files based on the different rRNA types. The six are Eukaryotic18S_rRNA Eukaryotic:28S_rRNA Bacterial:16S_rRNA Bacterial:23S_rRNA Archaeal:16S_rRNA Archaeal:23S_rRNA (note the missing : in Eukaryotic18S_rRNA is real, a mistake in the original program)

So a search for Bacterial:16S_rRNA would output to a different file

Code:
>HWI-ST766:129:D0WJDACXX:4:2308:5144:199799.1 /start=1 /end=85 /strand=- Bacterial:16S_rRNA
GGGGAGATCTCAAAGAGTCAGGTTGCTTGGAACTGCAGCCTTAAGCGGGAGATATGAAAC
TTCCAAAGCTAAATATAGATGGGAG
>HWI-ST766:129:D0WJDACXX:4:2308:4747:200053.1 /start=2 /end=96 /strand=+ Bacterial:16S_rRNA
AGATGACTCGCTGGACTTAAGCATATTATTAAGCGAAGGAAAAGAAATTAACAAAGATTG
CCTTAGTAAGGGCGACTGAACCGGCAATAGCTCGA

The input file could be searched serially for each key, or all at the same time, ouputing to different files. The input files are a few GB in size (but I do have a lot of memory).

Any help would be appreciated.
# 2  
Old 01-10-2013
try:
Code:
grep ">.*:.*[0-9]S_rRNA" infile | sed 's/.*[^0-9]\([0-9][0-9]*\)S_rRNA/\1S_rRNA/' | sort -u | while read rna
do
   awk -v rna="$rna" '
      BEGIN {s="^>.*" rna "$"; print s}
      $0 ~ s {p=1}
      $0 ~ /^>/ && $0 !~ s {p=0}
      p==1
   ' infile > "$rna.txt"
done
ls -l *.txt

# 3  
Old 01-10-2013
RE: Help: Parsing

Well that almost works. I did make a mistake in the input file. There are two more definitions that come up Bacterial:5S_rRNA and Eukaryotic:8S_rRNA. This leaves me to wonder whether there are others (such as Archaeal:5S_rRNA) that I had not considered in the input.

It also looks like the Archaeal:16S_rRNA and Bacterial:16S_rRNA end up in the same

16S_rRNA.txt output file.

Bob
# 4  
Old 01-10-2013
try version 1.1:
Code:
grep ">.* .*S_rRNA" infile | sed 's/ *$//; s/.* //' | sort -u | while read rna
do
   rm -f "$rna.txt"
   awk -v rna="$rna" '
      BEGIN {s="^>.*" rna "$";}
      $0 ~ s {p=1}
      $0 ~ /^>/ && $0 !~ s {p=0}
      p==1
   ' infile > "$rna.txt"
   ls -l "$rna.txt"
done

This User Gave Thanks to rdrtx1 For This Post:
# 5  
Old 01-10-2013
Excellent! It looks like that does the job and outputs 9 result files.

Thanks!

Bob
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help on parsing Oracle RMAN output for string and print sections of a file

Hi, I need some advise on how to print 'sections' of the attached file. I am searching for some that says Marked Corrupt and print some lines after it. At the moment I am running the command below: sed -n -e '/Marked Corrupt/{N;N;p;}' rman_list_validate.txtThis gives me the following... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. Shell Programming and Scripting

Help in parsing XML output file in perl.

Hi I have an XML output like : <?xml version="1.0" encoding="ISO-8859-1" ?> - <envelope> - <body> - <outputGetUsageSummary> - <usgSumm rerateDone="5"> - <usageAccum accumId="269" accumCaptn="VD_DP_AR" inclUnits="9999999.00" inclUnitsUsed="0.00" shared="false" pooled="false"... (7 Replies)
Discussion started by: rkrish
7 Replies

3. Shell Programming and Scripting

Parsing fields from class list files to use output with newusers command

Hello I am trying to develop a shell script that takes a text file such as this... E-mail@ Soc.Sec.No. *--------Name-----------* Class *School.Curriculum.Major.* Campus.Phone JCC2380 XXX-XX-XXXX CAREY, JULIE C JR-II BISS CPSC BS INFO TECH 412/779-9445 JAC1936 XXX-XX-XXXX... (7 Replies)
Discussion started by: crimputt
7 Replies

4. Shell Programming and Scripting

Parsing txt, xml files and preparing csv file

Hi, I need to parse text, xml files to get the statistic numbers and prepare summary csv file. What is the best way to parse these file and prepare csv file. Any idea you have , please? Regards, (2 Replies)
Discussion started by: LinuxLearner
2 Replies

5. Shell Programming and Scripting

parsing txt file, saving graphics files

hi everyone, i am a newbie in shell programming. and i want to simply go through a text file that contains 3 "columns", split by ';' customerID ; link-to-contract ; save-as-filename so an example would simply look like this now i want to loop through every line, and save the file from... (3 Replies)
Discussion started by: Confidence
3 Replies

6. Shell Programming and Scripting

parsing file names and then grouping similar files

Hello Friends, I have .tar files which exists under different directories after the below code is run: find . -name "*" -type f -print | grep .tar > tmp.txt cat tmp.txt ./dir1/subdir1/subdir2/database-db1_28112009.tar ./dir2/subdir3/database-db2_28112009.tar... (2 Replies)
Discussion started by: EAGL€
2 Replies

7. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

8. Shell Programming and Scripting

need help in Parsing a CSV file and generate a new output file

Hi Scripting Gurus, I am trying to parse a csv file and generate a new output file. The input file will be a variable length in turns of rows and columns. output file will have 8 columns. we have three columns from the header for each set. just to give little bit more clarification each row... (15 Replies)
Discussion started by: vkr
15 Replies

9. Shell Programming and Scripting

parsing output

I have a file that contains the output of the ls -iR command, something like this: ./results: 2504641011 result_1410 2500957642 result_525 2504641012 result_1425 2500957643 result_540 ./tests/1: 2500788755 1 2500788743 1000 ./tests/2: 2500788759 3 2500788758 999 ... (6 Replies)
Discussion started by: looza
6 Replies

10. Shell Programming and Scripting

problem parsing output file

Hi Gurus, I am using the following code to parse the output of a file. This code basically parses the file and adds | at the end of each field. But I am getting it wrong in some cases. I have explained it below #----- parse output file, get each field position, ----- #----- and construct... (13 Replies)
Discussion started by: ragha81
13 Replies
Login or Register to Ask a Question