1
1
/** Elixir BioHackathon 2022 */
2
2
package com .elixir .biohackaton .ISAToSRA .biosamples .service ;
3
3
4
- import com .elixir .biohackaton .ISAToSRA .biosamples .model .Attribute ;
5
- import com .elixir .biohackaton .ISAToSRA .biosamples .model .BiosampleAccessionsMap ;
6
- import com .elixir .biohackaton .ISAToSRA .biosamples .model .Relationship ;
7
- import com .elixir .biohackaton .ISAToSRA .biosamples .model .BioSample ;
8
- import com .elixir .biohackaton .ISAToSRA .receipt .MarsReceiptException ;
9
- import com .elixir .biohackaton .ISAToSRA .receipt .ReceiptAccessionsMap ;
10
- import com .elixir .biohackaton .ISAToSRA .receipt .isamodel .*;
11
-
12
4
import java .time .Instant ;
13
- import java .util .*;
5
+ import java .util .ArrayList ;
6
+ import java .util .Collections ;
7
+ import java .util .List ;
8
+ import java .util .Map ;
14
9
import java .util .concurrent .atomic .AtomicReference ;
15
- import lombok .extern .slf4j .Slf4j ;
10
+
11
+ import org .springframework .beans .factory .annotation .Autowired ;
16
12
import org .springframework .core .ParameterizedTypeReference ;
17
13
import org .springframework .hateoas .EntityModel ;
18
14
import org .springframework .http .HttpEntity ;
22
18
import org .springframework .stereotype .Service ;
23
19
import org .springframework .web .client .RestTemplate ;
24
20
21
+ import com .elixir .biohackaton .ISAToSRA .biosamples .model .Attribute ;
22
+ import com .elixir .biohackaton .ISAToSRA .biosamples .model .BioSample ;
23
+ import com .elixir .biohackaton .ISAToSRA .biosamples .model .BiosampleAccessionsMap ;
24
+ import com .elixir .biohackaton .ISAToSRA .biosamples .model .Relationship ;
25
+ import com .elixir .biohackaton .ISAToSRA .receipt .MarsReceiptException ;
26
+ import com .elixir .biohackaton .ISAToSRA .receipt .ReceiptAccessionsMap ;
27
+ import com .elixir .biohackaton .ISAToSRA .receipt .isamodel .Category ;
28
+ import com .elixir .biohackaton .ISAToSRA .receipt .isamodel .Characteristic ;
29
+ import com .elixir .biohackaton .ISAToSRA .receipt .isamodel .Sample ;
30
+ import com .elixir .biohackaton .ISAToSRA .receipt .isamodel .Source ;
31
+ import com .elixir .biohackaton .ISAToSRA .receipt .isamodel .Study ;
32
+ import com .elixir .biohackaton .ISAToSRA .receipt .isamodel .Value ;
33
+
34
+ import lombok .extern .slf4j .Slf4j ;
35
+
25
36
@ Service
26
37
@ Slf4j
27
38
public class BioSamplesSubmitter {
28
39
40
+ @ Autowired
41
+ private MarsReceiptService marsReceiptService ;
42
+
29
43
public BiosampleAccessionsMap createBioSamples (final List <Study > studies , final String webinToken ) {
30
44
final BiosampleAccessionsMap typeToBioSamplesAccessionMap = new BiosampleAccessionsMap ();
31
45
@@ -39,7 +53,7 @@ public BiosampleAccessionsMap createBioSamples(final List<Study> studies, final
39
53
}
40
54
}
41
55
42
- typeToBioSamplesAccessionMap .sourceAccessionsMap .keyName = Source .Fields .name ;
56
+ typeToBioSamplesAccessionMap .sourceAccessionsMap .isaItemName = Source .Fields .name ;
43
57
typeToBioSamplesAccessionMap .sourceAccessionsMap .accessionMap .put (
44
58
sourceBioSample .getName (),
45
59
sourceBioSample .getAccession ());
@@ -52,36 +66,44 @@ public BiosampleAccessionsMap createBioSamples(final List<Study> studies, final
52
66
typeToBioSamplesAccessionMap .studyAccessionsMap = new ReceiptAccessionsMap (
53
67
Study .Fields .title ,
54
68
study .getTitle ());
55
-
56
69
study
57
70
.getMaterials ()
58
71
.getSamples ()
59
72
.forEach (
60
73
sample -> {
61
- final BioSample persistedChildSample = this .createAndUpdateChildSampleWithRelationship (
62
- sample ,
63
- sourceBioSample .getAccession (),
64
- finalSourceBioSampleOrganismAttribute .getValue (),
65
- webinToken );
66
-
67
- if (persistedChildSample != null ) {
68
- final Characteristic biosampleAccessionCharacteristic = getBioSampleAccessionCharacteristic (
69
- new AtomicReference <>(persistedChildSample ));
70
- final ArrayList <Characteristic > sampleCharacteristics = sample .getCharacteristics () != null
71
- ? sample .getCharacteristics ()
72
- : new ArrayList <>();
73
- sampleCharacteristics .add (biosampleAccessionCharacteristic );
74
-
75
- typeToBioSamplesAccessionMap .sampleAccessionsMap .keyName = Sample .Fields .name ;
76
- typeToBioSamplesAccessionMap .sampleAccessionsMap .accessionMap .put (
77
- persistedChildSample .getName (),
78
- persistedChildSample .getAccession ());
74
+ try {
75
+ final BioSample persistedChildSample = this .createAndUpdateChildSampleWithRelationship (
76
+ sample ,
77
+ sourceBioSample .getAccession (),
78
+ finalSourceBioSampleOrganismAttribute .getValue (),
79
+ webinToken );
80
+
81
+ if (persistedChildSample != null ) {
82
+ final Characteristic biosampleAccessionCharacteristic = getBioSampleAccessionCharacteristic (
83
+ new AtomicReference <>(persistedChildSample ));
84
+ final ArrayList <Characteristic > sampleCharacteristics = sample
85
+ .getCharacteristics () != null
86
+ ? sample .getCharacteristics ()
87
+ : new ArrayList <>();
88
+ sampleCharacteristics .add (biosampleAccessionCharacteristic );
89
+
90
+ typeToBioSamplesAccessionMap .sampleAccessionsMap .isaItemName = Sample .Fields .name ;
91
+ typeToBioSamplesAccessionMap .sampleAccessionsMap .accessionMap .put (
92
+ persistedChildSample .getName (),
93
+ persistedChildSample .getAccession ());
94
+ }
95
+ } catch (Exception e ) {
96
+ throw new MarsReceiptException (e ,
97
+ "Failed to parse ISA Json and create samples in BioSamples (SAMPLE)" ,
98
+ marsReceiptService .getSampleMarsPath (
99
+ Map .entry (Study .Fields .title , study .title ),
100
+ Map .entry (Sample .Fields .id , sample .id )));
79
101
}
80
102
});
81
103
});
82
104
}
83
105
} catch (final Exception e ) {
84
- throw new MarsReceiptException ("Failed to parse ISA Json and create samples in BioSamples" , e );
106
+ throw new MarsReceiptException (e , "Failed to parse ISA Json and create samples in BioSamples" );
85
107
}
86
108
87
109
return typeToBioSamplesAccessionMap ;
@@ -96,8 +118,8 @@ private BioSample createAndUpdateChildSampleWithRelationship(
96
118
.withRelease (Instant .now ())
97
119
.withAttributes (
98
120
List .of (Attribute .build ("organism" , parentSampleOrganism ),
99
- Attribute .build ("collection date" , "not provided" ),
100
- Attribute .build ("geographic location (country and/or sea)" , "not provided" )))
121
+ Attribute .build ("collection date" , "not provided" ),
122
+ Attribute .build ("geographic location (country and/or sea)" , "not provided" )))
101
123
.build ();
102
124
try {
103
125
final EntityModel <BioSample > persistedSampleEntity = this .createSampleInBioSamples (bioSample , webinToken );
@@ -123,7 +145,7 @@ private BioSample createAndUpdateChildSampleWithRelationship(
123
145
return null ;
124
146
}
125
147
} catch (final Exception e ) {
126
- throw new MarsReceiptException ("Failed to handle child samples" , e );
148
+ throw new MarsReceiptException (e , "Failed to handle child samples" );
127
149
}
128
150
}
129
151
@@ -151,8 +173,8 @@ private BioSample createSourceBioSample(final List<Study> studies, final String
151
173
final BioSample sourceSample = new BioSample .Builder (source .getName ())
152
174
.withRelease (Instant .now ())
153
175
.withAttributes (List .of (organismAttribute .get (),
154
- Attribute .build ("collection date" , "not provided" ),
155
- Attribute .build ("geographic location (country and/or sea)" , "not provided" )))
176
+ Attribute .build ("collection date" , "not provided" ),
177
+ Attribute .build ("geographic location (country and/or sea)" , "not provided" )))
156
178
.build ();
157
179
final EntityModel <BioSample > persistedParentSampleEntity = this .createSampleInBioSamples (sourceSample ,
158
180
webinToken );
@@ -205,8 +227,8 @@ private BioSample updateSampleWithRelationshipsToBioSamples(
205
227
new ParameterizedTypeReference <>() {
206
228
});
207
229
return biosamplesResponse .getBody ().getContent ();
208
- } catch (final Exception ex ) {
209
- throw new MarsReceiptException ("Failed to add relationships to child samples" , ex );
230
+ } catch (final Exception e ) {
231
+ throw new MarsReceiptException (e , "Failed to add relationships to child samples" );
210
232
}
211
233
}
212
234
@@ -227,8 +249,8 @@ private EntityModel<BioSample> createSampleInBioSamples(
227
249
});
228
250
229
251
return biosamplesResponse .getBody ();
230
- } catch (final Exception ex ) {
231
- throw new MarsReceiptException ("Failed to create samples in BioSamples" , ex );
252
+ } catch (final Exception e ) {
253
+ throw new MarsReceiptException (e , "Failed to create samples in BioSamples" );
232
254
}
233
255
}
234
256
0 commit comments