Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
c45c81d1
Commit
c45c81d1
authored
Jun 25, 2021
by
Piotr Gawron
Browse files
get reference genome moved to controller
parent
aca38ed1
Changes
10
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java
View file @
c45c81d1
...
...
@@ -8,7 +8,6 @@ import javax.xml.transform.*;
import
javax.xml.transform.stream.StreamResult
;
import
javax.xml.transform.stream.StreamSource
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -17,7 +16,8 @@ import org.springframework.core.io.Resource;
import
org.springframework.transaction.annotation.Transactional
;
import
lcsb.mapviewer.annotation.data.Target
;
import
lcsb.mapviewer.annotation.services.*
;
import
lcsb.mapviewer.annotation.services.MiriamConnector
;
import
lcsb.mapviewer.annotation.services.PubmedParser
;
import
lcsb.mapviewer.common.comparator.StringComparator
;
import
lcsb.mapviewer.common.exception.*
;
import
lcsb.mapviewer.converter.Converter
;
...
...
@@ -26,7 +26,6 @@ import lcsb.mapviewer.model.Project;
import
lcsb.mapviewer.model.map.*
;
import
lcsb.mapviewer.model.map.reaction.Reaction
;
import
lcsb.mapviewer.model.map.species.Element
;
import
lcsb.mapviewer.model.user.annotator.*
;
import
lcsb.mapviewer.modelutils.map.ElementUtils
;
import
lcsb.mapviewer.persist.dao.map.species.ElementProperty
;
import
lcsb.mapviewer.services.QueryException
;
...
...
@@ -58,6 +57,9 @@ public abstract class BaseRestImpl {
@Autowired
private
PubmedParser
pubmedParser
;
@Autowired
private
IMiriamService
miriamService
;
@Autowired
private
IElementService
elementService
;
...
...
@@ -91,41 +93,7 @@ public abstract class BaseRestImpl {
};
protected
Map
<
String
,
Object
>
createAnnotation
(
MiriamData
annotation
)
{
if
(
annotation
!=
null
&&
annotation
.
getDataType
()
!=
null
)
{
Map
<
String
,
Object
>
result
=
new
TreeMap
<>();
if
(
annotation
.
getDataType
().
getUris
().
size
()
>
0
)
{
try
{
result
.
put
(
"link"
,
miriamConnector
.
getUrlString
(
annotation
));
}
catch
(
Exception
e
)
{
logger
.
error
(
"Problem with miriam: "
+
annotation
,
e
);
}
}
if
(
MiriamType
.
PUBMED
.
equals
(
annotation
.
getDataType
()))
{
if
(
NumberUtils
.
isDigits
(
annotation
.
getResource
()))
{
try
{
Article
article
=
pubmedParser
.
getPubmedArticleById
(
annotation
.
getResource
());
result
.
put
(
"article"
,
article
);
}
catch
(
PubmedSearchException
e
)
{
logger
.
error
(
"Problem with accessing info about pubmed"
,
e
);
}
}
else
{
logger
.
error
(
"Invalid pubmed identifier: "
+
annotation
.
getResource
());
}
}
result
.
put
(
"type"
,
annotation
.
getDataType
().
name
());
result
.
put
(
"resource"
,
annotation
.
getResource
());
result
.
put
(
"id"
,
annotation
.
getId
());
if
(
annotation
.
getAnnotator
()
!=
null
)
{
result
.
put
(
"annotatorClassName"
,
annotation
.
getAnnotator
().
getName
());
}
else
{
result
.
put
(
"annotatorClassName"
,
""
);
}
return
result
;
}
else
{
throw
new
InvalidArgumentException
(
"invalid miriam data: "
+
annotation
);
}
return
miriamService
.
serializeMiriamData
(
annotation
);
};
protected
Map
<
String
,
Object
>
createAnnotation
(
Article
article
)
{
...
...
rest-api/src/main/java/lcsb/mapviewer/api/genomics/ReferenceGenomeController.java
View file @
c45c81d1
package
lcsb.mapviewer.api.genomics
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
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
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.bind.annotation.*
;
import
lcsb.mapviewer.annotation.cache.BigFileCache
;
import
lcsb.mapviewer.annotation.services.genome.ReferenceGenomeConnectorException
;
import
lcsb.mapviewer.api.BaseController
;
import
lcsb.mapviewer.model.map.MiriamData
;
import
lcsb.mapviewer.model.map.MiriamType
;
import
lcsb.mapviewer.model.map.layout.*
;
import
lcsb.mapviewer.services.ObjectNotFoundException
;
import
lcsb.mapviewer.services.QueryException
;
import
lcsb.mapviewer.services.interfaces.*
;
@RestController
@RequestMapping
(
value
=
"/api/genomics"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
class
ReferenceGenomeController
extends
BaseController
{
private
Logger
logger
=
LogManager
.
getLogger
();
private
ReferenceGenomeRestImpl
referenceGenomeController
;
private
IReferenceGenomeService
referenceGenomeService
;
private
IFileService
fileService
;
private
IMiriamService
miriamService
;
@Autowired
public
ReferenceGenomeController
(
ReferenceGenomeRestImpl
referenceGenomeController
)
{
public
ReferenceGenomeController
(
ReferenceGenomeRestImpl
referenceGenomeController
,
IReferenceGenomeService
referenceGenomeService
,
IFileService
fileService
,
IMiriamService
miriamService
)
{
this
.
referenceGenomeController
=
referenceGenomeController
;
this
.
referenceGenomeService
=
referenceGenomeService
;
this
.
fileService
=
fileService
;
this
.
miriamService
=
miriamService
;
}
@GetMapping
(
value
=
"/taxonomies/{organismId}/genomeTypes/{type}/versions/{version}/"
)
public
Map
<
String
,
Object
>
getGenomesByQuery
(
@PathVariable
(
value
=
"organismId"
)
String
organism
,
@PathVariable
(
value
=
"organismId"
)
String
organism
Id
,
@PathVariable
(
value
=
"type"
)
String
type
,
@PathVariable
(
value
=
"version"
)
String
version
)
throws
QueryException
{
return
referenceGenomeController
.
getReferenceGenome
(
organism
,
type
,
version
);
MiriamData
organism
;
if
(
organismId
!=
null
&&
!
organismId
.
isEmpty
())
{
organism
=
new
MiriamData
(
MiriamType
.
TAXONOMY
,
organismId
);
}
else
{
throw
new
QueryException
(
"Unknown taxonomy organism: "
+
organismId
);
}
try
{
ReferenceGenomeType
genomeType
=
ReferenceGenomeType
.
valueOf
(
type
);
version
=
version
.
replaceAll
(
"\\*"
,
""
);
ReferenceGenome
genome
=
referenceGenomeService
.
getReferenceGenomeViewByParams
(
organism
,
genomeType
,
version
);
if
(
genome
==
null
)
{
throw
new
ObjectNotFoundException
(
"Cannot find requested reference genome"
);
}
return
genomeToMap
(
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"
,
miriamService
.
serializeMiriamData
(
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"
,
geneMappingToMaps
(
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
;
}
private
List
<
Map
<
String
,
Object
>>
geneMappingToMaps
(
List
<
ReferenceGenomeGeneMapping
>
geneMapping
)
{
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
for
(
ReferenceGenomeGeneMapping
referenceGenomeGeneMapping
:
geneMapping
)
{
result
.
add
(
geneMappingToMap
(
referenceGenomeGeneMapping
));
}
return
result
;
}
private
Map
<
String
,
Object
>
geneMappingToMap
(
ReferenceGenomeGeneMapping
mapping
)
{
Map
<
String
,
Object
>
result
=
new
TreeMap
<>();
result
.
put
(
"downloadProgress"
,
mapping
.
getDownloadProgress
());
result
.
put
(
"localUrl"
,
getLocalUrl
(
mapping
.
getSourceUrl
()));
result
.
put
(
"sourceUrl"
,
mapping
.
getSourceUrl
());
result
.
put
(
"name"
,
mapping
.
getName
());
result
.
put
(
"idObject"
,
mapping
.
getId
());
return
result
;
}
@GetMapping
(
value
=
"/taxonomies/{organismId}/genomeTypes/{type}/versions/{version}:getAvailableRemoteUrls"
)
...
...
rest-api/src/main/java/lcsb/mapviewer/api/genomics/ReferenceGenomeRestImpl.java
View file @
c45c81d1
...
...
@@ -45,26 +45,6 @@ public class ReferenceGenomeRestImpl extends BaseRestImpl {
this
.
bigFileCache
=
bigFileCache
;
}
public
Map
<
String
,
Object
>
getReferenceGenome
(
String
organismId
,
String
type
,
String
version
)
throws
QueryException
{
MiriamData
organism
;
if
(
organismId
!=
null
&&
!
organismId
.
isEmpty
())
{
organism
=
new
MiriamData
(
MiriamType
.
TAXONOMY
,
organismId
);
}
else
{
throw
new
QueryException
(
"Unknown taxonomy organism: "
+
organismId
);
}
try
{
ReferenceGenomeType
genomeType
=
ReferenceGenomeType
.
valueOf
(
type
);
version
=
version
.
replaceAll
(
"\\*"
,
""
);
ReferenceGenome
genome
=
referenceGenomeService
.
getReferenceGenomeViewByParams
(
organism
,
genomeType
,
version
);
if
(
genome
==
null
)
{
throw
new
ObjectNotFoundException
(
"Cannot find requested reference genome"
);
}
return
genomeToMap
(
genome
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
QueryException
(
"Cannot find type: "
+
type
);
}
}
public
List
<
Map
<
String
,
Object
>>
getRemoteUrls
(
String
organismId
,
String
type
,
String
version
)
throws
QueryException
{
MiriamData
organism
;
if
(
organismId
!=
null
&&
!
organismId
.
isEmpty
())
{
...
...
rest-api/src/test/java/lcsb/mapviewer/api/genomics/ReferenceGenomeControllerTest.java
View file @
c45c81d1
...
...
@@ -12,7 +12,6 @@ import org.junit.*;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lcsb.mapviewer.api.RestTestFunctions
;
import
lcsb.mapviewer.services.QueryException
;
public
class
ReferenceGenomeControllerTest
extends
RestTestFunctions
{
@Autowired
...
...
@@ -31,16 +30,6 @@ public class ReferenceGenomeControllerTest extends RestTestFunctions {
public
void
tearDown
()
throws
Exception
{
}
@Test
(
expected
=
QueryException
.
class
)
public
void
testGetForNonExistingType
()
throws
Exception
{
referenceGenomeRestImpl
.
getReferenceGenome
(
"9606"
,
"type"
,
"ver"
);
}
@Test
(
expected
=
QueryException
.
class
)
public
void
testGetForNonExistingOrganism
()
throws
Exception
{
referenceGenomeRestImpl
.
getReferenceGenome
(
"960000"
,
"UCSC"
,
"ver"
);
}
@Test
public
void
testGetReferenceGenomeTaxonomies
()
throws
Exception
{
List
<
Map
<
String
,
Object
>>
result
=
referenceGenomeRestImpl
.
getReferenceGenomeTaxonomies
();
...
...
service/src/main/java/lcsb/mapviewer/services/impl/ConfigurationService.java
View file @
c45c81d1
...
...
@@ -13,7 +13,6 @@ import org.springframework.transaction.annotation.Transactional;
import
lcsb.mapviewer.annotation.services.dapi.DapiConnector
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.common.FrameworkVersion
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
import
lcsb.mapviewer.model.security.PrivilegeType
;
import
lcsb.mapviewer.model.user.*
;
...
...
service/src/main/java/lcsb/mapviewer/services/impl/FileService.java
View file @
c45c81d1
package
lcsb.mapviewer.services.impl
;
import
java.io.FileNotFoundException
;
import
org.hibernate.Hibernate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
lcsb.mapviewer.annotation.cache.BigFileCache
;
import
lcsb.mapviewer.model.cache.UploadedFileEntry
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao
;
...
...
@@ -15,10 +18,13 @@ import lcsb.mapviewer.services.interfaces.IFileService;
public
class
FileService
implements
IFileService
{
private
UploadedFileEntryDao
uploadedFileEntryDao
;
private
BigFileCache
bigFileCache
;
@Autowired
public
FileService
(
UploadedFileEntryDao
uploadedFileEntryDao
)
{
public
FileService
(
UploadedFileEntryDao
uploadedFileEntryDao
,
BigFileCache
bigFileCache
)
{
this
.
uploadedFileEntryDao
=
uploadedFileEntryDao
;
this
.
bigFileCache
=
bigFileCache
;
}
@Override
...
...
@@ -50,4 +56,9 @@ public class FileService implements IFileService {
uploadedFileEntryDao
.
update
(
fileEntry
);
}
@Override
public
String
getLocalPathForFile
(
String
sourceUrl
)
throws
FileNotFoundException
{
return
bigFileCache
.
getLocalPathForFile
(
sourceUrl
);
}
}
service/src/main/java/lcsb/mapviewer/services/impl/MiriamService.java
View file @
c45c81d1
package
lcsb.mapviewer.services.impl
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
lcsb.mapviewer.annotation.services.MiriamConnector
;
import
lcsb.mapviewer.annotation.services.*
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
import
lcsb.mapviewer.model.Article
;
import
lcsb.mapviewer.model.map.MiriamData
;
import
lcsb.mapviewer.model.map.MiriamType
;
import
lcsb.mapviewer.services.interfaces.IMiriamService
;
/**
* Implementation of service responsible for accessing miriam registry.
*
* @author Piotr Gawron
*
*/
@Transactional
@Service
public
class
MiriamService
implements
IMiriamService
{
/**
* Object accessing <a href= "http://www.ebi.ac.uk/miriam/main/" >miriam
* registry</a>.
*/
private
static
Logger
logger
=
LogManager
.
getLogger
();
private
MiriamConnector
miriamConnector
;
private
PubmedParser
pubmedParser
;
@Autowired
public
MiriamService
(
MiriamConnector
miriamConnector
)
{
public
MiriamService
(
MiriamConnector
miriamConnector
,
PubmedParser
pubmedParser
)
{
this
.
miriamConnector
=
miriamConnector
;
this
.
pubmedParser
=
pubmedParser
;
}
@Override
public
String
getUrlForMiriamData
(
MiriamData
md
)
{
return
miriamConnector
.
getUrlString
(
md
);
}
public
Map
<
String
,
Object
>
serializeMiriamData
(
MiriamData
annotation
)
{
// TODO Auto-generated method stub
if
(
annotation
!=
null
&&
annotation
.
getDataType
()
!=
null
)
{
Map
<
String
,
Object
>
result
=
new
TreeMap
<>();
if
(
annotation
.
getDataType
().
getUris
().
size
()
>
0
)
{
try
{
result
.
put
(
"link"
,
miriamConnector
.
getUrlString
(
annotation
));
}
catch
(
Exception
e
)
{
logger
.
error
(
"Problem with miriam: "
+
annotation
,
e
);
}
}
if
(
MiriamType
.
PUBMED
.
equals
(
annotation
.
getDataType
()))
{
if
(
NumberUtils
.
isDigits
(
annotation
.
getResource
()))
{
try
{
Article
article
=
pubmedParser
.
getPubmedArticleById
(
annotation
.
getResource
());
result
.
put
(
"article"
,
article
);
}
catch
(
PubmedSearchException
e
)
{
logger
.
error
(
"Problem with accessing info about pubmed"
,
e
);
}
}
else
{
logger
.
error
(
"Invalid pubmed identifier: "
+
annotation
.
getResource
());
}
}
result
.
put
(
"type"
,
annotation
.
getDataType
().
name
());
result
.
put
(
"resource"
,
annotation
.
getResource
());
result
.
put
(
"id"
,
annotation
.
getId
());
@Override
public
MiriamType
getTypeForUri
(
String
uri
)
{
return
MiriamType
.
getTypeByUri
(
uri
);
}
/**
* @return the miriamConnector
* @see #miriamConnector
*/
public
MiriamConnector
getMiriamConnector
()
{
return
miriamConnector
;
}
/**
* @param miriamConnector
* the miriamConnector to set
* @see #miriamConnector
*/
public
void
setMiriamConnector
(
MiriamConnector
miriamConnector
)
{
this
.
miriamConnector
=
miriamConnector
;
}
if
(
annotation
.
getAnnotator
()
!=
null
)
{
result
.
put
(
"annotatorClassName"
,
annotation
.
getAnnotator
().
getName
());
}
else
{
result
.
put
(
"annotatorClassName"
,
""
);
}
return
result
;
}
else
{
throw
new
InvalidArgumentException
(
"invalid miriam data: "
+
annotation
);
}
};
}
service/src/main/java/lcsb/mapviewer/services/interfaces/IFileService.java
View file @
c45c81d1
package
lcsb.mapviewer.services.interfaces
;
import
java.io.FileNotFoundException
;
import
lcsb.mapviewer.model.cache.UploadedFileEntry
;
import
lcsb.mapviewer.model.user.User
;
...
...
@@ -13,4 +15,6 @@ public interface IFileService {
void
update
(
UploadedFileEntry
fileEntry
);
String
getLocalPathForFile
(
String
sourceUrl
)
throws
FileNotFoundException
;
}
service/src/main/java/lcsb/mapviewer/services/interfaces/IMiriamService.java
View file @
c45c81d1
package
lcsb.mapviewer.services.interfaces
;
import
java.util.Map
;
import
lcsb.mapviewer.model.map.MiriamData
;
import
lcsb.mapviewer.model.map.MiriamType
;
/**
* Service responsible for accessing miriam registry.
*
* @author Piotr Gawron
*
*/
public
interface
IMiriamService
{
/**
* Returns url for data represented by {@link MiriamData}.
*
* @param md
* object to which link will be returned
* @return url to miriam data
*/
String
getUrlForMiriamData
(
MiriamData
md
);
/**
* Returns {@link MiriamType} associated with parameter uri address.
*
* @param uri
* uri to check
* @return {@link MiriamType} for given uri
*/
MiriamType
getTypeForUri
(
String
uri
);
Map
<
String
,
Object
>
serializeMiriamData
(
MiriamData
md
);
}
web/src/test/java/lcsb/mapviewer/web/GenomicsControllerIntegrationTest.java
View file @
c45c81d1
...
...
@@ -412,4 +412,24 @@ public class GenomicsControllerIntegrationTest extends ControllerIntegrationTest
.
andExpect
(
status
().
isBadRequest
());
}
@Test
public
void
testGetNonExistingGenomeType
()
throws
Exception
{
RequestBuilder
request
=
get
(
"/api/genomics/taxonomies/{taxonomyId}/genomeTypes/{genomeType}/versions/{version}/"
,
"9606"
,
"type"
,
"ver"
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
isBadRequest
());
}
@Test
public
void
testGetNonExistingGenome2
()
throws
Exception
{
RequestBuilder
request
=
get
(
"/api/genomics/taxonomies/{taxonomyId}/genomeTypes/{genomeType}/versions/{version}/"
,
"960000"
,
"UCSC"
,
"ver"
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
isNotFound
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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