Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements to SAM reading and processing #2280

Merged
merged 2 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ case class Attribute(tag: String, tagType: TagType.Value, value: Any) {
val byteSequenceTypes = Array(TagType.NumericByteSequence, TagType.NumericUnsignedByteSequence)
val intSequenceTypes = Array(TagType.NumericIntSequence, TagType.NumericUnsignedIntSequence)
val shortSequenceTypes = Array(TagType.NumericShortSequence, TagType.NumericUnsignedShortSequence)
val sb = new StringBuilder
sb.append(tag)
sb.append(":")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be all one line for code style purposes, but I don't mind either way

sb.append(tagType)
if (byteSequenceTypes contains tagType) {
"%s:%s,%s".format(tag, tagType, value.asInstanceOf[Array[Byte]].mkString(","))
sb.append(",").append(value.asInstanceOf[Array[Byte]].mkString(",")).toString()
} else if (shortSequenceTypes contains tagType) {
"%s:%s,%s".format(tag, tagType, value.asInstanceOf[Array[Short]].mkString(","))
sb.append(",").append(value.asInstanceOf[Array[Short]].mkString(",")).toString()
} else if (intSequenceTypes contains tagType) {
"%s:%s,%s".format(tag, tagType, value.asInstanceOf[Array[Int]].mkString(","))
sb.append(",").append(value.asInstanceOf[Array[Int]].mkString(",")).toString()
} else if (tagType == TagType.NumericFloatSequence) {
"%s:%s,%s".format(tag, tagType, value.asInstanceOf[Array[Float]].mkString(","))
sb.append(",").append(value.asInstanceOf[Array[Float]].mkString(",")).toString()
} else {
"%s:%s:%s".format(tag, tagType, value.toString)
sb.append(":").append(value).toString()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class SequenceDictionary(val records: Vector[SequenceRecord]) extends Serializab
* @return Returns a SAM formatted sequence dictionary.
*/
def toSAMSequenceDictionary: SAMSequenceDictionary = {
new SAMSequenceDictionary(records.iterator.map(_.toSAMSequenceRecord).toList)
new SAMSequenceDictionary(records.map(_.toSAMSequenceRecord).asJava)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch, did you have profiling results leading you here, or were you able to eyeball it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Profiler, of course!

}

/**
Expand Down Expand Up @@ -259,7 +259,7 @@ class SequenceDictionary(val records: Vector[SequenceRecord]) extends Serializab
}

override def toString: String = {
records.map(_.toString).fold("SequenceDictionary{")(_ + "\n" + _) + "}"
records.map(_.toString).mkString("SequenceDictionary{", "\n", "}")
}

private[adam] def toAvro: Seq[Reference] = {
Expand Down