Last active
November 23, 2022 13:06
-
-
Save epaule/4db714f20bafef2801b93d87546c9cf0 to your computer and use it in GitHub Desktop.
quick thing to parse two cobiont files
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
#!/bin/env crystal | |
# cobiont_stats.cr contamination_file1 contamination_file_2 | |
# returns a Array of String | |
def read_contamination_file(file : String) | |
ids = Array(String).new | |
File.each_line(file){|line| | |
ids << $1 if /REMOVE\s+(\S+)/.match(line) | |
} | |
return ids.uniq | |
end | |
file1=ARGV[0] | |
file2=ARGV[1] | |
x1 = read_contamination_file(file1) | |
x2 = read_contamination_file(file2) | |
# do intersection / x1 - x2 / x2 - x1 | |
puts "#{file1} & #{file2}: #{(x1 & x2 ).size}" | |
puts "#{file1} - #{file2}: #{(x1 - x2).size} #{x1-x2}" | |
puts "#{file2} - #{file1}: #{(x2 - x1).size} #{x2-x1}" |
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
#!/bin/env python | |
# cobiont_stats.py contamination_file1 contamination_file_2 | |
import sys | |
import re | |
# returns a set | |
def read_contamination_file(file): | |
ids = set() | |
for line in open(file,'r'): | |
if match := re.search('REMOVE\s+(\S+)',line): | |
ids.add(match.group(1)) | |
return ids | |
file1=sys.argv[1] | |
file2=sys.argv[2] | |
x1 = read_contamination_file(file1) | |
x2 = read_contamination_file(file2) | |
# do intersection / x1 - x2 / x2 - x1 | |
print(f"{file1} & {file2}: {len(x1.intersection(x2))}") | |
print(f"{file1} - {file2}: {len(x1.difference(x2))} {x1.difference(x2)}") | |
print(f"{file2} - {file1}: {len(x2.difference(x1))} {x2.difference(x1)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment