-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from metabolomics-us/QA
FIEHNLAB-1820/Calculate all possible adducts for spectra
- Loading branch information
Showing
33 changed files
with
760 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
backend/app/server/proxy/src/main/mona-web/src/app/mocks/user.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export class User { | ||
emailAddress: string; | ||
id: string; | ||
firstName: string; | ||
lastName: string; | ||
institution: string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...a/edu/ucdavis/fiehnlab/mona/backend/curation/processor/metadata/CalculateAllAdducts.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package edu.ucdavis.fiehnlab.mona.backend.curation.processor.metadata | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import edu.ucdavis.fiehnlab.mona.backend.core.domain.{Compound, MetaData, Spectrum} | ||
import edu.ucdavis.fiehnlab.mona.backend.core.workflow.annotations.Step | ||
import edu.ucdavis.fiehnlab.mona.backend.curation.util.chemical.AdductBuilder | ||
import edu.ucdavis.fiehnlab.mona.backend.curation.util.{CommonMetaData, CurationUtilities} | ||
import org.springframework.batch.item.ItemProcessor | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
@Step(description = "this step will calculate all possible adducts") | ||
class CalculateAllAdducts extends ItemProcessor[Spectrum, Spectrum] with LazyLogging { | ||
|
||
private val PRECURSOR_MATCH_TOLERANCE: Double = 0.5 | ||
|
||
/** | ||
* processes the given spectrum | ||
* | ||
* @param spectrum to be processed | ||
* @return processed spectrum | ||
*/ | ||
override def process(spectrum: Spectrum): Spectrum = { | ||
// Get computed total exact mass from the biological compound if it exists | ||
if(spectrum.tags.exists(x => x.text == "GC-MS")) { | ||
logger.info(s"Process is only for LC-MS spectra") | ||
spectrum | ||
} else { | ||
val biologicalIndex: Int = | ||
if (spectrum.compound.exists(_.kind == "biological")) { | ||
spectrum.compound.indexWhere(_.kind == "biological") | ||
} else if (spectrum.compound.nonEmpty) { | ||
0 | ||
} else { | ||
-1 | ||
} | ||
|
||
if (biologicalIndex == -1) { | ||
logger.info(s"${spectrum.id}: Valid compound could not be found!") | ||
spectrum | ||
} else { | ||
// Get total exact mass from biological compound | ||
val theoreticalMass: Double = { | ||
val x: String = CurationUtilities.findMetaDataValue(spectrum.compound(biologicalIndex).metaData, CommonMetaData.TOTAL_EXACT_MASS) | ||
|
||
if (x == null) { | ||
-1 | ||
} else { | ||
x.toDouble | ||
} | ||
} | ||
|
||
val biologicalCompound = spectrum.compound(biologicalIndex) | ||
val adductMap = AdductBuilder.LCMS_POSITIVE_ADDUCTS ++ AdductBuilder.LCMS_NEGATIVE_ADDUCTS | ||
|
||
val updatedMetadata: ArrayBuffer[MetaData] = new ArrayBuffer[MetaData]() | ||
biologicalCompound.metaData.foreach(x => updatedMetadata.append(x)) | ||
|
||
val updatedCompoundSet: ArrayBuffer[Compound] = new ArrayBuffer[Compound]() | ||
spectrum.compound.foreach(x => updatedCompoundSet.append(x)) | ||
|
||
if (theoreticalMass < 0) { | ||
logger.info(s"${spectrum.id}: Computed exact mass was not found, unable to generate adduct information") | ||
spectrum | ||
} else { | ||
adductMap.foreach { | ||
case (x, f) => updatedMetadata.append(MetaData("theoretical adduct", true, true, x, null, null, null, f(theoreticalMass))) | ||
} | ||
|
||
val updatedCompound = biologicalCompound.copy( | ||
metaData = updatedMetadata.toArray | ||
) | ||
|
||
updatedCompoundSet.update(biologicalIndex, updatedCompound) | ||
|
||
spectrum.copy( | ||
compound = updatedCompoundSet.toArray | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...st/scala/edu/ucdavis/fiehnlab/mona/backend/curation/config/EmbeddedRestServerConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package edu.ucdavis.fiehnlab.mona.backend.curation.config | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import edu.ucdavis.fiehnlab.mona.backend.core.auth.jwt.service.MongoLoginService | ||
import edu.ucdavis.fiehnlab.mona.backend.core.domain.service.LoginService | ||
import edu.ucdavis.fiehnlab.mona.backend.core.persistence.rest.server.config.RestServerConfig | ||
import org.springframework.context.annotation.{Bean, Configuration, Import} | ||
|
||
/** | ||
* Created by wohlg on 3/11/2016. | ||
*/ | ||
@Configuration | ||
@Import(Array(classOf[RestServerConfig])) | ||
class EmbeddedRestServerConfig extends LazyLogging { | ||
|
||
/** | ||
* the service which actually does the login for us | ||
* | ||
* @return | ||
*/ | ||
@Bean | ||
def loginService: LoginService = new MongoLoginService | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...c/test/scala/edu/ucdavis/fiehnlab/mona/backend/curation/config/RestClientTestConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package edu.ucdavis.fiehnlab.mona.backend.curation.config | ||
|
||
import edu.ucdavis.fiehnlab.mona.backend.core.auth.jwt.service.MongoLoginService | ||
import edu.ucdavis.fiehnlab.mona.backend.core.auth.rest.config.AuthSecurityConfig | ||
import edu.ucdavis.fiehnlab.mona.backend.core.domain.service.LoginService | ||
import edu.ucdavis.fiehnlab.mona.backend.core.persistence.rest.client.config.RestClientConfig | ||
import edu.ucdavis.fiehnlab.mona.backend.core.persistence.rest.client.service.RestLoginService | ||
import edu.ucdavis.fiehnlab.mona.backend.core.statistics.config.StatisticsRepositoryConfig | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.context.annotation.{Bean, Import, Primary} | ||
|
||
/** | ||
* Created by wohlgemuth on 3/15/16. | ||
*/ | ||
@Import(Array(classOf[RestClientConfig], classOf[EmbeddedRestServerConfig], classOf[AuthSecurityConfig], classOf[StatisticsRepositoryConfig])) | ||
@SpringBootApplication | ||
class RestClientTestConfig { | ||
|
||
@Bean | ||
@Primary | ||
def loginService(@Value("${mona.rest.server.host}") host: String, @Value("${mona.rest.server.port}") port: Int): LoginService = | ||
new RestLoginService("localhost", port) | ||
|
||
@Bean | ||
def loginServiceDelegate: LoginService = new MongoLoginService | ||
} |
35 changes: 35 additions & 0 deletions
35
...u/ucdavis/fiehnlab/mona/backend/curation/processor/metadata/CalculateAllAdductsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package edu.ucdavis.fiehnlab.mona.backend.curation.processor.metadata | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
import edu.ucdavis.fiehnlab.mona.backend.core.domain.Spectrum | ||
import edu.ucdavis.fiehnlab.mona.backend.core.domain.io.json.JSONDomainReader | ||
|
||
import java.io.InputStreamReader | ||
|
||
class CalculateAllAdductsTest extends AnyWordSpec with Matchers with LazyLogging{ | ||
|
||
val reader: JSONDomainReader[Spectrum] = JSONDomainReader.create[Spectrum] | ||
|
||
"this processor" when { | ||
val processor = new CalculateAllAdducts | ||
|
||
val exampleRecord: Spectrum = JSONDomainReader.create[Spectrum].read(new InputStreamReader(getClass.getResourceAsStream("/monaRecord2.json"))) | ||
"given a spectra" must { | ||
"correctly calculate adduct list" in { | ||
val processedSpectrum = processor.process(exampleRecord) | ||
logger.info(s"${processedSpectrum.compound(0).metaData.filter(x => x.category == "theoretical adduct")}") | ||
assert(processedSpectrum.compound(0).metaData.filter(x => x.category == "theoretical adduct").length == 16) | ||
} | ||
|
||
"spot check calculations" in { | ||
val processedSpectrum = processor.process(exampleRecord) | ||
val sortedMetaData = processedSpectrum.compound(0).metaData.filter(x => x.category == "theoretical adduct") | ||
sortedMetaData.find(x => x.name == "[M+H]+").get.value shouldBe 165.041395368 | ||
sortedMetaData.find(x => x.name == "[2M+NH4]+").get.value shouldBe 346.105430736 | ||
sortedMetaData.find(x => x.name == "[2M+HAc-H]-").get.value shouldBe 387.110880736 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.