コード例 #1
0
 def test_cigar_complement(self):
     self.assertEqual(
         TestApiAlignment.cigar_gfa1_1_c_s,
         str(
             gfapy.Alignment(TestApiAlignment.cigar_gfa1_1_s,
                             version="gfa1").complement()))
     self.assertEqual(
         TestApiAlignment.cigar_gfa2_1_c_s,
         str(gfapy.Alignment(TestApiAlignment.cigar_gfa2_1_s).complement()))
コード例 #2
0
 def test_list_to_alignment(self):
     assert (isinstance(gfapy.Alignment([]), gfapy.AlignmentPlaceholder))
     self.assertEqual(TestUnitAlignment.cigar_1,
                      gfapy.Alignment(TestUnitAlignment.cigar_1_a))
     self.assertRaises(gfapy.VersionError,
                       gfapy.Alignment,
                       TestUnitAlignment.trace_1_a,
                       version="gfa1")
     self.assertEqual(
         TestUnitAlignment.trace_1,
         gfapy.Alignment(TestUnitAlignment.trace_1_a, version="gfa2"))
     self.assertRaises(gfapy.VersionError,
                       gfapy.Alignment,
                       TestUnitAlignment.cigar_1_a,
                       version="gfaX")
     self.assertRaises(gfapy.FormatError, gfapy.Alignment, ["x", 2, 1])
     # only the first element is checked, therefore:
     malformed1 = [1, 2, "x"]
     gfapy.Alignment(malformed1, version="gfa2")  # nothing raised
     assert (isinstance(gfapy.Alignment(malformed1, version="gfa2"),
                        gfapy.Trace))
     self.assertRaises(gfapy.TypeError,
                       gfapy.Alignment(malformed1, version="gfa2").validate)
     malformed2 = [gfapy.CIGAR.Operation(12, "M"), 2, "x"]
     gfapy.Alignment(malformed2)  # nothing raised
     assert (isinstance(gfapy.Alignment(malformed2), gfapy.CIGAR))
     self.assertRaises(gfapy.TypeError,
                       gfapy.Alignment(malformed2).validate)
コード例 #3
0
 def test_cigar_length_on(self):
     self.assertEqual(
         TestApiAlignment.cigar_gfa1_1_rlen,
         gfapy.Alignment(TestApiAlignment.cigar_gfa1_1_s,
                         version="gfa1").length_on_reference())
     self.assertEqual(
         TestApiAlignment.cigar_gfa1_1_qlen,
         gfapy.Alignment(TestApiAlignment.cigar_gfa1_1_s,
                         version="gfa1").length_on_query())
     self.assertEqual(
         TestApiAlignment.cigar_gfa1_1_qlen,
         gfapy.Alignment(TestApiAlignment.cigar_gfa1_1_c_s,
                         version="gfa1").length_on_reference())
     self.assertEqual(
         TestApiAlignment.cigar_gfa1_1_rlen,
         gfapy.Alignment(TestApiAlignment.cigar_gfa1_1_c_s,
                         version="gfa1").length_on_query())
     self.assertEqual(
         TestApiAlignment.cigar_gfa2_1_rlen,
         gfapy.Alignment(
             TestApiAlignment.cigar_gfa2_1_s).length_on_reference())
     self.assertEqual(
         TestApiAlignment.cigar_gfa2_1_qlen,
         gfapy.Alignment(TestApiAlignment.cigar_gfa2_1_s).length_on_query())
     self.assertEqual(
         TestApiAlignment.cigar_gfa2_1_qlen,
         gfapy.Alignment(
             TestApiAlignment.cigar_gfa2_1_c_s).length_on_reference())
     self.assertEqual(
         TestApiAlignment.cigar_gfa2_1_rlen,
         gfapy.Alignment(
             TestApiAlignment.cigar_gfa2_1_c_s).length_on_query())
コード例 #4
0
 def test_version_specific_validate(self):
     gfapy.Alignment(TestApiAlignment.cigar_gfa1_1_s,
                     version="gfa1",
                     valid=False)  # nothing raised
     self.assertRaises(gfapy.FormatError,
                       gfapy.Alignment,
                       TestApiAlignment.cigar_gfa1_1_s,
                       version="gfa2",
                       valid=False)
     gfapy.Alignment(TestApiAlignment.cigar_gfa2_1_s,
                     version="gfa1",
                     valid=False)  # nothing raised
     gfapy.Alignment(TestApiAlignment.cigar_gfa2_1_s,
                     version="gfa2",
                     valid=False)  # nothing raised
コード例 #5
0
 def test_to_alignment(self):
     self.assertEqual(TestApiAlignment.cigar_1,
                      gfapy.Alignment(TestApiAlignment.cigar_1_s))
     self.assertEqual(TestApiAlignment.trace_1,
                      gfapy.Alignment(TestApiAlignment.trace_1_s))
     self.assertEqual(TestApiAlignment.placeholder,
                      gfapy.Alignment(TestApiAlignment.placeholder_s))
     for alignment in [
             TestApiAlignment.cigar_1, TestApiAlignment.trace_1,
             TestApiAlignment.cigar_empty, TestApiAlignment.trace_empty,
             TestApiAlignment.placeholder
     ]:
         self.assertEqual(alignment, gfapy.Alignment(alignment))
     for string in TestApiAlignment.string_invalid:
         self.assertRaises(gfapy.FormatError, gfapy.Alignment, string)
コード例 #6
0
 def test_string_to_cigar(self):
     self.assertEqual(
         gfapy.CIGAR([
             gfapy.CIGAR.Operation(12, "M"),
             gfapy.CIGAR.Operation(1, "D"),
             gfapy.CIGAR.Operation(2, "I"),
         ]), gfapy.Alignment("12M1D2I"))
コード例 #7
0
ファイル: equivalence.py プロジェクト: sjackman/gfapy
  def is_compatible(self, other_oriented_from, other_oriented_to,
                    other_overlap = None, allow_complement = True):
    """
    Compares a link and optionally the complement link,
    with two oriented_segments and optionally an overlap.

    Parameters
    ----------
    other_oriented_from : gfapy.OrientedLine
    other_oriented_to : gfapy.OrientedLine
    allow_complement : bool
      Shall the complement link also be considered?
    other_overlap : gfapy.Alignment.CIGAR
      Compared only if not empty.

    Returns
    -------
    bool
      Does the link or, if **allow_complement**, the complement link go from
      the first, oriented segment to the second with an overlap equal to the
      provided one (if not empty)?
    """
    other_overlap = gfapy.Alignment(other_overlap, version = "gfa1",
        valid = True)
    if self.is_compatible_direct(other_oriented_from, other_oriented_to,
        other_overlap):
      return True
    elif allow_complement:
      return self.is_compatible_complement(other_oriented_from,
                                           other_oriented_to,
                                           other_overlap)
    else:
      return False
コード例 #8
0
 def test_cigar_clone(self):
     cigar1_clone = deepcopy(gfapy.Alignment(TestApiAlignment.cigar_1))
     self.assertEqual(TestApiAlignment.cigar_1_s, str(cigar1_clone))
     cigar1_clone[0].code = "="
     # copy is deep, only the clone has changed:
     self.assertNotEqual(TestApiAlignment.cigar_1_s, str(cigar1_clone))
     self.assertEqual(TestApiAlignment.cigar_1_s,
                      str(TestApiAlignment.cigar_1))
コード例 #9
0
ファイル: alignment_list_gfa1.py プロジェクト: ujjwalsh/gfapy
def unsafe_encode(obj):
    if isinstance(obj, gfapy.Placeholder):
        return str(obj)
    elif isinstance(obj, list):
        return ",".join([str(gfapy.Alignment(cig)) for cig in obj])
    else:
        raise gfapy.TypeError(
            "the class {} is incompatible with the datatype\n".format(
                obj.__class__.__name__) +
            "(accepted classes: list, AlignmentPlaceholder)")
コード例 #10
0
ファイル: alignment_list_gfa1.py プロジェクト: ujjwalsh/gfapy
def validate_decoded(obj):
    if isinstance(obj, gfapy.Placeholder):
        pass
    elif isinstance(obj, list):
        for e in obj:
            e = gfapy.Alignment(e, version="gfa1")
            e.validate()
    else:
        raise gfapy.TypeError(
            "the class {} is incompatible with the datatype\n".format(
                obj.__class__.__name__) +
            "(accepted classes: list, AlignmentPlaceholder)")
コード例 #11
0
 def test_list_to_cigar(self):
     self.assertEqual(
         gfapy.CIGAR([
             gfapy.CIGAR.Operation(12, "M"),
             gfapy.CIGAR.Operation(1, "D"),
             gfapy.CIGAR.Operation(2, "I")
         ]),
         gfapy.Alignment([
             gfapy.CIGAR.Operation(12, "M"),
             gfapy.CIGAR.Operation(1, "D"),
             gfapy.CIGAR.Operation(2, "I")
         ]))
コード例 #12
0
ファイル: alignment_list_gfa1.py プロジェクト: ujjwalsh/gfapy
def unsafe_decode(string):
    return [ gfapy.Alignment(s, version = "gfa1", valid = True) \
               for s in string.split(",") ]
コード例 #13
0
ファイル: alignment_list_gfa1.py プロジェクト: ujjwalsh/gfapy
 def f(cig):
     cig = gfapy.Alignment(cig)
     cig.validate()
     return str(cig)
コード例 #14
0
 def test_decode_encode_invariant(self):
     for string in [
             TestApiAlignment.trace_1_s, TestApiAlignment.cigar_1_s,
             TestApiAlignment.placeholder_s
     ]:
         self.assertEqual(string, str(gfapy.Alignment(string)))
コード例 #15
0
 def test_string_to_placeholder(self):
     self.assertIsInstance(gfapy.Alignment("*"), gfapy.Placeholder)
コード例 #16
0
ファイル: alignment_gfa2.py プロジェクト: ujjwalsh/gfapy
def decode(string):
    return gfapy.Alignment(string, valid=False, version="gfa2")
コード例 #17
0
ファイル: alignment_gfa2.py プロジェクト: ujjwalsh/gfapy
def unsafe_decode(string):
    return gfapy.Alignment(string, valid=True, version="gfa2")
コード例 #18
0
 def test_list_to_trace(self):
     self.assertEqual(gfapy.Trace([12, 14, 15]),
                      gfapy.Alignment([12, 14, 15]))
コード例 #19
0
 def test_string_to_trace(self):
     self.assertEqual(gfapy.Trace([12, 14, 15]),
                      gfapy.Alignment("12,14,15"))