Shell scripting : Help Me for this sequence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell scripting : Help Me for this sequence
# 1  
Old 10-06-2010
Network Shell scripting : Help Me for this sequence

I have two input files (given below) and to compare each line of the File1 with each line of File2 starts with '>sample1'. If a match occurs and that matched line in the File2 contains another line or sequence of lines starting with "Chr" they have to be displayed in output file with that sample. If a match occurs and the matched line in File2 does not contain a 'Chr' line(s) it has be omitted or not taken into consideration for output file. For easy understanding, I marked the matched lines in file1 and file2 with blue color which are taken into consideration for final output. I maked the matched lines in file1 with file2 (which doesnt contain 'Chr' lines) in red color which are not taken into account for output. The final output to be selected also given below. [COLOR="Blue"]PLS. KINDLY HELP ME FOR THE SHELL SCRIPTING OF THIS. [/COLOR



File1:
>sample1:1:1:1057:7503#0 0 0
>sample1:1:1:1057:12664#0 0 0
>sample1:1:1058:8130#0 5 830
>sample1:1:1:1059:6357#0 0 0
>sample1:1:1:1059:10418#0 0 0
>sample1:1:1:1059:12084#0 1 1
>sample1:1:1:1060:11510#0 0 0
>sample1:1:1:1060:5177#0 0 0
>sample1:1:1:1061:8105#0 0 0
>sample1:1:1:1063:6105#0 0 0
>sample1:1:1:1064:11266#0 0 0
>sample1:1:1:1066:5654#0 0 0
>sample1:1:1:1067:10266#0 0 0
>sample1:1:1:1068:2100#0 0 0
>sample1:1:1:1069:3450#0 0 0
>sample1:1:1:1070:7530#0 0 0
>sample1:1:1:1071:8627#0 0 0
>sample1:1:1:1071:8552#0 0 0
>sample1:1:1:1072:7060#0 0 0
>sample1:1:1:1073:7329#0 0 0
>sample1:1:1:1073:20394#0 0 0
>sample1:1:1:1074:7081#0 0 0
>sample1:1:1:1076:1654#0 0 0
>sample1:1:1:1077:15575#0 0 0
>sample1:1:1:1077:15683#0 0 0

File2:
>sample1:1:1:1056:8164#0 1 1
Chr21 +25913822 2
>sample1:1:1:1057:7503#0 0 0
>sample1:1:1:1057:18666#0 1 1
Chr21 +25913822 2
>sample1:1:1:1057:1725#0 1 1
Chr21 +25913822 2
>sample1:1:1:1057:12664#0 0 0
>sample1:1:1:1057:18537#0 1 1
Chr21 +25913822 2
>sample1:1:1:1058:8130#0 5 830
Chr19 +52245923 1
Chr17 +69679873 1
Chr23 +52121254 1
Chr11 +100949523 1
Chr8 +28333267 1

>sample1:1:1:1058:19619#0 1 1
Chr21 +25913822 2
>sample1:1:1:1059:6357#0 0 0
>sample1:1:1:1059:10418#0 0 0
>sample1:1:1:1059:12084#0 1 1
Chr12 -19596251 2

>sample1:1:1:1060:13498#0 1 1

Output:
sample1:1:1:1058:8130#0 5 830
Chr19 +52245923 1
Chr17 +69679873 1
Chr23 +52121254 1
Chr11 +100949523 1
Chr8 +28333267 1
sample1:1:1:1059:12084#0 1 1
Chr12 -19596251
# 2  
Old 10-06-2010
You posted the input data, but it would be kind to post us the expected result/output.

Regards
# 3  
Old 10-06-2010
Quote:
Originally Posted by hravisankar
I have to read a file- line by line using shell script. the format should be exactly same as given below

Chr18:4000-4010
Chr20:393939-400303
Chr30:38838-30020

I already posted a thread and 2 answers did not read the data like that. ...
That's because your problem statement is quite vague. A "read" operation does not "have" a format, which is why "read" cannot "be" in any format.

Your input data in a file or from a pipe "has" or "is in" some particular format. So, I'll assume that this -

Code:
Chr18:4000-4010
Chr20:393939-400303
Chr30:38838-30020

is the format of your input data. Again, I'll assume that this data is in a file, as opposed to a pipe stream.

In the shell, you'd read a file like so -

Code:
$
$ # display the content of the file. My file is called "f32", yours may be different.
$ cat f32
Chr18:4000-4010
Chr20:393939-400303
Chr30:38838-30020
$
$ # read data from input file "f32"
$ while read LINE; do   echo "Oh my! I've now read this line => $LINE"; done < f32
Oh my! I've now read this line => Chr18:4000-4010
Oh my! I've now read this line => Chr20:393939-400303
Oh my! I've now read this line => Chr30:38838-30020
$
$

HTH,
tyler_durden
# 4  
Old 10-07-2010
Shell scripting problem

My input file (data1) is like this
Code:
Chr8:4000-4500
Chr10:4000-4600

I written a shell program like this.
Code:
while read LINE;
do   echo "$LINE";
samtools faidx Bos_taurusUMD3.fa "$line";
done < data1


It has to read a line like Chr8:4000-4500 from input file and that line has to be executed in a command like 'samtools faidx Bos_taurusUMD3.fa
Code:
Chr8:4000-4500'. Then I will get the sequence like this.
>Chr8:4000-4500
TAATTCGTTTTTCTTTTTTCCTCTCTGACTCATTTATTTGTACCATTCTATCTTCTAATT
CACTAATCTTATCTTCTGCCTCTGTTATTCTACTATTTGTCGCCTCCAGAGTGTTTTTGA
TCTCATTTATTGCATTATTCATTATATATTGACTCTTTTTTATGTCTTCTAGGTCCTTGT
TAAACCTTTCTTGCATCTTCTCAATCCTTGTCTCCAGGTTATTTATCTGTGATTCCATTT
TGATTTCAAGATTTTGGATCAATTTCACTATCATTATTCAGAATTCTTTATCAGGTAGAT
TCCTTATCTCTTCCTCTTTTGTTTTGTTTGGTGGGCATTTATCCTGTTCCTTTACCTGCT
GGGTATTCCTCTGTCTCTTCATCTTGTTTATATTGCTGAGTTTGGGGTGTCCTTTCTGTA
TTCTGGCAGTTTGTGGAGTTCTCTTTATTGTGGAGTTTCCTCGCTGTGTATGGGTTTGTA
CAGGTGGCTTGTCAAGGTTTC

but when I execute the shell it is displaying the output like this
Code:
 Chr8:4000-4500
>
Chr10:4000-4600
>

but not displaying the sequence.but I execute the command at $ prompt like
$samtools faidx Bos_taurusUMD3.fa Chr8:4000-4500
it is running and displaying the sequence.

How to execute it in my shell by reading each line from input line, execute it in command and display the sequences.
KINDLY HELP ME
This User Gave Thanks to hravisankar For This Post:
# 5  
Old 10-07-2010
try like this
Code:
samtools faidx Bos_taurusUMD3.fa "$line"

This User Gave Thanks to ygemici For This Post:
# 6  
Old 10-07-2010
Reading input line problem

Thank u very much for your reply. I used as u specified "$line" in samtools command like samtools faidx Bos_taurusUMD3.fa "$line";

It is giving out like this. Sequence was not given. it displays it as > only.

Code:
Chr8:86884850-86884997
>
ChrX:96383583-96383703
>
Chr15:33347613-33347720
>
~

Kindly help me how to execute that to generate the sequence.
# 7  
Old 10-07-2010
Quote:
Originally Posted by hravisankar
I have an input file in this format (shown below). I have to select the lines which doesnt followed by 'miR-" and to save such lines into an output file. For easy identification they are shown here in blue color. They have to be selected. Pls. help me to write a shell script to select those lines which doesnt followed by miR- and have to write them in a file.
KINDLY DO THE HELP

>sample1:1:1:1056:8164#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1057:7503#0 0 0
>sample1:1:1:1057:18666#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1057:1725#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1057:12664#0 0 0
>sample1:1:1:1057:18537#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1058:8130#0 1 1
miR-2396;Chr26:42482649-42482717 -1 2
>sample1:1:1:1058:19619#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1059:6357#0 0 0
>sample1:1:1:1059:10418#0 0 0

>sample1:1:1:1059:12084#0 1 1
miR-16-1;Chr12:19596200-19596290 -52 2
>sample1:1:1:1060:13498#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1060:11510#0 0 0
>sample1:1:1:1060:2691#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1060:5177#0 0 0
>sample1:1:1:1060:13599#0 1 1
miR-16-1;Chr12:19596200-19596290 -52 2
>sample1:1:1:1060:12022#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1061:8105#0 0 0
>sample1:1:1:1062:4635#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1062:2052#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1062:17129#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1063:6105#0 0 0
>sample1:1:1:1064:11266#0 0 0

>sample1:1:1:1065:5224#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1065:14605#0 1 1
miR-152;Chr19:39081165-39081250 +53 2
>sample1:1:1:1066:5654#0 0 0
>sample1:1:1:1066:10310#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1067:3521#0 1 1
miR-184;Chr21:25913771-25913853 +52 2
>sample1:1:1:1067:1055#0 1 1
Little issue, but simple code.

Code:
awk 'BEGIN{RS=ORS=">";FS="\n"} NF==2' infile

sample1:1:1:1057:7503#0 0 0
>sample1:1:1:1057:12664#0 0 0
>sample1:1:1:1059:6357#0 0 0
>sample1:1:1:1059:10418#0 0 0
>sample1:1:1:1060:11510#0 0 0
>sample1:1:1:1060:5177#0 0 0
>sample1:1:1:1061:8105#0 0 0
>sample1:1:1:1063:6105#0 0 0
>sample1:1:1:1064:11266#0 0 0
>sample1:1:1:1066:5654#0 0 0
>sample1:1:1:1067:1055#0 1 1
>

This User Gave Thanks to rdcwayx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print Line as per the dependent sequence in shell script.

Hi i have a file like this as shown below: DA PROCESS_ID IDENTIFIER DA_FILE STATUS WAITING_FOR SCOPED_DEPENDENT 1836 21000 01052019 BH90P.TEMP.DA1836.FTP W NULL ... (6 Replies)
Discussion started by: krishnaswarnkar
6 Replies

2. Shell Programming and Scripting

Will shell script executes in sequence

I have a shell script scheduled in cron job to run at every 1 minute which transfers files to remote machine and then move the files to backup folder. cd /u01/app/ftp_tmp sftp user@hostname <<-EOF cd /home/user/ftp mput * bye EOF mv /u01/app/ftp_tmp/* /u01/app/ftp_bkp Now the problem is... (6 Replies)
Discussion started by: Bhavi
6 Replies

3. Shell Programming and Scripting

How to find a missing file sequence using shell scripting?

Hey guys, I want the below files to be processed with the help of BASH so that i will be able to find the missing file names : PP01674520141228X.gz PP01674620141228X.gz PP01674820141228X.gz PP01674920141228X.gz PP01675420141228X.gz PP01675520141228X.gz PP01676020141228X.gz . . . .... (4 Replies)
Discussion started by: TANUJ
4 Replies

4. Shell Programming and Scripting

Sequence generation in shell

Hi, I am using the nested for loops to generate the sequence , taking start and end sequence number input from test.txt (sample content mentioned below). Also , can I print the rest of columns as well with sequence number into the same file. for i in `cat test.txt|cut -d"," -f7` do ... (8 Replies)
Discussion started by: tushar.modgil
8 Replies

5. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

6. UNIX for Advanced & Expert Users

Sequence number merged with hypen, shell script

Hello Folks, i have to write shell scripting for given expected output manner. in given input we have to write shell script in such a way that sequence no can b merged/link between start and end digit with hyphen "-" symbol and rest of digit separated by "," Eg : For Input "2 6 7 8 11 12... (9 Replies)
Discussion started by: panchalh
9 Replies

7. Shell Programming and Scripting

How to insert a sequence number column inside a pipe delimited csv file using shell scripting?

Hi All, I need a shell script which could insert a sequence number column inside a dat file(pipe delimited). I have the dat file similar to the one as shown below.. |A|B|C||D|E |F|G|H||I|J |K|L|M||N|O |P|Q|R||S|T As shown above, the column 4 is currently blank and i need to insert sequence... (5 Replies)
Discussion started by: nithins007
5 Replies

8. Shell Programming and Scripting

Shell scripting for this sequence

KINDLY HELP ME FOR SHELL SCRIPTING FOR THIS TASK. My input file consists of thousands of sequence in this format. The given input file consists of four sequences which are starting with ‘>’ symbol (each sequence shown in different colour for easy understanding). I have to use a command at $... (3 Replies)
Discussion started by: kswapnadevi
3 Replies

9. Shell Programming and Scripting

Shell scripting for this sequence to compare

I have two input files (given below) and to compare each line of the File1 with each line of File2 starts with '>sample1'. If a match occurs and that matched line in the File2 contains another line or sequence of lines starting with "Chr" they have to be displayed in output file with that sample.... (4 Replies)
Discussion started by: hravisankar
4 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question