Skip to content

Commit

Permalink
2024/10/28-15:30:52 (Linux VDI0092.zit.bam.de x86_64)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbenner committed Oct 28, 2024
1 parent 8838a3e commit d797171
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/granges_bed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl GRanges {
Some(v) => v.clone(),
None => comp![ self.ranges[i].from as i64 for i in 0..self.num_rows() ]
};
let thick_end = match self.meta.get_column_int("thickStart") {
let thick_end = match self.meta.get_column_int("thickEnd") {
Some(v) => v.clone(),
None => comp![ self.ranges[i].to as i64 for i in 0..self.num_rows() ]
};
Expand Down Expand Up @@ -157,7 +157,7 @@ impl GRanges {
pub fn bufread_bed3<R: Read + BufRead>(&mut self, reader: &mut R) -> Result<(), Box<dyn Error>> {
let mut line = String::new();
while reader.read_line(&mut line)? > 0 {
let fields: Vec<&str> = line.trim().split('\t').collect();
let fields: Vec<&str> = line.split_whitespace().collect();
if fields.len() < 3 {
return Err(Box::new(io::Error::new(io::ErrorKind::InvalidInput, "Bed file must have at least 3 columns".to_string())));
}
Expand All @@ -177,7 +177,7 @@ impl GRanges {
let mut name = Vec::new();
let mut score = Vec::new();
while reader.read_line(&mut line)? > 0 {
let fields: Vec<&str> = line.trim().split('\t').collect();
let fields: Vec<&str> = line.split_whitespace().collect();
if fields.len() < 6 {
return Err(Box::new(io::Error::new(io::ErrorKind::InvalidInput, "Bed file must have at least 6 columns".to_string())));
}
Expand Down Expand Up @@ -205,7 +205,11 @@ impl GRanges {
let mut thick_end = Vec::new();
let mut item_rgb = Vec::new();
while reader.read_line(&mut line)? > 0 {
let fields: Vec<&str> = line.trim().split('\t').collect();
let fields: Vec<&str> = line.split_whitespace().collect();
if fields.len() > 0 && (fields[0] == "track" || fields[0] == "browser") {
line.clear();
continue;
}
if fields.len() < 9 {
return Err(Box::new(io::Error::new(io::ErrorKind::InvalidInput, "Bed file must have at least 9 columns".to_string())));
}
Expand All @@ -226,7 +230,7 @@ impl GRanges {
self.meta.add("score" , MetaData::IntArray (score))?;
self.meta.add("thickStart", MetaData::IntArray (thick_start))?;
self.meta.add("thickEnd" , MetaData::IntArray (thick_end ))?;
self.meta.add("item_rgb" , MetaData::StringArray(item_rgb ))?;
self.meta.add("itemRgb" , MetaData::StringArray(item_rgb ))?;
Ok(())
}

Expand Down
2 changes: 0 additions & 2 deletions src/granges_gtf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,6 @@ mod tests {
assert!(frame.is_none());
assert!(gene_id.is_some());

println!("{:?}", gene_id.unwrap());

assert_eq!(source.unwrap()[0], "transcribed_unprocessed_pseudogene");
assert_eq!(source.unwrap()[1], "processed_transcript");

Expand Down
46 changes: 40 additions & 6 deletions tests/test_granges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,47 @@ mod tests {

// Import given granges
assert!(
granges1.import_bed("tests/test_granges.bed", 3, false).is_ok());
granges1.import_bed("tests/test_granges_1.bed", 3, false).is_ok());

assert_eq!(
granges1.num_rows(), 20);

// Export to new file and import again
assert!(
granges1.export_bed3("tests/test_granges_1.bed.tmp", false).is_ok());
assert!(
granges2.import_bed3("tests/test_granges_1.bed.tmp", false).is_ok());
assert!(
granges1 == granges2);

// Modify granges and test for inequality
granges2.seqnames[2] = String::from("test");
assert!(
granges1 != granges2);

assert!(
remove_file("tests/test_granges_1.bed.tmp").is_ok());

}

#[test]
fn test_granges_bed9() {

let mut granges1 = GRanges::default();
let mut granges2 = GRanges::default();

// Import given granges
assert!(
granges1.import_bed("tests/test_granges_2.bed", 9, false).is_ok());

assert_eq!(
granges1.num_rows(), 9);

// Export to new file and import again
assert!(
granges1.export_bed3("tests/test_granges.bed.tmp", false).is_ok());
granges1.export_bed9("tests/test_granges_2.bed.tmp", false).is_ok());
assert!(
granges2.import_bed3("tests/test_granges.bed.tmp", false).is_ok());
granges2.import_bed9("tests/test_granges_2.bed.tmp", false).is_ok());
assert!(
granges1 == granges2);

Expand All @@ -54,7 +88,7 @@ mod tests {
granges1 != granges2);

assert!(
remove_file("tests/test_granges.bed.tmp").is_ok());
remove_file("tests/test_granges_2.bed.tmp").is_ok());

}

Expand All @@ -66,10 +100,10 @@ mod tests {

// Import given granges
assert!(
granges1.import_bed("tests/test_granges.bed", 3, false).is_ok()
granges1.import_bed("tests/test_granges_1.bed", 3, false).is_ok()
);
assert!(
granges2.import_bed("tests/test_granges.bed", 3, false).is_ok()
granges2.import_bed("tests/test_granges_1.bed", 3, false).is_ok()
);
granges1 = granges1.subset(&[0,1]);
granges2 = granges1.subset(&[0,1]);
Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions tests/test_granges_2.bed
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
browser position chr7:127471196-127495720
browser hide all
track name="ItemRGBDemo" description="Item RGB demonstration" visibility=2 itemRgb="On"
chr7 127471196 127472363 Pos1 0 + 127471196 127472363 255,0,0
chr7 127472363 127473530 Pos2 0 + 127472363 127473530 255,0,0
chr7 127473530 127474697 Pos3 0 + 127473530 127474697 255,0,0
chr7 127474697 127475864 Pos4 0 + 127474697 127475864 255,0,0
chr7 127475864 127477031 Neg1 0 - 127475864 127477031 0,0,255
chr7 127477031 127478198 Neg2 0 - 127477031 127478198 0,0,255
chr7 127478198 127479365 Neg3 0 - 127478198 127479365 0,0,255
chr7 127479365 127480532 Pos5 0 + 127479365 127480532 255,0,0
chr7 127480532 127481699 Neg4 0 - 127480532 127481699 0,0,255

0 comments on commit d797171

Please sign in to comment.