File size: 42,043 Bytes
0b09f74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:05:33.604063Z",
     "start_time": "2023-05-20T16:05:30.146945Z"
    },
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--2023-05-20 09:05:30--  https://www.mirbase.org/ftp/CURRENT/mature.fa.gz\r\n",
      "Resolving www.mirbase.org... 130.88.97.249\r\n",
      "Connecting to www.mirbase.org|130.88.97.249|:443... connected.\r\n",
      "HTTP request sent, awaiting response... 200 OK\r\n",
      "Length: 803746 (785K) [application/x-gzip]\r\n",
      "Saving to: ‘mature.fa.gz’\r\n",
      "\r\n",
      "mature.fa.gz        100%[===================>] 784.91K   342KB/s    in 2.3s    \r\n",
      "\r\n",
      "2023-05-20 09:05:33 (342 KB/s) - ‘mature.fa.gz’ saved [803746/803746]\r\n",
      "\r\n"
     ]
    }
   ],
   "source": [
    "!wget https://www.mirbase.org/ftp/CURRENT/mature.fa.gz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:08:16.201849Z",
     "start_time": "2023-05-20T16:08:16.145057Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">hsa-let-7a-5p MIMAT0000062 Homo sapiens let-7a-5p\n",
      "TGAGGTAGTAGGTTGTATAGTT\n",
      ">hsa-let-7a-3p MIMAT0004481 Homo sapiens let-7a-3p\n",
      "CTATACAATCTACTGTCTTTC\n",
      ">hsa-let-7a-2-3p MIMAT0010195 Homo sapiens let-7a-2-3p\n",
      "CTGTACAGCCTCCTAGCTTTCC\n",
      ">hsa-let-7b-5p MIMAT0000063 Homo sapiens let-7b-5p\n",
      "TGAGGTAGTAGGTTGTGTGGTT\n",
      ">hsa-let-7b-3p MIMAT0004482 Homo sapiens let-7b-3p\n",
      "CTATACAACCTACTGCCTTCCC\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "#extract human miRNAs\n",
    "zcat mature.fa.gz  | grep -A1 sapiens | sed '/^[^>]/s/U/T/g' > mature.hsa.fa\n",
    "head mature.hsa.fa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:14:51.607352Z",
     "start_time": "2023-05-20T16:14:51.443975Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%%bash\n",
    "samtools faidx mature.hsa.fa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:10:22.921848Z",
     "start_time": "2023-05-20T16:10:22.331328Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Settings:\n",
      "  Output files: \"mature_hsa.*.bt2\"\n",
      "  Line rate: 6 (line is 64 bytes)\n",
      "  Lines per side: 1 (side is 64 bytes)\n",
      "  Offset rate: 4 (one in 16)\n",
      "  FTable chars: 10\n",
      "  Strings: unpacked\n",
      "  Max bucket size: default\n",
      "  Max bucket size, sqrt multiplier: default\n",
      "  Max bucket size, len divisor: 4\n",
      "  Difference-cover sample period: 1024\n",
      "  Endianness: little\n",
      "  Actual local endianness: little\n",
      "  Sanity checking: disabled\n",
      "  Assertions: disabled\n",
      "  Random seed: 0\n",
      "  Sizeofs: void*:8, int:4, long:8, size_t:8\n",
      "Input files DNA, FASTA:\n",
      "  mature.hsa.fa\n",
      "Reading reference sizes\n",
      "  Time reading reference sizes: 00:00:00\n",
      "Calculating joined length\n",
      "Writing header\n",
      "Reserving space for joined string\n",
      "Joining reference sequences\n",
      "  Time to join reference sequences: 00:00:00\n",
      "bmax according to bmaxDivN setting: 14346\n",
      "Using parameters --bmax 10760 --dcv 1024\n",
      "  Doing ahead-of-time memory usage test\n",
      "  Passed!  Constructing with these parameters: --bmax 10760 --dcv 1024\n",
      "Constructing suffix-array element generator\n",
      "Building DifferenceCoverSample\n",
      "  Building sPrime\n",
      "  Building sPrimeOrder\n",
      "  V-Sorting samples\n",
      "  V-Sorting samples time: 00:00:00\n",
      "  Allocating rank array\n",
      "  Ranking v-sort output\n",
      "  Ranking v-sort output time: 00:00:00\n",
      "  Invoking Larsson-Sadakane on ranks\n",
      "  Invoking Larsson-Sadakane on ranks time: 00:00:00\n",
      "  Sanity-checking and returning\n",
      "Building samples\n",
      "Reserving space for 12 sample suffixes\n",
      "Generating random suffixes\n",
      "QSorting 12 sample offsets, eliminating duplicates\n",
      "QSorting sample offsets, eliminating duplicates time: 00:00:00\n",
      "Multikey QSorting 12 samples\n",
      "  (Using difference cover)\n",
      "  Multikey QSorting samples time: 00:00:00\n",
      "Calculating bucket sizes\n",
      "Splitting and merging\n",
      "  Splitting and merging time: 00:00:00\n",
      "Avg bucket size: 57386 (target: 10759)\n",
      "Converting suffix-array elements to index image\n",
      "Allocating ftab, absorbFtab\n",
      "Entering Ebwt loop\n",
      "Getting block 1 of 1\n",
      "  No samples; assembling all-inclusive block\n",
      "  Sorting block of length 57386 for bucket 1\n",
      "  (Using difference cover)\n",
      "  Sorting block time: 00:00:00\n",
      "Returning block of 57387 for bucket 1\n",
      "Exited Ebwt loop\n",
      "fchr[A]: 0\n",
      "fchr[C]: 12681\n",
      "fchr[G]: 26180\n",
      "fchr[T]: 42679\n",
      "fchr[$]: 57386\n",
      "Exiting Ebwt::buildToDisk()\n",
      "Returning from initFromVector\n",
      "Wrote 4393751 bytes to primary EBWT file: mature_hsa.1.bt2\n",
      "Wrote 14352 bytes to secondary EBWT file: mature_hsa.2.bt2\n",
      "Re-opening _in1 and _in2 as input streams\n",
      "Returning from Ebwt constructor\n",
      "Headers:\n",
      "    len: 57386\n",
      "    bwtLen: 57387\n",
      "    sz: 14347\n",
      "    bwtSz: 14347\n",
      "    lineRate: 6\n",
      "    offRate: 4\n",
      "    offMask: 0xfffffff0\n",
      "    ftabChars: 10\n",
      "    eftabLen: 20\n",
      "    eftabSz: 80\n",
      "    ftabLen: 1048577\n",
      "    ftabSz: 4194308\n",
      "    offsLen: 3587\n",
      "    offsSz: 14348\n",
      "    lineSz: 64\n",
      "    sideSz: 64\n",
      "    sideBwtSz: 48\n",
      "    sideBwtLen: 192\n",
      "    numSides: 299\n",
      "    numLines: 299\n",
      "    ebwtTotLen: 19136\n",
      "    ebwtTotSz: 19136\n",
      "    color: 0\n",
      "    reverse: 0\n",
      "Total time for call to driver() for forward index: 00:00:00\n",
      "Reading reference sizes\n",
      "  Time reading reference sizes: 00:00:00\n",
      "Calculating joined length\n",
      "Writing header\n",
      "Reserving space for joined string\n",
      "Joining reference sequences\n",
      "  Time to join reference sequences: 00:00:00\n",
      "  Time to reverse reference sequence: 00:00:00\n",
      "bmax according to bmaxDivN setting: 14346\n",
      "Using parameters --bmax 10760 --dcv 1024\n",
      "  Doing ahead-of-time memory usage test\n",
      "  Passed!  Constructing with these parameters: --bmax 10760 --dcv 1024\n",
      "Constructing suffix-array element generator\n",
      "Building DifferenceCoverSample\n",
      "  Building sPrime\n",
      "  Building sPrimeOrder\n",
      "  V-Sorting samples\n",
      "  V-Sorting samples time: 00:00:00\n",
      "  Allocating rank array\n",
      "  Ranking v-sort output\n",
      "  Ranking v-sort output time: 00:00:00\n",
      "  Invoking Larsson-Sadakane on ranks\n",
      "  Invoking Larsson-Sadakane on ranks time: 00:00:00\n",
      "  Sanity-checking and returning\n",
      "Building samples\n",
      "Reserving space for 12 sample suffixes\n",
      "Generating random suffixes\n",
      "QSorting 12 sample offsets, eliminating duplicates\n",
      "QSorting sample offsets, eliminating duplicates time: 00:00:00\n",
      "Multikey QSorting 12 samples\n",
      "  (Using difference cover)\n",
      "  Multikey QSorting samples time: 00:00:00\n",
      "Calculating bucket sizes\n",
      "Splitting and merging\n",
      "  Splitting and merging time: 00:00:00\n",
      "Avg bucket size: 57386 (target: 10759)\n",
      "Converting suffix-array elements to index image\n",
      "Allocating ftab, absorbFtab\n",
      "Entering Ebwt loop\n",
      "Getting block 1 of 1\n",
      "  No samples; assembling all-inclusive block\n",
      "  Sorting block of length 57386 for bucket 1\n",
      "  (Using difference cover)\n",
      "  Sorting block time: 00:00:00\n",
      "Returning block of 57387 for bucket 1\n",
      "Exited Ebwt loop\n",
      "fchr[A]: 0\n",
      "fchr[C]: 12681\n",
      "fchr[G]: 26180\n",
      "fchr[T]: 42679\n",
      "fchr[$]: 57386\n",
      "Exiting Ebwt::buildToDisk()\n",
      "Returning from initFromVector\n",
      "Wrote 4393751 bytes to primary EBWT file: mature_hsa.rev.1.bt2\n",
      "Wrote 14352 bytes to secondary EBWT file: mature_hsa.rev.2.bt2\n",
      "Re-opening _in1 and _in2 as input streams\n",
      "Returning from Ebwt constructor\n",
      "Headers:\n",
      "    len: 57386\n",
      "    bwtLen: 57387\n",
      "    sz: 14347\n",
      "    bwtSz: 14347\n",
      "    lineRate: 6\n",
      "    offRate: 4\n",
      "    offMask: 0xfffffff0\n",
      "    ftabChars: 10\n",
      "    eftabLen: 20\n",
      "    eftabSz: 80\n",
      "    ftabLen: 1048577\n",
      "    ftabSz: 4194308\n",
      "    offsLen: 3587\n",
      "    offsSz: 14348\n",
      "    lineSz: 64\n",
      "    sideSz: 64\n",
      "    sideBwtSz: 48\n",
      "    sideBwtLen: 192\n",
      "    numSides: 299\n",
      "    numLines: 299\n",
      "    ebwtTotLen: 19136\n",
      "    ebwtTotSz: 19136\n",
      "    color: 0\n",
      "    reverse: 1\n",
      "Total time for backward call to driver() for mirror index: 00:00:00\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Building a SMALL index\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "#buile index\n",
    "bowtie2-build mature.hsa.fa mature_hsa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:30:35.241341Z",
     "start_time": "2023-05-20T16:26:29.303820Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/A2508.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/A2508.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/A375.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/A375.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/A549.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/A549.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/BxPC3.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/BxPC3.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/C42Bu.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/C42Bu.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/Colo320.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/Colo320.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/H1299.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/H1299.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/H23u.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/H23u.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/H358u.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/H358u.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/HCC44.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/HCC44.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/HCT116.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/HCT116.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/HEK293T-16.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/HEK293T-16.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/HEK293T-1.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/HEK293T-1.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/HEK293T-26.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/HEK293T-26.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/HEK293T-9.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/HEK293T-9.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/HEPG2.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/HEPG2.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/HS707A.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/HS707A.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/K562.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/K562.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/LNCaP.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/LNCaP.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/LS174T.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/LS174T.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/MCF7.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/MCF7.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/MDA231.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/MDA231.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/MDA453.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/MDA453.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/PACA2.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/PACA2.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/PANC1.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/PANC1.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/PC3.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/PC3.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/SW480u.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/SW480u.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/SW620u.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/SW620u.hsa-miR.bam\n",
      "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U fastq/ZR751.trim.fastq.gz | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/ZR751.hsa-miR.bam\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "4821010 reads; of these:\n",
      "  4821010 (100.00%) were unpaired; of these:\n",
      "    4802725 (99.62%) aligned 0 times\n",
      "    8705 (0.18%) aligned exactly 1 time\n",
      "    9580 (0.20%) aligned >1 times\n",
      "0.38% overall alignment rate\n",
      "4776794 reads; of these:\n",
      "  4776794 (100.00%) were unpaired; of these:\n",
      "    4754325 (99.53%) aligned 0 times\n",
      "    9945 (0.21%) aligned exactly 1 time\n",
      "    12524 (0.26%) aligned >1 times\n",
      "0.47% overall alignment rate\n",
      "4955992 reads; of these:\n",
      "  4955992 (100.00%) were unpaired; of these:\n",
      "    4931131 (99.50%) aligned 0 times\n",
      "    12243 (0.25%) aligned exactly 1 time\n",
      "    12618 (0.25%) aligned >1 times\n",
      "0.50% overall alignment rate\n",
      "4932829 reads; of these:\n",
      "  4932829 (100.00%) were unpaired; of these:\n",
      "    4915807 (99.65%) aligned 0 times\n",
      "    7826 (0.16%) aligned exactly 1 time\n",
      "    9196 (0.19%) aligned >1 times\n",
      "0.35% overall alignment rate\n",
      "4553779 reads; of these:\n",
      "  4553779 (100.00%) were unpaired; of these:\n",
      "    4531848 (99.52%) aligned 0 times\n",
      "    7366 (0.16%) aligned exactly 1 time\n",
      "    14565 (0.32%) aligned >1 times\n",
      "0.48% overall alignment rate\n",
      "6464528 reads; of these:\n",
      "  6464528 (100.00%) were unpaired; of these:\n",
      "    6436582 (99.57%) aligned 0 times\n",
      "    10498 (0.16%) aligned exactly 1 time\n",
      "    17448 (0.27%) aligned >1 times\n",
      "0.43% overall alignment rate\n",
      "4489153 reads; of these:\n",
      "  4489153 (100.00%) were unpaired; of these:\n",
      "    4471925 (99.62%) aligned 0 times\n",
      "    8902 (0.20%) aligned exactly 1 time\n",
      "    8326 (0.19%) aligned >1 times\n",
      "0.38% overall alignment rate\n",
      "4019383 reads; of these:\n",
      "  4019383 (100.00%) were unpaired; of these:\n",
      "    3997543 (99.46%) aligned 0 times\n",
      "    11181 (0.28%) aligned exactly 1 time\n",
      "    10659 (0.27%) aligned >1 times\n",
      "0.54% overall alignment rate\n",
      "3655799 reads; of these:\n",
      "  3655799 (100.00%) were unpaired; of these:\n",
      "    3639679 (99.56%) aligned 0 times\n",
      "    7308 (0.20%) aligned exactly 1 time\n",
      "    8812 (0.24%) aligned >1 times\n",
      "0.44% overall alignment rate\n",
      "7007928 reads; of these:\n",
      "  7007928 (100.00%) were unpaired; of these:\n",
      "    6980739 (99.61%) aligned 0 times\n",
      "    10843 (0.15%) aligned exactly 1 time\n",
      "    16346 (0.23%) aligned >1 times\n",
      "0.39% overall alignment rate\n",
      "5966114 reads; of these:\n",
      "  5966114 (100.00%) were unpaired; of these:\n",
      "    5950253 (99.73%) aligned 0 times\n",
      "    6855 (0.11%) aligned exactly 1 time\n",
      "    9006 (0.15%) aligned >1 times\n",
      "0.27% overall alignment rate\n",
      "4217907 reads; of these:\n",
      "  4217907 (100.00%) were unpaired; of these:\n",
      "    4198913 (99.55%) aligned 0 times\n",
      "    7085 (0.17%) aligned exactly 1 time\n",
      "    11909 (0.28%) aligned >1 times\n",
      "0.45% overall alignment rate\n",
      "4101770 reads; of these:\n",
      "  4101770 (100.00%) were unpaired; of these:\n",
      "    4088791 (99.68%) aligned 0 times\n",
      "    5288 (0.13%) aligned exactly 1 time\n",
      "    7691 (0.19%) aligned >1 times\n",
      "0.32% overall alignment rate\n",
      "5970825 reads; of these:\n",
      "  5970825 (100.00%) were unpaired; of these:\n",
      "    5959974 (99.82%) aligned 0 times\n",
      "    5437 (0.09%) aligned exactly 1 time\n",
      "    5414 (0.09%) aligned >1 times\n",
      "0.18% overall alignment rate\n",
      "5948472 reads; of these:\n",
      "  5948472 (100.00%) were unpaired; of these:\n",
      "    5934365 (99.76%) aligned 0 times\n",
      "    6041 (0.10%) aligned exactly 1 time\n",
      "    8066 (0.14%) aligned >1 times\n",
      "0.24% overall alignment rate\n",
      "4079143 reads; of these:\n",
      "  4079143 (100.00%) were unpaired; of these:\n",
      "    4062616 (99.59%) aligned 0 times\n",
      "    8477 (0.21%) aligned exactly 1 time\n",
      "    8050 (0.20%) aligned >1 times\n",
      "0.41% overall alignment rate\n",
      "4486372 reads; of these:\n",
      "  4486372 (100.00%) were unpaired; of these:\n",
      "    4461801 (99.45%) aligned 0 times\n",
      "    10688 (0.24%) aligned exactly 1 time\n",
      "    13883 (0.31%) aligned >1 times\n",
      "0.55% overall alignment rate\n",
      "6052256 reads; of these:\n",
      "  6052256 (100.00%) were unpaired; of these:\n",
      "    6027059 (99.58%) aligned 0 times\n",
      "    9673 (0.16%) aligned exactly 1 time\n",
      "    15524 (0.26%) aligned >1 times\n",
      "0.42% overall alignment rate\n",
      "5058477 reads; of these:\n",
      "  5058477 (100.00%) were unpaired; of these:\n",
      "    5031761 (99.47%) aligned 0 times\n",
      "    8373 (0.17%) aligned exactly 1 time\n",
      "    18343 (0.36%) aligned >1 times\n",
      "0.53% overall alignment rate\n",
      "4495300 reads; of these:\n",
      "  4495300 (100.00%) were unpaired; of these:\n",
      "    4466388 (99.36%) aligned 0 times\n",
      "    14500 (0.32%) aligned exactly 1 time\n",
      "    14412 (0.32%) aligned >1 times\n",
      "0.64% overall alignment rate\n",
      "4878799 reads; of these:\n",
      "  4878799 (100.00%) were unpaired; of these:\n",
      "    4853373 (99.48%) aligned 0 times\n",
      "    13422 (0.28%) aligned exactly 1 time\n",
      "    12004 (0.25%) aligned >1 times\n",
      "0.52% overall alignment rate\n",
      "4911860 reads; of these:\n",
      "  4911860 (100.00%) were unpaired; of these:\n",
      "    4887113 (99.50%) aligned 0 times\n",
      "    10158 (0.21%) aligned exactly 1 time\n",
      "    14589 (0.30%) aligned >1 times\n",
      "0.50% overall alignment rate\n",
      "4908472 reads; of these:\n",
      "  4908472 (100.00%) were unpaired; of these:\n",
      "    4879950 (99.42%) aligned 0 times\n",
      "    11657 (0.24%) aligned exactly 1 time\n",
      "    16865 (0.34%) aligned >1 times\n",
      "0.58% overall alignment rate\n",
      "5741493 reads; of these:\n",
      "  5741493 (100.00%) were unpaired; of these:\n",
      "    5724200 (99.70%) aligned 0 times\n",
      "    7739 (0.13%) aligned exactly 1 time\n",
      "    9554 (0.17%) aligned >1 times\n",
      "0.30% overall alignment rate\n",
      "3805981 reads; of these:\n",
      "  3805981 (100.00%) were unpaired; of these:\n",
      "    3790834 (99.60%) aligned 0 times\n",
      "    6854 (0.18%) aligned exactly 1 time\n",
      "    8293 (0.22%) aligned >1 times\n",
      "0.40% overall alignment rate\n",
      "3026377 reads; of these:\n",
      "  3026377 (100.00%) were unpaired; of these:\n",
      "    3007927 (99.39%) aligned 0 times\n",
      "    7559 (0.25%) aligned exactly 1 time\n",
      "    10891 (0.36%) aligned >1 times\n",
      "0.61% overall alignment rate\n",
      "5734706 reads; of these:\n",
      "  5734706 (100.00%) were unpaired; of these:\n",
      "    5715120 (99.66%) aligned 0 times\n",
      "    9143 (0.16%) aligned exactly 1 time\n",
      "    10443 (0.18%) aligned >1 times\n",
      "0.34% overall alignment rate\n",
      "4477297 reads; of these:\n",
      "  4477297 (100.00%) were unpaired; of these:\n",
      "    4453612 (99.47%) aligned 0 times\n",
      "    9742 (0.22%) aligned exactly 1 time\n",
      "    13943 (0.31%) aligned >1 times\n",
      "0.53% overall alignment rate\n",
      "3595305 reads; of these:\n",
      "  3595305 (100.00%) were unpaired; of these:\n",
      "    3576052 (99.46%) aligned 0 times\n",
      "    8967 (0.25%) aligned exactly 1 time\n",
      "    10286 (0.29%) aligned >1 times\n",
      "0.54% overall alignment rate\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "for f in fastq/*.trim.fastq.gz; do\n",
    "out=${f/.trim.fastq.gz/.hsa-miR.bam}\n",
    "out=`basename $out`\n",
    "echo \"bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U $f | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/$out\";\n",
    "bowtie2 --sensitive --end-to-end -N 1 -p 12 -x mature_hsa -U $f | samtools view -q10 -F20 - -Sb -h -t mature.hsa.fa.fai -o bam/$out\n",
    "done"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:31:34.910317Z",
     "start_time": "2023-05-20T16:31:29.781463Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "samtools sort -o bam/A2508.hsa-miR.srt.bam bam/A2508.hsa-miR.bam\n",
      "samtools sort -o bam/A375.hsa-miR.srt.bam bam/A375.hsa-miR.bam\n",
      "samtools sort -o bam/A549.hsa-miR.srt.bam bam/A549.hsa-miR.bam\n",
      "samtools sort -o bam/BxPC3.hsa-miR.srt.bam bam/BxPC3.hsa-miR.bam\n",
      "samtools sort -o bam/C42Bu.hsa-miR.srt.bam bam/C42Bu.hsa-miR.bam\n",
      "samtools sort -o bam/Colo320.hsa-miR.srt.bam bam/Colo320.hsa-miR.bam\n",
      "samtools sort -o bam/H1299.hsa-miR.srt.bam bam/H1299.hsa-miR.bam\n",
      "samtools sort -o bam/H23u.hsa-miR.srt.bam bam/H23u.hsa-miR.bam\n",
      "samtools sort -o bam/H358u.hsa-miR.srt.bam bam/H358u.hsa-miR.bam\n",
      "samtools sort -o bam/HCC44.hsa-miR.srt.bam bam/HCC44.hsa-miR.bam\n",
      "samtools sort -o bam/HCT116.hsa-miR.srt.bam bam/HCT116.hsa-miR.bam\n",
      "samtools sort -o bam/HEK293T-16.hsa-miR.srt.bam bam/HEK293T-16.hsa-miR.bam\n",
      "samtools sort -o bam/HEK293T-1.hsa-miR.srt.bam bam/HEK293T-1.hsa-miR.bam\n",
      "samtools sort -o bam/HEK293T-26.hsa-miR.srt.bam bam/HEK293T-26.hsa-miR.bam\n",
      "samtools sort -o bam/HEK293T-9.hsa-miR.srt.bam bam/HEK293T-9.hsa-miR.bam\n",
      "samtools sort -o bam/HEPG2.hsa-miR.srt.bam bam/HEPG2.hsa-miR.bam\n",
      "samtools sort -o bam/HS707A.hsa-miR.srt.bam bam/HS707A.hsa-miR.bam\n",
      "samtools sort -o bam/K562.hsa-miR.srt.bam bam/K562.hsa-miR.bam\n",
      "samtools sort -o bam/LNCaP.hsa-miR.srt.bam bam/LNCaP.hsa-miR.bam\n",
      "samtools sort -o bam/LS174T.hsa-miR.srt.bam bam/LS174T.hsa-miR.bam\n",
      "samtools sort -o bam/MCF7.hsa-miR.srt.bam bam/MCF7.hsa-miR.bam\n",
      "samtools sort -o bam/MDA231.hsa-miR.srt.bam bam/MDA231.hsa-miR.bam\n",
      "samtools sort -o bam/MDA453.hsa-miR.srt.bam bam/MDA453.hsa-miR.bam\n",
      "samtools sort -o bam/PACA2.hsa-miR.srt.bam bam/PACA2.hsa-miR.bam\n",
      "samtools sort -o bam/PANC1.hsa-miR.srt.bam bam/PANC1.hsa-miR.bam\n",
      "samtools sort -o bam/PC3.hsa-miR.srt.bam bam/PC3.hsa-miR.bam\n",
      "samtools sort -o bam/SW480u.hsa-miR.srt.bam bam/SW480u.hsa-miR.bam\n",
      "samtools sort -o bam/SW620u.hsa-miR.srt.bam bam/SW620u.hsa-miR.bam\n",
      "samtools sort -o bam/ZR751.hsa-miR.srt.bam bam/ZR751.hsa-miR.bam\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "for f in bam/*.hsa-miR.bam; do\n",
    "out=${f/.bam/.srt.bam};\n",
    "echo \"samtools sort -o $out $f\";\n",
    "samtools sort -m 2G -o $out $f\n",
    "samtools index $out;\n",
    "done"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:32:10.395458Z",
     "start_time": "2023-05-20T16:32:10.342608Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "umi_tools dedup -I bam/A2508.hsa-miR.srt.bam -S bam/A2508.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/A375.hsa-miR.srt.bam -S bam/A375.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/A549.hsa-miR.srt.bam -S bam/A549.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/BxPC3.hsa-miR.srt.bam -S bam/BxPC3.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/C42Bu.hsa-miR.srt.bam -S bam/C42Bu.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/Colo320.hsa-miR.srt.bam -S bam/Colo320.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/H1299.hsa-miR.srt.bam -S bam/H1299.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/H23u.hsa-miR.srt.bam -S bam/H23u.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/H358u.hsa-miR.srt.bam -S bam/H358u.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/HCC44.hsa-miR.srt.bam -S bam/HCC44.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/HCT116.hsa-miR.srt.bam -S bam/HCT116.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/HEK293T-16.hsa-miR.srt.bam -S bam/HEK293T-16.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/HEK293T-1.hsa-miR.srt.bam -S bam/HEK293T-1.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/HEK293T-26.hsa-miR.srt.bam -S bam/HEK293T-26.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/HEK293T-9.hsa-miR.srt.bam -S bam/HEK293T-9.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/HEPG2.hsa-miR.srt.bam -S bam/HEPG2.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/HS707A.hsa-miR.srt.bam -S bam/HS707A.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/K562.hsa-miR.srt.bam -S bam/K562.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/LNCaP.hsa-miR.srt.bam -S bam/LNCaP.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/LS174T.hsa-miR.srt.bam -S bam/LS174T.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/MCF7.hsa-miR.srt.bam -S bam/MCF7.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/MDA231.hsa-miR.srt.bam -S bam/MDA231.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/MDA453.hsa-miR.srt.bam -S bam/MDA453.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/PACA2.hsa-miR.srt.bam -S bam/PACA2.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/PANC1.hsa-miR.srt.bam -S bam/PANC1.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/PC3.hsa-miR.srt.bam -S bam/PC3.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/SW480u.hsa-miR.srt.bam -S bam/SW480u.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/SW620u.hsa-miR.srt.bam -S bam/SW620u.hsa-miR.srt.dd.bam &\n",
      "umi_tools dedup -I bam/ZR751.hsa-miR.srt.bam -S bam/ZR751.hsa-miR.srt.dd.bam &\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "for f in bam/*.hsa-miR.srt.bam; do\n",
    "out=${f/.srt.bam/.srt.dd.bam};\n",
    "echo \"umi_tools dedup -I $f -S $out &\";\n",
    "#umi_tools dedup -I $f -S $out &\n",
    "done"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:33:55.460620Z",
     "start_time": "2023-05-20T16:33:55.353828Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%%bash\n",
    "for f in bam/*.hsa-miR.srt.dd.bam; do\n",
    "samtools index $f &\n",
    "done"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:39:03.632496Z",
     "start_time": "2023-05-20T16:39:02.067991Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bam/A2508.hsa-miR.srt.dd.bam\n",
      "bam/A375.hsa-miR.srt.dd.bam\n",
      "bam/A549.hsa-miR.srt.dd.bam\n",
      "bam/BxPC3.hsa-miR.srt.dd.bam\n",
      "bam/C42Bu.hsa-miR.srt.dd.bam\n",
      "bam/Colo320.hsa-miR.srt.dd.bam\n",
      "bam/H1299.hsa-miR.srt.dd.bam\n",
      "bam/H23u.hsa-miR.srt.dd.bam\n",
      "bam/H358u.hsa-miR.srt.dd.bam\n",
      "bam/HCC44.hsa-miR.srt.dd.bam\n",
      "bam/HCT116.hsa-miR.srt.dd.bam\n",
      "bam/HEK293T-16.hsa-miR.srt.dd.bam\n",
      "bam/HEK293T-1.hsa-miR.srt.dd.bam\n",
      "bam/HEK293T-26.hsa-miR.srt.dd.bam\n",
      "bam/HEK293T-9.hsa-miR.srt.dd.bam\n",
      "bam/HEPG2.hsa-miR.srt.dd.bam\n",
      "bam/HS707A.hsa-miR.srt.dd.bam\n",
      "bam/K562.hsa-miR.srt.dd.bam\n",
      "bam/LNCaP.hsa-miR.srt.dd.bam\n",
      "bam/LS174T.hsa-miR.srt.dd.bam\n",
      "bam/MCF7.hsa-miR.srt.dd.bam\n",
      "bam/MDA231.hsa-miR.srt.dd.bam\n",
      "bam/MDA453.hsa-miR.srt.dd.bam\n",
      "bam/PACA2.hsa-miR.srt.dd.bam\n",
      "bam/PANC1.hsa-miR.srt.dd.bam\n",
      "bam/PC3.hsa-miR.srt.dd.bam\n",
      "bam/SW480u.hsa-miR.srt.dd.bam\n",
      "bam/SW620u.hsa-miR.srt.dd.bam\n",
      "bam/ZR751.hsa-miR.srt.dd.bam\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "for f in bam/*.hsa-miR.srt.dd.bam; do\n",
    "out=${f/.srt.dd.bam/.cnt};\n",
    "out=`basename $out`\n",
    "echo $f\n",
    "samtools view $f | cut -f3 | sort | uniq -c | awk '{ print $2 \"\\t\" $1}' > count/$out\n",
    "done"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:39:27.678503Z",
     "start_time": "2023-05-20T16:39:24.308743Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import rpy2.ipython\n",
    "%load_ext rpy2.ipython\n",
    "import warnings\n",
    "from rpy2.rinterface import RRuntimeWarning\n",
    "warnings.filterwarnings(\"ignore\", category=RRuntimeWarning)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:42:10.187793Z",
     "start_time": "2023-05-20T16:42:09.845743Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                A2508 A375 A549 BxPC3 C42Bu Colo320 H1299 H23u H358u HCC44\n",
      "hsa-let-7a-2-3p     1    9    1     0     0       0     0    0     0     0\n",
      "hsa-let-7a-3p      30   65   29    32    66      36    13   10    13    31\n",
      "hsa-let-7a-5p     838  843  929   894  1108     892   692  541   773   936\n",
      "hsa-let-7b-3p      13   12   13    22   131      22     2    5     6    39\n",
      "hsa-let-7b-5p     282  195  511   306   833     521    36   71   172   643\n",
      "hsa-let-7c-5p      69   11   86     4   685      85     3    4     2     5\n",
      "                HCT116 HEK293T.1 HEK293T.16 HEK293T.26 HEK293T.9 HEPG2 HS707A\n",
      "hsa-let-7a-2-3p      1         0          0          0         0     0      6\n",
      "hsa-let-7a-3p       56        10          4          9        11     4     33\n",
      "hsa-let-7a-5p      897       277        228        404       272   257    975\n",
      "hsa-let-7b-3p       30         0          0          0         1     2     53\n",
      "hsa-let-7b-5p      321        11         10         11        10    13    657\n",
      "hsa-let-7c-5p        2        17         24         19        20     1     72\n",
      "                K562 LNCaP LS174T MCF7 MDA231 MDA453 PACA2 PANC1 PC3 SW480u\n",
      "hsa-let-7a-2-3p    0     0      0    0      2      0     0     1   1      0\n",
      "hsa-let-7a-3p      1    59     33   13     11    109    19    27  17     29\n",
      "hsa-let-7a-5p    169  1113    753  755   1074   1205   768   838 983    789\n",
      "hsa-let-7b-3p      1    47     64    4     10     65    16    23   9     27\n",
      "hsa-let-7b-5p      9   822    435  211    261    906   221   361 475    498\n",
      "hsa-let-7c-5p      2   966      4   91      3     34     5     6   0      2\n",
      "                SW620u ZR751\n",
      "hsa-let-7a-2-3p      1     0\n",
      "hsa-let-7a-3p       21    18\n",
      "hsa-let-7a-5p      736   786\n",
      "hsa-let-7b-3p       18    14\n",
      "hsa-let-7b-5p      453   300\n",
      "hsa-let-7c-5p        5    46\n"
     ]
    }
   ],
   "source": [
    "%%R\n",
    "files<-list.files(pattern=\".hsa-miR.cnt\", recursive=TRUE, full.names=TRUE)\n",
    "datalist = lapply(files, function(x){read.table(file=x,header=FALSE,col.names=c(\"miRNA\", sub(\"./count/(\\\\S+).hsa-miR.cnt\", \"\\\\1\", x)))})\n",
    "m <- Reduce(function(...) merge(..., by=1, all = TRUE), datalist)\n",
    "rownames(m) <- m[,1]\n",
    "m[is.na(m)] <- 0\n",
    "m <- m[,-1]\n",
    "head(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:43:34.724737Z",
     "start_time": "2023-05-20T16:43:22.580119Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "R[write to console]: Loading required package: S4Vectors\n",
      "\n",
      "R[write to console]: Loading required package: stats4\n",
      "\n",
      "R[write to console]: Loading required package: BiocGenerics\n",
      "\n",
      "R[write to console]: Loading required package: parallel\n",
      "\n",
      "R[write to console]: \n",
      "Attaching package: ‘BiocGenerics’\n",
      "\n",
      "\n",
      "R[write to console]: The following objects are masked from ‘package:parallel’:\n",
      "\n",
      "    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,\n",
      "    clusterExport, clusterMap, parApply, parCapply, parLapply,\n",
      "    parLapplyLB, parRapply, parSapply, parSapplyLB\n",
      "\n",
      "\n",
      "R[write to console]: The following objects are masked from ‘package:stats’:\n",
      "\n",
      "    IQR, mad, sd, var, xtabs\n",
      "\n",
      "\n",
      "R[write to console]: The following objects are masked from ‘package:base’:\n",
      "\n",
      "    anyDuplicated, append, as.data.frame, basename, cbind, colnames,\n",
      "    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,\n",
      "    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,\n",
      "    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,\n",
      "    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,\n",
      "    union, unique, unsplit, which, which.max, which.min\n",
      "\n",
      "\n",
      "R[write to console]: \n",
      "Attaching package: ‘S4Vectors’\n",
      "\n",
      "\n",
      "R[write to console]: The following object is masked from ‘package:base’:\n",
      "\n",
      "    expand.grid\n",
      "\n",
      "\n",
      "R[write to console]: Loading required package: IRanges\n",
      "\n",
      "R[write to console]: Loading required package: GenomicRanges\n",
      "\n",
      "R[write to console]: Loading required package: GenomeInfoDb\n",
      "\n",
      "R[write to console]: Loading required package: SummarizedExperiment\n",
      "\n",
      "R[write to console]: Loading required package: Biobase\n",
      "\n",
      "R[write to console]: Welcome to Bioconductor\n",
      "\n",
      "    Vignettes contain introductory material; view with\n",
      "    'browseVignettes()'. To cite Bioconductor, see\n",
      "    'citation(\"Biobase\")', and for packages 'citation(\"pkgname\")'.\n",
      "\n",
      "\n",
      "R[write to console]: Loading required package: DelayedArray\n",
      "\n",
      "R[write to console]: Loading required package: matrixStats\n",
      "\n",
      "R[write to console]: \n",
      "Attaching package: ‘matrixStats’\n",
      "\n",
      "\n",
      "R[write to console]: The following objects are masked from ‘package:Biobase’:\n",
      "\n",
      "    anyMissing, rowMedians\n",
      "\n",
      "\n",
      "R[write to console]: Loading required package: BiocParallel\n",
      "\n",
      "R[write to console]: \n",
      "Attaching package: ‘DelayedArray’\n",
      "\n",
      "\n",
      "R[write to console]: The following objects are masked from ‘package:matrixStats’:\n",
      "\n",
      "    colMaxs, colMins, colRanges, rowMaxs, rowMins, rowRanges\n",
      "\n",
      "\n",
      "R[write to console]: The following objects are masked from ‘package:base’:\n",
      "\n",
      "    aperm, apply, rowsum\n",
      "\n",
      "\n",
      "R[write to console]: converting counts to integer mode\n",
      "\n"
     ]
    }
   ],
   "source": [
    "%%R\n",
    "library(DESeq2)\n",
    "colData <- data.frame(cond=colnames(m), row.names=colnames(m))\n",
    "dds <- DESeqDataSetFromMatrix(countData = m, colData=colData, design = ~ cond)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-05-20T16:43:52.052339Z",
     "start_time": "2023-05-20T16:43:51.814855Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     A2508       A375       A549      BxPC3      C42Bu    Colo320      H1299 \n",
      " 1.0888061  1.2424944  1.0869263  1.0162428  1.0632169  1.6634946  1.0384271 \n",
      "      H23u      H358u      HCC44     HCT116  HEK293T.1 HEK293T.16 HEK293T.26 \n",
      " 1.2745386  0.9586256  1.4011483  0.7453279  0.8418885  1.0259433  0.7463888 \n",
      " HEK293T.9      HEPG2     HS707A       K562      LNCaP     LS174T       MCF7 \n",
      " 0.8957911  1.1909768  0.9530245  0.9804775  0.8729802  1.6712495  1.5413835 \n",
      "    MDA231     MDA453      PACA2      PANC1        PC3     SW480u     SW620u \n",
      " 1.0963836  1.4634479  1.0580141  1.0480069  0.8270327  1.0059966  1.1430368 \n",
      "     ZR751 \n",
      " 1.0876778 \n"
     ]
    }
   ],
   "source": [
    "%%R\n",
    "dds <- estimateSizeFactors(dds)\n",
    "sf <- sizeFactors(dds)\n",
    "ncu <- counts(dds, normalized=TRUE)\n",
    "write.table(m, file=\"miRNA_counts.txt\", sep=\"\\t\", quote=FALSE, col.names=NA )\n",
    "write.table(ncu, file=\"miRNA_norm-counts.txt\", sep=\"\\t\", quote=FALSE, col.names=NA )\n",
    "sf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}