Skip to content

2. File_Exercises

gitarunprasanna83 edited this page Jul 18, 2019 · 7 revisions
  1. Enter into Dir_1
  2. View the genome file -- > cat E.coli_genome.fna
  3. View only first 2 lines of the genome file -- > head -n 2 E.coli_genome.fa
  4. View the last 2 lines of the genome file -- > tail -n -2 E.coli_genome.fa
  5. Scroll through the file -- > more E.coli_genome.fa [Enter to scroll, after End of file, type q in : to exit]
  6. Scroll through the file -- > less E.coli_genome.fa
  7. Do word count of genome file -- > wc E.coli_genome.fa wc_output
  8. Find the number of “sequences” present in genome file -- > grep ‘>’ E.coli_genome.fa
  9. Find the number of “sequences” present in protein file -- > grep ‘>’ E.coli_protein.fa [too many to count?]
  10. Count the number of sequences present in genome & protein files -- > *grep -c ‘>’ .fa [Remember the * wildcard.. saves you lot of time]
  11. Find how many “lipoprotein” sequences are there in protein file -- > grep -c ‘lipoprotein’ E.coli_protein.fa [87 is the answer !]

Let’s crunch some numbers:

  1. Copy the gff file to current directory and rename it as E.coli_genome.gff
  2. View first 10 lines [see the number of columns and delimiter]
  3. 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]
  4. Extract the gene list from genes file -- > cut -f 9 1_E.coli_genes.gff > 2_E.coli_genes_identifiercut.out
  5. Extract the gene identifier -- > cut -d ';' -f1 2_E.coli_genes_identifiercut.out > 3_E.coli_genes_onlyIDs.out
  6. Extract the gene list -- > cut -d '=' -f2 3_E.coli_genes_onlyIDs.out > 4_genelist.out
  7. Find if they are unique list or duplicated -- > sort 4_genelist.out > 5_genelist.sorted

uniq 5_genelist.sorted > 6_genelist.sorted.uniq.out 19. Cross-check if there are any duplicates -- > wc -l 5_genelist.sorted 6_genelist.sorted.uniq.out 20. 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 21. 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

Clone this wiki locally