Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
421436f4
Commit
421436f4
authored
Sep 10, 2021
by
Piotr Gawron
Browse files
ReferenceGenomeSerializer implemented
parent
19686b15
Pipeline
#46934
passed with stage
in 17 minutes and 41 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
model/src/main/java/lcsb/mapviewer/modelutils/serializer/model/map/layout/ReferenceGenomeSerializer.java
0 → 100644
View file @
421436f4
package
lcsb.mapviewer.modelutils.serializer.model.map.layout
;
import
java.io.IOException
;
import
java.util.function.Function
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.databind.JsonSerializer
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
lcsb.mapviewer.model.map.layout.ReferenceGenome
;
public
class
ReferenceGenomeSerializer
extends
JsonSerializer
<
ReferenceGenome
>
{
private
Function
<
String
,
String
>
getLocalUrl
;
public
ReferenceGenomeSerializer
(
Function
<
String
,
String
>
getLocalUrl
)
{
this
.
getLocalUrl
=
getLocalUrl
;
}
@Override
public
void
serialize
(
final
ReferenceGenome
genome
,
final
JsonGenerator
gen
,
final
SerializerProvider
serializers
)
throws
IOException
{
gen
.
writeStartObject
();
gen
.
writeObjectField
(
"organism"
,
genome
.
getOrganism
());
gen
.
writeStringField
(
"version"
,
genome
.
getVersion
());
gen
.
writeObjectField
(
"type"
,
genome
.
getType
());
gen
.
writeNumberField
(
"downloadProgress"
,
genome
.
getDownloadProgress
());
gen
.
writeStringField
(
"sourceUrl"
,
genome
.
getSourceUrl
());
gen
.
writeStringField
(
"localUrl"
,
getLocalUrl
.
apply
(
genome
.
getSourceUrl
()));
gen
.
writeNumberField
(
"idObject"
,
genome
.
getId
());
gen
.
writeObjectField
(
"geneMapping"
,
genome
.
getGeneMapping
());
gen
.
writeEndObject
();
}
}
\ No newline at end of file
rest-api/src/main/java/lcsb/mapviewer/api/genomics/ReferenceGenomeController.java
View file @
421436f4
package
lcsb.mapviewer.api.genomics
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
import
java.util.ArrayList
;
...
...
@@ -9,10 +8,7 @@ import java.util.LinkedHashSet;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TreeMap
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.access.prepost.PreAuthorize
;
...
...
@@ -34,7 +30,6 @@ import lcsb.mapviewer.model.map.layout.ReferenceGenomeType;
import
lcsb.mapviewer.services.ObjectExistsException
;
import
lcsb.mapviewer.services.ObjectNotFoundException
;
import
lcsb.mapviewer.services.QueryException
;
import
lcsb.mapviewer.services.interfaces.IFileService
;
import
lcsb.mapviewer.services.interfaces.IReferenceGenomeService
;
import
lcsb.mapviewer.services.utils.ReferenceGenomeExistsException
;
...
...
@@ -42,19 +37,15 @@ import lcsb.mapviewer.services.utils.ReferenceGenomeExistsException;
@RequestMapping
(
value
=
"/api/genomics"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
class
ReferenceGenomeController
extends
BaseController
{
private
Logger
logger
=
LogManager
.
getLogger
();
private
IReferenceGenomeService
referenceGenomeService
;
private
IFileService
fileService
;
@Autowired
public
ReferenceGenomeController
(
IReferenceGenomeService
referenceGenomeService
,
IFileService
fileService
)
{
public
ReferenceGenomeController
(
IReferenceGenomeService
referenceGenomeService
)
{
this
.
referenceGenomeService
=
referenceGenomeService
;
this
.
fileService
=
fileService
;
}
@GetMapping
(
value
=
"/taxonomies/{organismId}/genomeTypes/{type}/versions/{version}/"
)
public
Map
<
String
,
Object
>
getGenomesByQuery
(
@PathVariable
(
value
=
"organismId"
)
String
organismId
,
@PathVariable
(
value
=
"type"
)
String
type
,
public
ReferenceGenome
getGenomesByQuery
(
@PathVariable
(
value
=
"organismId"
)
String
organismId
,
@PathVariable
(
value
=
"type"
)
String
type
,
@PathVariable
(
value
=
"version"
)
String
version
)
throws
QueryException
{
MiriamData
organism
;
if
(
organismId
!=
null
&&
!
organismId
.
isEmpty
())
{
...
...
@@ -69,36 +60,12 @@ public class ReferenceGenomeController extends BaseController {
if
(
genome
==
null
)
{
throw
new
ObjectNotFoundException
(
"Cannot find requested reference genome"
);
}
return
genome
ToMap
(
genome
)
;
return
genome
;
}
catch
(
IllegalArgumentException
e
)
{
throw
new
QueryException
(
"Cannot find type: "
+
type
);
}
}
private
Map
<
String
,
Object
>
genomeToMap
(
ReferenceGenome
genome
)
{
Map
<
String
,
Object
>
result
=
new
TreeMap
<>();
result
.
put
(
"organism"
,
genome
.
getOrganism
());
result
.
put
(
"version"
,
genome
.
getVersion
());
result
.
put
(
"type"
,
genome
.
getType
());
result
.
put
(
"downloadProgress"
,
genome
.
getDownloadProgress
());
result
.
put
(
"sourceUrl"
,
genome
.
getSourceUrl
());
result
.
put
(
"localUrl"
,
getLocalUrl
(
genome
.
getSourceUrl
()));
result
.
put
(
"idObject"
,
genome
.
getId
());
result
.
put
(
"geneMapping"
,
genome
.
getGeneMapping
());
return
result
;
}
private
String
getLocalUrl
(
String
sourceUrl
)
{
String
url
=
null
;
try
{
url
=
"../"
+
fileService
.
getLocalPathForFile
(
sourceUrl
);
}
catch
(
FileNotFoundException
e
)
{
logger
.
warn
(
"Cannot find local file"
,
e
);
}
return
url
;
}
static
class
RemoteUrl
{
public
String
url
;
}
...
...
@@ -111,7 +78,7 @@ public class ReferenceGenomeController extends BaseController {
throw
new
QueryException
(
"Unknown taxonomy organism: "
+
organismId
);
}
MiriamData
organism
=
new
MiriamData
(
MiriamType
.
TAXONOMY
,
organismId
);
if
(
genomeType
==
null
)
{
if
(
genomeType
==
null
)
{
throw
new
QueryException
(
"Unknown genome type"
);
}
String
url
=
referenceGenomeService
.
getUrlForGenomeVersion
(
genomeType
,
organism
,
version
);
...
...
@@ -160,12 +127,8 @@ public class ReferenceGenomeController extends BaseController {
}
@GetMapping
(
value
=
"/"
)
public
List
<
Map
<
String
,
Object
>>
getDownloaded
()
{
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
for
(
ReferenceGenome
genome
:
referenceGenomeService
.
getDownloadedGenomes
())
{
result
.
add
(
genomeToMap
(
genome
));
}
return
result
;
public
List
<
ReferenceGenome
>
getDownloaded
()
{
return
referenceGenomeService
.
getDownloadedGenomes
();
}
static
class
OrganismType
{
...
...
web/src/main/java/lcsb/mapviewer/web/config/SpringWebConfig.java
View file @
421436f4
...
...
@@ -37,6 +37,7 @@ import lcsb.mapviewer.api.SpringRestApiConfig;
import
lcsb.mapviewer.model.Article
;
import
lcsb.mapviewer.model.map.Comment
;
import
lcsb.mapviewer.model.map.MiriamData
;
import
lcsb.mapviewer.model.map.layout.ReferenceGenome
;
import
lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping
;
import
lcsb.mapviewer.model.map.reaction.Reaction
;
import
lcsb.mapviewer.model.map.species.Element
;
...
...
@@ -45,6 +46,7 @@ import lcsb.mapviewer.modelutils.serializer.ColorSerializer;
import
lcsb.mapviewer.modelutils.serializer.model.map.CommentSerializer
;
import
lcsb.mapviewer.modelutils.serializer.model.map.MiriamDataSerializer
;
import
lcsb.mapviewer.modelutils.serializer.model.map.layout.ReferenceGenomeGeneMappingSerializer
;
import
lcsb.mapviewer.modelutils.serializer.model.map.layout.ReferenceGenomeSerializer
;
import
lcsb.mapviewer.services.interfaces.IElementService
;
import
lcsb.mapviewer.services.interfaces.IFileService
;
import
lcsb.mapviewer.services.interfaces.IMeshService
;
...
...
@@ -149,6 +151,20 @@ public class SpringWebConfig implements WebMvcConfigurer {
}
}));
module
.
addSerializer
(
ReferenceGenome
.
class
,
new
ReferenceGenomeSerializer
(
new
Function
<
String
,
String
>()
{
@Override
public
String
apply
(
String
sourceUrl
)
{
String
url
=
null
;
try
{
url
=
"../"
+
fileService
.
getLocalPathForFile
(
sourceUrl
);
}
catch
(
FileNotFoundException
e
)
{
logger
.
warn
(
"Cannot find local file"
,
e
);
}
return
url
;
}
}));
m
.
getObjectMapper
().
registerModule
(
module
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment