-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmstodcm.sh
1636 lines (1556 loc) · 59.4 KB
/
rmstodcm.sh
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
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#
# Usage: ./rmstodcm.sh folder/filename.svs [outdir]
infile="$1"
outdir="$2"
#JAVATMPDIRARG="-Djava.io.tmpdir=/Volumes/Elements5TBNonEncD/tmp"
TMPJSONFILE="/tmp/`basename $0`.$$"
#CSVFILENAMEFORSAMPLE="CCDI_Submission_Template_v1.0.1_DM_Sample.csv"
CSVFILENAMEFORSAMPLE="CCDI_Submission_Template_v1.0.1_DM_v2_Sample_embeddedNLfixed.csv"
if [ ! -f "${CSVFILENAMEFORSAMPLE}" ]
then
echo 1>&2 "Error: no sample to patient mapping metadata CSV file called ${CSVFILENAMEFORSAMPLE}"
exit 1
fi
CSVFILENAMEFORIMAGING="CCDI_Submission_Template_v1.0.1_DM_v2_Imaging.csv"
if [ ! -f "${CSVFILENAMEFORIMAGING}" ]
then
echo 1>&2 "Error: no sample to patient mapping metadata CSV file called ${CSVFILENAMEFORIMAGING}"
exit 1
fi
#CSVFILENAMEFORPARTICIPANT="CCDI_Submission_Template_v1.0.1_DM_Participant.csv"
CSVFILENAMEFORPARTICIPANT="CCDI_Submission_Template_v1.0.1_DM_v2_Participant.csv"
if [ ! -f "${CSVFILENAMEFORPARTICIPANT}" ]
then
echo 1>&2 "Error: no participant metadata CSV file called ${CSVFILENAMEFORPARTICIPANT}"
exit 1
fi
#CSVFILENAMEFORDIAGNOSIS="CCDI_Submission_Template_v1.0.1_DM_Diagnosis.csv"
CSVFILENAMEFORDIAGNOSIS="CCDI_Submission_Template_v1.0.1_DM_v2_Diagnosis.csv"
if [ ! -f "${CSVFILENAMEFORDIAGNOSIS}" ]
then
echo 1>&2 "Error: no diagnosis metadata CSV file called ${CSVFILENAMEFORDIAGNOSIS}"
exit 1
fi
# these persist across invocations ...
FILEMAPPINGSPECIMENIDTOUID="RMSspecimenIDToUIDMap.csv"
FILEMAPPINGSTUDYIDTOUID="RMSstudyIDToUIDMap.csv"
FILEMAPPINGSTUDYIDTODATETIME="RMSstudyIDToDateTimeMap.csv"
#JHOVE="${HOME}/work/jhove/jhove"
#PIXELMEDDIR="${HOME}/work/pixelmed/imgbook"
PIXELMEDDIR="${HOME}"
#PATHTOADDITIONAL="${PIXELMEDDIR}/lib/additional"
PATHTOADDITIONAL="${HOME}"
# "source-data-rms/PARPDV-0BLRWU_A2-Q30.svs"
# "source-data-rms/PARPDV-0BLRWU_A2_RAW.tif"
# "source-data-rms/PANJXS-0BMX7D_A2.tif"
# "source-data-rms/PAMHCR-0BH98H.tif"
filename=`basename "${infile}" '.svs'`
filename=`basename "${filename}" '.tif'`
foldername=`dirname "${infile}"`
slide_id=`echo ${filename} | sed -e 's/^\([A-Z0-9]*-[A-Z0-9]*_[A-Z0-9]*\).*$/\1/'`
compressedvariant=`echo ${filename} | egrep '(RAW|Q[0-9]*)' | sed -e 's/^.*\([RQ][A0-9][W0]\)$/\1/'`
if [ -z "${compressedvariant}" ]
then
compressedvariant="RAW"
fi
if [ -z "${outdir}" ]
then
# note: variation between '_' and '-' use will be harmonized to '_' ...
outdir="Converted/${slide_id}_${compressedvariant}"
fi
sample_id=`echo ${slide_id} | sed -e 's/^\([A-Z]*\)-.*$/\1/'`
specimen_id=`echo ${slide_id} | sed -e 's/^\([A-Z]*-[A-Z0-9]*\).*$/\1/'`
# block_id may be absent
block_id=`echo ${slide_id} | egrep '_[A-Z0-9][A-Z0-9]*' | sed -e 's/^[A-Z]*-[A-Z0-9]*_\([A-Z0-9]*\).*$/\1/'`
echo "infile = ${infile}"
echo "filename = ${filename}"
echo "slide_id = ${slide_id}"
echo "sample_id = ${sample_id}"
echo "specimen_id = ${specimen_id}"
echo "block_id = ${block_id}"
anatomycodevalue=""
anatomycsd=""
anatomycodemeaning=""
lateralitycodevalue=""
lateralitycsd=""
lateralitycodemeaning=""
anatomymodifiercodevalue=""
anatomymodifiercsd=""
anatomymodifiercodemeaning=""
if [ -f "${CSVFILENAMEFORSAMPLE}" ]
then
# type,study.phs_accession,participant.participant_id,sample_id,sample_type,sample_anatomic_site,participant_age_at_collection,tumor_grade,tumor_stage_clinical_t,tumor_stage_clinical_n,tumor_stage_clinical_m,tumor_morphology,tumor_incidence_type,sample_description,sample_tumor_status
# ,,RMS2277,PARPDV,Tumor,"Soft tissue, pelvis-left",4.33,,,,,,,,Tumor
csvlineforsample=`grep ",${sample_id}," "${CSVFILENAMEFORSAMPLE}" | head -1`
echo "csvlineforsample = ${csvlineforsample}"
fi
if [ -z "${csvlineforsample}" ]
then
echo 1>&2 "Warning: cannot find metadata CSV file entry for sample_id ${sample_id} from which to extract patient_id and anatomy - using sample_id as patient_id"
patient_id="${sample_id}"
else
patient_id=`echo "${csvlineforsample}" | awk -F, '{print $3}'`
# due to quoting of earlier column entries +/- quoting of body site column entries, using following two numeric values as signal as to which is body site column
# type,study.phs_accession,participant.participant_id,sample_id,sample_type,sample_anatomic_site,participant_age_at_collection,Histological_Classification,tumor_grade,tumor_stage_clinical_t,tumor_stage_clinical_n,tumor_stage_clinical_m,tumor_morphology,tumor_incidence_type,sample_description,sample_tumor_status
# ,,RMS2277,PARPDV,Tumor,"Soft tissue, pelvis-left",4.33,,,,,,,,Tumor
# ,,RMS2520,PAWWNV,Tumor,Pelvis,8.44,EMBRYONAL RHABDOMYOSARCOMA,,,,,,,,Tumor
# ,,RMS2521,PAWXFU,Tumor,"Soft tissue, shoulder-left",0.28,EMBRYONAL RHABDOMYOSARCOMA,,,,,,,,Tumor
# ,,RMS2266,PAKPED,Tumor,Breast-right,14.49,ALVEOLAR RHABDOMYOSARCOMA,,,,,,,,Tumor
anatomyentry=`echo "${csvlineforsample}" | sed -e 's/^.*,Tumor,"\([^"]*\)".*$/\1/'`
if [ "${anatomyentry}" = "${csvlineforsample}" ]
then
anatomyentry=`echo "${csvlineforsample}" | sed -e 's/^.*,Tumor,\([^,]*\).*$/\1/'`
fi
if [ "${anatomyentry}" = "${csvlineforsample}" ]
then
# didn't work
anatomyentry=""
fi
echo "original anatomyentry = ${anatomyentry}"
if [ ! -z "${anatomyentry}" ]
then
anatomyentry=`echo "${anatomyentry}" | tr 'A-Z' 'a-z' | sed -e 's/[^a-z]/ /g' | sed -e 's/[ ][ ]*/ /g'`
echo "normalized anatomyentry = ${anatomyentry}"
isleft=`echo "${anatomyentry}" | fgrep 'left'`
if [ -z "${isleft}" ]
then
isright=`echo "${anatomyentry}" | fgrep 'right'`
if [ ! -z "${isright}" ]
then
lateralitycodevalue="24028007"
lateralitycsd="SCT"
lateralitycodemeaning="Right"
anatomyentry=`echo "${anatomyentry}" | sed -e 's/[ ]*right//'`
fi
else
lateralitycodevalue="7771000"
lateralitycsd="SCT"
lateralitycodemeaning="Left"
anatomyentry=`echo "${anatomyentry}" | sed -e 's/[ ]*left//'`
fi
echo "without laterality anatomyentry = ${anatomyentry}"
issofttissue=`echo "${anatomyentry}" | fgrep 'soft tissue'`
if [ ! -z "${issofttissue}" ]
then
# may get overridden if later "distal" or similar, since only tracking one non-laterality modifier, but good enough for now :(
anatomymodifiercodevalue="87784001"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Soft tissue"
anatomyentry=`echo "${anatomyentry}" | sed -e 's/[ ]*soft tissue[ ]*//'`
fi
echo "without soft tissue anatomyentry = ${anatomyentry}"
anatomyentry=`echo "${anatomyentry}" | sed -e 's/[ ][ ]*/ /g' | sed -e 's/^[ ]*//g' | sed -e 's/[ ]*$//g'`
echo "final spaces cleaned anatomyentry = ${anatomyentry}"
if [ "${anatomyentry}" = "abdomen" ]
then
anatomycodevalue="818981001"
anatomycsd="SCT"
anatomycodemeaning="Abdomen"
elif [ "${anatomyentry}" = "abdomen pelvis" ]
then
anatomycodevalue="818982008"
anatomycsd="SCT"
anatomycodemeaning="Abdomen and pelvis"
elif [ "${anatomyentry}" = "abdomen bladder" ]
then
anatomycodevalue="89837001"
anatomycsd="SCT"
anatomycodemeaning="Bladder"
elif [ "${anatomyentry}" = "abdominal wall" ]
then
# need to add to DICOM subset (currently only muscle) :(
anatomycodevalue="822992007"
anatomycsd="SCT"
anatomycodemeaning="Abdominal wall"
elif [ "${anatomyentry}" = "arm" ]
then
# "arm" unqualified is ambiguous - assume excludes forearm :(
anatomycodevalue="40983000"
anatomycsd="SCT"
anatomycodemeaning="Upper arm"
elif [ "${anatomyentry}" = "arm axillary" ]
then
anatomycodevalue="91470000"
anatomycsd="SCT"
anatomycodemeaning="Axilla"
elif [ "${anatomyentry}" = "armpit" ]
then
anatomycodevalue="91470000"
anatomycsd="SCT"
anatomycodemeaning="Axilla"
elif [ "${anatomyentry}" = "back" ]
then
anatomycodevalue="77568009"
anatomycsd="SCT"
anatomycodemeaning="Back"
elif [ "${anatomyentry}" = "bile duct bilary tract" ]
then
anatomycodevalue="34707002"
anatomycsd="SCT"
anatomycodemeaning="Bilary tract"
elif [ "${anatomyentry}" = "bladder" ]
then
anatomycodevalue="89837001"
anatomycsd="SCT"
anatomycodemeaning="Bladder"
elif [ "${anatomyentry}" = "bone femur distal" ]
then
anatomycodevalue="71341001"
anatomycsd="SCT"
anatomycodemeaning="Femur"
anatomymodifiercodevalue="46053002"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Distal"
elif [ "${anatomyentry}" = "bone mandible" ]
then
anatomycodevalue="91609006"
anatomycsd="SCT"
anatomycodemeaning="Mandible"
elif [ "${anatomyentry}" = "bone mandible pterygoid muscle" ]
then
# not in DICOM subset :(
anatomycodevalue="76738006"
anatomycsd="SCT"
anatomycodemeaning="Pterygoid muscle"
elif [ "${anatomyentry}" = "bone maxilla sinus" ]
then
# ?? not sure what to make of "bone" in context of "sinus" :(
anatomycodevalue="15924003"
anatomycsd="SCT"
anatomycodemeaning="Maxillary sinus"
elif [ "${anatomyentry}" = "bone marrow" ]
then
anatomycodevalue="14016003"
anatomycsd="SCT"
anatomycodemeaning="Bone marrow"
elif [ "${anatomyentry}" = "bone maxilla" ]
then
anatomycodevalue="70925003"
anatomycsd="SCT"
anatomycodemeaning="Maxilla"
elif [ "${anatomyentry}" = "bone temporal" ]
then
anatomycodevalue="60911003"
anatomycsd="SCT"
anatomycodemeaning="Temporal bone"
elif [ "${anatomyentry}" = "bone temporal infra" ]
then
# ?? assume infratemporal fossa, despite the word bone :(
# not in DICOM subset :(
anatomycodevalue="69541002"
anatomycsd="SCT"
anatomycodemeaning="Infratemporal fossa"
elif [ "${anatomyentry}" = "bone temporal infratemporal fossa" ]
then
# not in DICOM subset :(
anatomycodevalue="69541002"
anatomycsd="SCT"
anatomycodemeaning="Infratemporal fossa"
elif [ "${anatomyentry}" = "bone temporal infra infratemporal fossa" ]
then
# not in DICOM subset :(
anatomycodevalue="69541002"
anatomycsd="SCT"
anatomycodemeaning="Infratemporal fossa"
elif [ "${anatomyentry}" = "bone tibia" ]
then
anatomycodevalue="12611008"
anatomycsd="SCT"
anatomycodemeaning="Tibia"
elif [ "${anatomyentry}" = "brain" ]
then
anatomycodevalue="12738006"
anatomycsd="SCT"
anatomycodemeaning="Brain"
elif [ "${anatomyentry}" = "breast" ]
then
anatomycodevalue="76752008"
anatomycsd="SCT"
anatomycodemeaning="Breast"
elif [ "${anatomyentry}" = "buttock" ]
then
anatomycodevalue="46862004"
anatomycsd="SCT"
anatomycodemeaning="Buttock"
elif [ "${anatomyentry}" = "calf" ]
then
anatomycodevalue="53840002"
anatomycsd="SCT"
anatomycodemeaning="Calf"
elif [ "${anatomyentry}" = "cervix" ]
then
anatomycodevalue="71252005"
anatomycsd="SCT"
anatomycodemeaning="Cervix"
elif [ "${anatomyentry}" = "cheek" ]
then
anatomycodevalue="60819002"
anatomycsd="SCT"
anatomycodemeaning="Cheek"
elif [ "${anatomyentry}" = "chin" ]
then
anatomycodevalue="30291003"
anatomycsd="SCT"
anatomycodemeaning="Chin"
elif [ "${anatomyentry}" = "chest" ]
then
anatomycodevalue="43799004"
anatomycsd="SCT"
anatomycodemeaning="Chest"
elif [ "${anatomyentry}" = "chest anterior" ]
then
anatomycodevalue="43799004"
anatomycsd="SCT"
anatomycodemeaning="Chest"
anatomymodifiercodevalue="255549009"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Anterior"
elif [ "${anatomyentry}" = "ear" ]
then
anatomycodevalue="117590005"
anatomycsd="SCT"
anatomycodemeaning="Ear"
elif [ "${anatomyentry}" = "ear ear canal" ]
then
anatomycodevalue="84301002"
anatomycsd="SCT"
anatomycodemeaning="External auditory canal"
elif [ "${anatomyentry}" = "ear periauricular" ]
then
# not in DICOM subset :(
anatomycodevalue="113327001"
anatomycsd="SCT"
anatomycodemeaning="Pinna"
# not in DICOM subset :(
anatomymodifiercodevalue="272447003"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Peri-location"
elif [ "${anatomyentry}" = "ear middle ear" ]
then
anatomycodevalue="25342003"
anatomycsd="SCT"
anatomycodemeaning="Middle ear"
elif [ "${anatomyentry}" = "elbow" ]
then
# not sure if this really is specific to the joint :(
anatomycodevalue="16953009"
anatomycsd="SCT"
anatomycodemeaning="Elbow joint"
elif [ "${anatomyentry}" = "epididymis" ]
then
anatomycodevalue="87644002"
anatomycsd="SCT"
anatomycodemeaning="Epididymis"
elif [ "${anatomyentry}" = "eye" ]
then
anatomycodevalue="81745001"
anatomycsd="SCT"
anatomycodemeaning="Eye"
elif [ "${anatomyentry}" = "eye orbit" ]
then
anatomycodevalue="363654007"
anatomycsd="SCT"
anatomycodemeaning="Orbit"
elif [ "${anatomyentry}" = "eye orbit anterior" ]
then
anatomycodevalue="363654007"
anatomycsd="SCT"
anatomycodemeaning="Orbit"
anatomymodifiercodevalue="255549009"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Anterior"
elif [ "${anatomyentry}" = "eye orbit medial" ]
then
anatomycodevalue="363654007"
anatomycsd="SCT"
anatomycodemeaning="Orbit"
anatomymodifiercodevalue="255561001"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Medial"
elif [ "${anatomyentry}" = "eyelid" ]
then
anatomycodevalue="80243003"
anatomycsd="SCT"
anatomycodemeaning="Eyelid"
elif [ "${anatomyentry}" = "face head" ]
then
anatomycodevalue="69536005"
anatomycsd="SCT"
anatomycodemeaning="Head"
elif [ "${anatomyentry}" = "face head parapharyngeal pterygoid" ]
then
# not in DICOM subset :(
anatomycodevalue="84765007"
anatomycsd="SCT"
anatomycodemeaning="Pterygoid region"
elif [ "${anatomyentry}" = "foot" ]
then
anatomycodevalue="56459004"
anatomycsd="SCT"
anatomycodemeaning="Foot"
elif [ "${anatomyentry}" = "forearm" ]
then
anatomycodevalue="14975008"
anatomycsd="SCT"
anatomycodemeaning="Forearm"
elif [ "${anatomyentry}" = "groin" ]
then
anatomycodevalue="26893007"
anatomycsd="SCT"
anatomycodemeaning="Inguinal region"
elif [ "${anatomyentry}" = "groin mass" ]
then
anatomycodevalue="26893007"
anatomycsd="SCT"
anatomycodemeaning="Inguinal region"
elif [ "${anatomyentry}" = "hand" ]
then
anatomycodevalue="85562004"
anatomycsd="SCT"
anatomycodemeaning="Hand"
elif [ "${anatomyentry}" = "infratemporal" ]
then
# assume infratemporal fossa :(
# not in DICOM subset :(
anatomycodevalue="69541002"
anatomycsd="SCT"
anatomycodemeaning="Infratemporal fossa"
elif [ "${anatomyentry}" = "inguinal" ]
then
anatomycodevalue="26893007"
anatomycsd="SCT"
anatomycodemeaning="Inguinal region"
elif [ "${anatomyentry}" = "kidney" ]
then
anatomycodevalue="64033007"
anatomycsd="SCT"
anatomycodemeaning="Kidney"
elif [ "${anatomyentry}" = "l testicle mass" ]
then
anatomycodevalue="40689003"
anatomycsd="SCT"
anatomycodemeaning="Testis"
lateralitycodevalue="7771000"
lateralitycsd="SCT"
lateralitycodemeaning="Left"
elif [ "${anatomyentry}" = "leg" ]
then
# ambiguous -assume lower :(
anatomycodevalue="30021000"
anatomycsd="SCT"
anatomycodemeaning="Lower leg"
elif [ "${anatomyentry}" = "liver" ]
then
anatomycodevalue="10200004"
anatomycsd="SCT"
anatomycodemeaning="Liver"
elif [ "${anatomyentry}" = "lung" ]
then
anatomycodevalue="39607008"
anatomycsd="SCT"
anatomycodemeaning="Lung"
elif [ "${anatomyentry}" = "lymph node" ]
then
anatomycodevalue="59441001"
anatomycsd="SCT"
anatomycodemeaning="Lymph node"
elif [ "${anatomyentry}" = "lymph node metastatic site" ]
then
# ignore the "metastatic site" :(
anatomycodevalue="59441001"
anatomycsd="SCT"
anatomycodemeaning="Lymph node"
elif [ "${anatomyentry}" = "mandible" ]
then
anatomycodevalue="91609006"
anatomycsd="SCT"
anatomycodemeaning="Mandible"
elif [ "${anatomyentry}" = "maxillary sinus" ]
then
anatomycodevalue="15924003"
anatomycsd="SCT"
anatomycodemeaning="Maxillary sinus"
elif [ "${anatomyentry}" = "mediastinum" ]
then
anatomycodevalue="72410000"
anatomycsd="SCT"
anatomycodemeaning="Mediastinum"
elif [ "${anatomyentry}" = "mouth" ]
then
anatomycodevalue="123851003"
anatomycsd="SCT"
anatomycodemeaning="Mouth"
elif [ "${anatomyentry}" = "muscle back" ]
then
# just assume back for now, without muscle qualifier :(
anatomycodevalue="77568009"
anatomycsd="SCT"
anatomycodemeaning="Back"
elif [ "${anatomyentry}" = "nasal" ]
then
anatomycodevalue="45206002"
anatomycsd="SCT"
anatomycodemeaning="Nose"
elif [ "${anatomyentry}" = "nasal cavity" ]
then
anatomycodevalue="279549004"
anatomycsd="SCT"
anatomycodemeaning="Nasal cavity"
elif [ "${anatomyentry}" = "nasal cavity supra" ]
then
# ignore supra for now :(
anatomycodevalue="279549004"
anatomycsd="SCT"
anatomycodemeaning="Nasal cavity"
elif [ "${anatomyentry}" = "nasal mass" ]
then
anatomycodevalue="45206002"
anatomycsd="SCT"
anatomycodemeaning="Nose"
elif [ "${anatomyentry}" = "nasopharyngeal" ]
then
anatomycodevalue="360955006"
anatomycsd="SCT"
anatomycodemeaning="Nasopharynx"
elif [ "${anatomyentry}" = "nasopharynx" ]
then
anatomycodevalue="360955006"
anatomycsd="SCT"
anatomycodemeaning="Nasopharynx"
elif [ "${anatomyentry}" = "nasopharynx nose" ]
then
# ?? is this actually the nose proper and not the nasopharynx :(
anatomycodevalue="360955006"
anatomycsd="SCT"
anatomycodemeaning="Nasopharynx"
elif [ "${anatomyentry}" = "neck" ]
then
anatomycodevalue="45048000"
anatomycsd="SCT"
anatomycodemeaning="Neck"
elif [ "${anatomyentry}" = "neck posterior" ]
then
anatomycodevalue="45048000"
anatomycsd="SCT"
anatomycodemeaning="Neck"
anatomymodifiercodevalue="255551008"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Posterior"
elif [ "${anatomyentry}" = "nose" ]
then
anatomycodevalue="45206002"
anatomycsd="SCT"
anatomycodemeaning="Nose"
elif [ "${anatomyentry}" = "nose nasal cavity" ]
then
anatomycodevalue="279549004"
anatomycsd="SCT"
anatomycodemeaning="Nasal cavity"
elif [ "${anatomyentry}" = "oral dorsal soft palate" ]
then
anatomycodevalue="49460000"
anatomycsd="SCT"
anatomycodemeaning="Soft palate"
# dorsal is not in DICOM subset yet :(
anatomymodifiercodevalue="255554000"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Dorsal"
elif [ "${anatomyentry}" = "orbit" ]
then
anatomycodevalue="363654007"
anatomycsd="SCT"
anatomycodemeaning="Orbit"
elif [ "${anatomyentry}" = "orbital" ]
then
anatomycodevalue="363654007"
anatomycsd="SCT"
anatomycodemeaning="Orbit"
elif [ "${anatomyentry}" = "orbit anterior" ]
then
anatomycodevalue="363654007"
anatomycsd="SCT"
anatomycodemeaning="Orbit"
anatomymodifiercodevalue="255549009"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Anterior"
elif [ "${anatomyentry}" = "orbit posterior" ]
then
anatomycodevalue="363654007"
anatomycsd="SCT"
anatomycodemeaning="Orbit"
anatomymodifiercodevalue="255551008"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Posterior"
elif [ "${anatomyentry}" = "oropharynx" ]
then
anatomycodevalue="31389004"
anatomycsd="SCT"
anatomycodemeaning="Oropharynx"
elif [ "${anatomyentry}" = "parapharyngeal" ]
then
anatomycodevalue="54066008"
anatomycsd="SCT"
anatomycodemeaning="Pharynx"
anatomymodifiercodevalue="272444005"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Para-location"
elif [ "${anatomyentry}" = "paraspinal posterior" ]
then
# 261148001 | Paraspinal (qualifier value) - not actually antomy
anatomycodevalue="261148001"
anatomycsd="SCT"
anatomycodemeaning="Paraspinal"
anatomymodifiercodevalue="255551008"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Posterior"
elif [ "${anatomyentry}" = "paratesticular" ]
then
anatomycodevalue="40689003"
anatomycsd="SCT"
anatomycodemeaning="Testis"
anatomymodifiercodevalue="272444005"
# not in DICOM subset :(
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Para-location"
elif [ "${anatomyentry}" = "paratestes" ]
then
anatomycodevalue="40689003"
anatomycsd="SCT"
anatomycodemeaning="Testis"
# not in DICOM subset :(
anatomymodifiercodevalue="272444005"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Para-location"
elif [ "${anatomyentry}" = "parotid gland" ]
then
anatomycodevalue="45289007"
anatomycsd="SCT"
anatomycodemeaning="Parotid gland"
elif [ "${anatomyentry}" = "pelvis" ]
then
anatomycodevalue="816092008"
anatomycsd="SCT"
anatomycodemeaning="Pelvis"
elif [ "${anatomyentry}" = "pelvis prostate" ]
then
anatomycodevalue="41216001"
anatomycsd="SCT"
anatomycodemeaning="Prostate"
elif [ "${anatomyentry}" = "peri rectal mass" ]
then
# Perirectal region is not in DICOM subset yet :(
anatomycodevalue="13170006"
anatomycsd="SCT"
anatomycodemeaning="Perirectal region"
elif [ "${anatomyentry}" = "perianal" ]
then
# Perianal region is not in DICOM subset yet :(
anatomycodevalue="397158004"
anatomycsd="SCT"
anatomycodemeaning="Perianal region"
elif [ "${anatomyentry}" = "perineum" ]
then
anatomycodevalue="38864007"
anatomycsd="SCT"
anatomycodemeaning="Perineum"
elif [ "${anatomyentry}" = "peritoneum" ]
then
anatomycodevalue="15425007"
anatomycsd="SCT"
anatomycodemeaning="Peritoneum"
elif [ "${anatomyentry}" = "pharynx" ]
then
anatomycodevalue="54066008"
anatomycsd="SCT"
anatomycodemeaning="Pharynx"
elif [ "${anatomyentry}" = "pharynx para" ]
then
anatomycodevalue="54066008"
anatomycsd="SCT"
anatomycodemeaning="Pharynx"
anatomymodifiercodevalue="272444005"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Para-location"
elif [ "${anatomyentry}" = "pharynx parapharyngeal" ]
then
anatomycodevalue="54066008"
anatomycsd="SCT"
anatomycodemeaning="Pharynx"
anatomymodifiercodevalue="272444005"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Para-location"
elif [ "${anatomyentry}" = "prostate" ]
then
anatomycodevalue="41216001"
anatomycsd="SCT"
anatomycodemeaning="Prostate"
elif [ "${anatomyentry}" = "prostate peri" ]
then
# Periprostatic tissue is not in DICOM subset yet :( There is no "region" in SCT
anatomycodevalue="37446007"
anatomycsd="SCT"
anatomycodemeaning="Periprostatic tissue"
elif [ "${anatomyentry}" = "retroperitoneal" ]
then
anatomycodevalue="82849001"
anatomycsd="SCT"
anatomycodemeaning="Retroperitoneum"
elif [ "${anatomyentry}" = "retroperitoneum" ]
then
anatomycodevalue="82849001"
anatomycsd="SCT"
anatomycodemeaning="Retroperitoneum"
elif [ "${anatomyentry}" = "retropharynx" ]
then
# not in DICOM subset :(
anatomycodevalue="789564000"
anatomycsd="SCT"
anatomycodemeaning="Retropharyngeal space"
elif [ "${anatomyentry}" = "scalp" ]
then
anatomycodevalue="41695006"
anatomycsd="SCT"
anatomycodemeaning="Scalp"
elif [ "${anatomyentry}" = "scrotal" ]
then
anatomycodevalue="20233005"
anatomycsd="SCT"
anatomycodemeaning="Scrotum"
elif [ "${anatomyentry}" = "scrotum" ]
then
anatomycodevalue="20233005"
anatomycsd="SCT"
anatomycodemeaning="Scrotum"
elif [ "${anatomyentry}" = "shoulder" ]
then
anatomycodevalue="16982005"
anatomycsd="SCT"
anatomycodemeaning="Shoulder"
elif [ "${anatomyentry}" = "skin buttock" ]
then
anatomycodevalue="22180002"
anatomycsd="SCT"
anatomycodemeaning="Skin of buttock"
elif [ "${anatomyentry}" = "skull base" ]
then
# Base of skull is not in DICOM subset yet :(
anatomycodevalue="31467002"
anatomycsd="SCT"
anatomycodemeaning="Base of skull"
elif [ "${anatomyentry}" = "soft palate" ]
then
anatomycodevalue="49460000"
anatomycsd="SCT"
anatomycodemeaning="Soft palate"
elif [ "${anatomyentry}" = "spermatic cord" ]
then
# Spermatic cord is not in DICOM subset yet :(
anatomycodevalue="49957000"
anatomycsd="SCT"
anatomycodemeaning="Spermatic cord"
elif [ "${anatomyentry}" = "spinal cord" ]
then
anatomycodevalue="2748008"
anatomycsd="SCT"
anatomycodemeaning="Spinal cord"
elif [ "${anatomyentry}" = "spinal cord para" ]
then
# ?? "paraspinal" means around the bony spinal column :(
# cf. "paraspinal posterior" entry
anatomycodevalue="2748008"
anatomycsd="SCT"
anatomycodemeaning="Spinal cord"
anatomymodifiercodevalue="272444005"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Para-location"
elif [ "${anatomyentry}" = "spine" ]
then
anatomycodevalue="421060004"
anatomycsd="SCT"
anatomycodemeaning="Spine"
elif [ "${anatomyentry}" = "temple" ]
then
# not in DICOM subset :(
anatomycodevalue="450721000"
anatomycsd="SCT"
anatomycodemeaning="Temporal region"
elif [ "${anatomyentry}" = "testcle" ]
then
anatomycodevalue="40689003"
anatomycsd="SCT"
anatomycodemeaning="Testis"
elif [ "${anatomyentry}" = "testicle" ]
then
anatomycodevalue="40689003"
anatomycsd="SCT"
anatomycodemeaning="Testis"
elif [ "${anatomyentry}" = "testicle extratesticular" ]
then
anatomycodevalue="40689003"
anatomycsd="SCT"
anatomycodemeaning="Testis"
# not in DICOM subset :(
anatomymodifiercodevalue="272437001"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Extra-location"
elif [ "${anatomyentry}" = "testicle para" ]
then
anatomycodevalue="40689003"
anatomycsd="SCT"
anatomycodemeaning="Testis"
# not in DICOM subset :(
anatomymodifiercodevalue="272444005"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Para-location"
elif [ "${anatomyentry}" = "testis" ]
then
anatomycodevalue="40689003"
anatomycsd="SCT"
anatomycodemeaning="Testis"
elif [ "${anatomyentry}" = "thigh" ]
then
anatomycodevalue="68367000"
anatomycsd="SCT"
anatomycodemeaning="Thigh"
elif [ "${anatomyentry}" = "thigh mass" ]
then
anatomycodevalue="68367000"
anatomycsd="SCT"
anatomycodemeaning="Thigh"
elif [ "${anatomyentry}" = "thigh posterior" ]
then
anatomycodevalue="68367000"
anatomycsd="SCT"
anatomycodemeaning="Thigh"
anatomymodifiercodevalue="255551008"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Posterior"
elif [ "${anatomyentry}" = "thigh upper" ]
then
anatomycodevalue="68367000"
anatomycsd="SCT"
anatomycodemeaning="Thigh"
# Upper is not in DICOM subset yet :(
anatomymodifiercodevalue="261183002"
anatomymodifiercsd="SCT"
anatomymodifiercodemeaning="Upper"
elif [ "${anatomyentry}" = "tonsil" ]
then
anatomycodevalue="17861009"
anatomycsd="SCT"
anatomycodemeaning="Oropharyngeal tonsil"
elif [ "${anatomyentry}" = "uterus" ]
then
anatomycodevalue="35039007"
anatomycsd="SCT"
anatomycodemeaning="Uterus"
elif [ "${anatomyentry}" = "uvula" ]
then
anatomycodevalue="26140008"
anatomycsd="SCT"
anatomycodemeaning="Uvula"
elif [ "${anatomyentry}" = "vagina" ]
then
anatomycodevalue="76784001"
anatomycsd="SCT"
anatomycodemeaning="Vagina"
elif [ "${anatomyentry}" = "vulva" ]
then
anatomycodevalue="45292006"
anatomycsd="SCT"
anatomycodemeaning="Vulva"
elif [ "${anatomyentry}" = "wrist" ]
then
# not sure if this really is specific to the joint :(
anatomycodevalue="74670003"
anatomycsd="SCT"
anatomycodemeaning="Wrist joint"
else
echo 1>&2 "Warning: unrecognized body site \"${anatomyentry}\" for sample_id ${sample_id}"
fi
fi
fi
echo "patient_id = ${patient_id}"
echo "anatomycodemeaning = ${anatomycodemeaning}"
echo "lateralitycodemeaning = ${lateralitycodemeaning}"
echo "anatomymodifiercodemeaning = ${anatomymodifiercodemeaning}"
if [ -f "${CSVFILENAMEFORPARTICIPANT}" ]
then
# type,study.phs_accession,participant_id,race,gender,ethnicity
# ,,RMS2277,White,Male,Not Hispanic or Latino
csvlineforparticipant=`grep ",${patient_id}," "${CSVFILENAMEFORPARTICIPANT}" | head -1`
echo "csvlineforparticipant = ${csvlineforparticipant}"
fi
if [ -z "${csvlineforparticipant}" ]
then
echo 1>&2 "Warning: cannot find participant metadata CSV file entry for patient_id ${patient_id} from which to extract patient characteristics"
else
race=`echo "${csvlineforparticipant}" | awk -F, '{print $4}'`
gender=`echo "${csvlineforparticipant}" | awk -F, '{print $5}'`
#ethnicity=`echo "${csvlineforparticipant}" | awk -F, '{print $6}'`
fi
if [ -f "${CSVFILENAMEFORDIAGNOSIS}" ]
then
# type,participant.participant_id,diagnosis_id,disease_type,primary_diagnosis,primary_diagnosis_reference_source,primary_site,age_at_diagnosis,days_to_recurrence,last_known_disease_status,days_to_last_known_disease_status,tissue_or_organ_of_origin,days_to_last_followup,progression_or_recurrence,site_of_resection_or_biopsy
# ,RMS2277,,"Soft Tissue Tumors and Sarcomas, NOS","Rhabdomyosarcoma (RMS), embryonal",,"Pelvis, site indeterminate",4.33, ,No event,,,1555,,
csvlinefodiagnosis=`grep ",${patient_id}," "${CSVFILENAMEFORDIAGNOSIS}" | head -1`
echo "csvlinefodiagnosis = ${csvlinefodiagnosis}"
fi
if [ -z "${csvlinefodiagnosis}" ]
then
echo 1>&2 "Warning: cannot find diagnosis metadata CSV file entry for patient_id ${patient_id} from which to extract patient characteristics"
else
# some columns preceding age are sometimes quoted and sometimes not, so search for 1st numeric value (which may or mey not be floating point) after non-numeric string and before Metastatic or Non-metastatic
# diagnosis,RMS2448,,"Soft Tissue Tumors and Sarcomas, NOS",Rhabdomyosarcoma,,Scalp,6.94,Non-metastatic,1, ,No event,,,4186,,
# diagnosis,RMS2472,,"Soft Tissue Tumors and Sarcomas, NOS",Rhabdomyosarcoma,,"Pelvis, site indeterminate",6.87,Non-metastatic (unconfirmed),3, ,SMN,,,3247,,
age=`echo "${csvlinefodiagnosis}" | sed -e 's/^.*[a-z"],\([0-9.][0-9.]*\),[NM].*$/\1/'`
if [ "${age}" = "${csvlinefodiagnosis}" ]
then
# didn't work
age=""
fi
echo "age = ${age}"
# sometimes there is a conflict between differnt metadata files, e.g. :(
# csvlineforsample = RMS2502,PATHRZ,SPINDLE CELL RHABDOMYOSARCOMA,FN,Low,3099,3099,0,0,Intermediate,0.37386214
# csvlineforparticipant = ,,RMS2502,White,Male,Not Hispanic or Latino
# csvlinefodiagnosis = ,RMS2502,,"Soft Tissue Tumors and Sarcomas, NOS",Embryonal Rhabdomyosarcoma,,Nasopharynx (PM),5.07, ,No event,,,2715,,
# use the CSVFILENAMEFORDIAGNOSIS rather than the CSVFILENAMEFORSAMPLE file for now :(
# "Soft Tissue Tumors and Sarcomas, NOS" is always present in column preceding primary_diagnosis
diagnosis=`echo "${csvlinefodiagnosis}" | sed -e 's/^.*"Soft Tissue Tumors and Sarcomas, NOS","\([^"]*\)",.*$/\1/'`
if [ "${diagnosis}" = "${csvlinefodiagnosis}" ]
then
# was not quoted, so must not contain comma
diagnosis=`echo "${csvlinefodiagnosis}" | sed -e 's/^.*"Soft Tissue Tumors and Sarcomas, NOS",\([^,]*\),.*$/\1/'`
if [ "${diagnosis}" = "${csvlinefodiagnosis}" ]
then
# didn't work
diagnosis=""
fi
fi
echo "diagnosis = ${diagnosis}"
fi
#if [ -f "${CSVFILENAMEFORSPECIMENDETAILMANIFEST}" ]
#then
# USI,H&E Image on Hard Drive,SpecimenType,Protocols,Timepoint,BlockNo,SiteType,% Tumor vs. % Necrosis,% Tumor vs. %Stroma,Comments,,,,,,,,,,,,,
# PARPDV-0BLRWU,1,Paraffin Stained Primary H&E,D9902,Diagnosis,A2,"Soft tissue, pelvis-left",100,100,,,,,,,,,,,,,,
# NB. multiple entries in column may result in quotes around strings not normally quoted, so don't rely on position too much
# just in case there is more than one block for the same specimen ...
# if [ -z "${block_id}" ]
# then
# csvlineforspecimendetailmanifest=`grep "^${specimen_id}," "${CSVFILENAMEFORSPECIMENDETAILMANIFEST}" | head -1`
# else
# csvlineforspecimendetailmanifest=`grep "^${specimen_id}," "${CSVFILENAMEFORSPECIMENDETAILMANIFEST}" | grep ",${block_id}," | head -1`
# fi
# echo "csvlineforspecimendetailmanifest = ${csvlineforspecimendetailmanifest}"
#fi
fixation=""
staining=""
if [ -f "${CSVFILENAMEFORIMAGING}" ]
then
csvlineforimaging=`grep ",${sample_id}," "${CSVFILENAMEFORIMAGING}" | head -1`
echo "csvlineforimaging = ${csvlineforimaging}"
fi
if [ -z "${csvlineforimaging}" ]
then
echo 1>&2 "Warning: cannot find metadata CSV file entry for sample_id ${sample_id} from which to extract fixation and staining"
else
# ignore position in case quoted
isffpehe=`echo "${csvlineforimaging}" | fgrep 'FFPE_H&E_Image'`
if [ ! -z "${isffpehe}" ]
then
fixation="FFPE"
staining="HE"
fi