Skip to content

Commit

Permalink
Autogenerated literator docs for v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
eparejatobes committed Nov 9, 2016
1 parent 43d347c commit 8b77689
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 35 deletions.
12 changes: 9 additions & 3 deletions docs/src/main/scala/uniref.scala.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ package com.bio4j.data.uniref
trait AnyCluster extends Any {

def ID: String
def seedID: Option[String]
def representativeID: Option[String]
def nonRepresentativeMemberIDs: Seq[String]
def seed: ClusterMember
def representative: ClusterMember
def nonRepresentativeMembers: Seq[ClusterMember]
}

sealed trait ClusterMember extends Any {
def id: String
}
case class UniProtProtein(val id: String) extends ClusterMember
case class UniParcProtein(val id: String) extends ClusterMember

```


Expand Down
55 changes: 31 additions & 24 deletions docs/src/main/scala/xml/entry.scala.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,49 @@ case class Entry(val xml: Elem) extends AnyVal with AnyCluster {
def ID: String =
xml \ "@id" text

def representativeID: Option[String] =
(xml \ "representativeMember" \ "dbReference" \ "property" )
.filter( isUniProtAccessionProperty )
.map( _ \ "@value" text )
.headOption

def nonRepresentativeMemberIDs: Seq[String] =
nonRepresentativeMembers
.flatMap( dbRef =>
(dbRef \ "property").filter(isUniProtAccessionProperty)
.map(_ \ "@value" text)
def representative: ClusterMember =
dbRefToClusterMember(representativedbRef)

def seed: ClusterMember =
if(dbRefIsSeed(representativedbRef))
representative
else
dbRefToClusterMember(
nonRepresentativeMembersdbRefs
.filter(dbRefIsSeed)
.head
)

def seedID: Option[String] =
if( (xml \ "representativeMember" \ "dbReference" \ "property") exists isSeed )
representativeID
def nonRepresentativeMembers: Seq[ClusterMember] =
nonRepresentativeMembersdbRefs map dbRefToClusterMember

private def dbRefToClusterMember(dbRef: Node): ClusterMember = {

val id = dbRef \ "@id" text

if(isUniProtDBReference(dbRef))
UniProtProtein(id)
else
nonRepresentativeMembers
.filter( member => (member \ "property") exists isSeed )
.headOption
.flatMap(accession)
UniParcProtein(id)
}

private def isUniProtDBReference(dbRef: Node): Boolean =
(dbRef \ "@type" text) == "UniProtKB ID"

private def isUniProtAccessionProperty(property: Node): Boolean =
(property \ "@type" text) == "UniProtKB accession"
private def isUniParcDBReference(dbRef: Node): Boolean =
(dbRef \ "@type" text) == "UniParc ID"

private def dbRefIsSeed(dbRef: Node): Boolean =
(dbRef \ "property") exists isSeed

private def isSeed(property: Node): Boolean =
(property \ "@type" text) == "isSeed"

private def nonRepresentativeMembers =
(xml \ "member" \ "dbReference") filter isUniProtDBReference
private def representativedbRef: Node =
xml \ "representativeMember" \ "dbReference" head

private def accession(dbRef: Node): Option[String] =
(dbRef \ "property").filter(isUniProtAccessionProperty).headOption.map(_.text)
private def nonRepresentativeMembersdbRefs =
(xml \ "member" \ "dbReference")
}

```
Expand Down
28 changes: 20 additions & 8 deletions docs/src/test/scala/ParseUniRef50.scala.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ class ParseUniRef50 extends FunSuite {

xml.entries.fromLines(lines) foreach { e =>

val ID = e.ID
val seedID = e.seedID
val representativeID = e.representativeID
val nonRepresentativeMemberIDs = e.nonRepresentativeMemberIDs
val id = e.ID

val seed = e.seed
val seedID = seed.id

val representative = e.representative
val representativeID = representative.id

val nonRepresentativeMembers = e.nonRepresentativeMembers
val nonRepresentativeMembersIDs = nonRepresentativeMembers map { _.id }
}
}

Expand All @@ -30,10 +36,16 @@ class ParseUniRef50 extends FunSuite {

xml.entries.fromLines(bigLines) foreach { e =>

val ID = e.ID
val seedID = e.seedID
val representativeID = e.representativeID
val nonRepresentativeMemberIDs = e.nonRepresentativeMemberIDs
val id = e.ID

val seed = e.seed
val seedID = seed.id

val representative = e.representative
val representativeID = representative.id

val nonRepresentativeMembers = e.nonRepresentativeMembers
val nonRepresentativeMembersIDs = nonRepresentativeMembers map { _.id }
}
}

Expand Down

0 comments on commit 8b77689

Please sign in to comment.