-
Notifications
You must be signed in to change notification settings - Fork 0
2. File_Exercises
gitarunprasanna83 edited this page Jul 18, 2019
·
7 revisions
- Enter into Dir_1
- View the genome file -- > cat E.coli_genome.fna
- View only first 2 lines of the genome file -- > head -n 2 E.coli_genome.fa
- View the last 2 lines of the genome file -- > tail -n -2 E.coli_genome.fa
- Scroll through the file -- > more E.coli_genome.fa [Enter to scroll, after End of file, type q in : to exit]
- Scroll through the file -- > less E.coli_genome.fa
- Do word count of genome file -- > wc E.coli_genome.fa
- Find the number of “sequences” present in genome file -- > grep ‘>’ E.coli_genome.fa
- Find the number of “sequences” present in protein file -- > grep ‘>’ E.coli_protein.fa [too many to count?]
- Count the number of sequences present in genome & protein files -- > grep -c ‘>’ E.coli_genome.fa E.coli_protein.fa [Remember the * wildcard.. saves you lot of time]
- Find how many “lipoprotein” sequences are there in protein file -- > grep -c ‘lipoprotein’ E.coli_protein.fa [87 is the answer !]
- Copy the gff file to current directory and rename it as E.coli_genome.gff
- View first 10 lines [see the number of columns and delimiter]
- Extract the “gene” entries alone into new file -- > grep "\tgene" E.coli_genomic.gff > 1_E.coli_genes.gff [_\t_ is important, else you will end up with all the entries matching the pattern 'gene' ! count how many genes are there = wc -l 1_E.coli_genes.gff]
- Extract the gene list from genes file -- > cut -f 9 1_E.coli_genes.gff > 2_E.coli_genes_identifiercut.out
- Extract the gene identifier -- > cut -d ';' -f1 2_E.coli_genes_identifiercut.out > 3_E.coli_genes_onlyIDs.out
- Extract the gene list -- > cut -d '=' -f2 3_E.coli_genes_onlyIDs.out > 4_genelist.out
- Find if they are unique list or duplicated -- > sort 4_genelist.out > 5_genelist.sorted
uniq 5_genelist.sorted > 6_genelist.sorted.uniq.out
- Cross-check if there are any duplicates -- > wc -l 5_genelist.sorted 6_genelist.sorted.uniq.out
- Now make a power-full one-liner with pipes [|]: grep "\tgene" E.coli_genomic.gff |cut -f 9 |cut -d ';' -f1 |cut -d '=' -f2 |sort|uniq > 6.1_E.coli_genelist.out
- Compare two outputs: -- >
diff 6_genelist.sorted.uniq.out 6.1_E.coli_genelist.out
or
comm 6_genelist.sorted.uniq.out 6.1_E.coli_genelist.out |wc -l
Diff – should return nothing
Comm – should return everything
You learnt to view the files with head, tail, more, less --> Searched for patterns with grep --> learnt to count the number of occurrences of pattern 'grep -c' --> Extracted columns from tabular data using cut --> Extracted specific fields using delimiters 'cut -d' --> sorted the entries --> removed duplicates with uniq --> In parallel, learnt to create a one-liner !
Bravo !! Next go to 3.batch processing